From ec00e4e6aca37c9c43226c10d745de67fd5ad5e0 Mon Sep 17 00:00:00 2001 From: Jeremy <51220084+jeremy-rifkin@users.noreply.github.com> Date: Thu, 15 Jun 2023 19:38:59 -0400 Subject: [PATCH] Some quick llvm ir fixes --- lib/demangler/base.ts | 8 +++++--- lib/demangler/tic2000.ts | 3 +-- lib/llvm-ir.ts | 8 +++++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/demangler/base.ts b/lib/demangler/base.ts index 60dd089e0..1befdbea1 100644 --- a/lib/demangler/base.ts +++ b/lib/demangler/base.ts @@ -36,12 +36,12 @@ import {PrefixTree} from './prefix-tree.js'; export class BaseDemangler extends AsmRegex { readonly demanglerExe: string; - demanglerArguments: string[]; + readonly demanglerArguments: string[]; symbolstore: SymbolStore | null; othersymbols: SymbolStore; result: ParsedAsmResult; input: string[]; - includeMetadata: boolean; + readonly includeMetadata: boolean; readonly compiler: BaseCompiler; readonly jumpDef = /(j\w+|b|bl|blx)\s+([$_a-z][\w$@]*)/i; @@ -212,14 +212,16 @@ export class BaseDemangler extends AsmRegex { if (!this.symbolstore) { this.symbolstore = new SymbolStore(); - this.collectLabels(); } + this.collectLabels(); + options.input = this.getInput(); if (options.input === '') { return this.result; } + return this.processOutput(await this.execDemangler(options)); } } diff --git a/lib/demangler/tic2000.ts b/lib/demangler/tic2000.ts index 0a14cd0ff..d4b3241ac 100644 --- a/lib/demangler/tic2000.ts +++ b/lib/demangler/tic2000.ts @@ -30,7 +30,6 @@ export class TiC2000Demangler extends CppDemangler { } constructor(demanglerExe, compiler) { - super(demanglerExe, compiler); - this.demanglerArguments = ['-q']; + super(demanglerExe, compiler, ['-q']); } } diff --git a/lib/llvm-ir.ts b/lib/llvm-ir.ts index 4ddf9e58f..68377081b 100644 --- a/lib/llvm-ir.ts +++ b/lib/llvm-ir.ts @@ -45,13 +45,12 @@ export class LlvmIrParser { private metaNodeOptionsRe: RegExp; private llvmDebugLine: RegExp; private llvmDebugAnnotation: RegExp; + private otherMetadataAnnotation: RegExp; private attributeAnnotation: RegExp; private attributeDirective: RegExp; private moduleMetadata: RegExp; private functionAttrs: RegExp; - // TODO(jeremy-rifkin) can awful state things happen because of soring a demangler? Usually they're constructed - // fresh for each compile. constructor(compilerProps, private readonly irDemangler: LLVMIRDemangler) { this.maxIrLines = 5000; if (compilerProps) { @@ -66,6 +65,7 @@ export class LlvmIrParser { this.llvmDebugLine = /^\s*call void @llvm\.dbg\..*$/; this.llvmDebugAnnotation = /,? !dbg !\d+/; + this.otherMetadataAnnotation = /,? !(?!dbg)[\w.]+ (!\d+)/; this.attributeAnnotation = /,? #\d+(?= )/; this.attributeDirective = /^attributes #\d+ = { .+ }$/; this.functionAttrs = /^; Function Attrs: .+$/; @@ -150,7 +150,8 @@ export class LlvmIrParser { const result: IRResultLine[] = []; const irLines = utils.splitLines(ir); const debugInfo: Record = {}; - let prevLineEmpty = false; + // Set to true initially to prevent any leading newlines as a result of filtering + let prevLineEmpty = true; const filters: RegExp[] = []; const lineFilters: RegExp[] = []; @@ -164,6 +165,7 @@ export class LlvmIrParser { filters.push(this.metaNodeRe); filters.push(this.otherMetaDirective); filters.push(this.namedMetaDirective); + lineFilters.push(this.otherMetadataAnnotation); } if (options.filterAttributes) { filters.push(this.attributeDirective);