Skip to content

Commit

Permalink
Fix compiler-explorer#5987: make rustc generate *only* IR output in g…
Browse files Browse the repository at this point in the history
…enerateIR
  • Loading branch information
OfekShilon committed Jan 13, 2024
1 parent f3277b8 commit 1351360
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions lib/compilers/rust.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import {parseRustOutput, changeExtension} from '../utils.js';

import {RustParser} from './argument-parsers.js';
import {CompilerOverrideType} from '../../types/compilation/compiler-overrides.interfaces.js';
import {LLVMIrBackendOptions} from '../../types/compilation/ir.interfaces.js';
import {SemVer} from 'semver';

export class RustCompiler extends BaseCompiler {
Expand Down Expand Up @@ -67,6 +68,30 @@ export class RustCompiler extends BaseCompiler {
this.linker = this.compilerProps<string>('linker');
}

override async generateIR(
inputFilename: string,
options: string[],
irOptions: LLVMIrBackendOptions,
produceCfg: boolean,
filters: ParseFiltersAndOutputOptions,
) {
// Filter out the options pairs `--emit mir=*` and `emit asm`, and specify explicit `.ll` extension
const newOptions = options
.filter(option => !option.startsWith('--color='))
.filter(
(opt, idx, allOpts) =>
!(opt === '--emit' && allOpts[idx + 1].startsWith('mir=')) && !opt.startsWith('mir='),
)
.filter((opt, idx, allOpts) => !(opt === '--emit' && allOpts[idx + 1] === 'asm') && opt !== 'asm')
.map((opt, idx, allOpts) =>
opt.endsWith('.s') && idx > 0 && allOpts[idx - 1] === '-o'
? this.getIrOutputFilename(inputFilename, filters)
: opt,
);

return await super.generateIR(inputFilename, newOptions, irOptions, produceCfg, filters);
}

private isNightly() {
return (
this.compiler.name === 'nightly' ||
Expand Down

0 comments on commit 1351360

Please sign in to comment.