Skip to content

Commit ce644ee

Browse files
#57 Utility to replace 1 instruction with many
1 parent c77a931 commit ce644ee

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

optvm/src/main/java/com/compilerprogramming/ezlang/compiler/BasicBlock.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,17 @@ public int whichSucc(BasicBlock succ) {
172172
}
173173
throw new IllegalStateException();
174174
}
175-
175+
public void replaceInstruction(Instruction instruction, List<Instruction> replacements) {
176+
int i;
177+
for (i = 0; i < instructions.size(); i++)
178+
if (instructions.get(i) == instruction)
179+
break;
180+
assert i < instructions.size();
181+
for (int j = replacements.size()-1; j >= 0; j--) {
182+
instructions.add(i+1, replacements.get(j));
183+
}
184+
instructions.remove(i);
185+
}
176186
public static StringBuilder toStr(StringBuilder sb, BasicBlock bb, BitSet visited, boolean dumpLiveness)
177187
{
178188
if (visited.get(bb.bid))

0 commit comments

Comments
 (0)