Skip to content

Commit 36a601f

Browse files
committed
Moved writeInit() out of Constructor. Course instructions say to only write the initialization if processing a directory with multiple .VM files. Passes all unit tests and grader 100/100!
1 parent 64a3ba3 commit 36a601f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/CodeWriter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ public class CodeWriter {
6767
} catch (IOException e) {
6868
throw new RuntimeException(e); // rethrow the exception as an unchecked exception
6969
}
70-
71-
// write the bootstrap code to initialize the VM
72-
writeInit(); //TODO: implement commandline argument to disable the bootstrap code
7370
}
7471

7572
/**

src/VMTranslator.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public static void main (String[] args) {
3434
outputFileName = input.getPath() + File.separator + outputFileName; // concatenate the directory name with the output file name
3535
codewriter = new CodeWriter(outputFileName); // instantiate the CodeWriter class
3636

37+
// write the bootstrap code to initialize the VM when translating a directory
38+
codewriter.writeInit();
39+
3740
File[] files = input.listFiles();
3841
if (files == null) {
3942
System.out.println("No files found in directory: " + inputFileName);
@@ -60,6 +63,9 @@ public static void main (String[] args) {
6063
outputFileName = inputFileName.substring(0, inputFileName.lastIndexOf('.')) + ".asm"; // replace .vm with .asm
6164
codewriter = new CodeWriter(outputFileName); // instantiate the CodeWriter class
6265

66+
// Do not write the bootstrap code when translating a single file. Otherwise online grader will fail.
67+
Debug.println("Skipping writing bootstrap code to output file");
68+
6369
Parser parser = new Parser(inputFileName); // unique parser object for each file per API
6470
parseInput(parser, inputFileName, codewriter); // shared output file
6571
}

0 commit comments

Comments
 (0)