diff options
author | Alex D <duzhar@googlemail.com> | 2023-06-20 02:26:35 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-19 20:26:35 -0500 |
commit | a34f81241cf9fd5969cf11e592d498d75da4e8d8 (patch) | |
tree | 43f417d1ffe828a12db52f8cdc7d3d4cabb708ca /lib/compilers/typescript-native.ts | |
parent | 7651874a98982430258c4c037221229b92ca69d7 (diff) | |
download | compiler-explorer-a34f81241cf9fd5969cf11e592d498d75da4e8d8.tar.gz compiler-explorer-a34f81241cf9fd5969cf11e592d498d75da4e8d8.zip |
Added TypeScript Native ver 0.0.35-alpha (#5136)gh-7882
Added TypeScript Native ver 0.0.35-alpha
Diffstat (limited to 'lib/compilers/typescript-native.ts')
-rw-r--r-- | lib/compilers/typescript-native.ts | 123 |
1 files changed, 50 insertions, 73 deletions
diff --git a/lib/compilers/typescript-native.ts b/lib/compilers/typescript-native.ts index adf3db24d..a830dd910 100644 --- a/lib/compilers/typescript-native.ts +++ b/lib/compilers/typescript-native.ts @@ -23,15 +23,15 @@ // POSSIBILITY OF SUCH DAMAGE. import Semver from 'semver'; +import path from 'path'; -import type {CompilationResult, ExecutionOptions} from '../../types/compilation/compilation.interfaces.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; +import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import {asSafeVer} from '../utils.js'; import {TypeScriptNativeParser} from './argument-parsers.js'; -import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; export class TypeScriptNativeCompiler extends BaseCompiler { static get key() { @@ -41,107 +41,84 @@ export class TypeScriptNativeCompiler extends BaseCompiler { tscJit: string; tscSharedLib: string; tscNewOutput: boolean; + tscAsmOutput: boolean; constructor(compilerInfo: PreliminaryCompilerInfo, env) { super(compilerInfo, env); - this.compiler.supportsIntel = false; - this.compiler.supportsIrView = true; - this.tscJit = this.compiler.exe; this.tscSharedLib = this.compilerProps<string>(`compiler.${this.compiler.id}.sharedlibs`); this.tscNewOutput = Semver.gt(asSafeVer(this.compiler.semver || '0.0.0'), '0.0.32', true); + this.tscAsmOutput = Semver.gt(asSafeVer(this.compiler.semver || '0.0.0'), '0.0.34', true); + + this.compiler.irArg = ['--emit=llvm']; + this.compiler.supportsIntel = this.tscAsmOutput; + this.compiler.supportsIrView = true; } override getSharedLibraryPathsAsArguments() { return []; } - override optionsForFilter(filters: ParseFiltersAndOutputOptions, outputFilename: string) { - return [this.filename(outputFilename)]; - } - - override async handleInterpreting(key, executeParameters) { - executeParameters.args = [ - '--emit=jit', - this.tscSharedLib ? '--shared-libs=' + this.tscSharedLib : '-nogc', - ...executeParameters.args, - ]; + override optionsForFilter( + filters: ParseFiltersAndOutputOptions, + outputFilename: string, + userOptions?: string[], + ): string[] { + return []; + } - return await super.handleInterpreting(key, executeParameters); - } + override optionsForBackend(backendOptions: Record<string, any>, outputFilename: string): string[] { + const addOpts: string[] = []; - override async runCompiler( - compiler: string, - options: string[], - inputFilename: string, - execOptions: ExecutionOptions, - ): Promise<CompilationResult> { - // These options make Clang produce an IR - const newOptions = ['--emit=mlir-llvm', inputFilename]; + addOpts.push(this.tscAsmOutput ? '--emit=asm' : '--emit=mlir'); if (!this.tscSharedLib) { - newOptions.push('-nogc'); + addOpts.push('-nogc'); } - const output = await this.runCompilerRawOutput( - this.tscJit, - newOptions, - this.filename(inputFilename), - execOptions, - ); - if (output.code !== 0) { - return { - code: output.code, - timedOut: false, - stdout: [], - stderr: [ - { - text: 'Failed to run compiler to get MLIR code', - }, - ], - }; + if (this.tscNewOutput) { + addOpts.push('-o=' + this.filename(outputFilename)); } - return {code: 0, timedOut: false, stdout: [], stderr: []}; + return addOpts; + } + + override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string { + const outputFilename = this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase); + // As per #4054, if we are asked for binary mode, the output will be in the .s file, no .ll will be emited + if (!filters.binary) { + return outputFilename.replace('.s', '.ll'); + } + return outputFilename; } - override async generateIR( - inputFilename: string, - options: string[], - irOptions: LLVMIrBackendOptions, - filters: ParseFiltersAndOutputOptions, - ) { - // These options make Clang produce an IR - let newOptions = ['--emit=llvm', inputFilename]; + override async generateIR(inputFilename: string, options: string[], + irOptions: LLVMIrBackendOptions, filters: ParseFiltersAndOutputOptions) { + const newOptions = [ ...options.filter(e => !e.startsWith('--emit=') && !e.startsWith('-o=')) ]; if (this.tscNewOutput) { - newOptions = ['--emit=llvm', '-o=-', inputFilename]; + newOptions.push('-o=' + this.getIrOutputFilename(inputFilename, filters)); } - if (!this.tscSharedLib) { - newOptions.push('-nogc'); - } + return await super.generateIR(inputFilename, newOptions, irOptions, filters); + } - const execOptions = this.getDefaultExecOptions(); - // TODO: maybe this isn't needed? - execOptions.maxOutput = 1024 * 1024 * 1024; - - const output = await this.runCompilerRawOutput( - this.tscJit, - newOptions, - this.filename(inputFilename), - execOptions, - ); - if (output.code !== 0) { - return [{text: 'Failed to run compiler to get IR code'}]; + override async processIrOutput(output, irOptions: LLVMIrBackendOptions, filters: ParseFiltersAndOutputOptions) { + if (this.tscNewOutput) { + return await super.processIrOutput(output, irOptions, filters); } - filters.commentOnly = false; - filters.libraryCode = true; - filters.directives = true; + return this.llvmIr.process(output.stderr.map(l => l.text).join('\n'), irOptions); + } - const ir = await this.llvmIr.process(this.tscNewOutput ? output.stdout : output.stderr, irOptions); - return ir.asm; + override async handleInterpreting(key, executeParameters) { + executeParameters.args = [ + '--emit=jit', + this.tscSharedLib ? '--shared-libs=' + this.tscSharedLib : '-nogc', + ...executeParameters.args, + ]; + + return await super.handleInterpreting(key, executeParameters); } override isCfgCompiler() { |