Implement more or less proper user interaction.

This commit is contained in:
cfreksen 2017-10-30 02:31:29 +01:00
parent d63c5c1d05
commit 5198d44417
No known key found for this signature in database
GPG Key ID: EAC13EE101008978
2 changed files with 56 additions and 33 deletions

54
llvm--emulator.py Executable file
View File

@ -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()

View File

@ -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()