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