From 30fb92e228229c587212312ca2299287c67aa178 Mon Sep 17 00:00:00 2001 From: partouf Date: Wed, 19 Jan 2022 23:55:29 +0000 Subject: [PATCH 01/11] work in progress --- lib/external-parsers/base.ts | 86 +++++++++++++++++++ .../external-parser.interface.ts | 15 ++++ lib/utils.ts | 12 +-- types/execution/execution.interfaces.ts | 12 +++ types/features/filters.interfaces.ts | 12 +++ types/resultline/resultline.interfaces.ts | 11 +++ 6 files changed, 137 insertions(+), 11 deletions(-) create mode 100644 lib/external-parsers/base.ts create mode 100644 lib/external-parsers/external-parser.interface.ts create mode 100644 types/execution/execution.interfaces.ts create mode 100644 types/features/filters.interfaces.ts create mode 100644 types/resultline/resultline.interfaces.ts diff --git a/lib/external-parsers/base.ts b/lib/external-parsers/base.ts new file mode 100644 index 000000000..0723eff1d --- /dev/null +++ b/lib/external-parsers/base.ts @@ -0,0 +1,86 @@ +import fs from 'fs'; +import path from 'path'; + +import { TypicalExecutionFunc } from '../../types/execution/execution.interfaces'; +import { IParseFilters } from '../../types/features/filters.interfaces'; + +import { IParsedAsmResult } from './external-parser.interface'; + +export class ExternalParserBase { + private objdumperPath: string; + private parserPath: string; + private execFunc: TypicalExecutionFunc; + + constructor(objdumperPath: string, parserPath: string, execFunc: TypicalExecutionFunc) { + this.objdumperPath = objdumperPath; + this.parserPath = parserPath; + this.execFunc = execFunc; + } + + private getParserArguments(filters: IParseFilters, fromStdin: boolean): string[] { + const parameters = []; + + if (fromStdin) parameters.push('-stdin'); + if (filters.binary) parameters.push('-binary'); + if (filters.labels) parameters.push('-unused_labels'); + if (filters.directives) parameters.push('-directives'); + if (filters.commentOnly) parameters.push('-comment_only'); + if (filters.trim) parameters.push('-whitespace'); + if (filters.libraryCode) parameters.push('-library_functions'); + + return parameters; + } + + private getObjdumpStarterScriptContent(filters: IParseFilters) { + const parserArgs = this.getParserArguments(filters, true); + + return '#!/bin/sh\n' + + `OBJDUMP=${this.objdumperPath}\n` + + `ASMPARSER=${this.parserPath}\n` + + `$OBJDUMP "$@" | $ASMPARSER ${parserArgs.join(' ')}\n`; + } + + private async writeStarterScriptObjdump(buildfolder: string, filters: IParseFilters): Promise { + const scriptFilepath = path.join(buildfolder, 'dump-and-parse.sh'); + + return new Promise((resolve) => { + fs.writeFile(scriptFilepath, + this.getObjdumpStarterScriptContent(filters), { + encoding: 'utf8', + mode: 0o777, + }, () => { + resolve(scriptFilepath); + }); + }); + } + + private parseAsmExecResult(execResult): IParsedAsmResult { + const result = Object.assign({}, JSON.parse(execResult.stdout)); + if (result.stderr) { + throw result.stderr; + } + return result; + } + + public async objdumpAndParseAssembly(buildfolder: string, objdumpArgs: string[], + filters: IParseFilters): Promise { + const scriptFilepath = await this.writeStarterScriptObjdump(buildfolder, filters); + const execOptions = { + customCwd: buildfolder, + }; + const execResult = await this.execFunc(scriptFilepath, objdumpArgs, execOptions); + return this.parseAsmExecResult(execResult); + } + + public async parseAssembly(filepath: string, filters: IParseFilters): Promise { + const execOptions = { + customCwd: path.dirname(filepath), + }; + + const parserArgs = this.getParserArguments(filters, false); + parserArgs.push(filepath); + + const execResult = await this.execFunc(this.parserPath, parserArgs, execOptions); + return this.parseAsmExecResult(execResult); + } +} diff --git a/lib/external-parsers/external-parser.interface.ts b/lib/external-parsers/external-parser.interface.ts new file mode 100644 index 000000000..250bf23d2 --- /dev/null +++ b/lib/external-parsers/external-parser.interface.ts @@ -0,0 +1,15 @@ +import { IParseFilters } from '../../types/features/filters.interfaces'; +import { IResultLineTag } from '../../types/resultline/resultline.interfaces'; + +export interface IParsedAsmResult { + asm: IResultLineTag[]; + labelDefinitions: Set; + parsingTime: string; + filteredCount: number; +} + +export interface IExternalParser { + objdumpAndParseAssembly(buildfolder: string, objdumpArgs: string[], + filters: IParseFilters): Promise; + parseAssembly(filepath: string, filters: IParseFilters): Promise; +} diff --git a/lib/utils.ts b/lib/utils.ts index fea13bc6e..b050300d9 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -30,17 +30,7 @@ import fs from 'fs-extra'; import quote from 'shell-quote'; import _ from 'underscore'; -interface IResultLineTag { - line?: number; - column?: number; - file?: string; - text: string; -} - -interface IResultLine { - text: string; - tag?: IResultLineTag; -} +import { IResultLine } from '../types/resultline/resultline.interfaces'; const tabsRe = /\t/g; const lineRe = /\r?\n/; diff --git a/types/execution/execution.interfaces.ts b/types/execution/execution.interfaces.ts new file mode 100644 index 000000000..04251c936 --- /dev/null +++ b/types/execution/execution.interfaces.ts @@ -0,0 +1,12 @@ +export type FilenameTransformFunc = (filename: string) => string; + +export interface UnprocessedExecResult { + code: number; + okToCache: boolean; + filenameTransform: FilenameTransformFunc; + stdout: string; + stderr: string; + execTime: string; +} + +export type TypicalExecutionFunc = (executable: string, args: string[], execOptions: object) => UnprocessedExecResult; diff --git a/types/features/filters.interfaces.ts b/types/features/filters.interfaces.ts new file mode 100644 index 000000000..1cebce5f9 --- /dev/null +++ b/types/features/filters.interfaces.ts @@ -0,0 +1,12 @@ +export interface IParseFilters { + binary: boolean; + execute: boolean; + demangle: boolean; + intel: boolean; + commentOnly: boolean; + directives: boolean; + labels: boolean; + optOutput: boolean; + libraryCode: boolean; + trim: boolean; +} diff --git a/types/resultline/resultline.interfaces.ts b/types/resultline/resultline.interfaces.ts new file mode 100644 index 000000000..c46e7944e --- /dev/null +++ b/types/resultline/resultline.interfaces.ts @@ -0,0 +1,11 @@ +export interface IResultLineTag { + line?: number; + column?: number; + file?: string; + text: string; +} + +export interface IResultLine { + text: string; + tag?: IResultLineTag; +} From 36e1d3168595872782727a21eb9771f660d47a7a Mon Sep 17 00:00:00 2001 From: partouf Date: Thu, 20 Jan 2022 01:07:10 +0000 Subject: [PATCH 02/11] map --- lib/external-parsers/external-parser.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/external-parsers/external-parser.interface.ts b/lib/external-parsers/external-parser.interface.ts index 250bf23d2..c55c4256e 100644 --- a/lib/external-parsers/external-parser.interface.ts +++ b/lib/external-parsers/external-parser.interface.ts @@ -3,7 +3,7 @@ import { IResultLineTag } from '../../types/resultline/resultline.interfaces'; export interface IParsedAsmResult { asm: IResultLineTag[]; - labelDefinitions: Set; + labelDefinitions: Map; parsingTime: string; filteredCount: number; } From 40cece5081d2b1837c8d74b50099f0bc0070bb3a Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 02:57:38 +0000 Subject: [PATCH 03/11] objdumpandparse with extparser, doesnt work yet for unknown reasons --- lib/base-compiler.js | 25 +++++++++++++++++++++---- lib/compiler-finder.js | 12 ++++++++++++ lib/external-parsers/_all.ts | 1 + lib/external-parsers/base.ts | 12 +++++++----- lib/external-parsers/ce-asm-parser.ts | 5 +++++ lib/external-parsers/index.ts | 7 +++++++ 6 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 lib/external-parsers/_all.ts create mode 100644 lib/external-parsers/ce-asm-parser.ts create mode 100644 lib/external-parsers/index.ts diff --git a/lib/base-compiler.js b/lib/base-compiler.js index febdab7a0..a19b1b489 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -45,6 +45,7 @@ import { getObjdumperTypeByKey } from './objdumper'; import { Packager } from './packager'; import { getToolchainPath } from './toolchain-utils'; import * as utils from './utils'; +import { getExternalParserByKey } from './external-parsers'; export class BaseCompiler { constructor(compilerInfo, env) { @@ -106,6 +107,12 @@ export class BaseCompiler { }); } + this.externalparser = null; + if (this.compiler.externalparser && this.compiler.externalparser.id) { + const externalparserclass = getExternalParserByKey(this.compiler.externalparser.id); + this.externalparser = new externalparserclass(this.compiler, this.env, this.exec); + } + if (!this.compiler.instructionSet) { const isets = new InstructionSets(); if (this.buildenvsetup) { @@ -304,7 +311,7 @@ export class BaseCompiler { return output; } - async objdump(outputFilename, result, maxSize, intelAsm, demangle) { + async objdump(outputFilename, result, maxSize, intelAsm, demangle, filters) { outputFilename = this.getObjdumpOutputFilename(outputFilename); if (!await utils.fileExists(outputFilename)) { @@ -316,15 +323,25 @@ export class BaseCompiler { const args = ['-d', outputFilename, '-l', ...objdumper.widthOptions]; if (demangle) args.push('-C'); if (intelAsm) args.push(...objdumper.intelAsmOptions); - const execOptions = {maxOutput: maxSize, customCwd: result.dirPath || path.dirname(outputFilename)}; - const objResult = await this.exec(this.compiler.objdumper, args, execOptions); + let objResult; + if (this.externalparser) { + objResult = await this.externalparser.objdumpAndParseAssembly( + path.dirname(outputFilename), + args, + filters); + } else { + const execOptions = {maxOutput: maxSize, customCwd: result.dirPath || path.dirname(outputFilename)}; + objResult = await this.exec(this.compiler.objdumper, args, execOptions); + } + if (objResult.code !== 0) { result.asm = ``; } else { result.objdumpTime = objResult.execTime; result.asm = this.postProcessObjdumpOutput(objResult.stdout); } + return result; } @@ -1903,7 +1920,7 @@ but nothing was dumped. Possible causes are: const maxSize = this.env.ceProps('max-asm-size', 64 * 1024 * 1024); const optPromise = result.hasOptOutput ? this.processOptOutput(result.optPath) : ''; const asmPromise = (filters.binary && this.supportsObjdump()) - ? this.objdump(outputFilename, result, maxSize, filters.intel, filters.demangle) + ? this.objdump(outputFilename, result, maxSize, filters.intel, filters.demangle, filters) : (async () => { if (result.asmSize === undefined) { result.asm = ''; diff --git a/lib/compiler-finder.js b/lib/compiler-finder.js index 9729d8a2c..dafd471a0 100644 --- a/lib/compiler-finder.js +++ b/lib/compiler-finder.js @@ -247,6 +247,12 @@ export class CompilerFinder { return props(`buildenvsetup.${name}`, def); }, }, + externalparser: { + id: props('externalparser', ''), + props: (name, def) => { + return props(`externalparser.${name}`, def); + }, + }, }; if (props('demanglerClassFile') !== undefined) { @@ -381,6 +387,12 @@ export class CompilerFinder { }; } + if (compiler.externalparser) { + compiler.externalparser.props = (propName, def) => { + return this.compilerProps(langId, 'externalparser.' + propName, def); + }; + } + const fullOptions = this.optionsHandler.get(); compiler.tools = _.omit( diff --git a/lib/external-parsers/_all.ts b/lib/external-parsers/_all.ts new file mode 100644 index 000000000..1d804beeb --- /dev/null +++ b/lib/external-parsers/_all.ts @@ -0,0 +1 @@ +export { CEAsmParser } from './ce-asm-parser'; diff --git a/lib/external-parsers/base.ts b/lib/external-parsers/base.ts index 0723eff1d..1de513392 100644 --- a/lib/external-parsers/base.ts +++ b/lib/external-parsers/base.ts @@ -4,16 +4,16 @@ import path from 'path'; import { TypicalExecutionFunc } from '../../types/execution/execution.interfaces'; import { IParseFilters } from '../../types/features/filters.interfaces'; -import { IParsedAsmResult } from './external-parser.interface'; +import { IExternalParser, IParsedAsmResult } from './external-parser.interface'; -export class ExternalParserBase { +export class ExternalParserBase implements IExternalParser { private objdumperPath: string; private parserPath: string; private execFunc: TypicalExecutionFunc; - constructor(objdumperPath: string, parserPath: string, execFunc: TypicalExecutionFunc) { - this.objdumperPath = objdumperPath; - this.parserPath = parserPath; + constructor(compilerInfo, envInfo, execFunc: TypicalExecutionFunc) { + this.objdumperPath = compilerInfo.objdumper; + this.parserPath = compilerInfo.externalparser.props('exe', ''); this.execFunc = execFunc; } @@ -55,6 +55,8 @@ export class ExternalParserBase { } private parseAsmExecResult(execResult): IParsedAsmResult { + console.log(execResult.stdout); + console.log(execResult.stderr); const result = Object.assign({}, JSON.parse(execResult.stdout)); if (result.stderr) { throw result.stderr; diff --git a/lib/external-parsers/ce-asm-parser.ts b/lib/external-parsers/ce-asm-parser.ts new file mode 100644 index 000000000..10e330be9 --- /dev/null +++ b/lib/external-parsers/ce-asm-parser.ts @@ -0,0 +1,5 @@ +import { ExternalParserBase } from "./base"; + +export class CEAsmParser extends ExternalParserBase { + static get key() { return 'CEAsmParser'; } +} diff --git a/lib/external-parsers/index.ts b/lib/external-parsers/index.ts new file mode 100644 index 000000000..6d9833820 --- /dev/null +++ b/lib/external-parsers/index.ts @@ -0,0 +1,7 @@ + +import { makeKeyedTypeGetter } from '../keyed-type'; + +import * as all from './_all'; +export * from './_all'; + +export const getExternalParserByKey = makeKeyedTypeGetter('externalParser', all); From 9da940154c60c7b41a4438e98dd6ca817a16e43c Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 03:02:54 +0000 Subject: [PATCH 04/11] lintfixes --- lib/base-compiler.js | 2 +- lib/external-parsers/ce-asm-parser.ts | 2 +- lib/external-parsers/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index a19b1b489..5b56cbac6 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -36,6 +36,7 @@ import { CompilerArguments } from './compiler-arguments'; import { ClangParser, GCCParser } from './compilers/argument-parsers'; import { getDemanglerTypeByKey } from './demangler'; import * as exec from './exec'; +import { getExternalParserByKey } from './external-parsers'; import { InstructionSets } from './instructionsets'; import { languages } from './languages'; import { LlvmAstParser } from './llvm-ast'; @@ -45,7 +46,6 @@ import { getObjdumperTypeByKey } from './objdumper'; import { Packager } from './packager'; import { getToolchainPath } from './toolchain-utils'; import * as utils from './utils'; -import { getExternalParserByKey } from './external-parsers'; export class BaseCompiler { constructor(compilerInfo, env) { diff --git a/lib/external-parsers/ce-asm-parser.ts b/lib/external-parsers/ce-asm-parser.ts index 10e330be9..75a79442a 100644 --- a/lib/external-parsers/ce-asm-parser.ts +++ b/lib/external-parsers/ce-asm-parser.ts @@ -1,4 +1,4 @@ -import { ExternalParserBase } from "./base"; +import { ExternalParserBase } from './base'; export class CEAsmParser extends ExternalParserBase { static get key() { return 'CEAsmParser'; } diff --git a/lib/external-parsers/index.ts b/lib/external-parsers/index.ts index 6d9833820..255dcd985 100644 --- a/lib/external-parsers/index.ts +++ b/lib/external-parsers/index.ts @@ -1,7 +1,7 @@ - import { makeKeyedTypeGetter } from '../keyed-type'; import * as all from './_all'; + export * from './_all'; export const getExternalParserByKey = makeKeyedTypeGetter('externalParser', all); From 077943879d92d4bad2fad91640244232d3149b4e Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 03:03:28 +0000 Subject: [PATCH 05/11] disovery thign --- app.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app.js b/app.js index 12f8b417d..69515cb44 100755 --- a/app.js +++ b/app.js @@ -488,6 +488,9 @@ async function main() { if (compiler.buildenvsetup && compiler.buildenvsetup.id === '') delete compiler.buildenvsetup; + if (compiler.externalparser && compiler.externalParser.id === '') + delete compiler.externalparser; + const compilerInstance = compilerFinder.compileHandler.findCompiler(compiler.lang, compiler.id); if (compilerInstance) { compiler.cachedPossibleArguments = compilerInstance.possibleArguments.possibleArguments; From a408ffca469cdc4ae10ecf4d26a52c44917841b8 Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 11:31:27 +0000 Subject: [PATCH 06/11] sandbox instead of exec --- lib/base-compiler.js | 2 +- lib/external-parsers/base.ts | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 5b56cbac6..2b0c7143a 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -110,7 +110,7 @@ export class BaseCompiler { this.externalparser = null; if (this.compiler.externalparser && this.compiler.externalparser.id) { const externalparserclass = getExternalParserByKey(this.compiler.externalparser.id); - this.externalparser = new externalparserclass(this.compiler, this.env, this.exec); + this.externalparser = new externalparserclass(this.compiler, this.env, exec.sandbox); } if (!this.compiler.instructionSet) { diff --git a/lib/external-parsers/base.ts b/lib/external-parsers/base.ts index 1de513392..8c34d11c1 100644 --- a/lib/external-parsers/base.ts +++ b/lib/external-parsers/base.ts @@ -67,17 +67,13 @@ export class ExternalParserBase implements IExternalParser { public async objdumpAndParseAssembly(buildfolder: string, objdumpArgs: string[], filters: IParseFilters): Promise { const scriptFilepath = await this.writeStarterScriptObjdump(buildfolder, filters); - const execOptions = { - customCwd: buildfolder, - }; + const execOptions = {}; const execResult = await this.execFunc(scriptFilepath, objdumpArgs, execOptions); return this.parseAsmExecResult(execResult); } public async parseAssembly(filepath: string, filters: IParseFilters): Promise { - const execOptions = { - customCwd: path.dirname(filepath), - }; + const execOptions = {}; const parserArgs = this.getParserArguments(filters, false); parserArgs.push(filepath); From 753550d72acdff6ca6b52f9da05abf49aba6074b Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 18:33:49 +0100 Subject: [PATCH 07/11] working version --- etc/config/c++.amazon.properties | 3 ++ lib/base-compiler.js | 37 +++++++++++----------- lib/external-parsers/base.ts | 42 ++++++++++++++++--------- types/execution/execution.interfaces.ts | 2 +- 4 files changed, 50 insertions(+), 34 deletions(-) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index a45bd20da..6d4c493c1 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -7,6 +7,9 @@ needsMulti=false buildenvsetup=ceconan buildenvsetup.host=https://conan.compiler-explorer.com +externalparser=CEAsmParser +externalparser.exe=/opt/compiler-explorer/asm-parser/build/bin/asm-parser + ############################### # GCC for x86 group.gcc86.compilers=g412:g447:g453:g464:g471:g472:g473:g474:g481:g482:g483:g484:g485:g490:g491:g492:g493:g494:g510:g520:g530:g540:g550:g6:g62:g63:g64:g71:g72:g73:g74:g75:g81:g82:g83:g84:g85:g91:g92:g93:g94:g101:g102:g103:g111:g112:gsnapshot:gcontracts-trunk:gcontract-labels-trunk:gcxx-modules-trunk:gcxx-coroutines-trunk:gcc-embed-trunk:gcc-static-analysis-trunk diff --git a/lib/base-compiler.js b/lib/base-compiler.js index 2b0c7143a..e6d1b828e 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -110,7 +110,7 @@ export class BaseCompiler { this.externalparser = null; if (this.compiler.externalparser && this.compiler.externalparser.id) { const externalparserclass = getExternalParserByKey(this.compiler.externalparser.id); - this.externalparser = new externalparserclass(this.compiler, this.env, exec.sandbox); + this.externalparser = new externalparserclass(this.compiler, this.env, this.exec); } if (!this.compiler.instructionSet) { @@ -324,22 +324,21 @@ export class BaseCompiler { if (demangle) args.push('-C'); if (intelAsm) args.push(...objdumper.intelAsmOptions); - let objResult; if (this.externalparser) { - objResult = await this.externalparser.objdumpAndParseAssembly( + result = await this.externalparser.objdumpAndParseAssembly( path.dirname(outputFilename), args, filters); } else { const execOptions = {maxOutput: maxSize, customCwd: result.dirPath || path.dirname(outputFilename)}; - objResult = await this.exec(this.compiler.objdumper, args, execOptions); - } + const objResult = await this.exec(this.compiler.objdumper, args, execOptions); - if (objResult.code !== 0) { - result.asm = ``; - } else { - result.objdumpTime = objResult.execTime; - result.asm = this.postProcessObjdumpOutput(objResult.stdout); + if (objResult.code !== 0) { + result.asm = ``; + } else { + result.objdumpTime = objResult.execTime; + result.asm = this.postProcessObjdumpOutput(objResult.stdout); + } } return result; @@ -1692,14 +1691,16 @@ export class BaseCompiler { } if (!backendOptions.skipAsm) { - if (result.okToCache) { - const res = this.processAsm(result, filters, options); - result.asm = res.asm; - result.labelDefinitions = res.labelDefinitions; - result.parsingTime = res.parsingTime; - result.filteredCount = res.filteredCount; - } else { - result.asm = [{text: result.asm}]; + if (typeof result.asm === 'string') { + if (result.okToCache) { + const res = this.processAsm(result, filters, options); + result.asm = res.asm; + result.labelDefinitions = res.labelDefinitions; + result.parsingTime = res.parsingTime; + result.filteredCount = res.filteredCount; + } else { + result.asm = [{text: result.asm}]; + } } // TODO rephrase this so we don't need to reassign result = filters.demangle ? await this.postProcessAsm(result, filters) : result; diff --git a/lib/external-parsers/base.ts b/lib/external-parsers/base.ts index 8c34d11c1..4a7b4d01d 100644 --- a/lib/external-parsers/base.ts +++ b/lib/external-parsers/base.ts @@ -1,17 +1,24 @@ import fs from 'fs'; import path from 'path'; -import { TypicalExecutionFunc } from '../../types/execution/execution.interfaces'; +import { TypicalExecutionFunc, UnprocessedExecResult } from '../../types/execution/execution.interfaces'; import { IParseFilters } from '../../types/features/filters.interfaces'; +import { maskRootdir } from '../utils'; import { IExternalParser, IParsedAsmResult } from './external-parser.interface'; +const starterScriptName = 'dump-and-parse.sh'; + export class ExternalParserBase implements IExternalParser { private objdumperPath: string; private parserPath: string; private execFunc: TypicalExecutionFunc; + private compilerInfo; + private envInfo; constructor(compilerInfo, envInfo, execFunc: TypicalExecutionFunc) { + this.compilerInfo = compilerInfo; + this.envInfo = envInfo; this.objdumperPath = compilerInfo.objdumper; this.parserPath = compilerInfo.externalparser.props('exe', ''); this.execFunc = execFunc; @@ -34,14 +41,14 @@ export class ExternalParserBase implements IExternalParser { private getObjdumpStarterScriptContent(filters: IParseFilters) { const parserArgs = this.getParserArguments(filters, true); - return '#!/bin/sh\n' + + return '#!/bin/bash\n' + `OBJDUMP=${this.objdumperPath}\n` + `ASMPARSER=${this.parserPath}\n` + `$OBJDUMP "$@" | $ASMPARSER ${parserArgs.join(' ')}\n`; } private async writeStarterScriptObjdump(buildfolder: string, filters: IParseFilters): Promise { - const scriptFilepath = path.join(buildfolder, 'dump-and-parse.sh'); + const scriptFilepath = path.join(buildfolder, starterScriptName); return new Promise((resolve) => { fs.writeFile(scriptFilepath, @@ -49,31 +56,36 @@ export class ExternalParserBase implements IExternalParser { encoding: 'utf8', mode: 0o777, }, () => { - resolve(scriptFilepath); + resolve(maskRootdir(scriptFilepath)); }); }); } - private parseAsmExecResult(execResult): IParsedAsmResult { - console.log(execResult.stdout); - console.log(execResult.stderr); - const result = Object.assign({}, JSON.parse(execResult.stdout)); - if (result.stderr) { - throw result.stderr; - } + private parseAsmExecResult(execResult: UnprocessedExecResult): IParsedAsmResult { + const result = Object.assign({}, execResult, JSON.parse(execResult.stdout)); + delete result.stdout; + delete result.stderr; return result; } public async objdumpAndParseAssembly(buildfolder: string, objdumpArgs: string[], filters: IParseFilters): Promise { - const scriptFilepath = await this.writeStarterScriptObjdump(buildfolder, filters); - const execOptions = {}; - const execResult = await this.execFunc(scriptFilepath, objdumpArgs, execOptions); + objdumpArgs = objdumpArgs.map((v) => { + return maskRootdir(v); + }); + await this.writeStarterScriptObjdump(buildfolder, filters); + const execOptions = { + env: this.envInfo.getEnv(this.compilerInfo.needsMulti), + customCwd: buildfolder, + }; + const execResult = await this.execFunc('./' + starterScriptName, objdumpArgs, execOptions); return this.parseAsmExecResult(execResult); } public async parseAssembly(filepath: string, filters: IParseFilters): Promise { - const execOptions = {}; + const execOptions = { + env: this.envInfo.getEnv(this.compilerInfo.needsMulti), + }; const parserArgs = this.getParserArguments(filters, false); parserArgs.push(filepath); diff --git a/types/execution/execution.interfaces.ts b/types/execution/execution.interfaces.ts index 04251c936..424e96ee8 100644 --- a/types/execution/execution.interfaces.ts +++ b/types/execution/execution.interfaces.ts @@ -9,4 +9,4 @@ export interface UnprocessedExecResult { execTime: string; } -export type TypicalExecutionFunc = (executable: string, args: string[], execOptions: object) => UnprocessedExecResult; +export type TypicalExecutionFunc = (executable: string, args: string[], execOptions: object) => IUnprocessedExecResult; From 1a58cb0aee6be37b8b09d2e5a3dce6fd5e5f3f10 Mon Sep 17 00:00:00 2001 From: partouf Date: Sat, 22 Jan 2022 20:52:03 +0100 Subject: [PATCH 08/11] new location --- etc/config/c++.amazon.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/etc/config/c++.amazon.properties b/etc/config/c++.amazon.properties index 6d4c493c1..57da80c4c 100644 --- a/etc/config/c++.amazon.properties +++ b/etc/config/c++.amazon.properties @@ -8,7 +8,7 @@ buildenvsetup=ceconan buildenvsetup.host=https://conan.compiler-explorer.com externalparser=CEAsmParser -externalparser.exe=/opt/compiler-explorer/asm-parser/build/bin/asm-parser +externalparser.exe=/usr/local/bin/asm-parser ############################### # GCC for x86 From ef51db4660d99b709ec0d51ee9f80e46e133e852 Mon Sep 17 00:00:00 2001 From: partouf Date: Sat, 22 Jan 2022 21:20:06 +0100 Subject: [PATCH 09/11] bugfix extparser discovery --- app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app.js b/app.js index 69515cb44..4c3a8bd37 100755 --- a/app.js +++ b/app.js @@ -488,7 +488,7 @@ async function main() { if (compiler.buildenvsetup && compiler.buildenvsetup.id === '') delete compiler.buildenvsetup; - if (compiler.externalparser && compiler.externalParser.id === '') + if (compiler.externalparser && compiler.externalparser.id === '') delete compiler.externalparser; const compilerInstance = compilerFinder.compileHandler.findCompiler(compiler.lang, compiler.id); From e74a57c935109952a10b94d7c63ea2f1b27751fe Mon Sep 17 00:00:00 2001 From: partouf Date: Sat, 22 Jan 2022 22:41:07 +0100 Subject: [PATCH 10/11] bugfix --- lib/base-compiler.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index e6d1b828e..df706c0d1 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -326,7 +326,7 @@ export class BaseCompiler { if (this.externalparser) { result = await this.externalparser.objdumpAndParseAssembly( - path.dirname(outputFilename), + result.dirPath, args, filters); } else { From 4f8f3ad80e129bc8eedf6ac7380e8245856eb2b6 Mon Sep 17 00:00:00 2001 From: partouf Date: Sun, 23 Jan 2022 00:53:32 +0100 Subject: [PATCH 11/11] fixes dontMaskFilenames, add external parsingtime --- lib/base-compiler.js | 8 ++++++-- lib/compilers/pascal-win.js | 2 +- lib/compilers/pascal.js | 2 +- lib/external-parsers/base.ts | 3 ++- types/features/filters.interfaces.ts | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/base-compiler.js b/lib/base-compiler.js index df706c0d1..78b54cc7b 100644 --- a/lib/base-compiler.js +++ b/lib/base-compiler.js @@ -329,6 +329,10 @@ export class BaseCompiler { result.dirPath, args, filters); + if (result.parsingTime !== undefined) { + result.objdumpTime = parseInt(result.execTime) - parseInt(result.parsingTime); + delete result.execTime; + } } else { const execOptions = {maxOutput: maxSize, customCwd: result.dirPath || path.dirname(outputFilename)}; const objResult = await this.exec(this.compiler.objdumper, args, execOptions); @@ -990,7 +994,7 @@ export class BaseCompiler { const inputFilename = path.join(dirPath, this.compileFilename); await fs.writeFile(inputFilename, source); - if (files) { + if (files && files.length > 0) { filters.dontMaskFilenames = true; await this.writeMultipleFiles(files, dirPath); @@ -1007,7 +1011,7 @@ export class BaseCompiler { const inputFilename = path.join(dirPath, 'CMakeLists.txt'); await fs.writeFile(inputFilename, source); - if (files) { + if (files && files.length > 0) { filters.dontMaskFilenames = true; await this.writeMultipleFiles(files, dirPath); diff --git a/lib/compilers/pascal-win.js b/lib/compilers/pascal-win.js index cef8a1856..b8dbfc7b0 100644 --- a/lib/compilers/pascal-win.js +++ b/lib/compilers/pascal-win.js @@ -126,7 +126,7 @@ export class PascalWinCompiler extends BaseCompiler { await fs.writeFile(inputFilename, source); - if (files) { + if (files && files.length > 0) { filters.dontMaskFilenames = true; await this.writeMultipleFiles(files, dirPath); diff --git a/lib/compilers/pascal.js b/lib/compilers/pascal.js index f4abd54fe..2da67f83e 100644 --- a/lib/compilers/pascal.js +++ b/lib/compilers/pascal.js @@ -153,7 +153,7 @@ export class FPCCompiler extends BaseCompiler { await fs.writeFile(inputFilename, source); } - if (files) { + if (files && files.length > 0) { filters.dontMaskFilenames = true; await this.writeMultipleFiles(files, dirPath); diff --git a/lib/external-parsers/base.ts b/lib/external-parsers/base.ts index 4a7b4d01d..a1a0665e5 100644 --- a/lib/external-parsers/base.ts +++ b/lib/external-parsers/base.ts @@ -34,6 +34,7 @@ export class ExternalParserBase implements IExternalParser { if (filters.commentOnly) parameters.push('-comment_only'); if (filters.trim) parameters.push('-whitespace'); if (filters.libraryCode) parameters.push('-library_functions'); + if (filters.dontMaskFilenames) parameters.push('-dont_mask_filenames'); return parameters; } @@ -78,7 +79,7 @@ export class ExternalParserBase implements IExternalParser { env: this.envInfo.getEnv(this.compilerInfo.needsMulti), customCwd: buildfolder, }; - const execResult = await this.execFunc('./' + starterScriptName, objdumpArgs, execOptions); + const execResult = await this.execFunc(`./${starterScriptName}`, objdumpArgs, execOptions); return this.parseAsmExecResult(execResult); } diff --git a/types/features/filters.interfaces.ts b/types/features/filters.interfaces.ts index 1cebce5f9..cc1696fec 100644 --- a/types/features/filters.interfaces.ts +++ b/types/features/filters.interfaces.ts @@ -9,4 +9,5 @@ export interface IParseFilters { optOutput: boolean; libraryCode: boolean; trim: boolean; + dontMaskFilenames?: boolean; }