2017-10-30 01:31:29 +00:00
|
|
|
"""
|
|
|
|
Main module of the program.
|
|
|
|
|
2017-10-31 19:03:16 +00:00
|
|
|
To start the application, call the main function. For the end user,
|
|
|
|
this is achieved by a script stored in the bin folder.
|
2017-10-30 01:31:29 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
import argparse
|
|
|
|
|
2017-10-31 18:52:08 +00:00
|
|
|
from llvm_emulator import stepper, parser
|
2017-10-30 01:31:29 +00:00
|
|
|
|
|
|
|
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')
|
|
|
|
|
2017-11-13 17:05:44 +00:00
|
|
|
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')
|
|
|
|
|
2017-10-30 01:31:29 +00:00
|
|
|
parse_res_raw = arg_parser.parse_args()
|
|
|
|
parse_res = vars(parse_res_raw)
|
|
|
|
|
|
|
|
global llvm_parser
|
|
|
|
llvm_parser = parser.LLVMParser()
|
2017-11-13 17:14:53 +00:00
|
|
|
llvm_parser.build( parse_res['print_level'] <= 1 )
|
2017-10-30 01:31:29 +00:00
|
|
|
|
|
|
|
if parse_res['auto_path'] is not None:
|
2017-11-13 17:05:44 +00:00
|
|
|
step_behavior = {
|
|
|
|
'step_ask': parse_res['auto_step'],
|
|
|
|
'step_print_level': parse_res['print_level']
|
|
|
|
}
|
|
|
|
go_auto(parse_res['auto_path'], step_behavior)
|
2017-10-30 01:31:29 +00:00
|
|
|
else:
|
|
|
|
enter_interactive_mode()
|
|
|
|
|
|
|
|
|
2017-11-13 17:05:44 +00:00
|
|
|
def go_auto(path_to_file, step_behavior):
|
2017-10-30 01:31:29 +00:00
|
|
|
with open(path_to_file, 'r') as f:
|
|
|
|
file_contents = f.read()
|
2017-11-13 17:14:53 +00:00
|
|
|
if step_behavior['step_print_level'] > 1:
|
|
|
|
print('Parsing {}'
|
|
|
|
.format(path_to_file))
|
2017-10-30 01:31:29 +00:00
|
|
|
ast = llvm_parser.parse(file_contents)
|
2017-11-13 17:14:53 +00:00
|
|
|
if step_behavior['step_print_level'] > 1:
|
|
|
|
print('Beginning execution of {}'
|
|
|
|
.format(path_to_file))
|
2017-11-13 17:05:44 +00:00
|
|
|
stepper.auto_step(ast, step_behavior = step_behavior)
|
2017-10-30 01:31:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def enter_interactive_mode():
|
|
|
|
print('TODO: Interactive mode has not been implemented yet. Sorry...')
|