From 753550d72acdff6ca6b52f9da05abf49aba6074b Mon Sep 17 00:00:00 2001 From: partouf Date: Fri, 21 Jan 2022 18:33:49 +0100 Subject: [PATCH] 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;