Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix the name of the entry block in an IR control flow graph.
  • Loading branch information
OfekShilon authored Nov 27, 2023
1 parent 62ec36d commit c0db474
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
16 changes: 10 additions & 6 deletions lib/cfg/cfg-parsers/llvm-ir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {BaseInstructionSetInfo} from '../instruction-sets/base.js';
import {assert, unwrap} from '../../assert.js';

export type BBRange = {
namePrefix: string; // used to encode the function name in the first block
nameId: string;
start: number;
end: number;
Expand Down Expand Up @@ -79,29 +80,32 @@ export class LlvmIrCfgParser extends BaseCFGParser {
const result: BBRange[] = [];
let i = fn.start + 1;
let bbStart = i;
let currentName = fnName;
let currentName: string = '';
let namePrefix: string = fnName + '\n\n';
while (i < fn.end) {
const match = code[i].text.match(this.labelRe);
if (match) {
const label = match[1];
if (bbStart === i) {
// for -emit-llvm the first basic block doesn't have a label, for the ir viewer it does though
assert(result.length === 0);
bbStart = i + 1;
currentName = label;
} else {
const label = match[1];
// start is the fn / label define, end is exclusive
result.push({
namePrefix: namePrefix,
nameId: currentName,
start: bbStart,
end: i,
});
currentName = label;
bbStart = i + 1;
namePrefix = '';
}
bbStart = i + 1;
}
i++;
}
result.push({
namePrefix: '',
nameId: currentName,
start: bbStart,
end: i,
Expand All @@ -118,7 +122,7 @@ export class LlvmIrCfgParser extends BaseCFGParser {
}
return {
id: e.nameId,
label: `${e.nameId}${e.nameId.includes(':') ? '' : ':'}\n${this.concatInstructions(
label: `${e.namePrefix}${e.nameId}${e.nameId.includes(':') ? '' : ':'}\n${this.concatInstructions(
asms,
e.start,
end,
Expand Down
8 changes: 4 additions & 4 deletions test/cfg-cases/cfg-llvmir.invoke.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions test/cfg-cases/cfg-llvmir.loop.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c0db474

Please sign in to comment.