diff options
Diffstat (limited to 'lib/compilers/ldc.ts')
-rw-r--r-- | lib/compilers/ldc.ts | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/compilers/ldc.ts b/lib/compilers/ldc.ts index 2b98655f9..389a857ef 100644 --- a/lib/compilers/ldc.ts +++ b/lib/compilers/ldc.ts @@ -26,9 +26,11 @@ import path from 'path'; import fs from 'fs-extra'; import semverParser from 'semver'; - +import * as utils from '../utils.js'; import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js'; +import type {ResultLine} from '../../types/resultline/resultline.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; +import type {CompilationResult} from '../../types/compilation/compilation.interfaces.js'; import {logger} from '../logger.js'; import {LDCParser} from './argument-parsers.js'; @@ -99,30 +101,34 @@ export class LDCCompiler extends BaseCompiler { return versionMatch ? semverParser.compare(versionMatch[1] + '.0', '1.4.0', true) >= 0 : false; } - override async generateAST(inputFilename, options) { + override async generateAST(inputFilename, options): Promise<ResultLine[]> { // These options make LDC produce an AST dump in a separate file `<inputFilename>.cg`. const newOptions = options.concat('-vcg-ast'); const execOptions = this.getDefaultExecOptions(); - // TODO(#4654) generateAST expects to return a ResultLine[] not a string + return this.loadASTOutput( await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions), ) as any; } - async loadASTOutput(output) { - if (output.code !== 0) { - return `Error generating AST: ${output.code}`; + async loadASTOutput(result: CompilationResult): Promise<ResultLine[]> { + if (result.code !== 0) { + return [{text: `Error generating AST: ${result.code}`}]; } // Load the AST output from the `.cg` file. // Demangling is not needed. - const astFilename = output.inputFilename.concat('.cg'); + const astFilename = result.inputFilename!.concat('.cg'); try { - return await fs.readFile(astFilename, 'utf8'); + const rawAST: string = await fs.readFile(astFilename, 'utf8'); + return utils.parseOutput(rawAST, result.inputFilename); + // In theory we'd want to run this through this.llvmAst.processAst, but ldc's so-called-AST + // output is very different and processAst is moot: + // https://github.com/dlang/dmd/pull/6556#issuecomment-282353400 } catch (e) { // TODO(jeremy-rifkin) why does e have .code here if (e instanceof Error && (e as any).code === 'ENOENT') { logger.warn(`LDC AST file ${astFilename} requested but it does not exist`); - return ''; + return [{text: ''}]; } throw e; } @@ -130,6 +136,6 @@ export class LDCCompiler extends BaseCompiler { // Override the IR file name method for LDC because the output file is different from clang. override getIrOutputFilename(inputFilename) { - return this.getOutputFilename(path.dirname(inputFilename), this.outputFilebase).replace('.s', '.ll'); + return utils.changeExtension(inputFilename, '.ll'); } } |