From 9a6c961345dfd2aaa0affdf7ef5ae46d2c29ecfb Mon Sep 17 00:00:00 2001 From: Ofek Shilon Date: Thu, 10 Oct 2024 02:01:38 +0300 Subject: [PATCH] can't... stop... adding... types --- lib/base-compiler.ts | 2 +- lib/compilers/carbon.ts | 6 +++++- lib/compilers/hlsl.ts | 2 +- lib/compilers/hook.ts | 2 +- lib/compilers/mlir.ts | 2 +- lib/compilers/pascal-win.ts | 2 +- lib/compilers/pascal.ts | 2 +- lib/compilers/racket.ts | 2 +- lib/compilers/v.ts | 2 +- lib/compilers/win32.ts | 14 +++++++++----- lib/parsers/asm-parser-dotnet.ts | 5 +++-- lib/parsers/asm-parser-mads.ts | 16 ++++++++-------- test/compilers/hook-tests.ts | 2 +- 13 files changed, 34 insertions(+), 25 deletions(-) diff --git a/lib/base-compiler.ts b/lib/base-compiler.ts index 46339acc5..93cf05ed8 100644 --- a/lib/base-compiler.ts +++ b/lib/base-compiler.ts @@ -2997,7 +2997,7 @@ export class BaseCompiler implements ICompiler { return result; } - async processAsm(result, filters, options) { + async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) { if ((options && options.includes('-emit-llvm')) || this.llvmIr.isLlvmIr(result.asm)) { return await this.llvmIr.processFromFilters(result.asm, filters); } diff --git a/lib/compilers/carbon.ts b/lib/compilers/carbon.ts index 87c5b0dd3..b0ec58c17 100644 --- a/lib/compilers/carbon.ts +++ b/lib/compilers/carbon.ts @@ -47,7 +47,11 @@ export class CarbonCompiler extends BaseCompiler { return ['--color', `--trace_file=${outputFilename}`]; } - override async processAsm(result, filters, options): Promise { + override async processAsm( + result, + filters: ParseFiltersAndOutputOptions, + options: string[], + ): Promise { // Really should write a custom parser, but for now just don't filter anything. return await super.processAsm( result, diff --git a/lib/compilers/hlsl.ts b/lib/compilers/hlsl.ts index eb42685c8..9e58f1a05 100644 --- a/lib/compilers/hlsl.ts +++ b/lib/compilers/hlsl.ts @@ -95,7 +95,7 @@ export class HLSLCompiler extends BaseCompiler { return options; } - override async processAsm(result, filters, options) { + override async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) { if (this.isSpirv(result.asm)) { return this.spirvAsm.processAsm(result.asm, filters); } diff --git a/lib/compilers/hook.ts b/lib/compilers/hook.ts index 91959cbc2..7ee14e128 100644 --- a/lib/compilers/hook.ts +++ b/lib/compilers/hook.ts @@ -79,7 +79,7 @@ export class HookCompiler extends BaseCompiler { return super.runCompiler(compiler, options, inputFilename, execOptions); } - override async processAsm(result, filters, options) { + override async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) { // Ignoring `trim` filter because it is not supported by Hook. filters.trim = false; const _result = await super.processAsm(result, filters, options); diff --git a/lib/compilers/mlir.ts b/lib/compilers/mlir.ts index 4803f09a9..1e20aa737 100644 --- a/lib/compilers/mlir.ts +++ b/lib/compilers/mlir.ts @@ -81,7 +81,7 @@ export class MLIRCompiler extends BaseCompiler { return []; } - override async processAsm(result, filters, options) { + override async processAsm(result, filters: ParseFiltersAndOutputOptions, options: string[]) { // at some point maybe a custom parser can be written, for now just don't filter anything return super.processAsm( result, diff --git a/lib/compilers/pascal-win.ts b/lib/compilers/pascal-win.ts index 5110fc39a..f861cd8ac 100644 --- a/lib/compilers/pascal-win.ts +++ b/lib/compilers/pascal-win.ts @@ -193,7 +193,7 @@ export class PascalWinCompiler extends BaseCompiler { override optionsForFilter(filters: ParseFiltersAndOutputOptions) { filters.binary = true; filters.dontMaskFilenames = true; - (filters as any).preProcessBinaryAsmLines = (asmLines: string[]) => { + filters.preProcessBinaryAsmLines = (asmLines: string[]) => { const mapFileReader = new MapFileReaderDelphi(unwrap(this.mapFilename)); const reconstructor = new PELabelReconstructor(asmLines, false, mapFileReader, false); reconstructor.run('output'); diff --git a/lib/compilers/pascal.ts b/lib/compilers/pascal.ts index 425c740da..4c77cfc11 100644 --- a/lib/compilers/pascal.ts +++ b/lib/compilers/pascal.ts @@ -63,7 +63,7 @@ export class FPCCompiler extends BaseCompiler { return []; } - override async processAsm(result, filters) { + override async processAsm(result, filters: ParseFiltersAndOutputOptions) { // TODO: Pascal doesn't have a demangler exe, it's the only compiler that's weird like this this.demangler = new (unwrap(this.demanglerClass))(null as any, this); return this.asm.process(result.asm, filters); diff --git a/lib/compilers/racket.ts b/lib/compilers/racket.ts index 89c582274..3ce3daf1d 100644 --- a/lib/compilers/racket.ts +++ b/lib/compilers/racket.ts @@ -175,7 +175,7 @@ export class RacketCompiler extends BaseCompiler { return result; } - override async processAsm(result: any, filters: any, options: any) { + override async processAsm(result: any, filters: ParseFiltersAndOutputOptions, options: string[]) { // TODO: Process and highlight decompiled output return { asm: [{text: result.asm}], diff --git a/lib/compilers/v.ts b/lib/compilers/v.ts index bb40b7a66..cf6ab3cce 100644 --- a/lib/compilers/v.ts +++ b/lib/compilers/v.ts @@ -68,7 +68,7 @@ export class VCompiler extends BaseCompiler { return compilerOptions; } - override async processAsm(result: any, filters, options: string[]): Promise { + override async processAsm(result: any, filters: ParseFiltersAndOutputOptions, options: string[]): Promise { const backend = this.getBackendFromOptions(options); switch (backend) { case 'c': diff --git a/lib/compilers/win32.ts b/lib/compilers/win32.ts index 8701a4840..e19ae2250 100644 --- a/lib/compilers/win32.ts +++ b/lib/compilers/win32.ts @@ -26,7 +26,11 @@ import path from 'path'; import _ from 'underscore'; -import type {CompileChildLibraries, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; +import type { + CacheKey, + CompileChildLibraries, + ExecutionOptions, +} from '../../types/compilation/compilation.interfaces.js'; import type {ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; @@ -55,7 +59,7 @@ export class Win32Compiler extends BaseCompiler { return ['/std:']; } - override getExecutableFilename(dirPath: string, outputFilebase: string, key?) { + override getExecutableFilename(dirPath: string, outputFilebase: string, key?: CacheKey) { return this.getOutputFilename(dirPath, outputFilebase, key) + '.exe'; } @@ -81,7 +85,7 @@ export class Win32Compiler extends BaseCompiler { ); } - override getStaticLibraryLinks(libraries) { + override getStaticLibraryLinks(libraries: CompileChildLibraries[]) { return super.getSortedStaticLibraries(libraries).map(lib => { return '"' + lib + '.lib"'; }); @@ -142,7 +146,7 @@ export class Win32Compiler extends BaseCompiler { const mapFilename = outputFilename + '.map'; const mapFileReader = new MapFileReaderVS(mapFilename); - (filters as any).preProcessBinaryAsmLines = asmLines => { + filters.preProcessBinaryAsmLines = asmLines => { const reconstructor = new PELabelReconstructor(asmLines, false, mapFileReader); reconstructor.run('output.s.obj'); @@ -168,7 +172,7 @@ export class Win32Compiler extends BaseCompiler { } } - override async processAsm(result, filters /*, options*/) { + override async processAsm(result, filters: ParseFiltersAndOutputOptions) { if (filters.binary) { filters.dontMaskFilenames = true; return this.binaryAsmParser.process(result.asm, filters); diff --git a/lib/parsers/asm-parser-dotnet.ts b/lib/parsers/asm-parser-dotnet.ts index 4c0455354..a576f26e4 100644 --- a/lib/parsers/asm-parser-dotnet.ts +++ b/lib/parsers/asm-parser-dotnet.ts @@ -22,6 +22,7 @@ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. +import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import * as utils from '../utils.js'; import {IAsmParser} from './asm-parser.interfaces.js'; @@ -132,7 +133,7 @@ export class DotNetAsmParser implements IAsmParser { return cleanedAsm; } - process(asmResult: string, filters) { + process(asmResult: string, filters: ParseFiltersAndOutputOptions) { const startTime = process.hrtime.bigint(); const asm: { @@ -150,7 +151,7 @@ export class DotNetAsmParser implements IAsmParser { asmLines = asmLines.flatMap(l => (commentRe.test(l) ? [] : [l])); } - const result = this.scanLabelsAndMethods(asmLines, filters.labels); + const result = this.scanLabelsAndMethods(asmLines, filters.labels!); for (const i in result.labelDef) { const label = result.labelDef[i]; diff --git a/lib/parsers/asm-parser-mads.ts b/lib/parsers/asm-parser-mads.ts index 9e7a6454e..2a70f7efc 100644 --- a/lib/parsers/asm-parser-mads.ts +++ b/lib/parsers/asm-parser-mads.ts @@ -78,17 +78,17 @@ export class MadsAsmParser extends AsmParser { line: string, source: AsmResultSource | undefined | null, filters: ParseFiltersAndOutputOptions, - match, + matchGroups: {[key: string]: string}, ): ParsedAsmResultLine { const labelsInLine: AsmResultLabel[] = []; - const address = parseInt(match.groups.address, 16); - const opcodes = (match.groups.opcodes || '').split(' ').filter(x => !!x); + const address = parseInt(matchGroups.address, 16); + const opcodes = (matchGroups.opcodes || '').split(' ').filter(x => !!x); let text = ''; - if (match.groups.label) { - text = match.groups.label.trim() + ': '; + if (matchGroups.label) { + text = matchGroups.label.trim() + ': '; } - const disassembly = ' ' + AsmRegex.filterAsmLine(match.groups.disasm, filters); + const disassembly = ' ' + AsmRegex.filterAsmLine(matchGroups.disasm, filters); const destMatch = line.match(this.destRe); if (destMatch) { const labelName = destMatch[2]; @@ -152,7 +152,7 @@ export class MadsAsmParser extends AsmParser { assert(match.groups); labelDefinitions[match.groups.label] = asm.length; - asm.push(this.getAsmLineWithOpcodeReMatch(line, source, filters, match)); + asm.push(this.getAsmLineWithOpcodeReMatch(line, source, filters, match.groups)); continue; } @@ -161,7 +161,7 @@ export class MadsAsmParser extends AsmParser { if (match) { assert(match.groups); - const parsedLine = this.getAsmLineWithOpcodeReMatch(line, source, filters, match); + const parsedLine = this.getAsmLineWithOpcodeReMatch(line, source, filters, match.groups); parsedLine.text = linePrefix + parsedLine.text; asm.push(parsedLine); diff --git a/test/compilers/hook-tests.ts b/test/compilers/hook-tests.ts index 85ed24198..7d811307f 100644 --- a/test/compilers/hook-tests.ts +++ b/test/compilers/hook-tests.ts @@ -156,7 +156,7 @@ describe('Hook compiler', () => { labelDefinitions: {}, }; const filters = {trim: false}; - const result = await hook.processAsm({asm: asm}, filters, null); + const result = await hook.processAsm({asm: asm}, filters, []); delete result.parsingTime; expect(result).toEqual(expected); });