summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederick Yin <fkfd@fkfd.me>2022-08-24 08:32:15 +0800
committerFrederick Yin <fkfd@fkfd.me>2022-08-24 08:32:15 +0800
commita4587ecd741310585af0a667770be555a0f2f1f3 (patch)
tree25f89c2a787df25aca8640dc8083b5dc5f7aed21
parentb3ee892850d512f143822b78f7714951d25d064a (diff)
hack-vm: CLI argument -I/--no-init
-rw-r--r--projects/hack-vm/__main__.py8
1 files changed, 4 insertions, 4 deletions
diff --git a/projects/hack-vm/__main__.py b/projects/hack-vm/__main__.py
index 5335583..b849edb 100644
--- a/projects/hack-vm/__main__.py
+++ b/projects/hack-vm/__main__.py
@@ -10,7 +10,7 @@ from .function import translate_function, translate_return
from .utils import *
-def vm_translate(input_path, verbose):
+def vm_translate(input_path, verbose, init):
# if input_path is a file, translate the file
# if it is a directory, translate every .vm file inside
try:
@@ -25,8 +25,7 @@ def vm_translate(input_path, verbose):
exit_on_error(f"Cannot open input path: {input_path}", EXIT_CODE_FILE_ERROR)
# assembly translated from all .vm files will be concatenated here
- asm = ""
- # asm = vminit(input_path.stem)
+ asm = vminit(input_path.stem) if init else ""
for input_fn in vm_files:
# load all vm commands from file, e.g. program/Main.vm
@@ -81,6 +80,7 @@ def vm_translate(input_path, verbose):
if __name__ == "__main__":
parser = ArgumentParser("hack-vm")
parser.add_argument("-v", "--verbose", action="store_true", help="verbose mode")
+ parser.add_argument("-I", "--no-init", action="store_true", help="do not write bootstrap code")
parser.add_argument("input_path", help="HACK VM file or directory")
args = parser.parse_args()
- vm_translate(Path(args.input_path), args.verbose)
+ vm_translate(Path(args.input_path), args.verbose, not args.no_init)