Add methodnode to assembler output
@@ -22,7 +22,7 @@ public class AssemblyVisitor implements Visitor {
private static final Map<Integer, Function<AssemblyVisitor, Visitor>> visitors =
new HashMap<>();
private int line;
- private InsnList insnList;
+ private MethodNode method;
private Variables variables = new Variables();
// TODO: Labels
// TODO: Try-catch ranges
@@ -30,6 +30,9 @@ public class AssemblyVisitor implements Visitor {
//
// TODO: private boolean debug;
// TODO: private boolean verify;
+ // Method definition
+ private int access;
+ private String desc;
/**
* Registers variables to <i>"this"</i> and method paramters.
@@ -40,6 +43,8 @@ public class AssemblyVisitor implements Visitor {
* Method descriptor.
*/
public void setupMethod(int access, String desc) {
+ this.access = access;
+ this.desc = desc;
variables.setup(access, desc);
}
@@ -48,14 +53,21 @@ public class AssemblyVisitor implements Visitor {
* Instruction to append to the instructions list.
*/
public void appendInsn(AbstractInsnNode insn) {
- insnList.add(insn);
+ method.instructions.add(insn);
+ }
+
+ /**
+ * @return Method generated by {{@link #visit(String)}}.
+ */
+ public MethodNode getMethod() {
+ return method;
}
/**
* @return Method instructions generated by {{@link #visit(String)}}.
*/
public InsnList getInsnList() {
- return insnList;
+ return method.instructions;
}
/**
@@ -71,7 +83,12 @@ public class AssemblyVisitor implements Visitor {
// - Debug collection
// - Instruction parsing
try {
- insnList = new InsnList();
+ // Setup method to fill
+ method = new MethodNode();
+ method.access = access;
+ method.desc = desc;
+ method.name = "assembled";
+ // Preparse
line = 1;
String[] lines = StringUtil.splitNewline(text);
for(String lineStr : lines) {
@@ -79,6 +96,7 @@ public class AssemblyVisitor implements Visitor {
line++;
}
// TODO: When adding alias support, update strings in "lines"
+ // Add instructions to method
line = 1;
for(String lineStr : lines) {
getVisitor(lineStr).visit(lineStr);
