diff --git a/src/main/java/bytecode/ByteCodeGenerator.java b/src/main/java/bytecode/ByteCodeGenerator.java index 60c8d46..f8a5570 100644 --- a/src/main/java/bytecode/ByteCodeGenerator.java +++ b/src/main/java/bytecode/ByteCodeGenerator.java @@ -1,43 +1,14 @@ package bytecode; -import java.io.FileOutputStream; -import java.io.IOException; - import ast.ClassNode; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.Opcodes; import ast.ProgramNode; public class ByteCodeGenerator { public void generateByteCode(ProgramNode ast) { for (ClassNode classNode : ast.classes) { - ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - 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); - - classWriter.visitEnd(); - printIntoClassFile(classWriter.toByteArray(), classNode.name); - - classWriter.visitEnd(); - } - } - - private void printIntoClassFile(byte[] byteCode, String name) { - String filePath = "./classFileOutput/" + name + ".class"; - - try { - FileOutputStream fileOutputStream = new FileOutputStream(filePath); - fileOutputStream.write(byteCode); - fileOutputStream.close(); - } catch (IOException e) { - e.printStackTrace(); + ClassCodeGen classCodeGen = new ClassCodeGen(); + classCodeGen.generateClassCode(classNode); } } }