Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -o flag for compile options #101

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update -o option behavior
Print error message when use -o option but not enter file name argument.
  • Loading branch information
splasky committed May 24, 2018
commit c4228ab24c671013808d08deed9a014f07afdfc6
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
15 changes: 10 additions & 5 deletions shivyc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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=" ")
Expand All @@ -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 <file>",
help="place output into <file>",
dest="output_name")

return parser.parse_args()
Expand Down