Commit 4542b9c5 authored by Taddeus Kroes's avatar Taddeus Kroes

Added command line options to main.py.

parent aeb435c7
......@@ -4,24 +4,44 @@ from sys import argv, exit
from src.parser import parse_file
verbose_level = 2
options = {'-v': 1}
# Parse arguments
if len(argv) < 2:
print 'Usage: python %s SOURCE_FILE [ OUT_FILE [ SOURCE_OUT_FILE ] ]' \
% argv[0]
def exit_with_usage():
print 'Usage: python %s [ options ] SOURCE_FILE' % argv[0]
print 'options: -i SOURCE_OUT_FILE | -o OUT_FILE | -v VERBOSE_LEVEL'
exit(1)
if len(argv) % 2:
exit_with_usage()
elif len(argv) > 2:
values = argv[2:-1:2]
if argv[1][0] != '-':
exit_with_usage()
for i, option in enumerate(argv[1:-1:2]):
if option not in ['-i', '-o', '-v']:
print 'unknown option "%s"' % option
exit(1)
if i >= len(values):
print 'No value given for option "%s"' % option
exit(1)
options[option] = values[i]
# Parse file
program = parse_file(argv[1])
program.verbose = verbose_level
program = parse_file(argv[-1])
program.verbose = int(options['-v'])
# Save input assembly in new file for easy comparison
if len(argv) > 3:
program.save(argv[3])
if '-i' in options:
program.save(options['-i'])
# Perform optimizations
......@@ -29,5 +49,5 @@ program.optimize()
# Save output assembly
if len(argv) > 2:
program.save(argv[2])
if '-o' in options:
program.save(options['-o'])
#!/bin/sh
python main.py benchmarks/build/$1.s out.s in.s && meld in.s out.s
#!/bin/bash
python main.py -v ${2-1} -i in.s -o out.s benchmarks/build/$1.s && meld in.s out.s
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment