diff options
author | Jeremy Rifkin <51220084+jeremy-rifkin@users.noreply.github.com> | 2023-06-11 17:00:53 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-11 17:00:53 -0400 |
commit | 10851a1ddaea3e1111ea9f50afba1ff993a0967b (patch) | |
tree | 9792df118f580afb5988a607ce048244455be2c5 /lib/compilers | |
parent | 79bba4c1d1031fa250919539e7681cfcba250b7a (diff) | |
download | compiler-explorer-10851a1ddaea3e1111ea9f50afba1ff993a0967b.tar.gz compiler-explorer-10851a1ddaea3e1111ea9f50afba1ff993a0967b.zip |
LLVM IR pane improvements (#5078)gh-7669
This PR will add filtering and other output options to the LLVM IR pane


Closes #5062
Related to #5045
Diffstat (limited to 'lib/compilers')
-rw-r--r-- | lib/compilers/c3c.ts | 2 | ||||
-rw-r--r-- | lib/compilers/carbon.ts | 4 | ||||
-rw-r--r-- | lib/compilers/clangcl.ts | 12 | ||||
-rw-r--r-- | lib/compilers/hook.ts | 4 | ||||
-rw-r--r-- | lib/compilers/ispc.ts | 17 | ||||
-rw-r--r-- | lib/compilers/java.ts | 2 | ||||
-rw-r--r-- | lib/compilers/julia.ts | 2 | ||||
-rw-r--r-- | lib/compilers/mlir.ts | 2 | ||||
-rw-r--r-- | lib/compilers/pascal.ts | 2 | ||||
-rw-r--r-- | lib/compilers/pony.ts | 10 | ||||
-rw-r--r-- | lib/compilers/python.ts | 2 | ||||
-rw-r--r-- | lib/compilers/racket.ts | 2 | ||||
-rw-r--r-- | lib/compilers/ruby.ts | 2 | ||||
-rw-r--r-- | lib/compilers/solidity.ts | 2 | ||||
-rw-r--r-- | lib/compilers/spirv.ts | 10 | ||||
-rw-r--r-- | lib/compilers/typescript-native.ts | 10 | ||||
-rw-r--r-- | lib/compilers/v8.ts | 2 | ||||
-rw-r--r-- | lib/compilers/win32.ts | 2 |
18 files changed, 62 insertions, 27 deletions
diff --git a/lib/compilers/c3c.ts b/lib/compilers/c3c.ts index 7f8591c82..e39220aae 100644 --- a/lib/compilers/c3c.ts +++ b/lib/compilers/c3c.ts @@ -18,7 +18,7 @@ export class C3Compiler extends BaseCompiler { return ['compile-only', '-g', '-l', 'pthread', '--emit-asm']; } - override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string { + override getIrOutputFilename(inputFilename: string): string { return this.filename(path.dirname(inputFilename) + '/output.ll'); } } diff --git a/lib/compilers/carbon.ts b/lib/compilers/carbon.ts index 13aa1ad3f..bdb68bf7b 100644 --- a/lib/compilers/carbon.ts +++ b/lib/compilers/carbon.ts @@ -47,9 +47,9 @@ export class CarbonCompiler extends BaseCompiler { return ['--color', `--trace_file=${outputFilename}`]; } - override processAsm(result, filters, options): ParsedAsmResult { + override async processAsm(result, filters, options): Promise<ParsedAsmResult> { // Really should write a custom parser, but for now just don't filter anything. - return super.processAsm( + return await super.processAsm( result, { labels: false, diff --git a/lib/compilers/clangcl.ts b/lib/compilers/clangcl.ts index 3b182496a..25c40c41c 100644 --- a/lib/compilers/clangcl.ts +++ b/lib/compilers/clangcl.ts @@ -29,6 +29,7 @@ import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.in import {Win32Compiler} from './win32.js'; import {unwrap} from '../assert.js'; +import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; export class ClangCLCompiler extends Win32Compiler { static override get key() { @@ -45,7 +46,12 @@ export class ClangCLCompiler extends Win32Compiler { this.compiler.includeFlag = '/clang:-isystem'; } - override async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) { + override async generateIR( + inputFilename: string, + options: string[], + irOptions: LLVMIrBackendOptions, + filters: ParseFiltersAndOutputOptions, + ) { // These options make Clang produce an IR const newOptions = options .filter(option => option !== '/FA' && !option.startsWith('/Fa')) @@ -59,11 +65,11 @@ export class ClangCLCompiler extends Win32Compiler { if (output.code !== 0) { return [{text: 'Failed to run compiler to get IR code'}]; } - const ir = await this.processIrOutput(output, filters); + const ir = await this.processIrOutput(output, irOptions, filters); return ir.asm; } - override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string { + override getIrOutputFilename(inputFilename: string): string { return this.filename(path.dirname(inputFilename) + '/output.s.obj'); } diff --git a/lib/compilers/hook.ts b/lib/compilers/hook.ts index c731cc530..9de40faf8 100644 --- a/lib/compilers/hook.ts +++ b/lib/compilers/hook.ts @@ -72,10 +72,10 @@ export class HookCompiler extends BaseCompiler { return super.runCompiler(compiler, options, inputFilename, execOptions); } - override processAsm(result, filters, options) { + override async processAsm(result, filters, options) { // Ignoring `trim` filter because it is not supported by Hook. filters.trim = false; - const _result = super.processAsm(result, filters, options); + const _result = await super.processAsm(result, filters, options); const commentRegex = /^\s*;(.*)/; const instructionRegex = /^\s{2}(\d+)(.*)/; const asm = _result.asm; diff --git a/lib/compilers/ispc.ts b/lib/compilers/ispc.ts index bfd097abd..e7c25390b 100644 --- a/lib/compilers/ispc.ts +++ b/lib/compilers/ispc.ts @@ -32,6 +32,7 @@ import {asSafeVer} from '../utils.js'; import {ISPCParser} from './argument-parsers.js'; import {unwrap} from '../assert.js'; +import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; export class ISPCCompiler extends BaseCompiler { static get key() { @@ -56,9 +57,19 @@ export class ISPCCompiler extends BaseCompiler { return options; } - override async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) { - const newOptions = [...options, ...unwrap(this.compiler.irArg), '-o', this.getIrOutputFilename(inputFilename)]; - return super.generateIR(inputFilename, newOptions, filters); + override async generateIR( + inputFilename: string, + options: string[], + irOptions: LLVMIrBackendOptions, + filters: ParseFiltersAndOutputOptions, + ) { + const newOptions = [ + ...options, + ...unwrap(this.compiler.irArg), + '-o', + this.getIrOutputFilename(inputFilename, filters), + ]; + return super.generateIR(inputFilename, newOptions, irOptions, filters); } override getArgumentParser() { diff --git a/lib/compilers/java.ts b/lib/compilers/java.ts index 654aab039..320469f6e 100644 --- a/lib/compilers/java.ts +++ b/lib/compilers/java.ts @@ -237,7 +237,7 @@ export class JavaCompiler extends BaseCompiler { return this.filterUserOptionsWithArg(userOptions, oneArgForbiddenList); } - override processAsm(result) { + override async processAsm(result) { // Handle "error" documents. if (!result.asm.includes('\n') && result.asm[0] === '<') { return [{text: result.asm, source: null}]; diff --git a/lib/compilers/julia.ts b/lib/compilers/julia.ts index c72a52b98..01bb96679 100644 --- a/lib/compilers/julia.ts +++ b/lib/compilers/julia.ts @@ -58,7 +58,7 @@ export class JuliaCompiler extends BaseCompiler { return []; } - override processAsm(result, filters, options) { + override async processAsm(result, filters, options) { const lineRe = /^<(\d+) (\d+) ([^ ]+) ([^>]*)>$/; const bytecodeLines = result.asm.split('\n'); const bytecodeResult: ParsedAsmResultLine[] = []; diff --git a/lib/compilers/mlir.ts b/lib/compilers/mlir.ts index 90f2443d2..59d5d5439 100644 --- a/lib/compilers/mlir.ts +++ b/lib/compilers/mlir.ts @@ -80,7 +80,7 @@ export class MLIRCompiler extends BaseCompiler { return []; } - override processAsm(result, filters, options) { + override async processAsm(result, filters, options) { // 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.ts b/lib/compilers/pascal.ts index 01b04b607..569821feb 100644 --- a/lib/compilers/pascal.ts +++ b/lib/compilers/pascal.ts @@ -62,7 +62,7 @@ export class FPCCompiler extends BaseCompiler { return []; } - override processAsm(result, filters) { + override async processAsm(result, filters) { // 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/pony.ts b/lib/compilers/pony.ts index 081f84ebb..854e41ac5 100644 --- a/lib/compilers/pony.ts +++ b/lib/compilers/pony.ts @@ -30,6 +30,7 @@ import type {CompilationResult, ExecutionOptions} from '../../types/compilation/ import type {ParseFiltersAndOutputOptions} from '../../types/features/filters.interfaces.js'; import {BaseCompiler} from '../base-compiler.js'; import {unwrap} from '../assert.js'; +import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js'; export class PonyCompiler extends BaseCompiler { static get key() { @@ -62,7 +63,12 @@ export class PonyCompiler extends BaseCompiler { return source; } - override async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) { + override async generateIR( + inputFilename: string, + options: string[], + irOptions: LLVMIrBackendOptions, + filters: ParseFiltersAndOutputOptions, + ) { const newOptions = _.filter(options, option => !['--pass', 'asm'].includes(option)).concat( unwrap(this.compiler.irArg), ); @@ -75,7 +81,7 @@ export class PonyCompiler extends BaseCompiler { if (output.code !== 0) { return [{text: 'Failed to run compiler to get IR code'}]; } - const ir = await this.processIrOutput(output, filters); + const ir = await this.processIrOutput(output, irOptions, filters); return ir.asm; } diff --git a/lib/compilers/python.ts b/lib/compilers/python.ts index 6bca3ce4f..0d9cc8dde 100644 --- a/lib/compilers/python.ts +++ b/lib/compilers/python.ts @@ -46,7 +46,7 @@ export class PythonCompiler extends BaseCompiler { resolvePathFromAppRoot('etc', 'scripts', 'disasms', 'dis_all.py'); } - override processAsm(result) { + override async processAsm(result) { const lineRe = /^\s{0,4}(\d+)(.*)/; const bytecodeLines = result.asm.split('\n'); diff --git a/lib/compilers/racket.ts b/lib/compilers/racket.ts index 8a4ba784b..c86c61e54 100644 --- a/lib/compilers/racket.ts +++ b/lib/compilers/racket.ts @@ -123,7 +123,7 @@ export class RacketCompiler extends BaseCompiler { return result; } - override processAsm(result: any, filters: any, options: any) { + override async processAsm(result: any, filters: any, options: any) { // TODO: Process and highlight decompiled output return { asm: [{text: result.asm}], diff --git a/lib/compilers/ruby.ts b/lib/compilers/ruby.ts index f19cf1638..07886c3b8 100644 --- a/lib/compilers/ruby.ts +++ b/lib/compilers/ruby.ts @@ -48,7 +48,7 @@ export class RubyCompiler extends BaseCompiler { return 'asmruby'; } - override processAsm(result) { + override async processAsm(result) { const lineRe = /\(\s*(\d+)\)(?:\[[^\]]+])?$/; const fileRe = /ISeq:.*?@(.*?):(\d+) /; const baseFile = path.basename(this.compileFilename); diff --git a/lib/compilers/solidity.ts b/lib/compilers/solidity.ts index 073a834c9..13812b052 100644 --- a/lib/compilers/solidity.ts +++ b/lib/compilers/solidity.ts @@ -65,7 +65,7 @@ export class SolidityCompiler extends BaseCompiler { return path.join(dirPath, 'contracts/combined.json'); } - override processAsm(result) { + override async processAsm(result) { // Handle "error" documents. if (!result.asm.includes('\n') && result.asm[0] === '<') { return {asm: [{text: result.asm}]}; diff --git a/lib/compilers/spirv.ts b/lib/compilers/spirv.ts index 8c62e4830..1937faf57 100644 --- a/lib/compilers/spirv.ts +++ b/lib/compilers/spirv.ts @@ -35,6 +35,7 @@ import {SPIRVAsmParser} from '../parsers/asm-parser-spirv.js'; 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'; export class SPIRVCompiler extends BaseCompiler { protected translatorPath: string; @@ -201,7 +202,12 @@ export class SPIRVCompiler extends BaseCompiler { ); } - override async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) { + override async generateIR( + inputFilename: string, + options: string[], + irOptions: LLVMIrBackendOptions, + filters: ParseFiltersAndOutputOptions, + ) { const newOptions = _.filter(options, option => option !== '-fcolor-diagnostics').concat('-emit-llvm'); const execOptions = this.getDefaultExecOptions(); @@ -217,7 +223,7 @@ export class SPIRVCompiler extends BaseCompiler { logger.error('Failed to run compiler to get IR code'); return output.stderr; } - const ir = await this.processIrOutput(output, filters); + const ir = await this.processIrOutput(output, irOptions, filters); return ir.asm; } } diff --git a/lib/compilers/typescript-native.ts b/lib/compilers/typescript-native.ts index d450bcb94..adf3db24d 100644 --- a/lib/compilers/typescript-native.ts +++ b/lib/compilers/typescript-native.ts @@ -31,6 +31,7 @@ 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() { @@ -105,7 +106,12 @@ export class TypeScriptNativeCompiler extends BaseCompiler { return {code: 0, timedOut: false, stdout: [], stderr: []}; } - override async generateIR(inputFilename: string, options: string[], filters: ParseFiltersAndOutputOptions) { + override async generateIR( + inputFilename: string, + options: string[], + irOptions: LLVMIrBackendOptions, + filters: ParseFiltersAndOutputOptions, + ) { // These options make Clang produce an IR let newOptions = ['--emit=llvm', inputFilename]; if (this.tscNewOutput) { @@ -134,7 +140,7 @@ export class TypeScriptNativeCompiler extends BaseCompiler { filters.libraryCode = true; filters.directives = true; - const ir = await this.llvmIr.process(this.tscNewOutput ? output.stdout : output.stderr, filters); + const ir = await this.llvmIr.process(this.tscNewOutput ? output.stdout : output.stderr, irOptions); return ir.asm; } diff --git a/lib/compilers/v8.ts b/lib/compilers/v8.ts index 14d24c5b8..c5b1a832c 100644 --- a/lib/compilers/v8.ts +++ b/lib/compilers/v8.ts @@ -38,7 +38,7 @@ export class V8Compiler extends BaseCompiler { this.demanglerClass = null; } - override getIrOutputFilename(inputFilename: string, filters: ParseFiltersAndOutputOptions): string { + override getIrOutputFilename(inputFilename: string): string { return this.filename(path.dirname(inputFilename) + '/code.asm'); } diff --git a/lib/compilers/win32.ts b/lib/compilers/win32.ts index ebdb803ad..8f2cff314 100644 --- a/lib/compilers/win32.ts +++ b/lib/compilers/win32.ts @@ -174,7 +174,7 @@ export class Win32Compiler extends BaseCompiler { } } - override processAsm(result, filters /*, options*/) { + override async processAsm(result, filters /*, options*/) { if (filters.binary) { filters.dontMaskFilenames = true; return this.binaryAsmParser.process(result.asm, filters); |