public ArrayList<FunctionRepr> partitionCodeByFunction() {
int funCount = (exports==null?0:exports.length)
+ (localFunctions==null?0:localFunctions.length);
ArrayList<FunctionRepr> functions = new ArrayList<FunctionRepr>(funCount);
FunctionInfo fi = null;
ArrayList<Insn> currentFunctionBody = null;
for (Insn insn : code) {
FunctionInfo newFI = null;
if (insn.opcode() == BeamOpcode.label) { // We might switch to a new function
int labelNr = ((Insn.I)insn).i1;
newFI = functionAtLabel(labelNr+1);
if (newFI==null) newFI = functionAtLabel(labelNr);
} else if (insn.opcode() == BeamOpcode.int_code_end) {
newFI = new FunctionInfo(null,null,-1,-1); // Easy way to handle last function
}
if (newFI != null && newFI != fi) { // Do switch
if (fi != null) { // Add previous
FunctionRepr fun = new FunctionRepr(fi, currentFunctionBody);
functions.add(fun);