From 94c037467ee1835c8235315a9496067b108a9729 Mon Sep 17 00:00:00 2001 From: i22007 Date: Wed, 8 May 2024 14:07:16 +0200 Subject: [PATCH 1/2] Fixed write bytecode into file --- src/main/java/CompilerInput.txt | 2 +- src/main/java/bytecode/ClassCodeGen.java | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/CompilerInput.txt b/src/main/java/CompilerInput.txt index 75d8cd9..106dace 100644 --- a/src/main/java/CompilerInput.txt +++ b/src/main/java/CompilerInput.txt @@ -1,3 +1,3 @@ -public class Example() { +public class Example { } \ No newline at end of file diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index a59a632..e9eb641 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -4,6 +4,7 @@ import ast.ClassNode; import ast.FieldNode; import ast.MemberNode; import ast.MethodNode; +import java.io.File; import org.objectweb.asm.ClassWriter; import org.objectweb.asm.Opcodes; @@ -34,7 +35,14 @@ public class ClassCodeGen { } private void printIntoClassFile(byte[] byteCode, String name) { - String filePath = "./classFileOutput/" + name + ".class"; + String filePath = "src/main/java/classFileOutput/" + name + ".class"; + + String directoryPath = "src/main/java/classFileOutput"; + File directory = new File(directoryPath); + if (!directory.exists()) { + directory.mkdirs(); + } + try { FileOutputStream fileOutputStream = new FileOutputStream(filePath); From 458983fc68b7325ad61793914f4e7a418f83a144 Mon Sep 17 00:00:00 2001 From: i22007 Date: Wed, 8 May 2024 16:12:04 +0200 Subject: [PATCH 2/2] Change on filepath --- src/main/java/bytecode/ClassCodeGen.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/bytecode/ClassCodeGen.java b/src/main/java/bytecode/ClassCodeGen.java index e9eb641..77316a6 100644 --- a/src/main/java/bytecode/ClassCodeGen.java +++ b/src/main/java/bytecode/ClassCodeGen.java @@ -35,15 +35,13 @@ public class ClassCodeGen { } private void printIntoClassFile(byte[] byteCode, String name) { - String filePath = "src/main/java/classFileOutput/" + name + ".class"; - String directoryPath = "src/main/java/classFileOutput"; File directory = new File(directoryPath); if (!directory.exists()) { directory.mkdirs(); } - + String filePath = directoryPath + "/" + name + ".class"; try { FileOutputStream fileOutputStream = new FileOutputStream(filePath); fileOutputStream.write(byteCode);