mirror of
https://github.com/compiler-explorer/compiler-explorer.git
synced 2026-12-01 13:16:08 -06:00
Merge branch 'master' into monaco-webpack
This commit is contained in:
@@ -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.
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
+16
-12
@@ -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) {
|
||||
|
||||
+13
-10
@@ -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);
|
||||
|
||||
+4
-2
@@ -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();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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("<cannot run analysis on binary>"));
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+10
-10
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
@@ -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("<need AT&T notation assembly>"));
|
||||
});
|
||||
}
|
||||
|
||||
if (compilationInfo.filters.binary) {
|
||||
return new Promise((resolve) => {
|
||||
resolve(this.createErrorResponse("<cannot run x86to6502 on binary>"));
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
Generated
+5
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
+65
-29
@@ -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 = $("<button class='dropdown-item btn btn-light btn-sm'>");
|
||||
btn.addClass('.view-' + toolName);
|
||||
btn.data('toolname', toolName);
|
||||
btn.append("<span class='dropdown-icon fas fa-cog' />" + title);
|
||||
this.toolsMenu.append(btn);
|
||||
|
||||
if (toolName !== "none") {
|
||||
this.initToolButton(togglePannerAdder, btn, toolName);
|
||||
}
|
||||
}, this);
|
||||
|
||||
if (_.isEmpty(this.compiler.tools)) {
|
||||
addTool("none", "No tools available");
|
||||
} else {
|
||||
_.each(this.compiler.tools, function (tool) {
|
||||
addTool(tool.tool.id, tool.tool.name);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Compiler.prototype.enableToolButtons = function () {
|
||||
var activeTools = this.getActiveTools();
|
||||
|
||||
var buttons = this.toolsMenu.find('button');
|
||||
$(buttons).each(_.bind(function (idx, button) {
|
||||
var toolButton = $(button);
|
||||
var toolName = toolButton.data('toolname');
|
||||
toolButton.prop('disabled',
|
||||
!(this.supportsTool(toolName)
|
||||
&& !this.isToolActive(activeTools, toolName)));
|
||||
}, this));
|
||||
};
|
||||
|
||||
Compiler.prototype.updateButtons = function () {
|
||||
@@ -1044,13 +1081,7 @@ Compiler.prototype.updateButtons = function () {
|
||||
this.cfgButton.prop('disabled', !this.compiler.supportsCfg);
|
||||
this.gccDumpButton.prop('disabled', !this.compiler.supportsGccDump);
|
||||
|
||||
var activeTools = this.getActiveTools();
|
||||
this.clangtidyToolButton.prop('disabled',
|
||||
!(this.supportsTool("clangtidytrunk") && !this.isToolActive(activeTools, "clangtidytrunk")));
|
||||
this.llvmmcaToolButton.prop('disabled',
|
||||
!(this.supportsTool("llvm-mcatrunk") && !this.isToolActive(activeTools, "llvm-mcatrunk")));
|
||||
this.paholeToolButton.prop('disabled',
|
||||
!(this.supportsTool("pahole") && !this.isToolActive(activeTools, "pahole")));
|
||||
this.enableToolButtons();
|
||||
};
|
||||
|
||||
Compiler.prototype.handlePopularArgumentsResult = function (result) {
|
||||
@@ -1236,6 +1267,11 @@ Compiler.prototype.updateCompilerInfo = function () {
|
||||
};
|
||||
|
||||
Compiler.prototype.updateCompilerUI = function () {
|
||||
var panerDropdown = this.domRoot.find('.pane-dropdown');
|
||||
var togglePannerAdder = function () {
|
||||
panerDropdown.dropdown('toggle');
|
||||
};
|
||||
this.initToolButtons(togglePannerAdder);
|
||||
this.updateButtons();
|
||||
this.updateCompilerInfo();
|
||||
// Resize in case the new compiler name is too big
|
||||
|
||||
@@ -618,6 +618,12 @@ Executor.prototype.initCallbacks = function () {
|
||||
}, this));
|
||||
|
||||
this.eventHub.on('initialised', this.undefer, this);
|
||||
|
||||
if (MutationObserver !== undefined) {
|
||||
new MutationObserver(_.bind(this.resize, this)).observe(this.execStdinField[0], {
|
||||
attributes: true, attributeFilter: ["style"]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Executor.prototype.onOptionsChange = function (options) {
|
||||
|
||||
+230
-51
@@ -30,6 +30,7 @@ var FontScale = require('../fontscale');
|
||||
var AnsiToHtml = require('../ansi-to-html');
|
||||
var Toggles = require('../toggles');
|
||||
var ga = require('../analytics');
|
||||
var monaco = require('../monaco');
|
||||
|
||||
function makeAnsiToHtml(color) {
|
||||
return new AnsiToHtml({
|
||||
@@ -50,30 +51,41 @@ function Tool(hub, container, state) {
|
||||
this.eventHub = hub.createEventHub();
|
||||
this.domRoot = container.getElement();
|
||||
this.domRoot.html($('#tool-output').html());
|
||||
this.contentRoot = this.domRoot.find('.content');
|
||||
this.editorContentRoot = this.domRoot.find('.monaco-placeholder');
|
||||
this.plainContentRoot = this.domRoot.find('pre.content');
|
||||
this.optionsToolbar = this.domRoot.find('.options-toolbar');
|
||||
this.compilerName = "";
|
||||
this.fontScale = new FontScale(this.domRoot, state, ".content");
|
||||
this.fontScale.on('change', _.bind(function () {
|
||||
this.saveState();
|
||||
}, this));
|
||||
this.normalAnsiToHtml = makeAnsiToHtml();
|
||||
this.errorAnsiToHtml = makeAnsiToHtml('red');
|
||||
|
||||
this.optionsField = this.domRoot.find('input.options');
|
||||
this.stdinField = this.domRoot.find('textarea.tool-stdin');
|
||||
|
||||
this.initButtons();
|
||||
this.outputEditor = monaco.editor.create(this.editorContentRoot[0], {
|
||||
scrollBeyondLastLine: false,
|
||||
readOnly: true,
|
||||
language: 'text',
|
||||
fontFamily: "courier new",
|
||||
glyphMargin: true,
|
||||
fixedOverflowWidgets: true,
|
||||
minimap: {
|
||||
maxColumn: 80
|
||||
},
|
||||
lineNumbersMinChars: 5,
|
||||
renderIndentGuides: false
|
||||
});
|
||||
|
||||
this.fontScale = new FontScale(this.domRoot, state, ".content,.monaco-editor");
|
||||
this.fontScale.on('change', _.bind(function () {
|
||||
this.saveState();
|
||||
}, this));
|
||||
|
||||
this.initButtons(state);
|
||||
this.options = new Toggles(this.domRoot.find('.options'), state);
|
||||
this.options.on('change', _.bind(this.onOptionsChange, this));
|
||||
|
||||
this.initArgs(state);
|
||||
|
||||
this.container.on('resize', this.resize, this);
|
||||
this.container.on('shown', this.resize, this);
|
||||
this.container.on('destroy', this.close, this);
|
||||
|
||||
this.eventHub.on('compileResult', this.onCompileResult, this);
|
||||
this.eventHub.on('compilerClose', this.onCompilerClose, this);
|
||||
this.initCallbacks();
|
||||
|
||||
this.onOptionsChange();
|
||||
this.updateCompilerName();
|
||||
@@ -87,14 +99,37 @@ function Tool(hub, container, state) {
|
||||
this.eventHub.emit('toolOpened', this.compilerId, this.currentState());
|
||||
}
|
||||
|
||||
Tool.prototype.initCallbacks = function () {
|
||||
this.container.on('resize', this.resize, this);
|
||||
this.container.on('shown', this.resize, this);
|
||||
this.container.on('destroy', this.close, this);
|
||||
|
||||
this.eventHub.on('compileResult', this.onCompileResult, this);
|
||||
this.eventHub.on('compilerClose', this.onCompilerClose, this);
|
||||
|
||||
this.toggleArgs.on('click', _.bind(function () {
|
||||
this.togglePanel(this.toggleArgs, this.panelArgs);
|
||||
}, this));
|
||||
|
||||
this.toggleStdin.on('click', _.bind(function () {
|
||||
this.togglePanel(this.toggleStdin, this.panelStdin);
|
||||
}, this));
|
||||
|
||||
if (MutationObserver !== undefined) {
|
||||
new MutationObserver(_.bind(this.resize, this)).observe(this.stdinField[0], {
|
||||
attributes: true, attributeFilter: ["style"]
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.initArgs = function (state) {
|
||||
var optionsChange = _.debounce(_.bind(function (e) {
|
||||
this.onOptionsChange($(e.target).val());
|
||||
|
||||
this.eventHub.emit('toolSettingsChange', this.compilerId);
|
||||
}, this), 800);
|
||||
|
||||
if (this.optionsField) {
|
||||
var optionsChange = _.debounce(_.bind(function (e) {
|
||||
this.onOptionsChange($(e.target).val());
|
||||
|
||||
this.eventHub.emit('toolSettingsChange', this.compilerId);
|
||||
}, this), 800);
|
||||
|
||||
this.optionsField
|
||||
.on('change', optionsChange)
|
||||
.on('keyup', optionsChange);
|
||||
@@ -103,6 +138,16 @@ Tool.prototype.initArgs = function (state) {
|
||||
this.optionsField.val(state.args);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.stdinField) {
|
||||
this.stdinField
|
||||
.on('change', optionsChange)
|
||||
.on('keyup', optionsChange);
|
||||
|
||||
if (state.stdin) {
|
||||
this.stdinField.val(state.stdin);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.getInputArgs = function () {
|
||||
@@ -113,25 +158,85 @@ Tool.prototype.getInputArgs = function () {
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.getInputStdin = function () {
|
||||
if (this.stdinField) {
|
||||
return this.stdinField.val();
|
||||
} else {
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.getEffectiveOptions = function () {
|
||||
return this.options.get();
|
||||
};
|
||||
|
||||
Tool.prototype.resize = function () {
|
||||
this.contentRoot.height(this.domRoot.height() - this.optionsToolbar.height() - 5);
|
||||
var barsHeight = this.optionsToolbar.outerHeight() + 2;
|
||||
if (!this.panelArgs.hasClass("d-none")) {
|
||||
barsHeight += this.panelArgs.outerHeight();
|
||||
}
|
||||
if (!this.panelStdin.hasClass("d-none")) {
|
||||
barsHeight += this.panelStdin.outerHeight();
|
||||
}
|
||||
|
||||
this.outputEditor.layout({
|
||||
width: this.domRoot.width(),
|
||||
height: this.domRoot.height() - barsHeight
|
||||
});
|
||||
|
||||
this.plainContentRoot.height(this.domRoot.height() - barsHeight);
|
||||
};
|
||||
|
||||
Tool.prototype.onOptionsChange = function () {
|
||||
var options = this.getEffectiveOptions();
|
||||
this.contentRoot.toggleClass('wrap', options.wrap);
|
||||
this.plainContentRoot.toggleClass('wrap', options.wrap);
|
||||
this.wrapButton.prop('title', '[' + (options.wrap ? 'ON' : 'OFF') + '] ' + this.wrapTitle);
|
||||
|
||||
this.saveState();
|
||||
};
|
||||
|
||||
Tool.prototype.initButtons = function () {
|
||||
Tool.prototype.initButtons = function (state) {
|
||||
this.wrapButton = this.domRoot.find('.wrap-lines');
|
||||
this.wrapTitle = this.wrapButton.prop('title');
|
||||
|
||||
this.panelArgs = this.domRoot.find('.panel-args');
|
||||
this.panelStdin = this.domRoot.find('.panel-stdin');
|
||||
|
||||
this.initToggleButtons(state);
|
||||
};
|
||||
|
||||
Tool.prototype.initToggleButtons = function (state) {
|
||||
this.toggleArgs = this.domRoot.find('.toggle-args');
|
||||
this.toggleStdin = this.domRoot.find('.toggle-stdin');
|
||||
|
||||
if (state.argsPanelShown === true) {
|
||||
this.showPanel(this.toggleArgs, this.panelArgs);
|
||||
}
|
||||
|
||||
if (state.stdinPanelShown === true) {
|
||||
this.showPanel(this.toggleStdin, this.panelStdin);
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.showPanel = function (button, panel) {
|
||||
panel.removeClass('d-none');
|
||||
button.addClass('active');
|
||||
this.resize();
|
||||
};
|
||||
|
||||
Tool.prototype.hidePanel = function (button, panel) {
|
||||
panel.addClass('d-none');
|
||||
button.removeClass('active');
|
||||
this.resize();
|
||||
};
|
||||
|
||||
Tool.prototype.togglePanel = function (button, panel) {
|
||||
if (panel.hasClass('d-none')) {
|
||||
this.showPanel(button, panel);
|
||||
} else {
|
||||
this.hidePanel(button, panel);
|
||||
}
|
||||
this.saveState();
|
||||
};
|
||||
|
||||
Tool.prototype.currentState = function () {
|
||||
@@ -141,7 +246,10 @@ Tool.prototype.currentState = function () {
|
||||
editor: this.editorId,
|
||||
wrap: options.wrap,
|
||||
toolId: this.toolId,
|
||||
args: this.getInputArgs()
|
||||
args: this.getInputArgs(),
|
||||
stdin: this.getInputStdin(),
|
||||
stdinPanelShown: !this.panelStdin.hasClass('d-none'),
|
||||
argsPanelShow: !this.panelArgs.hasClass('d-none')
|
||||
};
|
||||
this.fontScale.addState(state);
|
||||
return state;
|
||||
@@ -151,39 +259,89 @@ Tool.prototype.saveState = function () {
|
||||
this.container.setState(this.currentState());
|
||||
};
|
||||
|
||||
Tool.prototype.onCompileResult = function (id, compiler, result) {
|
||||
if (id !== this.compilerId) return;
|
||||
if (compiler) this.compilerName = compiler.name;
|
||||
|
||||
this.contentRoot.empty();
|
||||
|
||||
var toolResult = null;
|
||||
if (result && result.tools) {
|
||||
toolResult = _.find(result.tools, function (tool) {
|
||||
return (tool.id === this.toolId);
|
||||
}, this);
|
||||
}
|
||||
|
||||
if (toolResult) {
|
||||
_.each((toolResult.stdout || []).concat(toolResult.stderr || []), function (obj) {
|
||||
this.add(this.normalAnsiToHtml.toHtml(obj.text), obj.tag ? obj.tag.line : obj.line);
|
||||
}, this);
|
||||
|
||||
this.toolName = toolResult.name;
|
||||
this.add(this.toolName + " returned: " + toolResult.code);
|
||||
|
||||
this.updateCompilerName();
|
||||
|
||||
if (toolResult.sourcechanged) {
|
||||
this.eventHub.emit('newSource', this.editorId, toolResult.newsource);
|
||||
}
|
||||
Tool.prototype.setLanguage = function (languageId) {
|
||||
if (languageId) {
|
||||
this.options.enableToggle("wrap", false);
|
||||
monaco.editor.setModelLanguage(this.outputEditor.getModel(), languageId);
|
||||
this.outputEditor.setValue("");
|
||||
$(this.plainContentRoot).hide();
|
||||
$(this.editorContentRoot).show();
|
||||
} else {
|
||||
this.add("No tool result");
|
||||
this.options.enableToggle("wrap", true);
|
||||
this.plainContentRoot.empty();
|
||||
$(this.editorContentRoot).hide();
|
||||
$(this.plainContentRoot).show();
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.onCompileResult = function (id, compiler, result) {
|
||||
try{
|
||||
if (id !== this.compilerId) return;
|
||||
if (compiler) this.compilerName = compiler.name;
|
||||
|
||||
var toolResult = null;
|
||||
if (result && result.tools) {
|
||||
toolResult = _.find(result.tools, function (tool) {
|
||||
return (tool.id === this.toolId);
|
||||
}, this);
|
||||
}
|
||||
|
||||
var toolInfo = null;
|
||||
if (compiler && compiler.tools) {
|
||||
toolInfo = _.find(compiler.tools, function (tool) {
|
||||
return (tool.tool.id === this.toolId);
|
||||
}, this);
|
||||
}
|
||||
|
||||
if (toolInfo) {
|
||||
this.toggleStdin.prop("disabled", false);
|
||||
|
||||
if (toolInfo.tool.stdinHint) {
|
||||
this.stdinField.prop("placeholder", toolInfo.tool.stdinHint);
|
||||
if (toolInfo.tool.stdinHint === "disabled") {
|
||||
this.toggleStdin.prop("disabled", true);
|
||||
}
|
||||
} else {
|
||||
this.stdinField.prop("placeholder", "Tool stdin...");
|
||||
}
|
||||
}
|
||||
|
||||
if (toolResult) {
|
||||
if (toolResult.languageId && (toolResult.languageId === "stderr")) {
|
||||
toolResult.languageId = false;
|
||||
}
|
||||
|
||||
this.setLanguage(toolResult.languageId);
|
||||
|
||||
if (toolResult.languageId) {
|
||||
this.setEditorContent(_.pluck(toolResult.stdout, 'text').join('\n'));
|
||||
} else {
|
||||
_.each((toolResult.stdout || []).concat(toolResult.stderr || []), function (obj) {
|
||||
if (obj.text === "") {
|
||||
this.add('<br/>');
|
||||
} else {
|
||||
this.add(this.normalAnsiToHtml.toHtml(obj.text), obj.tag ? obj.tag.line : obj.line);
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
|
||||
this.toolName = toolResult.name;
|
||||
this.updateCompilerName();
|
||||
|
||||
if (toolResult.sourcechanged) {
|
||||
this.eventHub.emit('newSource', this.editorId, toolResult.newsource);
|
||||
}
|
||||
} else {
|
||||
this.setEditorContent("No tool result");
|
||||
}
|
||||
} catch(e) {
|
||||
this.setLanguage(false);
|
||||
this.add("javascript error: " + e.message);
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.add = function (msg, lineNum) {
|
||||
var elem = $('<p></p>').appendTo(this.contentRoot);
|
||||
var elem = $('<p></p>').appendTo(this.plainContentRoot);
|
||||
if (lineNum) {
|
||||
elem.html(
|
||||
$('<a></a>')
|
||||
@@ -203,6 +361,26 @@ Tool.prototype.add = function (msg, lineNum) {
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.setEditorContent = function (content) {
|
||||
if (!this.outputEditor || !this.outputEditor.getModel()) return;
|
||||
var editorModel = this.outputEditor.getModel();
|
||||
var visibleRanges = this.outputEditor.getVisibleRanges();
|
||||
var currentTopLine = visibleRanges.length > 0 ? visibleRanges[0].startLineNumber : 1;
|
||||
editorModel.setValue(content);
|
||||
this.outputEditor.revealLine(currentTopLine);
|
||||
this.setNormalContent();
|
||||
};
|
||||
|
||||
Tool.prototype.setNormalContent = function () {
|
||||
this.outputEditor.updateOptions({
|
||||
lineNumbers: true,
|
||||
codeLens: false
|
||||
});
|
||||
if (this.codeLensProvider) {
|
||||
this.codeLensProvider.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
Tool.prototype.updateCompilerName = function () {
|
||||
var name = this.toolName + " #" + this.compilerId;
|
||||
if (this.compilerName) name += " with " + this.compilerName;
|
||||
@@ -221,6 +399,7 @@ Tool.prototype.onCompilerClose = function (id) {
|
||||
Tool.prototype.close = function () {
|
||||
this.eventHub.emit('toolClosed', this.compilerId, this.currentState());
|
||||
this.eventHub.unsubscribe();
|
||||
this.outputEditor.dispose();
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -32,6 +32,7 @@ function Togglesv2(root, state) {
|
||||
EventEmitter.call(this);
|
||||
var buttons = root.find('.button-checkbox');
|
||||
var self = this;
|
||||
this.buttons = buttons;
|
||||
this.state = _.extend({}, state);
|
||||
// Based on https://bootsnipp.com/snippets/featured/jquery-checkbox-buttons
|
||||
buttons.each(function () {
|
||||
@@ -105,6 +106,17 @@ Togglesv2.prototype.set = function (key, value) {
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
Togglesv2.prototype.enableToggle = function (key, enable) {
|
||||
this.buttons.each(function () {
|
||||
var widget = $(this);
|
||||
var button = $(widget.find('button'));
|
||||
var bind = button.data('bind');
|
||||
if (bind === key) {
|
||||
button.prop("disabled", !enable);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Togglesv2.prototype._change = function (update) {
|
||||
var before = this.get();
|
||||
update();
|
||||
|
||||
+13
-12
@@ -139,16 +139,7 @@
|
||||
button.btn.btn-light.btn-sm.dropdown-toggle.add-tool(type="button" title="Add tool" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="Add tooling to this editor and compiler")
|
||||
span.fas.fa-cogs
|
||||
span.hideable Add tool...
|
||||
.dropdown-menu.dropdown-menu-right
|
||||
button.dropdown-item.btn.btn-light.btn-sm.view-clangtidytool(title="Clang-tidy")
|
||||
span.dropdown-icon.fas.fa-cog
|
||||
| Clang-tidy
|
||||
button.dropdown-item.btn.btn-light.btn-sm.view-llvmmcatool(title="LLVM MCA")
|
||||
span.dropdown-icon.fas.fa-cog
|
||||
| LLVM MCA
|
||||
button.dropdown-item.btn.btn-light.btn-sm.view-pahole(title="Pahole")
|
||||
span.dropdown-icon.fas.fa-cog
|
||||
| Pahole
|
||||
.dropdown-menu.dropdown-menu-right.toolsmenu
|
||||
.monaco-placeholder
|
||||
.bottom-bar.bg-light
|
||||
if !embedded
|
||||
@@ -201,7 +192,7 @@
|
||||
.top-bar.btn-toolbar.bg-light.panel-args.d-none(role="toolbar")
|
||||
input.execution-arguments.form-control(type="text" placeholder="Execution arguments..." size="256" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false")
|
||||
.top-bar.btn-toolbar.bg-light.panel-stdin.d-none(role="toolbar")
|
||||
textarea.execution-stdin.form-control(placeholder="Execution stdin..." cols="1024" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" aria-multiline="false" style="resize: none")
|
||||
textarea.execution-stdin.form-control(placeholder="Execution stdin..." cols="1024" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" aria-multiline="false" style="resize: vertical")
|
||||
pre.content
|
||||
.execution-status
|
||||
.compiler-output
|
||||
@@ -230,8 +221,18 @@
|
||||
button.btn.btn-light.btn-sm.wrap-lines(type="button" title="Wrap lines" data-bind="wrap" aria-pressed="false" aria-label="Wrap lines")
|
||||
span Wrap lines
|
||||
input.d-none(type="checkbox" checked=false)
|
||||
input.options.form-control(type="text" placeholder="Tool options..." size="256" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false")
|
||||
button.btn.btn-light.btn-sm.toggle-args
|
||||
span.fas.fa-terminal
|
||||
span.hideable Arguments
|
||||
button.btn.btn-light.btn-sm.toggle-stdin
|
||||
span.fas.fa-sign-in-alt
|
||||
span.hideable Stdin
|
||||
.top-bar.btn-toolbar.bg-light.panel-args.d-none(role="toolbar")
|
||||
input.options.form-control(type="text" placeholder="Tool arguments..." size="256" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false")
|
||||
.top-bar.btn-toolbar.bg-light.panel-stdin.d-none(role="toolbar")
|
||||
textarea.tool-stdin.form-control(placeholder="Tool stdin..." cols="1024" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false" aria-multiline="false" style="resize: vertical")
|
||||
pre.content
|
||||
.monaco-placeholder
|
||||
|
||||
#diff
|
||||
.top-bar.btn-toolbar.bg-light(role="toolbar")
|
||||
|
||||
Reference in New Issue
Block a user