String staticStr = isStatic ? "static " : "";
String overrideStr = isOverride ? "override " : "";
String nativeStr = methodInfo.isNative() ? "native " : "";
String finalStr = isFinal ? "final " : "";
printer.println(qualStr + staticStr + nativeStr + finalStr + overrideStr + kindStr + " " + nameStr + "(" + joinOn(",", paramTypeStrings) + "):" + nameToString(methodInfo.getReturnType()));
MethodBodyInfo mb = getMethodBodyForMethodInfo(methodInfo);
if (mb != null)
{
printer.println("{");
printer.indent();
TablePrinter tablePrinter = new TablePrinter(3, 2);
tablePrinter.addRow(new String[]{"//", "derivedName", methodInfo.getMethodName()});
tablePrinter.addRow(new String[]{"//", "method_info", String.valueOf(getMethodInfos().getId(mb.getMethodInfo()))});
tablePrinter.addRow(new String[]{"//", "max_stack", String.valueOf(mb.max_stack)});
tablePrinter.addRow(new String[]{"//", "max_regs", String.valueOf(mb.max_local)});
tablePrinter.addRow(new String[]{"//", "scope_depth", String.valueOf(mb.initial_scope)});
tablePrinter.addRow(new String[]{"//", "max_scope", String.valueOf(mb.max_scope)});
tablePrinter.addRow(new String[]{"//", "code_length", String.valueOf(mb.code_len)});
//tablePrinter.addRow(["//", "code_offset", mb.code_offset]);
tablePrinter.print(printer);
if (mb.getTraits() != null && mb.getTraits().getTraitCount() > 0)
{
printer.println("activation_traits {");
printer.indent();
for (Trait trait : mb.getTraits())
{
//var kindStr : String;
switch (trait.getKind())
{
case TRAIT_Var:
kindStr = "var";
break;
case TRAIT_Const:
kindStr = "const";
break;
default:
throw new Error("Illegal activation trait in " + methodInfo.getMethodName());
}
writeSlotTrait(kindStr, trait, false);
}
printer.unindent();
printer.println("}");
}
IFlowgraph cfg = mb.getCfg();
Map<IBasicBlock, String> blockNames = new HashMap<IBasicBlock, String>();
int i = 0;
for (IBasicBlock block : cfg.getBlocksInEntryOrder())
{
blockNames.put(block, "bb" + i++);
}
int offset = 0;
for (IBasicBlock block : cfg.getBlocksInEntryOrder())
{
printer.println(blockNames.get(block));
printer.indent();
// TODO: preds
//printer.println("preds=[" + block.getPredeccessor()mb.blocks[i].getPredIds(mb.blocks).join(", ") + "]");
Collection<? extends IBasicBlock> succs = block.getSuccessors();
List<String> succNames = new ArrayList<String>();
for (IBasicBlock s : succs)
succNames.add(blockNames.get(s));
printer.println("succs=[" + joinOn(",", succNames) + "]");
/*
// TODO: implement this with FrameModelEncoder
if(mb.blocks[i].state != null) {
printer.println("verification = " + (mb.blocks[i].state.verifyError == null ? "ok" : "failed: " + mb.blocks[i].state.verifyError));
}
*/
tablePrinter = new TablePrinter(4, 2);
for (int j = 0; j < block.size(); j++)
{
Instruction inst = block.get(j);
String constantStr = "";
if (inst.hasOperands() && inst.getOperand(0) instanceof Name)
{
constantStr = nameToString((Name) inst.getOperand(0));
}
else if (inst.isBranch() && inst.getOpcode() != OP_lookupswitch)
{
constantStr = blockNames.get(cfg.getBlock((Label) inst.getOperand(0)));
}
else
{
switch (inst.getOpcode())
{
case OP_debugfile:
case OP_pushstring:
constantStr = "\"" + stringToEscapedString((String) inst.getOperand(0)) + "\"";
break;
case OP_lookupswitch:
constantStr = stringForLookupSwitch(inst, mb, blockNames, cfg);
break;
}
}
tablePrinter.addRow(new String[]{offset + " ",
Instruction.decodeOp(inst.getOpcode()),
constantStr,
inst.isImmediate() ? String.valueOf(inst.getImmediate()) : ""
// TODO : Use FrameModelEncoder to keep track
// TODO: of stack/local values
//(inst.getStackDepth() == null ? "" : "// stack: " + inst.getStackDepth()),
//(inst.getState() == null ? "" : "// stack["+inst.getState().stackDepth+"]: " + inst.getState().stackTypeString()),
//(inst.getState() == null ? "" : "// locals: " + inst.getState().localsTypeString()),
//inst.getVerifyError()
});
offset++;
}
tablePrinter.print(printer);
printer.unindent();
}
printer.unindent();
printer.println("}");
if (mb.getExceptions().size() > 0)
{
tablePrinter = new TablePrinter(7, 2);
tablePrinter.addRow(new String[]{"//", "exception", "start", "end", "target", "type string", "name string"});
for (i = 0; i < mb.getExceptions().size(); i++)
{
ExceptionInfo exception = mb.getExceptions().get(i);
tablePrinter.addRow(new String[]{"//", String.valueOf(i), String.valueOf(exception.getFrom().getPosition()),
String.valueOf(exception.getTo().getPosition()),
String.valueOf(exception.getTarget().getPosition()),
nameToString(exception.getExceptionType()),
nameToString(exception.getCatchVar())});