use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.
the class GenerationPass method makeBlock.
protected BasicBlock makeBlock(LabelNode label) {
BasicBlock b = new BasicBlock(builder.graph, ++builder.count, label);
queue(label);
builder.graph.addVertex(b);
return b;
}
use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.
the class GenerationPass method _switch.
protected void _switch(LinkedHashMap<Integer, BasicBlock> targets, BasicBlock dflt) {
save_stack(false);
Expr expr = pop();
for (Entry<Integer, BasicBlock> e : targets.entrySet()) {
update_target_stack(currentBlock, e.getValue(), currentStack);
}
update_target_stack(currentBlock, dflt, currentStack);
addStmt(new SwitchStmt(expr, targets, dflt));
}
use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.
the class GenerationPass method makeRanges.
private void makeRanges(List<BasicBlock> order) {
// System.out.println(builder.graph);
// BasicDotConfiguration<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>> config = new BasicDotConfiguration<>(DotConfiguration.GraphType.DIRECTED);
// DotWriter<ControlFlowGraph, BasicBlock, FlowEdge<BasicBlock>> writer = new DotWriter<>(config, builder.graph);
// writer.removeAll().add(new ControlFlowGraphDecorator().setFlags(ControlFlowGraphDecorator.OPT_DEEP)).setName("test9999").export();
Map<String, ExceptionRange<BasicBlock>> ranges = new HashMap<>();
for (TryCatchBlockNode tc : builder.method.tryCatchBlocks) {
// System.out.printf("from %d to %d, handler:%d, type:%s.%n", insns.indexOf(tc.start), insns.indexOf(tc.end), insns.indexOf(tc.handler), tc.type);
// System.out.println(String.format("%s:%s:%s", BasicBlock.createBlockName(insns.indexOf(tc.start)), BasicBlock.createBlockName(insns.indexOf(tc.end)), builder.graph.getBlock(tc.handler).getId()));
int start = builder.graph.getBlock(tc.start).getNumericId();
int end = builder.graph.getBlock(tc.end).getNumericId() - 1;
List<BasicBlock> range = range(order, start, end);
BasicBlock handler = builder.graph.getBlock(tc.handler);
String key = String.format("%d:%d:%s", start, end, handler.getNumericId());
ExceptionRange<BasicBlock> erange;
if (ranges.containsKey(key)) {
erange = ranges.get(key);
} else {
erange = new ExceptionRange<>(tc);
erange.setHandler(handler);
erange.addVertices(range);
ranges.put(key, erange);
if (!erange.isContiguous()) {
System.out.println(erange + " not contiguous");
}
builder.graph.addRange(erange);
}
/* add L; so that the internal descriptor here matches the
* one provided by Type.getType(Class) and therefore
* ExceptionAnalysis.getType(Class).
*
* 26/08/17: changed Type.getType to return consistent
* object refs and to not create Types of sort METHOD
* if the given descriptor isn't intended for getType
* (getObjectType instead), shouldn't have this problem now.*/
erange.addType(tc.type != null ? Type.getType("L" + tc.type + ";") : TypeUtils.THROWABLE);
ListIterator<BasicBlock> lit = range.listIterator();
while (lit.hasNext()) {
BasicBlock block = lit.next();
builder.graph.addEdge(block, new TryCatchEdge<>(block, erange));
}
}
}
use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.
the class GenerationPass method entry.
protected void entry(LabelNode firstLabel) {
LabelNode l = new LabelNode();
BasicBlock entry = new BasicBlock(builder.graph, ++builder.count, l);
entry.setFlag(BasicBlock.FLAG_NO_MERGE, true);
builder.graph.addVertex(entry);
builder.graph.getEntries().add(entry);
setInputStack(entry, new ExpressionStack(16));
defineInputs(builder.method, entry);
insns.insertBefore(firstLabel, l);
BasicBlock b = makeBlock(firstLabel);
setInputStack(b, new ExpressionStack(16));
queue(firstLabel);
builder.graph.addEdge(entry, new ImmediateEdge<>(entry, b));
}
use of org.mapleir.ir.cfg.BasicBlock in project maple-ir by LLVM-but-worse.
the class NaturalisationPass2 method run.
@Override
public void run() {
TarjanSCC<BasicBlock> scc = new TarjanSCC<>(builder.graph);
for (BasicBlock b : builder.graph.vertices()) {
if (scc.low(b) == -1) {
scc.search(b);
}
}
List<BasicBlock> order = new ArrayList<>();
for (List<BasicBlock> c : scc.getComponents()) {
order.addAll(c);
}
builder.graph.naturalise(order);
}
Aggregations