MCPcopy
hub / github.com/compiler-explorer/compiler-explorer / generateIR

Method generateIR

lib/base-compiler.ts:1433–1486  ·  view source on GitHub ↗
(
        inputFilename: string,
        options: string[],
        irOptions: LLVMIrBackendOptions,
        produceCfg: boolean,
        filters: ParseFiltersAndOutputOptions,
    )

Source from the content-addressed store, hash-verified

1431 }
1432
1433 async generateIR(
1434 inputFilename: string,
1435 options: string[],
1436 irOptions: LLVMIrBackendOptions,
1437 produceCfg: boolean,
1438 filters: ParseFiltersAndOutputOptions,
1439 ) {
1440 const newOptions: string[] = [];
1441
1442 if (irOptions.noDiscardValueNames && this.compiler.optPipeline?.noDiscardValueNamesArg) {
1443 newOptions.push(...this.compiler.optPipeline.noDiscardValueNamesArg);
1444 }
1445
1446 newOptions.push(
1447 // `-E` /`-fsave-optimization-record` switches caused simultaneus writes into some output files,
1448 // see bugs #5854 / #6745
1449 ...options.filter(option => !['-fcolor-diagnostics', '-E', '-fsave-optimization-record'].includes(option)),
1450 // produce IR
1451 ...unwrap(this.compiler.irArg),
1452 );
1453
1454 const execOptions = this.getDefaultExecOptions();
1455 // A higher max output is needed for when the user includes headers
1456 execOptions.maxOutput = 1024 * 1024 * 1024;
1457
1458 const output = await this.runCompiler(this.compiler.exe, newOptions, this.filename(inputFilename), execOptions);
1459 if (output.code !== 0) {
1460 return {
1461 asm: [{text: 'Failed to run compiler to get IR code'}],
1462 };
1463 }
1464 const ir = await this.processIrOutput(output, irOptions, filters);
1465
1466 const result: {
1467 asm: ParsedAsmResultLine[];
1468 cfg?: Record<string, cfg.CFG>;
1469 } = {
1470 asm: ir.asm,
1471 };
1472
1473 if (result.asm.length > 0 && result.asm[result.asm.length - 1].text === '[truncated; too many lines]') {
1474 return result;
1475 }
1476
1477 if (produceCfg) {
1478 result.cfg = await cfg.generateStructure(
1479 this.compiler,
1480 ir.asm.map(line => ({text: line.text})),
1481 true,
1482 );
1483 }
1484
1485 return result;
1486 }
1487
1488 async processIrOutput(
1489 output: CompilationResult,

Callers 1

doCompilationMethod · 0.95

Calls 6

getDefaultExecOptionsMethod · 0.95
runCompilerMethod · 0.95
filenameMethod · 0.95
processIrOutputMethod · 0.95
pushMethod · 0.80
unwrapFunction · 0.70

Tested by

no test coverage detected