diff --git a/docs/AddingATool.md b/docs/AddingATool.md new file mode 100644 index 000000000..100d20ba3 --- /dev/null +++ b/docs/AddingATool.md @@ -0,0 +1,97 @@ +# Adding a new tool + +Tools are a way to execute something on your code or the output of a compilation. + +Adding tools requires adding configuration to a properties file for a specific language: + +```yaml +tools=rewritecpp + +tools.rewritecpp.name=rewritecpp +tools.rewritecpp.exe=/opt/compiler-explorer/rewritertool/bin/rewritecpp +tools.rewritecpp.type=independent +tools.rewritecpp.exclude= +tools.rewritecpp.class=base-tool +tools.rewritecpp.stdinHint=disabled +tools.rewritecpp.languageId=cppp +``` + +The `name` and `exe` are what they say they are, this is the display name for within CE and the tool executable that will be used. + +The `type` of the tool represents the stage in which the tool will run: +* independent - when running a tool on sourcecode +* postcompilation - when running a tool on the assembly or a binary + +The `exclude` property is to indicate which compilers are proven to be incompatible with the tool. +You can supply the full id of the compiler or a partial id (for example 'arm' to exclude all arm compilers). + +The `class` of the tool says which javascript class is needed to run the tool and process its output. The folder _lib/tooling_ is used for these classes. + +Should you want to deviate from the standard behaviour of `base-tool`, which runs the tool on the sourcecode filename, +you should add a new class that extends from `base-tool`. + +The `stdinHint` is there to show the user a hint as to what the stdin field is used for in the tool. To disable stdin you can use _disabled_ here. + +The `languageId` can be used to highlight the output of the tool according to a language known within CE. For example `cppp` will highlight c++ output. Leaving `languageId` empty will use the terminal-like output. + +# compilationInfo + +When writing a special class for a tool, you will probably need the `compilationInfo` parameter to pass the correct parameters to the tool. + +The contents of `compilationInfo` varies slightly between the different `type`s of tools. + +## compilationInfo for independent tools + +```json +{ + "backendOptions": {"produceGccDump": {}, "produceCfg": false}, + "compiler": {"id": "clang_trunk", "exe": "clang++", ...}, + "filters": {"binary": false, "commentOnly": true, "demangle": true, ... }, + "inputFilename": "/tmp/ce-tmp/example.cpp", + "dirPath": "/tmp/ce-tmp", + "libraries": [{"id": "ctre", "version": "v2"}], + "options": ["-O3"], + "source": "int main() {\nreturn 1;\n}\n" +} +``` + +The `filters` can be used to assert boundary conditions or adjust the tooling process based on the filters the user checked on or off. + +The `inputFilename` contains the path to the sourcecode stored on disk. The `source` contains the sourcecode as text. + +The `dirPath` can be used to write extra files to disk which the tool might need. + +The `options` are the arguments the user gave for the compilation. + + +## compilationInfo for postcompilation tools + +```json +{ + ... everything from the compilationInfo for independent tools + "compilationOptions": ["-O3", "-S", "/tmp/ce-tmp/example.cpp", ...], + "code": 0, + "asm": [ + {"text": "main:", "source": null}, + {"text": " mov eax, 1", "source": {"file": null, "line": 2}} + {"text": " ret", "source": {"file": null, "line": 3}} + ], + "asmSize": 123, + "stderr": [ + {"text": "warning: 'x' is used uninitialized in this function [-Wuninitialized]", "tag": {"line": 4, "column": 16}} + ], + "stdout": [], + "outputFilename": "/tmp/ce-tmp/example.o", + "executableFilename": "/tmp/ce-tmp/a.out" +} +``` + +`code` indicates the exitcode of the compilation. Usually, 0 means everything's ok. + +`asm` contains the returned assembly. This is the same assembly that is shown within compiler-explorer, including extra information like for which sourcecode line the assembly was generated. + +`stderr` and `stdout` contain the different outputs from the compilation process. + +The `outputFilename` is always filled, but not guaranteed to exist, for example when the compilation has failed. + +The `executableFilename` is always filled, but does not guarantee the existance of an executable. diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 43759531b..3530710b2 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -942,7 +942,7 @@ libs.pegtl.versions.280.path=/opt/compiler-explorer/libs/PEGTL/2.8.0/include ################################# # Installed tools -tools=clangtidytrunk:llvm-mcatrunk:pahole +tools=clangtidytrunk:llvm-mcatrunk:pahole:clangquerytrunk:readelf:x86to6502 tools.clangtidytrunk.exe=/opt/compiler-explorer/clang-trunk/bin/clang-tidy tools.clangtidytrunk.name=clang-tidy @@ -950,15 +950,40 @@ tools.clangtidytrunk.type=independent tools.clangtidytrunk.class=clang-tidy-tool tools.clangtidytrunk.exclude=cl19:cl_new tools.clangtidytrunk.options=--gcc-toolchain=/opt/compiler-explorer/gcc-8.2.0 +tools.clangtidytrunk.stdinHint=disabled tools.llvm-mcatrunk.name=llvm-mca tools.llvm-mcatrunk.exe=/opt/compiler-explorer/clang-trunk/bin/llvm-mca tools.llvm-mcatrunk.type=postcompilation tools.llvm-mcatrunk.class=llvm-mca-tool tools.llvm-mcatrunk.exclude=avr:rv32:arm:aarch:mips:msp:ppc:cl19:cl_new:djggp +tools.llvm-mcatrunk.stdinHint=disabled tools.pahole.name=pahole tools.pahole.exe=/opt/compiler-explorer/pahole/bin/pahole tools.pahole.type=postcompilation tools.pahole.class=pahole-tool tools.pahole.exclude=djggp +tools.pahole.stdinHint=disabled +tools.pahole.languageId=cppp + +tools.readelf.name=readelf +tools.readelf.exe=/opt/compiler-explorer/gcc-snapshot/bin/readelf +tools.readelf.type=postcompilation +tools.readelf.class=readelf-tool +tools.readelf.exclude=djggp +tools.readelf.stdinHint=disabled + +tools.clangquerytrunk.exe=/opt/compiler-explorer/clang-trunk/bin/clang-query +tools.clangquerytrunk.name=clang-query +tools.clangquerytrunk.type=independent +tools.clangquerytrunk.class=clang-query-tool +tools.clangquerytrunk.stdinHint=Query commands + +tools.x86to6502.exe=/opt/compiler-explorer/x86-to-6502/lefticus/x86-to-6502 +tools.x86to6502.name=x86-to-6502 +tools.x86to6502.type=postcompilation +tools.x86to6502.class=x86to6502-tool +tools.x86to6502.exclude=avr:rv32:arm:aarch:mips:msp:ppc:cl19:cl_new:djggp:riscv:wasm:frc2019:raspbian:arduino +tools.x86to6502.stdinHint=disabled +tools.x86to6502.languageId=asm diff --git a/etc/config/c.amazon.properties b/etc/config/c.amazon.properties index ca3eaa306..c174ca660 100644 --- a/etc/config/c.amazon.properties +++ b/etc/config/c.amazon.properties @@ -417,10 +417,18 @@ compiler.cc65_217.semver=2.17 ################################# # Installed tools -tools=llvm-mcatrunk +tools=llvm-mcatrunk:pahole tools.llvm-mcatrunk.name=llvm-mca tools.llvm-mcatrunk.exe=/opt/compiler-explorer/clang-trunk/bin/llvm-mca tools.llvm-mcatrunk.type=postcompilation tools.llvm-mcatrunk.class=llvm-mca-tool tools.llvm-mcatrunk.exclude=cavr:carm:caarch:cmips:cmsp:cppc:ppci + +tools.pahole.name=pahole +tools.pahole.exe=/opt/compiler-explorer/pahole/bin/pahole +tools.pahole.type=postcompilation +tools.pahole.class=pahole-tool +tools.pahole.exclude= +tools.pahole.stdinHint=disabled +tools.pahole.languageId=cppp diff --git a/etc/config/pascal.amazon.properties b/etc/config/pascal.amazon.properties index 3cc812368..e69a74511 100644 --- a/etc/config/pascal.amazon.properties +++ b/etc/config/pascal.amazon.properties @@ -27,9 +27,15 @@ libs= ################################# # Installed tools -tools=llvm-mcatrunk +tools=llvm-mcatrunk:pahole tools.llvm-mcatrunk.name=llvm-mca tools.llvm-mcatrunk.exe=/opt/compiler-explorer/clang-trunk/bin/llvm-mca tools.llvm-mcatrunk.type=postcompilation tools.llvm-mcatrunk.class=llvm-mca-tool + +tools.pahole.name=pahole +tools.pahole.exe=/opt/compiler-explorer/pahole/bin/pahole +tools.pahole.type=postcompilation +tools.pahole.class=pahole-tool +tools.pahole.languageId=cppp diff --git a/lib/base-compiler.js b/lib/base-compiler.js index e57a2192f..bab04f203 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -321,7 +321,7 @@ class BaseCompiler { .then(() => this.postProcess(asmResult, outputFilename, filters)); } - runToolsOfType(sourcefile, tools, type, compilerExe, outputFilename, options, filters, asm) { + runToolsOfType(tools, type, compilationInfo) { let tooling = []; if (tools) { tools.forEach((tool) => { @@ -331,8 +331,8 @@ class BaseCompiler { }); if (matches[0]) { - const toolPromise = matches[0].runTool(sourcefile, tool.args, - compilerExe, outputFilename, options, filters, asm); + const toolPromise = matches[0].runTool(compilationInfo, + compilationInfo.inputFilename, tool.args, tool.stdin); tooling.push(toolPromise); } }); @@ -432,6 +432,14 @@ class BaseCompiler { return {compiler: this.compiler, source, options, backendOptions, filters, tools, libraries}; } + getCompilationInfo(key, result) { + const compilationinfo = Object.assign({}, key, result); + compilationinfo.outputFilename = this.getOutputFilename(result.dirPath, this.outputFilebase); + compilationinfo.executableFilename = this.getExecutableFilename(result.dirPath, this.outputFilebase); + + return compilationinfo; + } + compile(source, options, backendOptions, filters, bypassCache, tools, executionParameters, libraries) { const optionsError = this.checkOptions(options); if (optionsError) return Promise.reject(optionsError); @@ -494,9 +502,8 @@ class BaseCompiler { inputFilename, outputFilename, libraries) ); - const toolsPromise = this.runToolsOfType( - inputFilename, tools, "independent", - this.compiler.exe, outputFilename, options, filters); + const toolsPromise = this.runToolsOfType(tools, "independent", + this.getCompilationInfo(key, {inputFilename, dirPath, outputFilename})); const execOptions = this.getDefaultExecOptions(); @@ -596,11 +603,8 @@ class BaseCompiler { return result; }) .then(result => { - const outputFilename = this.getOutputFilename(result.dirPath, this.outputFilebase); - - const postToolsPromise = this.runToolsOfType( - result.inputFilename, tools, "postcompilation", - this.compiler.exe, outputFilename, options, filters, result.asm); + const postToolsPromise = this.runToolsOfType(tools, "postcompilation", + this.getCompilationInfo(key, result)); return Promise.all([Promise.all(postToolsPromise)]).then(([postToolsResult]) => { result.tools = _.union(result.tools, postToolsResult); @@ -698,7 +702,7 @@ class BaseCompiler { } couldSupportASTDump(version) { - const versionRegex = /version (\d.\d+)/; + const versionRegex = /version (\d+.\d+)/; const versionMatch = versionRegex.exec(version); if (versionMatch) { diff --git a/lib/compiler-finder.js b/lib/compiler-finder.js index 6f92d8290..beb7a9c41 100644 --- a/lib/compiler-finder.js +++ b/lib/compiler-finder.js @@ -26,6 +26,7 @@ const logger = require('./logger').logger, _ = require('underscore'), fs = require('fs-extra'), path = require('path'), + urljoin = require('url-join'), http = require('http'), https = require('https'), aws = require('./aws'); @@ -56,14 +57,11 @@ class CompilerFinder { return this.awsPoller.getInstances(); } - fetchRemote(host, port, props, langId) { + fetchRemote(host, port, uriBase, props, langId) { const requestLib = port === 443 ? https : http; const uriSchema = port === 443 ? "https" : "http"; - const uri = `${uriSchema}://${host}:${port}`; - let apiPath = '/api/compilers'; - if (langId !== null) { - apiPath += `/${langId}`; - } + const uri = urljoin(`${uriSchema}://${host}:${port}`, uriBase); + let apiPath = urljoin('/', uriBase || '', 'api/compilers', langId || ''); logger.info(`Fetching compilers from remote source ${uri}`); return this.retryPromise( () => { @@ -102,7 +100,10 @@ class CompilerFinder { try { const compilers = JSON.parse(str).map(compiler => { compiler.exe = null; - compiler.remote = `${uriSchema}://${host}:${port}`; + compiler.remote = { + target: `${uriSchema}://${host}:${port}`, + path: urljoin('/', uriBase, 'api/compiler', compiler.id, 'compile') + }; return compiler; }); resolve(compilers); @@ -135,7 +136,7 @@ class CompilerFinder { if (this.awsProps("externalTestMode", false)) { address = instance.PublicDnsName; } - return this.fetchRemote(address, this.args.port, this.awsProps, null); + return this.fetchRemote(address, this.args.port, '', this.awsProps, null); })); }); } @@ -221,8 +222,10 @@ class CompilerFinder { if (this.args.fetchCompilersFromRemote && compilerName.indexOf("@") !== -1) { const bits = compilerName.split("@"); const host = bits[0]; - const port = parseInt(bits[1]); - return this.fetchRemote(host, port, this.ceProps, langId); + const pathParts = bits[1].split('/'); + const port = parseInt(pathParts.shift()); + const path = pathParts.join('/'); + return this.fetchRemote(host, port, path, this.ceProps, langId); } if (compilerName.indexOf("&") === 0) { const groupName = compilerName.substr(1); diff --git a/lib/exec.js b/lib/exec.js index 0d463a7fd..c3317f99f 100644 --- a/lib/exec.js +++ b/lib/exec.js @@ -134,8 +134,10 @@ function executeDirect(command, args, options, filenameTransform) { logger.debug("Execution", {type: "executed", command: command, args: args, result: result}); resolve(result); }); - if (options.input) child.stdin.write(options.input); - child.stdin.end(); + if (child.stdin) { + if (options.input) child.stdin.write(options.input); + child.stdin.end(); + } }); } diff --git a/lib/handlers/compile.js b/lib/handlers/compile.js index 17082eb22..c09167aed 100644 --- a/lib/handlers/compile.js +++ b/lib/handlers/compile.js @@ -260,9 +260,8 @@ class CompileHandler { bypassCache, tools, executionParameters, libraries} = this.parseRequest(req, compiler); const remote = compiler.getRemote(); if (remote) { - // Undo any routing that was done to get here (i.e. /api/* path has been removed) - req.url = req.originalUrl; - this.proxy.web(req, res, {target: remote, changeOrigin: true}, e => { + req.url = remote.path; + this.proxy.web(req, res, {target: remote.target, changeOrigin: true}, e => { logger.error("Proxy error: ", e); next(e); }); diff --git a/lib/options-handler.js b/lib/options-handler.js index 8535f80bb..96fd91327 100644 --- a/lib/options-handler.js +++ b/lib/options-handler.js @@ -135,7 +135,9 @@ class ClientOptionsHandler { type: this.compilerProps(lang, toolBaseName + '.type'), exe: this.compilerProps(lang, toolBaseName + '.exe'), exclude: this.compilerProps(lang, toolBaseName + '.exclude'), - options: this.compilerProps(lang, toolBaseName + '.options') + options: this.compilerProps(lang, toolBaseName + '.options'), + languageId: this.compilerProps(lang, toolBaseName + '.languageId'), + stdinHint: this.compilerProps(lang, toolBaseName + '.stdinHint') }, { ceProps: this.ceProps, diff --git a/lib/tooling/base-tool.js b/lib/tooling/base-tool.js index a42016160..60965bf3d 100644 --- a/lib/tooling/base-tool.js +++ b/lib/tooling/base-tool.js @@ -26,6 +26,7 @@ const exec = require('../exec'), utils = require('../utils'), + logger = require('../logger').logger, path = require('path'); class BaseTool { @@ -64,17 +65,19 @@ class BaseTool { id: this.tool.id, name: this.tool.name, code: -1, + languageId: "stderr", stdout: utils.parseOutput(message) }; } - runTool(sourcefile, args) { + runTool(compilationInfo, inputFilepath, args, stdin) { let execOptions = this.getDefaultExecOptions(); - execOptions.customCwd = path.dirname(sourcefile); + if (inputFilepath) execOptions.customCwd = path.dirname(inputFilepath); + execOptions.input = stdin; args = args ? args : []; args = args.filter((arg) => !arg.includes('/')); - args.push(sourcefile); + if (inputFilepath) args.push(inputFilepath); const exeDir = path.dirname(this.tool.exe); @@ -83,10 +86,12 @@ class BaseTool { id: this.tool.id, name: this.tool.name, code: result.code, - stderr: utils.parseOutput(result.stderr, sourcefile, exeDir), - stdout: utils.parseOutput(result.stdout, sourcefile, exeDir) + languageId: this.tool.languageId, + stderr: utils.parseOutput(result.stderr, inputFilepath, exeDir), + stdout: utils.parseOutput(result.stdout, inputFilepath, exeDir) }; - }).catch(() => { + }).catch((e) => { + logger.error("Error while running tool: ", e); return this.createErrorResponse("Error while running tool"); }); } diff --git a/lib/tooling/clang-query-tool.js b/lib/tooling/clang-query-tool.js new file mode 100644 index 000000000..34952c69e --- /dev/null +++ b/lib/tooling/clang-query-tool.js @@ -0,0 +1,59 @@ +// Copyright (c) 2018, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +"use strict"; + +const + fs = require('fs-extra'), + path = require('path'), + BaseTool = require('./base-tool'); + +class ClangQueryTool extends BaseTool { + constructor(toolInfo, env) { + super(toolInfo, env); + } + + async runTool(compilationInfo, inputFilepath, args, stdin) { + const sourcefile = inputFilepath; + const compilerExe = compilationInfo.compiler.exe; + const options = compilationInfo.options; + const dir = path.dirname(sourcefile); + + const compileFlags = options.filter(option => (option !== sourcefile)); + if (!compilerExe.includes("clang++")) { + compileFlags.push(this.tool.options); + } + + await fs.writeFile(path.join(dir, "compile_flags.txt"), compileFlags.join('\n')); + const toolResult = await super.runTool(compilationInfo, sourcefile, args, stdin); + + if (toolResult.stdout.length > 0) { + const lastLine = toolResult.stdout.length - 1; + toolResult.stdout[lastLine].text = toolResult.stdout[lastLine].text.replace(/(clang-query>\s)/gi, ""); + } + + return toolResult; + } +} + +module.exports = ClangQueryTool; diff --git a/lib/tooling/clang-tidy-tool.js b/lib/tooling/clang-tidy-tool.js index 4c35cc77d..56e8ab5f3 100644 --- a/lib/tooling/clang-tidy-tool.js +++ b/lib/tooling/clang-tidy-tool.js @@ -33,7 +33,10 @@ class ClangTidyTool extends BaseTool { super(toolInfo, env); } - runTool(sourcefile, args, compilerExe, outputFilename, options) { + runTool(compilationInfo, inputFilepath, args) { + const sourcefile = inputFilepath; + const compilerExe = compilationInfo.compiler.exe; + const options = compilationInfo.options; const dir = path.dirname(sourcefile); let source; @@ -53,7 +56,7 @@ class ClangTidyTool extends BaseTool { return fs.writeFile( path.join(dir, "compile_flags.txt"), compileFlags.join("\n") - ).then(() => super.runTool(sourcefile, args) + ).then(() => super.runTool(compilationInfo, sourcefile, args) ).then((result) => { result.sourcechanged = false; diff --git a/lib/tooling/llvm-mca-tool.js b/lib/tooling/llvm-mca-tool.js index 7cd9fd34a..45eff5d7e 100644 --- a/lib/tooling/llvm-mca-tool.js +++ b/lib/tooling/llvm-mca-tool.js @@ -43,22 +43,22 @@ class LLVMMcaTool extends BaseTool { return fs.writeFile(destination, this.rewriteAsm(data)); } - runTool(sourcefile, args, compilerExe, outputFilename, options, filters, asm) { + runTool(compilationInfo, inputFilepath, args) { let extraargs = []; - if (filters.intel) { + if (compilationInfo.filters.intel) { extraargs.push("--x86-asm-syntax=intel"); extraargs.push("-output-asm-variant=1"); } - if (filters.binary) { + if (compilationInfo.filters.binary) { return new Promise((resolve) => { resolve(this.createErrorResponse("")); }); } - const rewrittenOutputFilename = outputFilename + ".mca"; - return this.writeAsmFile(asm, rewrittenOutputFilename).then(() => { - return super.runTool(rewrittenOutputFilename, args); + const rewrittenOutputFilename = compilationInfo.outputFilename + ".mca"; + return this.writeAsmFile(compilationInfo.asm, rewrittenOutputFilename).then(() => { + return super.runTool(compilationInfo, rewrittenOutputFilename, args); }); } } diff --git a/lib/tooling/pahole-tool.js b/lib/tooling/pahole-tool.js index 6818227ef..a4db61dc8 100644 --- a/lib/tooling/pahole-tool.js +++ b/lib/tooling/pahole-tool.js @@ -24,7 +24,7 @@ "use strict"; const - utils = require('../utils'), + fs = require('fs-extra'), BaseTool = require('./base-tool'); class PaholeTool extends BaseTool { @@ -32,17 +32,17 @@ class PaholeTool extends BaseTool { super(toolInfo, env); } - runTool(sourcefile, args, compilerExe, outputFilename, option, filters) { - if(!filters.binary) + runTool(compilationInfo, inputFilepath, args) { + if(!compilationInfo.filters.binary) { - return { - id: this.tool.id, - name: this.tool.name, - code: 0, - stdout: utils.parseOutput("Pahole requires a binary output") - }; + return this.createErrorResponse("Pahole requires a binary output"); } - return super.runTool(outputFilename, args); + + return fs.stat(compilationInfo.executableFilename).then(() => { + return super.runTool(compilationInfo, compilationInfo.executableFilename, args); + }).catch(() => { + return super.runTool(compilationInfo, compilationInfo.outputFilename, args); + }); } } diff --git a/lib/tooling/readelf-tool.js b/lib/tooling/readelf-tool.js new file mode 100644 index 000000000..15db1b5eb --- /dev/null +++ b/lib/tooling/readelf-tool.js @@ -0,0 +1,43 @@ +// Copyright (c) 2019, Compiler Explorer Authors +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +"use strict"; + +const + BaseTool = require('./base-tool'); + +class ReadElfTool extends BaseTool { + constructor(toolInfo, env) { + super(toolInfo, env); + } + + runTool(compilationInfo, inputFilename, args) { + if(!compilationInfo.filters.binary) + { + return this.createErrorResponse("readelf requires an executable"); + } + return super.runTool(compilationInfo, compilationInfo.executableFilename, args); + } +} + +module.exports = ReadElfTool; diff --git a/lib/tooling/x86to6502-tool.js b/lib/tooling/x86to6502-tool.js new file mode 100644 index 000000000..6c3400eec --- /dev/null +++ b/lib/tooling/x86to6502-tool.js @@ -0,0 +1,67 @@ +// Copyright (c) 2019, Compiler Explorer Team +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +"use strict"; + +const + BaseTool = require('./base-tool'), + _ = require('underscore'), + AsmParser = require('../asm-parser.js'); + +class x86to6502Tool extends BaseTool { + constructor(toolInfo, env) { + super(toolInfo, env); + } + + runTool(compilationInfo, sourcefile, args) { + if (compilationInfo.filters.intel) { + return new Promise((resolve) => { + resolve(this.createErrorResponse("")); + }); + } + + if (compilationInfo.filters.binary) { + return new Promise((resolve) => { + resolve(this.createErrorResponse("")); + }); + } + + const parser = new AsmParser(); + const filters = Object.assign({}, compilationInfo.filters); + + let asm = parser.process(compilationInfo.asm, filters); + asm = _.map(asm, (obj) => { + if (obj.text.trim() === "") { + return ""; + } else if (obj.text.match(/.*:/)) { + return obj.text.replace(/^\s*/, ""); + } else { + return obj.text.replace(/^\s*/, "\t"); + } + }).join("\n"); + + return super.runTool(compilationInfo, false, args, asm); + } +} + +module.exports = x86to6502Tool; diff --git a/package-lock.json b/package-lock.json index c0c83ba9b..ffde0be2a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9364,6 +9364,11 @@ "querystring": "0.2.0" } }, + "url-join": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/url-join/-/url-join-4.0.1.tgz", + "integrity": "sha512-jk1+QP6ZJqyOiuEI9AEWQfju/nB2Pw466kbA0LEZljHwKeMgd9WrAEgEGxjPDD2+TNbbb37rTyhEfrCXfuKXnA==" + }, "url-loader": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/url-loader/-/url-loader-2.0.1.tgz", diff --git a/package.json b/package.json index ed9ed0c2d..2f98f1947 100644 --- a/package.json +++ b/package.json @@ -62,6 +62,7 @@ "tree-kill": "^1.2.0", "uglifyjs-webpack-plugin": "^2.1.3", "underscore": "1.9.1", + "url-join": "^4.0.1", "vis": "4.20.1", "winston": "^3.2.1", "winston-papertrail": "^1.0.5", diff --git a/static/panes/compiler.js b/static/panes/compiler.js index ac865b734..ad3c20dd8 100644 --- a/static/panes/compiler.js +++ b/static/panes/compiler.js @@ -99,6 +99,7 @@ function Compiler(hub, container, state) { this.alertSystem.prefixMessage = "Compiler #" + this.id + ": "; this.linkedFadeTimeoutId = -1; + this.toolsMenu = null; this.initButtons(state); @@ -425,7 +426,8 @@ Compiler.prototype.findTools = function (content, tools) { (content.componentState.compiler === this.id)) { tools.push({ id: content.componentState.toolId, - args: content.componentState.args + args: content.componentState.args, + stdin: content.componentState.stdin }); } } else if (content.content) { @@ -444,7 +446,8 @@ Compiler.prototype.getActiveTools = function (newToolSettings) { if (newToolSettings) { tools.push({ id: newToolSettings.toolId, - args: newToolSettings.args + args: newToolSettings.args, + stdin: newToolSettings.stdin }); } @@ -723,13 +726,15 @@ Compiler.prototype.onEditorChange = function (editor, source, langId, compilerId Compiler.prototype.onToolOpened = function (compilerId, toolSettings) { if (this.id === compilerId) { var toolId = toolSettings.toolId; - if (toolId === "clangtidytrunk") { - this.clangtidyToolButton.prop('disabled', true); - } else if (toolId === "llvm-mcatrunk") { - this.llvmmcaToolButton.prop('disabled', true); - } else if (toolId === "pahole") { - this.paholeToolButton.prop('disabled', true); - } + + var buttons = this.toolsMenu.find('button'); + $(buttons).each(_.bind(function (idx, button) { + var toolButton = $(button); + var toolName = toolButton.data('toolname'); + if (toolId === toolName) { + toolButton.prop('disabled', true); + } + }, this)); this.compile(false, toolSettings); } @@ -738,13 +743,15 @@ Compiler.prototype.onToolOpened = function (compilerId, toolSettings) { Compiler.prototype.onToolClosed = function (compilerId, toolSettings) { if (this.id === compilerId) { var toolId = toolSettings.toolId; - if (toolId === "clangtidytrunk") { - this.clangtidyToolButton.prop('disabled', !this.supportsTool(toolId)); - } else if (toolId === "llvm-mcatrunk") { - this.llvmmcaToolButton.prop('disabled', !this.supportsTool(toolId)); - } else if (toolId === "pahole") { - this.paholeToolButton.prop('disabled', !this.supportsTool(toolId)); - } + + var buttons = this.toolsMenu.find('button'); + $(buttons).each(_.bind(function (idx, button) { + var toolButton = $(button); + var toolName = toolButton.data('toolname'); + if (toolId === toolName) { + toolButton.prop('disabled', !this.supportsTool(toolId)); + } + }, this)); } }; @@ -993,13 +1000,43 @@ Compiler.prototype.initToolButton = function (togglePannerAdder, button, toolId) }; Compiler.prototype.initToolButtons = function (togglePannerAdder) { - this.clangtidyToolButton = this.domRoot.find('.view-clangtidytool'); - this.llvmmcaToolButton = this.domRoot.find('.view-llvmmcatool'); - this.paholeToolButton = this.domRoot.find('.view-pahole'); + this.toolsMenu = this.domRoot.find('.toolsmenu'); + this.toolsMenu.empty(); - this.initToolButton(togglePannerAdder, this.clangtidyToolButton, "clangtidytrunk"); - this.initToolButton(togglePannerAdder, this.llvmmcaToolButton, "llvm-mcatrunk"); - this.initToolButton(togglePannerAdder, this.paholeToolButton, "pahole"); + if (!this.compiler) return; + + var addTool = _.bind(function (toolName, title) { + var btn = $("