From 55e2af4502cda042b22ab2f78e8721f927049dcb Mon Sep 17 00:00:00 2001 From: splasky Date: Sat, 5 May 2018 13:35:48 +0800 Subject: [PATCH 1/2] Generate file with file name --- shivyc/main.py | 12 +++++++++++- tests/test_all.py | 1 + 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/shivyc/main.py b/shivyc/main.py index 4d72e8d..eadf6f5 100755 --- a/shivyc/main.py +++ b/shivyc/main.py @@ -33,7 +33,11 @@ def main(): if any(not obj for obj in objs): return 1 else: - if not link("out", objs): + # set the output ELF name + out = "out" + if arguments.output_name is not None: + out = arguments.output_name + if not link(out, objs): err = "linker returned non-zero status" print(CompilerError(err)) return 1 @@ -118,6 +122,12 @@ def get_arguments(): parser.add_argument("-z-reg-alloc-perf", help="display register allocator performance info", dest="show_reg_alloc_perf", action="store_true") + parser.add_argument( + "-o", + nargs="?", + metavar="file", + help="Place output into ", + dest="output_name") return parser.parse_args() diff --git a/tests/test_all.py b/tests/test_all.py index 9a4fa3e..18a11e7 100644 --- a/tests/test_all.py +++ b/tests/test_all.py @@ -46,6 +46,7 @@ class MockArguments: files = test_file_names show_reg_alloc_perf = False variables_on_stack = False + output_name = None shivyc.main.get_arguments = lambda: MockArguments() From c4228ab24c671013808d08deed9a014f07afdfc6 Mon Sep 17 00:00:00 2001 From: splasky Date: Wed, 23 May 2018 15:55:56 +0800 Subject: [PATCH 2/2] Update -o option behavior Print error message when use -o option but not enter file name argument. --- README.md | 1 + shivyc/main.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d0cb48c..38eb447 100644 --- a/README.md +++ b/README.md @@ -80,6 +80,7 @@ Many thanks to our current and past contributers: * [TBladen](https://github.com/tbladen) * [christian-stephen](https://github.com/christian-stephen) * [jubnzv](https://github.com/jubnzv) +* [splasky](https://github.com/splasky) ## References - [ShivC](https://github.com/ShivamSarodia/ShivC) - ShivyC is a rewrite from scratch of my old C compiler, ShivC, with much more emphasis on feature completeness and code quality. See the ShivC README for more details. diff --git a/shivyc/main.py b/shivyc/main.py index eadf6f5..6c48048 100755 --- a/shivyc/main.py +++ b/shivyc/main.py @@ -35,8 +35,10 @@ def main(): else: # set the output ELF name out = "out" - if arguments.output_name is not None: - out = arguments.output_name + if arguments.output_name is not None and \ + len(arguments.output_name) == 1: + # set the output ELF name + out = arguments.output_name[0] if not link(out, objs): err = "linker returned non-zero status" print(CompilerError(err)) @@ -113,7 +115,9 @@ def get_arguments(): desc = """Compile, assemble, and link C files. Option flags starting with `-z` are primarily for debugging or diagnostic purposes.""" parser = argparse.ArgumentParser( - description=desc, usage="shivyc [-h] [options] files...") + prog='ShivyC', + description=desc, + usage="shivyc [-h] [options] files...") # Files to compile parser.add_argument("files", metavar="files", nargs="+") @@ -122,11 +126,12 @@ def get_arguments(): parser.add_argument("-z-reg-alloc-perf", help="display register allocator performance info", dest="show_reg_alloc_perf", action="store_true") + # Generate binary file with file name parser.add_argument( "-o", - nargs="?", + nargs=1, metavar="file", - help="Place output into ", + help="place output into ", dest="output_name") return parser.parse_args()