Skip to content

Commit

Permalink
add support for -print-changed
Browse files Browse the repository at this point in the history
  • Loading branch information
sunxfancy committed May 30, 2024
1 parent da8892d commit ef2ca4f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/clang.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,10 @@ export class ClangCommand extends Command {
args = args.concat(["-mllvm", "-print-after-all"]);
}

if (this.bPrintChanged && args.indexOf('-print-changed') === -1) {
args = args.concat(["-mllvm", "-print-changed"]);
}

if (this.bOutputToStdout)
args = args.concat(["-o", "-"]);
else {
Expand Down Expand Up @@ -335,8 +339,9 @@ export class ClangCommand extends Command {
public bDebug = true;
public sFilter?: string;
public bPrintModuleScope = true;
public bPrintBefore = true;
public bPrintAfter = true;
public bPrintBefore = false;
public bPrintAfter = false;
public bPrintChanged = true;
public bDumpAST = false;
public mode?: string;
}
Expand Down
25 changes: 24 additions & 1 deletion src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class Pipeline {
this.output = readFileSync(output_path).toString();

// Then, we should parse the LLVM dump data in stderr
this.parseLLVMDump(stderr);
this.parseLLVMDumpChanged(stderr);

// Get the human-readable LLVM IR
if (this.command instanceof ClangCommand) {
Expand Down Expand Up @@ -141,6 +141,29 @@ export class Pipeline {
}
}

public parseLLVMDumpChanged(data: string) {
const re = /^(# )?\*\*\* (.+) \*\*\*\s*(\(function\: ([^\)]+)\))?\:?\s*$/m;
const isMachineCode = /^# Machine code for function (.+)$/m;
let pass = data.split(re);
let last_ir = "";
for (let i = 1; i < pass.length; i += 5) {
let sharp = pass[i];
let name = pass[i + 1];
let func_name = pass[i + 3];
let ir = pass[i + 4].trim();
if (ir == '') ir = last_ir;

if (!isMachineCode.test(ir)) {
this.passList.push(new Pass(
this, name, last_ir, ir, this.passList.length, false));
} else {
this.backendList.push(new Pass(
this, name, last_ir, ir, this.backendList.length, true));
}

last_ir = ir;
}
}
public isCompare() {
return false;
}
Expand Down

0 comments on commit ef2ca4f

Please sign in to comment.