aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers/hook.ts
diff options
context:
space:
mode:
authorFábio de Souza Villaça Medeiros <fabiosvm@outlook.com>2023-01-13 13:25:35 -0300
committerGitHub <noreply@github.com>2023-01-13 17:25:35 +0100
commitb94325e3d2084036a4393cb551bfcf3d9e4750be (patch)
tree22dfa2dcc768bcea6f7b1794c7bbdf3831adb5cc /lib/compilers/hook.ts
parentb0de7de3e9434332a48258c418691a8aef650112 (diff)
downloadcompiler-explorer-b94325e3d2084036a4393cb551bfcf3d9e4750be.tar.gz
compiler-explorer-b94325e3d2084036a4393cb551bfcf3d9e4750be.zip
Add Line Mapping Support to Hook (#4580)gh-5780
Diffstat (limited to 'lib/compilers/hook.ts')
-rw-r--r--lib/compilers/hook.ts31
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/compilers/hook.ts b/lib/compilers/hook.ts
index c30c1a981..10443c189 100644
--- a/lib/compilers/hook.ts
+++ b/lib/compilers/hook.ts
@@ -28,6 +28,8 @@ import {CompilationResult, ExecutionOptions} from '../../types/compilation/compi
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
import {BaseCompiler} from '../base-compiler';
+import {AsmResultSource, ParsedAsmResultLine} from '../../types/asmresult/asmresult.interfaces';
+
export class HookCompiler extends BaseCompiler {
static get key(): string {
return 'hook';
@@ -52,4 +54,33 @@ export class HookCompiler extends BaseCompiler {
options.push(outputFilename);
return super.runCompiler(compiler, options, inputFilename, execOptions);
}
+
+ override processAsm(result) {
+ const commentRegex = /^\s*;(.*)/;
+ const instructionRegex = /^\s{2}(\d+)(.*)/;
+ const lines = result.asm.split('\n');
+ const asm: ParsedAsmResultLine[] = [];
+ let lastLineNo: number | undefined;
+ for (const line of lines) {
+ if (commentRegex.test(line)) {
+ asm.push({text: line, source: {line: undefined, file: null}});
+ lastLineNo = undefined;
+ continue;
+ }
+ const match = line.match(instructionRegex);
+ if (match) {
+ const lineNo = parseInt(match[1]);
+ asm.push({text: line, source: {line: lineNo, file: null}});
+ lastLineNo = lineNo;
+ continue;
+ }
+ if (line) {
+ asm.push({text: line, source: {line: lastLineNo, file: null}});
+ continue;
+ }
+ asm.push({text: line, source: {line: undefined, file: null}});
+ lastLineNo = undefined;
+ }
+ return {asm: asm};
+ }
}