diff --git a/llvm--emulator.py b/llvm--emulator.py new file mode 100755 index 0000000..d771b32 --- /dev/null +++ b/llvm--emulator.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 + +""" +Main module of the program. + +This module is the one that should be run, e.g.:: + + $ ./llvm--emulator.py + +""" + +import argparse + +import stepper +import 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') + + 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: + go_auto(parse_res['auto_path']) + else: + enter_interactive_mode() + + +def go_auto(path_to_file): + 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) + + +def enter_interactive_mode(): + print('TODO: Interactive mode has not been implemented yet. Sorry...') + + +if __name__ == '__main__': + main() diff --git a/stepper.py b/stepper.py index ba6edca..d8717ed 100644 --- a/stepper.py +++ b/stepper.py @@ -1,8 +1,7 @@ -import ll -import parser - from enum import Enum +import ll + def TODO(msg): print('TODO: not implemented yet at {}' @@ -549,33 +548,3 @@ def auto_step(ast, function_name='tigermain', function_args=[1234, 5678]): break if stop_q in ['n', 'no']: break - - -def gogo(): - p = parser.LLVMParser() - p.build() - data = r''' -%T_tigermain = type { i64, i64, {i64, i64}, i64 } - -@G_str_111 = global { i64, [4 x i8] } {i64 4, [4 x i8] c"Hej\0A"} -@G_str_999 = global { i64, [5 x i8] } {i64 5, [5 x i8] c"QRST\0A"} - -define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) { - %t = alloca %T_tigermain - %a = getelementptr %T_tigermain, %T_tigermain* %t, i32 0, i32 2, i32 1 - store i64 9, i64* %a - %r = load i64, i64* %a - ret i64 %r -} -''' - - print(data) - ast = p.parse(data) - - auto_step(ast) - if True: - return - - -if __name__ == '__main__': - gogo()