diff options
author | Rubén <RabsRincon@users.noreply.github.com> | 2017-12-19 17:19:47 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-19 17:19:47 +0100 |
commit | e4ef9cf303c6605b73d5a07dc4432353271de5b5 (patch) | |
tree | 3e9b1b3862023014f0062ca46329917bd7718446 /lib | |
parent | f1f5bafc4d5bf89ce4083de643b4c7055196a3aa (diff) | |
parent | 6e7e30bf4988958664a7c713053c4203dd6caf74 (diff) | |
download | compiler-explorer-e4ef9cf303c6605b73d5a07dc4432353271de5b5.tar.gz compiler-explorer-e4ef9cf303c6605b73d5a07dc4432353271de5b5.zip |
Merge branch 'master' into unification
Diffstat (limited to 'lib')
-rw-r--r-- | lib/asm.js | 18 | ||||
-rw-r--r-- | lib/base-compiler.js | 6 | ||||
-rw-r--r-- | lib/compilers/argument-parsers.js | 60 | ||||
-rw-r--r-- | lib/compilers/golang.js | 29 | ||||
-rw-r--r-- | lib/handlers/api.js | 3 | ||||
-rw-r--r-- | lib/utils.js | 3 |
6 files changed, 63 insertions, 56 deletions
diff --git a/lib/asm.js b/lib/asm.js index 6360a92aa..49d07b9df 100644 --- a/lib/asm.js +++ b/lib/asm.js @@ -160,23 +160,23 @@ function AsmParser(compilerProps) { var commentOnly = /^\s*(((#|@|\/\/).*)|(\/\*.*\*\/))$/; var sourceTag = /^\s*\.loc\s+(\d+)\s+(\d+).*/; var sourceStab = /^\s*\.stabn\s+(\d+),0,(\d+),.*/; - var stdInLooking = /.*<stdin>|^-$|example\.[^/]+$|<autogenerated>/; + const stdInLooking = /.*<stdin>|^-$|example\.[^/]+$|<source>/; var endBlock = /\.(cfi_endproc|data|text|section)/; - var source = null; + let source = null; asmLines.forEach(function (line) { - var match; + let match; if (line.trim() === "") { result.push({text: "", source: null}); return; } if (!!(match = line.match(sourceTag))) { - var file = files[parseInt(match[1])]; - var sourceLine = parseInt(match[2]); + const file = files[parseInt(match[1])]; + const sourceLine = parseInt(match[2]); if (file) { - if (file.match(stdInLooking)) - source = {'file': null, 'line': sourceLine}; - else - source = {'file': file, 'line': sourceLine}; + source = { + file: !file.match(stdInLooking) ? file : null, + line: sourceLine + }; } else { source = null; } diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 0119d04db..0bc9e65ec 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -313,7 +313,6 @@ Compile.prototype.compile = function (source, options, backendOptions, filters) asmResult.hasGccDumpOutput = true; asmResult.gccDumpOutput = gccDumpResult; } - return self.postProcess(asmResult, outputFilename, filters); }); }); @@ -659,10 +658,7 @@ Compile.prototype.initialise = function () { } logger.debug(compiler + " is version '" + version + "'"); this.compiler.version = version; - return argumentParser(this).then(function (compiler) { - delete compiler.compiler.supportedOptions; - return compiler; - }); + return argumentParser(this); }, this), _.bind(function (err) { logger.error("Unable to get version for compiler '" + compiler + "' - " + err); diff --git a/lib/compilers/argument-parsers.js b/lib/compilers/argument-parsers.js index 500d1e9b2..5022def1b 100644 --- a/lib/compilers/argument-parsers.js +++ b/lib/compilers/argument-parsers.js @@ -27,48 +27,60 @@ const _ = require('underscore-node'), utils = require('../utils'); const getOptions = function (compiler, helpArg) { - "use strict"; return compiler.exec(compiler.compiler.exe, [helpArg]) - .then(_.bind(function (result) { - let options = {}; + .then(result => { + const options = {}; if (result.code === 0) { - let optionFinder = /^\s+(--?[-a-zA-Z]+)/; + const optionFinder = /^\s*(--?[-a-zA-Z]+)/; - utils.eachLine(result.stdout + result.stderr, function (line) { - var match = line.match(optionFinder); + utils.eachLine(result.stdout + result.stderr, line => { + const match = line.match(optionFinder); if (!match) return; options[match[1]] = true; }); } - compiler.compiler.supportedOptions = options; - logger.debug("compiler options: ", compiler.compiler.supportedOptions); - return compiler; - })); + return options; + }); }; -const gccparser = function (compiler) { - return getOptions(compiler, "--target-help").then(function (compiler) { - compiler.compiler.supportsGccDump = true; - if (compiler.compiler.supportedOptions['-masm']) { - compiler.compiler.intelAsm = "-masm=intel"; - compiler.compiler.supportsIntel = true; - } - return compiler; - }); +const gccParser = function (compiler) { + return Promise.all([ + getOptions(compiler, "--target-help"), + 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(" ")); + if (options['-masm']) { + compiler.compiler.intelAsm = "-masm=intel"; + compiler.compiler.supportsIntel = true; + } + if (options['-fdiagnostics-color']) { + if (compiler.compiler.options) compiler.compiler.options += " "; + compiler.compiler.options += "-fdiagnostics-color=always"; + } + return compiler; + }); }; -const clangparser = function (compiler) { - return getOptions(compiler, "--help").then(function (compiler) { - if (compiler.compiler.supportedOptions['-fsave-optimization-record']) { +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; }); }; module.exports = { - clang: clangparser, - gcc: gccparser + getOptions: getOptions, + clang: clangParser, + gcc: gccParser };
\ No newline at end of file diff --git a/lib/compilers/golang.js b/lib/compilers/golang.js index b550ee0d6..776461d04 100644 --- a/lib/compilers/golang.js +++ b/lib/compilers/golang.js @@ -22,34 +22,33 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. -var Compile = require('../base-compiler'); -var _ = require('underscore-node'); +const Compile = require('../base-compiler'), + _ = require('underscore-node'); function compilenewgol(info, env, langId) { - var compiler = new Compile(info, env, langId); + const compiler = new Compile(info, env, langId); compiler.originalGetDefaultExecOptions = compiler.getDefaultExecOptions; function convertNewGoL(code) { - var re = /^\s+(0[xX]?[0-9A-Za-z]+)?\s?[0-9]+\s*\(([^:]+):([0-9]+)\)\s*([A-Z]+)(.*)/; - var prevLine = null; - var file = null; - var fileCount = 1; + const re = /^\s+(0[xX]?[0-9A-Za-z]+)?\s?[0-9]+\s*\(([^:]+):([0-9]+)\)\s*([A-Z]+)(.*)/; + let prevLine = null; + let file = null; + let fileCount = 0; return code.map(function (obj) { - var line = obj.text; - var match = line.match(re); + const line = obj.text; + const match = line.match(re); if (match) { - var res = ""; + let res = ""; if (file !== match[2]) { + fileCount++; res += "\t.file " + fileCount + ' "' + match[2] + '"\n'; file = match[2]; - fileCount++; } if (prevLine !== match[3]) { res += "\t.loc " + fileCount + " " + match[3] + " 0\n"; prevLine = match[3]; } - var ret = res + "\t" + match[4].toLowerCase() + match[5]; - return ret; + return res + "\t" + match[4].toLowerCase() + match[5]; } else return null; }).filter(_.identity).join("\n"); @@ -70,8 +69,8 @@ function compilenewgol(info, env, langId) { }; compiler.getDefaultExecOptions = function () { - var execOptions = this.originalGetDefaultExecOptions(); - var goroot = this.compilerProps("compiler." + this.compiler.id + ".goroot"); + const execOptions = this.originalGetDefaultExecOptions(); + const goroot = this.compilerProps("compiler." + this.compiler.id + ".goroot"); if (goroot) { execOptions.env.GOROOT = goroot; } diff --git a/lib/handlers/api.js b/lib/handlers/api.js index 7af9ee015..cd1c69078 100644 --- a/lib/handlers/api.js +++ b/lib/handlers/api.js @@ -30,7 +30,6 @@ const express = require('express'), class ApiHandler { constructor(compileHandler) { this.compilers = []; - this.compileHandler = compileHandler; this.handle = express.Router(); this.handle.use((req, res, next) => { res.header("Access-Control-Allow-Origin", "*"); @@ -56,7 +55,7 @@ class ApiHandler { req.compiler = compilerName; next(); }); - this.handle.post('/compiler/:compiler/compile', this.compileHandler.handler); + this.handle.post('/compiler/:compiler/compile', compileHandler.handler); } setCompilers(compilers) { diff --git a/lib/utils.js b/lib/utils.js index 8e4da75ee..422fc8a63 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -58,10 +58,11 @@ function parseOutput(lines, inputFilename) { const re = /^\s*<source>[:(]([0-9]+)(:([0-9]+):)?[):]*\s*(.*)/; const result = []; eachLine(lines, function (line) { + line = line.split('<stdin>').join('<source>'); if (inputFilename) line = line.split(inputFilename).join('<source>'); if (line !== "" && line.indexOf("fixme:") !== 0) { const lineObj = {text: line}; - const match = line.match(re); + const match = line.replace(/\x1b\[[\d;]*[mK]/g,'').match(re); if (match) { lineObj.tag = { line: parseInt(match[1]), |