Skip to content

Commit 6a6efae

Browse files
Tsify lib/compilers (#4609)
1 parent 87203f7 commit 6a6efae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+829
-493
lines changed

lib/base-compiler.ts

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ import * as cfg from './cfg';
6060
import {CompilationEnvironment} from './compilation-env';
6161
import {CompilerArguments} from './compiler-arguments';
6262
import {ClangParser, GCCParser} from './compilers/argument-parsers';
63-
import {getDemanglerTypeByKey} from './demangler';
63+
import {BaseDemangler, getDemanglerTypeByKey} from './demangler';
6464
import {LLVMIRDemangler} from './demangler/llvm';
6565
import * as exec from './exec';
6666
import {getExternalParserByKey} from './external-parsers';
@@ -94,7 +94,7 @@ const executionTimeHistogram = new PromClient.Histogram({
9494
});
9595

9696
export class BaseCompiler implements ICompiler {
97-
protected compiler: CompilerInfo & Record<string, any>; // TODO: Some missing types still present in Compiler type
97+
protected compiler: CompilerInfo; // TODO: Some missing types still present in Compiler type
9898
public lang: Language;
9999
protected compileFilename: string;
100100
protected env: CompilationEnvironment;
@@ -111,7 +111,7 @@ export class BaseCompiler implements ICompiler {
111111
protected toolchainPath: any;
112112
public possibleArguments: CompilerArguments;
113113
protected possibleTools: ITool[];
114-
protected demanglerClass: any;
114+
protected demanglerClass: typeof BaseDemangler | null = null;
115115
protected objdumperClass: any;
116116
public outputFilebase: string;
117117
protected mtime: Date | null = null;
@@ -126,7 +126,7 @@ export class BaseCompiler implements ICompiler {
126126
labelNames: [],
127127
});
128128

129-
constructor(compilerInfo: CompilerInfo & Record<string, any>, env: CompilationEnvironment) {
129+
constructor(compilerInfo: CompilerInfo, env: CompilationEnvironment) {
130130
// Information about our compiler
131131
this.compiler = compilerInfo;
132132
this.lang = languages[compilerInfo.lang];
@@ -300,7 +300,7 @@ export class BaseCompiler implements ICompiler {
300300
});
301301
}
302302

303-
optOutputRequested(options) {
303+
optOutputRequested(options: string[]) {
304304
return options.includes('-fsave-optimization-record');
305305
}
306306

@@ -401,7 +401,7 @@ export class BaseCompiler implements ICompiler {
401401
return !!this.objdumperClass;
402402
}
403403

404-
getObjdumpOutputFilename(defaultOutputFilename) {
404+
getObjdumpOutputFilename(defaultOutputFilename: string): string {
405405
return defaultOutputFilename;
406406
}
407407

@@ -533,7 +533,7 @@ export class BaseCompiler implements ICompiler {
533533
return outputFilename.replace(path.extname(outputFilename), '.dump');
534534
}
535535

536-
getGccDumpOptions(gccDumpOptions, outputFilename) {
536+
getGccDumpOptions(gccDumpOptions, outputFilename: string) {
537537
const addOpts = ['-fdump-passes'];
538538

539539
// Build dump options to append to the end of the -fdump command-line flag.
@@ -756,7 +756,7 @@ export class BaseCompiler implements ICompiler {
756756
}) as string[];
757757
}
758758

759-
getSharedLibraryLinks(libraries): string[] {
759+
getSharedLibraryLinks(libraries: any[]): string[] {
760760
const linkFlag = this.compiler.linkFlag || '-l';
761761

762762
return _.flatten(
@@ -1248,7 +1248,7 @@ export class BaseCompiler implements ICompiler {
12481248
return [{text: 'Internal error; unable to open output path'}];
12491249
}
12501250

1251-
getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string {
1251+
getIrOutputFilename(inputFilename: string, filters?: ParseFiltersAndOutputOptions): string {
12521252
return inputFilename.replace(path.extname(inputFilename), '.ll');
12531253
}
12541254

@@ -1267,7 +1267,7 @@ export class BaseCompiler implements ICompiler {
12671267
}
12681268
}
12691269

1270-
getExecutableFilename(dirPath, outputFilebase, key?) {
1270+
getExecutableFilename(dirPath: string, outputFilebase: string, key?) {
12711271
return this.getOutputFilename(dirPath, outputFilebase, key);
12721272
}
12731273

@@ -1436,7 +1436,7 @@ export class BaseCompiler implements ICompiler {
14361436
result.artifacts.push(artifact);
14371437
}
14381438

1439-
protected async writeMultipleFiles(files, dirPath) {
1439+
protected async writeMultipleFiles(files: any[], dirPath: string) {
14401440
const filesToWrite: Promise<void>[] = [];
14411441

14421442
for (const file of files) {
@@ -1449,7 +1449,12 @@ export class BaseCompiler implements ICompiler {
14491449
return Promise.all(filesToWrite);
14501450
}
14511451

1452-
protected async writeAllFiles(dirPath, source, files, filters: ParseFiltersAndOutputOptions) {
1452+
protected async writeAllFiles(
1453+
dirPath: string,
1454+
source: string,
1455+
files: any[],
1456+
filters: ParseFiltersAndOutputOptions,
1457+
) {
14531458
if (!source) throw new Error(`File ${this.compileFilename} has no content or file is missing`);
14541459

14551460
const inputFilename = path.join(dirPath, this.compileFilename);
@@ -1479,7 +1484,7 @@ export class BaseCompiler implements ICompiler {
14791484
};
14801485
}
14811486

1482-
async buildExecutableInFolder(key, dirPath): Promise<BuildResult> {
1487+
async buildExecutableInFolder(key, dirPath: string): Promise<BuildResult> {
14831488
const writeSummary = await this.writeAllFiles(dirPath, key.source, key.files, key.filters);
14841489
const downloads = await this.setupBuildEnvironment(key, dirPath, true);
14851490

@@ -2237,7 +2242,10 @@ export class BaseCompiler implements ICompiler {
22372242

22382243
if (!bypassCache) {
22392244
const cacheRetreiveTimeStart = process.hrtime.bigint();
2240-
const result = await this.env.cacheGet(key);
2245+
// TODO: We should be able to eliminate this any cast. `key` should be cacheable (if it's not that's a big
2246+
// problem) Because key coantains a CompilerInfo which contains a function member it can't be assigned to a
2247+
// CacheableValue.
2248+
const result = await this.env.cacheGet(key as any);
22412249
if (result) {
22422250
const cacheRetreiveTimeEnd = process.hrtime.bigint();
22432251
result.retreivedFromCacheTime = (
@@ -2762,7 +2770,7 @@ but nothing was dumped. Possible causes are:
27622770
return this.compiler;
27632771
}
27642772

2765-
getDefaultFilters() {
2773+
getDefaultFilters(): ParseFiltersAndOutputOptions {
27662774
return {
27672775
binary: false,
27682776
execute: false,
@@ -2774,6 +2782,7 @@ but nothing was dumped. Possible causes are:
27742782
optOutput: false,
27752783
libraryCode: false,
27762784
trim: false,
2785+
binaryObject: false,
27772786
};
27782787
}
27792788
}
File renamed without changes.

lib/compilers/ada.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,8 @@
2525

2626
import path from 'path';
2727

28-
import fs from 'fs-extra';
29-
30-
import {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces';
28+
import {CompilerInfo} from '../../types/compiler.interfaces';
29+
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
3130
import {BaseCompiler} from '../base-compiler';
3231
import * as utils from '../utils';
3332

@@ -36,7 +35,7 @@ export class AdaCompiler extends BaseCompiler {
3635
return 'ada';
3736
}
3837

39-
constructor(info, env) {
38+
constructor(info: CompilerInfo, env) {
4039
super(info, env);
4140
this.compiler.supportsGccDump = true;
4241
this.compiler.removeEmptyGccDump = true;
@@ -45,7 +44,7 @@ export class AdaCompiler extends BaseCompiler {
4544
this.compiler.supportsGnatDebugViews = true;
4645
}
4746

48-
override getExecutableFilename(dirPath) {
47+
override getExecutableFilename(dirPath: string, outputFilebase: string, key?) {
4948
// The name here must match the value used in the pragma Source_File
5049
// in the user provided source.
5150
return path.join(dirPath, 'example');
@@ -70,7 +69,14 @@ export class AdaCompiler extends BaseCompiler {
7069
}
7170
}
7271

73-
override prepareArguments(userOptions, filters, backendOptions, inputFilename, outputFilename, libraries) {
72+
override prepareArguments(
73+
userOptions: string[],
74+
filters: ParseFiltersAndOutputOptions,
75+
backendOptions: Record<string, any>,
76+
inputFilename: string,
77+
outputFilename: string,
78+
libraries,
79+
) {
7480
backendOptions = backendOptions || {};
7581

7682
// super call is needed as it handles the GCC Dump files.

lib/compilers/analysis-tool.js renamed to lib/compilers/analysis-tool.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2323
// POSSIBILITY OF SUCH DAMAGE.
2424

25+
import {CompilerInfo} from '../../types/compiler.interfaces';
2526
import {BaseCompiler} from '../base-compiler';
2627

2728
// Plain compiler, which just runs the tool and returns whatever the output was
@@ -30,20 +31,26 @@ export class AnalysisTool extends BaseCompiler {
3031
return 'analysis-tool';
3132
}
3233

33-
constructor(info, env) {
34+
constructor(info: CompilerInfo, env) {
3435
// Default is to disable all "cosmetic" filters
3536
if (!info.disabledFilters) info.disabledFilters = ['labels', 'directives', 'commentOnly', 'trim'];
3637
super(info, env);
3738
}
3839

39-
getDefaultFilters() {
40+
override getDefaultFilters() {
4041
// Disable everything but intel syntax
4142
return {
4243
intel: true,
4344
commentOnly: false,
4445
directives: false,
4546
labels: false,
4647
optOutput: false,
48+
binary: false,
49+
execute: false,
50+
demangle: false,
51+
libraryCode: false,
52+
trim: false,
53+
binaryObject: false,
4754
};
4855
}
4956
}

lib/compilers/assembly.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import path from 'path';
2828
import _ from 'underscore';
2929

3030
import {BuildResult} from '../../types/compilation/compilation.interfaces';
31+
import {CompilerInfo} from '../../types/compiler.interfaces';
3132
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
3233
import {BaseCompiler} from '../base-compiler';
3334
import {AsmRaw} from '../parsers/asm-raw';
@@ -40,7 +41,7 @@ export class AssemblyCompiler extends BaseCompiler {
4041
return 'assembly';
4142
}
4243

43-
constructor(info, env) {
44+
constructor(info: CompilerInfo, env) {
4445
super(info, env);
4546
this.asm = new AsmRaw();
4647
}
@@ -53,12 +54,12 @@ export class AssemblyCompiler extends BaseCompiler {
5354
return BaseParser;
5455
}
5556

56-
override optionsForFilter(filters) {
57+
override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string, userOptions?: string[]) {
5758
filters.binary = true;
5859
return [];
5960
}
6061

61-
getGeneratedOutputFilename(fn) {
62+
getGeneratedOutputFilename(fn: string) {
6263
const outputFolder = path.dirname(fn);
6364
const files = fs.readdirSync(outputFolder);
6465

@@ -72,7 +73,7 @@ export class AssemblyCompiler extends BaseCompiler {
7273
return outputFilename;
7374
}
7475

75-
override getOutputFilename(dirPath) {
76+
override getOutputFilename(dirPath: string) {
7677
return this.getGeneratedOutputFilename(path.join(dirPath, 'example.asm'));
7778
}
7879

@@ -126,11 +127,11 @@ export class AssemblyCompiler extends BaseCompiler {
126127
return this.doBuildstepAndAddToResult(fullResult, 'ld', this.env.ceProps('ld'), options, execOptions);
127128
}
128129

129-
override getExecutableFilename(dirPath) {
130+
override getExecutableFilename(dirPath: string) {
130131
return path.join(dirPath, 'ce-asm-executable');
131132
}
132133

133-
override async buildExecutableInFolder(key, dirPath): Promise<BuildResult> {
134+
override async buildExecutableInFolder(key, dirPath: string): Promise<BuildResult> {
134135
const buildEnvironment = this.setupBuildEnvironment(key, dirPath, true);
135136

136137
const writeSummary = await this.writeAllFiles(dirPath, key.source, key.files, key.filters);
@@ -178,11 +179,11 @@ export class AssemblyCompiler extends BaseCompiler {
178179
return fullResult;
179180
}
180181

181-
override checkOutputFileAndDoPostProcess(asmResult, outputFilename, filters) {
182+
override checkOutputFileAndDoPostProcess(asmResult, outputFilename, filters: ParseFiltersAndOutputOptions) {
182183
return this.postProcess(asmResult, outputFilename, filters);
183184
}
184185

185-
override getObjdumpOutputFilename(defaultOutputFilename) {
186+
override getObjdumpOutputFilename(defaultOutputFilename: string): string {
186187
return this.getGeneratedOutputFilename(defaultOutputFilename);
187188
}
188189

lib/compilers/avrgcc6502.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424

2525
import path from 'path';
2626

27+
import {ExecutionOptions} from '../../types/compilation/compilation.interfaces';
28+
import {CompilerInfo} from '../../types/compiler.interfaces';
29+
import {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces';
2730
import {BaseCompiler} from '../base-compiler';
2831

2932
export class AvrGcc6502Compiler extends BaseCompiler {
@@ -35,7 +38,7 @@ export class AvrGcc6502Compiler extends BaseCompiler {
3538
return 'avrgcc6502';
3639
}
3740

38-
constructor(compilerInfo, env) {
41+
constructor(compilerInfo: CompilerInfo, env) {
3942
super(compilerInfo, env);
4043

4144
this.avrgccpath = this.compilerProps<string>(`compiler.${this.compiler.id}.avrgccpath`);
@@ -44,7 +47,7 @@ export class AvrGcc6502Compiler extends BaseCompiler {
4447
this.outputFilebase = 'example';
4548
}
4649

47-
public override getOutputFilename(dirPath, outputFilebase, key) {
50+
public override getOutputFilename(dirPath: string, outputFilebase: string, key?: any) {
4851
let filename;
4952
if (key && key.backendOptions && key.backendOptions.customOutputFilename) {
5053
filename = key.backendOptions.customOutputFilename;
@@ -59,11 +62,16 @@ export class AvrGcc6502Compiler extends BaseCompiler {
5962
}
6063
}
6164

62-
protected override optionsForFilter(filters: object, outputFilename: string): string[] {
65+
protected override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string): string[] {
6366
return [`-I${this.avrlibstdcpppath}`];
6467
}
6568

66-
public override async runCompiler(compiler, options, inputFilename, execOptions) {
69+
public override async runCompiler(
70+
compiler: string,
71+
options: string[],
72+
inputFilename: string,
73+
execOptions: ExecutionOptions,
74+
) {
6775
if (!execOptions) {
6876
execOptions = this.getDefaultExecOptions();
6977
}

lib/compilers/beebasm.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ import path from 'path';
2626

2727
import fs from 'fs-extra';
2828

29+
import {ExecutionOptions} from '../../types/compilation/compilation.interfaces';
30+
import {CompilerInfo} from '../../types/compiler.interfaces';
2931
import {ArtifactType} from '../../types/tool.interfaces';
3032
import {BaseCompiler} from '../base-compiler';
3133
import {AsmParserBeebAsm} from '../parsers/asm-parser-beebasm';
@@ -36,7 +38,7 @@ export class BeebAsmCompiler extends BaseCompiler {
3638
return 'beebasm';
3739
}
3840

39-
constructor(compilerInfo, env) {
41+
constructor(compilerInfo: CompilerInfo, env) {
4042
super(compilerInfo, env);
4143

4244
this.asm = new AsmParserBeebAsm(this.compilerProps);
@@ -50,7 +52,12 @@ export class BeebAsmCompiler extends BaseCompiler {
5052
return [];
5153
}
5254

53-
override async runCompiler(compiler, options, inputFilename, execOptions) {
55+
override async runCompiler(
56+
compiler: string,
57+
options: string[],
58+
inputFilename: string,
59+
execOptions: ExecutionOptions,
60+
) {
5461
if (!execOptions) {
5562
execOptions = this.getDefaultExecOptions();
5663
}

lib/compilers/carbon.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export class CarbonCompiler extends BaseCompiler {
3737
return 'carbon';
3838
}
3939

40-
constructor(compilerInfo: CompilerInfo & Record<string, any>, env) {
40+
constructor(compilerInfo: CompilerInfo, env) {
4141
super(compilerInfo, env);
4242
this.compiler.demangler = '';
4343
this.demanglerClass = null;

0 commit comments

Comments
 (0)