From a4587ecd741310585af0a667770be555a0f2f1f3 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Wed, 24 Aug 2022 08:32:15 +0800 Subject: hack-vm: CLI argument -I/--no-init --- projects/hack-vm/__main__.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'projects') 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) -- cgit v1.2.3