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 all commits
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
19 changes: 17 additions & 2 deletions shivyc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@ 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 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))
return 1
Expand Down Expand Up @@ -109,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 @@ -118,6 +126,13 @@ 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=1,
metavar="file",
help="place output into <file>",
dest="output_name")

return parser.parse_args()

Expand Down
1 change: 1 addition & 0 deletions tests/test_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down