aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/argument-parsers.js226
1 files changed, 104 insertions, 122 deletions
diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js
index abd967471..03ddc30c1 100644
--- a/lib/compilers/argument-parsers.js
+++ b/lib/compilers/argument-parsers.js
@@ -65,17 +65,13 @@ class BaseParser {
return options;
}
- static getOptions(compiler, helpArg) {
- return compiler.execCompilerCached(compiler.compiler.exe, [helpArg]).then(result => {
- let options = {};
- if (result.code === 0) {
- const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i;
-
- options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
- }
- compiler.possibleArguments.populateOptions(options);
- return options;
- });
+ static async getOptions(compiler, helpArg) {
+ const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i;
+ const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]);
+ const options = result.code === 0
+ ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {};
+ compiler.possibleArguments.populateOptions(options);
+ return options;
}
static parse(compiler) {
@@ -84,102 +80,93 @@ class BaseParser {
}
class GCCParser extends BaseParser {
- static parse(compiler) {
- return Promise.all([
+ static async parse(compiler) {
+ const results = await Promise.all([
GCCParser.getOptions(compiler, "--target-help"),
GCCParser.getOptions(compiler, "--help=common"),
GCCParser.getOptions(compiler, "--help=optimizers")
- ]).then(results => {
- const options = _.extend.apply(_.extend, results);
- const keys = _.keys(options);
- logger.debug(`gcc-like compiler options: ${keys.join(" ")}`);
- if (BaseParser.hasSupport(options, "-masm=")) {
- compiler.compiler.intelAsm = "-masm=intel";
- compiler.compiler.supportsIntel = true;
- }
- if (BaseParser.hasSupport(options, "-fdiagnostics-color")) {
- if (compiler.compiler.options) compiler.compiler.options += " ";
- compiler.compiler.options += "-fdiagnostics-color=always";
- }
- // This check is not infallible, but takes care of Rust and Swift being picked up :)
- if (_.find(keys, key => key.startsWith('-fdump-'))) {
- compiler.compiler.supportsGccDump = true;
- }
- return compiler;
- });
+ ]);
+ const options = Object.assign({}, ...results);
+ const keys = _.keys(options);
+ logger.debug(`gcc-like compiler options: ${keys.join(" ")}`);
+ if (BaseParser.hasSupport(options, "-masm=")) {
+ compiler.compiler.intelAsm = "-masm=intel";
+ compiler.compiler.supportsIntel = true;
+ }
+ if (BaseParser.hasSupport(options, "-fdiagnostics-color")) {
+ if (compiler.compiler.options) compiler.compiler.options += " ";
+ compiler.compiler.options += "-fdiagnostics-color=always";
+ }
+ // This check is not infallible, but takes care of Rust and Swift being picked up :)
+ if (_.find(keys, key => key.startsWith('-fdump-'))) {
+ compiler.compiler.supportsGccDump = true;
+ }
+ 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 (BaseParser.hasSupport(options, '-fsave-optimization-record')) {
- compiler.compiler.optArg = "-fsave-optimization-record";
- compiler.compiler.supportsOptOutput = true;
- }
- if (BaseParser.hasSupport(options, "-fcolor-diagnostics")) {
- if (compiler.compiler.options) compiler.compiler.options += " ";
- compiler.compiler.options += "-fcolor-diagnostics";
- }
- if (BaseParser.hasSupport(options, "-emit-llvm")) {
- compiler.compiler.supportsIrView = true;
- compiler.compiler.irArg = ['-Xclang', '-emit-llvm', '-fsyntax-only'];
- }
- if (BaseParser.hasSupport(options, "-fno-crash-diagnostics")) {
- if (compiler.compiler.options) compiler.compiler.options += " ";
- compiler.compiler.options += "-fno-crash-diagnostics";
- }
- return compiler;
- });
+ static async parse(compiler) {
+ const options = await ClangParser.getOptions(compiler, "--help");
+ logger.debug(`clang-like compiler options: ${_.keys(options).join(" ")}`);
+ if (BaseParser.hasSupport(options, '-fsave-optimization-record')) {
+ compiler.compiler.optArg = "-fsave-optimization-record";
+ compiler.compiler.supportsOptOutput = true;
+ }
+ if (BaseParser.hasSupport(options, "-fcolor-diagnostics")) {
+ if (compiler.compiler.options) compiler.compiler.options += " ";
+ compiler.compiler.options += "-fcolor-diagnostics";
+ }
+ if (BaseParser.hasSupport(options, "-emit-llvm")) {
+ compiler.compiler.supportsIrView = true;
+ compiler.compiler.irArg = ['-Xclang', '-emit-llvm', '-fsyntax-only'];
+ }
+ if (BaseParser.hasSupport(options, "-fno-crash-diagnostics")) {
+ if (compiler.compiler.options) compiler.compiler.options += " ";
+ compiler.compiler.options += "-fno-crash-diagnostics";
+ }
+ return compiler;
}
}
class PascalParser extends BaseParser {
- static parse(compiler) {
- return PascalParser.getOptions(compiler, "-help").then(() => compiler);
+ static async parse(compiler) {
+ await PascalParser.getOptions(compiler, "-help");
+ return compiler;
}
}
class ISPCParser extends BaseParser {
- static parse(compiler) {
- return ISPCParser.getOptions(compiler, "--help").then(options => {
- if (BaseParser.hasSupport(options, "--x86-asm-syntax")) {
- compiler.compiler.intelAsm = "--x86-asm-syntax=intel";
- compiler.compiler.supportsIntel = true;
- }
- return compiler;
- });
+ static async parse(compiler) {
+ const options = await ISPCParser.getOptions(compiler, "--help");
+ if (BaseParser.hasSupport(options, "--x86-asm-syntax")) {
+ compiler.compiler.intelAsm = "--x86-asm-syntax=intel";
+ compiler.compiler.supportsIntel = true;
+ }
+ return compiler;
}
- static getOptions(compiler, helpArg) {
- return compiler.execCompilerCached(compiler.compiler.exe, [helpArg]).then(result => {
- let options = {};
- if (result.code === 0) {
- const optionFinder = /^\s*\[(--?[a-z0-9=+,{}()\s<>/|-]*)\]\s*(.*)/i;
-
- options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
- }
- compiler.possibleArguments.populateOptions(options);
- return options;
- });
+ static async getOptions(compiler, helpArg) {
+ const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]);
+ const optionFinder = /^\s*\[(--?[a-z0-9=+,{}()\s<>/|-]*)\]\s*(.*)/i;
+ const options = result.code === 0
+ ? BaseParser.parseLines(result.stdout + result.stderr, optionFinder) : {};
+ compiler.possibleArguments.populateOptions(options);
+ return options;
}
}
class JavaParser extends BaseParser {
-
- static parse(compiler) {
- return JavaParser.getOptions(compiler, "-help").then(() => compiler);
+ static async parse(compiler) {
+ await JavaParser.getOptions(compiler, "-help");
+ return compiler;
}
}
class VCParser extends BaseParser {
- static parse(compiler) {
- return Promise.all([
- VCParser.getOptions(compiler, "/help")
- ]).then(() => {
- return compiler;
- });
+ static async parse(compiler) {
+ await VCParser.getOptions(compiler, "/help");
+ return compiler;
}
static parseLines(stdout, optionRegex) {
@@ -214,7 +201,7 @@ class VCParser extends BaseParser {
};
}
};
-
+
utils.eachLine(stdout, line => {
if (line.length === 0) return;
if (line.includes("C/C++ COMPILER OPTIONS")) return;
@@ -237,60 +224,55 @@ class VCParser extends BaseParser {
return options;
}
- static getOptions(compiler, helpArg) {
- return compiler.execCompilerCached(compiler.compiler.exe, [helpArg]).then(result => {
- let options = {};
- if (result.code === 0) {
- const optionFinder = /^\s*(\/[a-z0-9=:+#.,[\]{}<>|_-]*)\s*(.*)/i;
-
- options = this.parseLines(result.stdout, optionFinder);
- }
- compiler.possibleArguments.populateOptions(options);
- return options;
- });
+ static async getOptions(compiler, helpArg) {
+ const result = await compiler.execCompilerCached(compiler.compiler.exe, [helpArg]);
+ const optionFinder = /^\s*(\/[a-z0-9=:+#.,[\]{}<>|_-]*)\s*(.*)/i;
+ const options = result.code === 0
+ ? this.parseLines(result.stdout, optionFinder) : {};
+ compiler.possibleArguments.populateOptions(options);
+ return options;
}
}
+
class RustParser extends BaseParser {
- static parse(compiler) {
- return Promise.all([
+ static async parse(compiler) {
+ const results = await Promise.all([
RustParser.getOptions(compiler, "--help"),
RustParser.getOptions(compiler, "-C help"),
RustParser.getOptions(compiler, "--help -v")
- ]).then(results => {
- const options = _.extend.apply(_.extend, results);
- if (BaseParser.hasSupport(options, "--color")) {
- if (compiler.compiler.options) compiler.compiler.options += " ";
- compiler.compiler.options += "--color=always";
- }
- return compiler;
- });
+ ]);
+ const options = Object.assign({}, ...results);
+ if (BaseParser.hasSupport(options, "--color")) {
+ if (compiler.compiler.options) compiler.compiler.options += " ";
+ compiler.compiler.options += "--color=always";
+ }
+ return compiler;
}
- static getOptions(compiler, helpArg) {
- return compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' ')).then(result => {
- let options = {};
- if (result.code === 0) {
- if (helpArg === "-C help") {
- const optionFinder = /^\s*(-C\s*[a-z0-9=-]*)\s--\s(.*)/i;
+ static async getOptions(compiler, helpArg) {
+ const result = await compiler.execCompilerCached(compiler.compiler.exe, helpArg.split(' '));
+ let options = {};
+ if (result.code === 0) {
+ if (helpArg === "-C help") {
+ const optionFinder = /^\s*(-C\s*[a-z0-9=-]*)\s--\s(.*)/i;
- options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
- } else {
- const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i;
+ options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
+ } else {
+ const optionFinder = /^\s*(--?[a-z0-9=+,[\]<>|-]*)\s*(.*)/i;
- options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
- }
+ options = BaseParser.parseLines(result.stdout + result.stderr, optionFinder);
}
- compiler.possibleArguments.populateOptions(options);
- return options;
- });
+ }
+ compiler.possibleArguments.populateOptions(options);
+ return options;
}
}
class NimParser extends BaseParser {
-
- static parse(compiler) {
- return NimParser.getOptions(compiler, "-help").then(() => compiler);
+ static async parse(compiler) {
+ await NimParser.getOptions(compiler, "-help");
+ return compiler;
}
}
@@ -303,5 +285,5 @@ module.exports = {
Pascal: PascalParser,
ISPC: ISPCParser,
Rust: RustParser,
- Nim: NimParser,
+ Nim: NimParser
};