public Instruction[] prepareForInterpret() { final CFG cfg = new CFG(this); final DirectedGraph<BasicBlock> graph = cfg.build(getInstructions()); // FIXME: Add debug config for this System.out.println(cfg.toStringInstrs()); System.out.println(graph.toString()); // FIXME: We don't save this linearized set yet return prepareIPCs(CFGLinearizer.linearize(cfg), cfg); }
private Instruction[] prepareIPCs(List<BasicBlock> list, CFG cfg) { // Set up IPCs List<Instruction> newInstrs = new ArrayList<Instruction>(); HashMap<Label, Integer> labelIPCMap = new HashMap<Label, Integer>(); int ipc = 0; for (BasicBlock basicBlock : list) { Label label = basicBlock.getLabel(); labelIPCMap.put(label, ipc); // This assumes if multiple equal/same labels exist which are scattered around the scope // must be the same Java instance or only this one will get a targetPC set. label.setTargetIPC(ipc); List<Instruction> bbInstrs = basicBlock.getInstructions(); int bbInstrsLength = bbInstrs.size(); for (int i = 0; i < bbInstrsLength; i++) { Instruction instr = bbInstrs.get(i); newInstrs.add(instr); instr.setIPC(ipc); ipc++; } } cfg.getExitBB().getLabel().setTargetIPC(ipc + 1); // Exit BasicBlock IPC setupRescueMap(list, cfg); // Set up the rescue map return newInstrs.toArray(new Instruction[newInstrs.size()]); }
public void setupRescueMap(List<BasicBlock> list, CFG cfg) { rescueMap = new HashMap<Integer, Integer>(); for (BasicBlock basicBlock : list) { BasicBlock rescuerBB = cfg.getRescuerBBFor(basicBlock); int rescuerPC = (rescuerBB == null) ? -1 : rescuerBB.getLabel().getTargetIPC(); for (Instruction instruction : basicBlock.getInstructions()) { rescueMap.put(instruction.getIPC(), rescuerPC); } } }
public List<BasicBlock> prepareForCompilation() { final CFG cfg = new CFG(this); cfg.build(getInstructions()); return CFGLinearizer.linearize(cfg); }