llvm--emulator/llvm_emulator/emulator.py

60 lines
1.9 KiB
Python

"""
Main module of the program.
To start the application, call the main function. For the end user,
this is achieved by a script stored in the bin folder.
"""
import argparse
from llvm_emulator import stepper, parser
def main():
arg_parser = argparse.ArgumentParser(description='A hacky LLVM-- emulator/debugger')
arg_parser.add_argument('-a', '--auto',
action='store', type=str, dest='auto_path',
help='Automatically step through llvm in the given file')
arg_parser.add_argument('-s', '--step',
action='store', type=int, dest='auto_step',
default=100,
help='How often to prompt for continuation in auto-mode, 0 is never')
arg_parser.add_argument('-p', '--print',
action='store', type=int, dest='print_level',
default=3,
help='Verboseness of the emulator')
parse_res_raw = arg_parser.parse_args()
parse_res = vars(parse_res_raw)
global llvm_parser
llvm_parser = parser.LLVMParser()
llvm_parser.build()
if parse_res['auto_path'] is not None:
step_behavior = {
'step_ask': parse_res['auto_step'],
'step_print_level': parse_res['print_level']
}
go_auto(parse_res['auto_path'], step_behavior)
else:
enter_interactive_mode()
def go_auto(path_to_file, step_behavior):
with open(path_to_file, 'r') as f:
file_contents = f.read()
print('Parsing {}'
.format(path_to_file))
ast = llvm_parser.parse(file_contents)
print('Beginning execution of {}'
.format(path_to_file))
stepper.auto_step(ast, step_behavior = step_behavior)
def enter_interactive_mode():
print('TODO: Interactive mode has not been implemented yet. Sorry...')