Cleanup arguments
This commit is contained in:
parent
8656d74139
commit
8c8d294527
|
@ -644,8 +644,9 @@ if __name__ == '__main__':
|
||||||
group = parser.add_mutually_exclusive_group(required=True)
|
group = parser.add_mutually_exclusive_group(required=True)
|
||||||
group.add_argument('--who', action='store_true', help='print out student IDs and NAMEs of authors')
|
group.add_argument('--who', action='store_true', help='print out student IDs and NAMEs of authors')
|
||||||
group.add_argument('-f', '--file', help='filename to process')
|
group.add_argument('-f', '--file', help='filename to process')
|
||||||
parser.add_argument('-o', '--compile', help='output filename for compiled code. if not given, no compilation is done')
|
parser.add_argument('-o', '--output', help='output filename for compiled code. default (a.out)', default='a.out')
|
||||||
parser.add_argument('-a', '--assembly', help='output filename for generated assembly code')
|
parser.add_argument('-a', '--assembly', help='output filename for generated assembly code')
|
||||||
|
parser.add_argument('-r', '--run', action='store_true', help='run the compiled code after compilation')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
@ -667,12 +668,11 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
assembly = compile_data.get_full_code()
|
assembly = compile_data.get_full_code()
|
||||||
|
|
||||||
if args.assembly is None:
|
if args.assembly is not None:
|
||||||
if args.compile is None:
|
|
||||||
print(assembly)
|
|
||||||
else:
|
|
||||||
with open(args.assembly, 'w', encoding='utf-8') as file:
|
with open(args.assembly, 'w', encoding='utf-8') as file:
|
||||||
file.write(assembly)
|
file.write(assembly)
|
||||||
|
|
||||||
if args.compile is not None:
|
subprocess.run(['gcc', '-x', 'assembler', '-o', args.output, '-static', '-'], input=assembly, encoding='utf-8')
|
||||||
subprocess.run(['gcc', '-x', 'assembler', '-o', args.compile, '-static', '-'], input=assembly, encoding='utf-8')
|
|
||||||
|
if args.run:
|
||||||
|
subprocess.run([f'./{args.output}'])
|
||||||
|
|
Loading…
Reference in New Issue