Make optimization optional with flag
This commit is contained in:
parent
999cc0d5d1
commit
e70b078b35
|
@ -903,6 +903,7 @@ if __name__ == '__main__':
|
||||||
group.add_argument('-f', '--file', help='filename to process')
|
group.add_argument('-f', '--file', help='filename to process')
|
||||||
parser.add_argument('-o', '--output', help='output filename for compiled code. default (a.out)', default='a.out')
|
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('-O', '--optimize', action='store_true', help='run simple optimization steps on the generated assembly code')
|
||||||
parser.add_argument('-r', '--run', action='store_true', help='run the compiled code after compilation')
|
parser.add_argument('-r', '--run', action='store_true', help='run the compiled code after compilation')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -923,7 +924,9 @@ if __name__ == '__main__':
|
||||||
compile_data = CompileData(sem_data)
|
compile_data = CompileData(sem_data)
|
||||||
compile_ast(ast, compile_data)
|
compile_ast(ast, compile_data)
|
||||||
|
|
||||||
compile_data.optimize_assembly()
|
if args.optimize:
|
||||||
|
compile_data.optimize_assembly()
|
||||||
|
|
||||||
assembly = compile_data.get_full_code()
|
assembly = compile_data.get_full_code()
|
||||||
|
|
||||||
if args.assembly is not None:
|
if args.assembly is not None:
|
||||||
|
@ -933,4 +936,7 @@ if __name__ == '__main__':
|
||||||
subprocess.run(['gcc', '-x', 'assembler', '-o', args.output, '-static', '-'], input=assembly, encoding='utf-8')
|
subprocess.run(['gcc', '-x', 'assembler', '-o', args.output, '-static', '-'], input=assembly, encoding='utf-8')
|
||||||
|
|
||||||
if args.run:
|
if args.run:
|
||||||
subprocess.run([f'./{args.output}'])
|
if args.output.startswith('/'):
|
||||||
|
subprocess.run([args.output])
|
||||||
|
else:
|
||||||
|
subprocess.run([f'./{args.output}'])
|
||||||
|
|
Loading…
Reference in New Issue