This commit is contained in:
Patrick Quist
2022-01-22 23:56:53 +00:00
committed by GitHub
15 changed files with 222 additions and 31 deletions
+3
View File
@@ -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;
+3
View File
@@ -7,6 +7,9 @@ needsMulti=false
buildenvsetup=ceconan
buildenvsetup.host=https://conan.compiler-explorer.com
externalparser=CEAsmParser
externalparser.exe=/usr/local/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
+40 -18
View File
@@ -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';
@@ -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,28 @@ 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);
if (objResult.code !== 0) {
result.asm = `<No output: objdump returned ${objResult.code}>`;
if (this.externalparser) {
result = await this.externalparser.objdumpAndParseAssembly(
result.dirPath,
args,
filters);
if (result.parsingTime !== undefined) {
result.objdumpTime = parseInt(result.execTime) - parseInt(result.parsingTime);
delete result.execTime;
}
} else {
result.objdumpTime = objResult.execTime;
result.asm = this.postProcessObjdumpOutput(objResult.stdout);
const execOptions = {maxOutput: maxSize, customCwd: result.dirPath || path.dirname(outputFilename)};
const objResult = await this.exec(this.compiler.objdumper, args, execOptions);
if (objResult.code !== 0) {
result.asm = `<No output: objdump returned ${objResult.code}>`;
} else {
result.objdumpTime = objResult.execTime;
result.asm = this.postProcessObjdumpOutput(objResult.stdout);
}
}
return result;
}
@@ -974,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);
@@ -991,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);
@@ -1675,14 +1695,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;
@@ -1903,7 +1925,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 = '<No output file>';
+12
View File
@@ -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(
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
+1
View File
@@ -0,0 +1 @@
export { CEAsmParser } from './ce-asm-parser';
+97
View File
@@ -0,0 +1,97 @@
import fs from 'fs';
import path from 'path';
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;
}
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');
if (filters.dontMaskFilenames) parameters.push('-dont_mask_filenames');
return parameters;
}
private getObjdumpStarterScriptContent(filters: IParseFilters) {
const parserArgs = this.getParserArguments(filters, true);
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<string> {
const scriptFilepath = path.join(buildfolder, starterScriptName);
return new Promise((resolve) => {
fs.writeFile(scriptFilepath,
this.getObjdumpStarterScriptContent(filters), {
encoding: 'utf8',
mode: 0o777,
}, () => {
resolve(maskRootdir(scriptFilepath));
});
});
}
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<IParsedAsmResult> {
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<IParsedAsmResult> {
const execOptions = {
env: this.envInfo.getEnv(this.compilerInfo.needsMulti),
};
const parserArgs = this.getParserArguments(filters, false);
parserArgs.push(filepath);
const execResult = await this.execFunc(this.parserPath, parserArgs, execOptions);
return this.parseAsmExecResult(execResult);
}
}
+5
View File
@@ -0,0 +1,5 @@
import { ExternalParserBase } from './base';
export class CEAsmParser extends ExternalParserBase {
static get key() { return 'CEAsmParser'; }
}
@@ -0,0 +1,15 @@
import { IParseFilters } from '../../types/features/filters.interfaces';
import { IResultLineTag } from '../../types/resultline/resultline.interfaces';
export interface IParsedAsmResult {
asm: IResultLineTag[];
labelDefinitions: Map<string, number>;
parsingTime: string;
filteredCount: number;
}
export interface IExternalParser {
objdumpAndParseAssembly(buildfolder: string, objdumpArgs: string[],
filters: IParseFilters): Promise<IParsedAsmResult>;
parseAssembly(filepath: string, filters: IParseFilters): Promise<IParsedAsmResult>;
}
+7
View File
@@ -0,0 +1,7 @@
import { makeKeyedTypeGetter } from '../keyed-type';
import * as all from './_all';
export * from './_all';
export const getExternalParserByKey = makeKeyedTypeGetter('externalParser', all);
+1 -11
View File
@@ -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/;
+12
View File
@@ -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) => IUnprocessedExecResult;
+13
View File
@@ -0,0 +1,13 @@
export interface IParseFilters {
binary: boolean;
execute: boolean;
demangle: boolean;
intel: boolean;
commentOnly: boolean;
directives: boolean;
labels: boolean;
optOutput: boolean;
libraryCode: boolean;
trim: boolean;
dontMaskFilenames?: boolean;
}
+11
View File
@@ -0,0 +1,11 @@
export interface IResultLineTag {
line?: number;
column?: number;
file?: string;
text: string;
}
export interface IResultLine {
text: string;
tag?: IResultLineTag;
}