aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/argument-parsers.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compilers/argument-parsers.js')
-rw-r--r--lib/compilers/argument-parsers.js65
1 files changed, 36 insertions, 29 deletions
diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js
index a0803a676..bf26271e5 100644
--- a/lib/compilers/argument-parsers.js
+++ b/lib/compilers/argument-parsers.js
@@ -26,9 +26,9 @@ const _ = require('underscore-node'),
logger = require('../logger').logger,
utils = require('../utils');
-const getOptions = function (compiler, helpArg) {
- return compiler.exec(compiler.compiler.exe, [helpArg])
- .then(result => {
+class BaseParser {
+ static getOptions(compiler, helpArg) {
+ return compiler.exec(compiler.compiler.exe, [helpArg]).then(result => {
const options = {};
if (result.code === 0) {
const optionFinder = /^\s*(--?[-a-zA-Z]+)/;
@@ -41,13 +41,18 @@ const getOptions = function (compiler, helpArg) {
}
return options;
});
-};
+ }
+ static parse(compiler) {
+ return compiler;
+ }
+}
-const gccParser = function (compiler) {
- return Promise.all([
- getOptions(compiler, "--target-help"),
- getOptions(compiler, "--help=common")])
- .then(results => {
+class GCCParser extends BaseParser {
+ static parse(compiler) {
+ return Promise.all([
+ GCCParser.getOptions(compiler, "--target-help"),
+ GCCParser.getOptions(compiler, "--help=common")
+ ]).then(results => {
const options = _.extend.apply(_.extend, results);
compiler.compiler.supportsGccDump = true;
logger.debug("gcc-like compiler options: ", _.keys(options).join(" "));
@@ -61,26 +66,28 @@ const gccParser = function (compiler) {
}
return compiler;
});
-};
-
-const clangParser = function (compiler) {
- return getOptions(compiler, "--help").then(options => {
- logger.debug("clang-like compiler options: ", _.keys(options).join(" "));
- if (options['-fsave-optimization-record']) {
- compiler.compiler.optArg = "-fsave-optimization-record";
- compiler.compiler.supportsOptOutput = true;
- }
- if (options['-fcolor-diagnostics']) {
- if (compiler.compiler.options) compiler.compiler.options += " ";
- compiler.compiler.options += "-fcolor-diagnostics";
- }
- return compiler;
- });
-};
+ }
+}
+class ClangParser extends BaseParser {
+ static parse(compiler) {
+ return ClangParser.getOptions(compiler, "--help").then(options => {
+ logger.debug("clang-like compiler options: ", _.keys(options).join(" "));
+ if (options['-fsave-optimization-record']) {
+ compiler.compiler.optArg = "-fsave-optimization-record";
+ compiler.compiler.supportsOptOutput = true;
+ }
+ if (options['-fcolor-diagnostics']) {
+ if (compiler.compiler.options) compiler.compiler.options += " ";
+ compiler.compiler.options += "-fcolor-diagnostics";
+ }
+ return compiler;
+ });
+ }
+}
module.exports = {
- getOptions: getOptions,
- clang: clangParser,
- gcc: gccParser
-}; \ No newline at end of file
+ Base: BaseParser,
+ Clang: ClangParser,
+ GCC: GCCParser
+};