aboutsummaryrefslogtreecommitdiff
path: root/lib/compilers
diff options
context:
space:
mode:
authorOfek <ofekshilon@gmail.com>2023-11-14 04:11:16 +0200
committerGitHub <noreply@github.com>2023-11-13 20:11:16 -0600
commita280d8d305e1caa03a8c72a056170b6a2885186c (patch)
tree93810ec94b9f8382351b00ed02da96f2ceb312e3 /lib/compilers
parent6b94b29f55a765e44ee876609b72dbe49d81f143 (diff)
downloadcompiler-explorer-a280d8d305e1caa03a8c72a056170b6a2885186c.tar.gz
compiler-explorer-a280d8d305e1caa03a8c72a056170b6a2885186c.zip
Fix #4654 (#5749)gh-9567
Apparently AST for ldc is an abuse of terminology, as it doesn't produces anything resembling a syntax tree: https://github.com/dlang/dmd/pull/6556#issuecomment-282353400 . It is potentially meaningful only to ldc developers. Anyway the `generateAST` result type is fixed, along with some other small stuff around.
Diffstat (limited to 'lib/compilers')
-rw-r--r--lib/compilers/hlsl.ts3
-rw-r--r--lib/compilers/ispc.ts3
-rw-r--r--lib/compilers/ldc.ts26
-rw-r--r--lib/compilers/spirv.ts3
4 files changed, 22 insertions, 13 deletions
diff --git a/lib/compilers/hlsl.ts b/lib/compilers/hlsl.ts
index f103869b7..0b5662ac7 100644
--- a/lib/compilers/hlsl.ts
+++ b/lib/compilers/hlsl.ts
@@ -27,6 +27,7 @@ import _ from 'underscore';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {SPIRVAsmParser} from '../parsers/asm-parser-spirv.js';
+import {ResultLine} from '../../types/resultline/resultline.interfaces.js';
export class HLSLCompiler extends BaseCompiler {
protected spirvAsm: SPIRVAsmParser;
@@ -45,7 +46,7 @@ export class HLSLCompiler extends BaseCompiler {
this.compiler.llvmOptNoDiscardValueNamesArg = [];
}
- override async generateAST(inputFilename, options) {
+ override async generateAST(inputFilename, options): Promise<ResultLine[]> {
// These options make DXC produce an AST dump
const newOptions = _.filter(options, option => option !== '-Zi' && option !== '-Qembed_debug').concat([
'-ast-dump',
diff --git a/lib/compilers/ispc.ts b/lib/compilers/ispc.ts
index c44fdb20a..a75217961 100644
--- a/lib/compilers/ispc.ts
+++ b/lib/compilers/ispc.ts
@@ -27,6 +27,7 @@ import _ from 'underscore';
import type {PreliminaryCompilerInfo} from '../../types/compiler.interfaces.js';
import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js';
+import type {ResultLine} from '../../types/resultline/resultline.interfaces.js';
import {BaseCompiler} from '../base-compiler.js';
import {asSafeVer} from '../utils.js';
@@ -77,7 +78,7 @@ export class ISPCCompiler extends BaseCompiler {
return ISPCParser;
}
- override async generateAST(inputFilename, options) {
+ override async generateAST(inputFilename, options): Promise<ResultLine[]> {
// These options make Clang produce an AST dump
const newOptions = _.filter(options, option => option !== '--colored-output').concat(['--ast-dump']);
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');
}
}
diff --git a/lib/compilers/spirv.ts b/lib/compilers/spirv.ts
index 0dd0f86b8..ba28749b4 100644
--- a/lib/compilers/spirv.ts
+++ b/lib/compilers/spirv.ts
@@ -36,6 +36,7 @@ import * as utils from '../utils.js';
import {unwrap} from '../assert.js';
import type {ConfiguredOverrides} from '../../types/compilation/compiler-overrides.interfaces.js';
import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js';
+import {ResultLine} from '../../types/resultline/resultline.interfaces.js';
export class SPIRVCompiler extends BaseCompiler {
protected translatorPath: string;
@@ -191,7 +192,7 @@ export class SPIRVCompiler extends BaseCompiler {
return super.runCompiler(compiler, newOptions, inputFilename, execOptions);
}
- override async generateAST(inputFilename, options) {
+ override async generateAST(inputFilename, options): Promise<ResultLine[]> {
const newOptions = _.filter(options, option => option !== '-fcolor-diagnostics').concat(['-ast-dump']);
const execOptions = this.getDefaultExecOptions();