Add accesTypeToOpcode mapper
This commit is contained in:
parent
3cbef38c5e
commit
44452d204b
@ -1,3 +1,3 @@
|
||||
public class Example {
|
||||
}
|
||||
public class Example() {
|
||||
|
||||
}
|
@ -14,7 +14,7 @@ public class Main {
|
||||
public static void main(String[] args) throws Exception {
|
||||
CharStream codeCharStream = null;
|
||||
try {
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src\\main\\java\\Example.java"));
|
||||
codeCharStream = CharStreams.fromPath(Paths.get("src/main/java/Example.java"));
|
||||
parsefile(codeCharStream);
|
||||
} catch (IOException e) {
|
||||
System.err.println("Error reading the file: " + e.getMessage());
|
||||
|
@ -1,6 +1,9 @@
|
||||
package bytecode;
|
||||
|
||||
import ast.ClassNode;
|
||||
import ast.FieldNode;
|
||||
import ast.MemberNode;
|
||||
import ast.MethodNode;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
@ -13,11 +16,15 @@ public class ClassCodeGen {
|
||||
classWriter.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, classNode.name, null,
|
||||
"java/lang/Object", null);
|
||||
|
||||
FieldCodeGen fieldCodeGen = new FieldCodeGen();
|
||||
fieldCodeGen.generateFieldCode(classWriter);
|
||||
|
||||
MethodCodeGen methodCodeGen = new MethodCodeGen();
|
||||
methodCodeGen.generateMethodCode(classWriter);
|
||||
for (MemberNode memberNode : classNode.members) {
|
||||
if (memberNode instanceof FieldNode) {
|
||||
FieldCodeGen fieldCodeGen = new FieldCodeGen();
|
||||
fieldCodeGen.generateFieldCode(classWriter, (FieldNode) memberNode);
|
||||
} else if (memberNode instanceof MethodNode) {
|
||||
MethodCodeGen methodCodeGen = new MethodCodeGen();
|
||||
methodCodeGen.generateMethodCode(classWriter, (MethodNode) memberNode);
|
||||
}
|
||||
}
|
||||
|
||||
classWriter.visitEnd();
|
||||
printIntoClassFile(classWriter.toByteArray(), classNode.name);
|
||||
|
@ -1,10 +1,13 @@
|
||||
package bytecode;
|
||||
|
||||
import ast.FieldNode;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.FieldVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class FieldCodeGen {
|
||||
|
||||
public void generateFieldCode(ClassWriter classWriter) {
|
||||
|
||||
public void generateFieldCode(ClassWriter classWriter, FieldNode fieldNode) {
|
||||
FieldVisitor fieldVisitor = classWriter.visitField(Opcodes.ACC_PUBLIC, fieldNode.name, "", null, null);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
package bytecode;
|
||||
|
||||
import ast.MethodNode;
|
||||
import org.objectweb.asm.ClassWriter;
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.Opcodes;
|
||||
|
||||
public class MethodCodeGen {
|
||||
public void generateMethodCode(ClassWriter classWriter) {
|
||||
public void generateMethodCode(ClassWriter classWriter, MethodNode methodNode) {
|
||||
MethodVisitor constructor =
|
||||
classWriter.visitMethod(Opcodes.ACC_PUBLIC,
|
||||
"<init>",
|
||||
|
Loading…
Reference in New Issue
Block a user