Move some of the scaffolding into a more permanent function.
This commit is contained in:
parent
0536c7e683
commit
d63c5c1d05
93
stepper.py
93
stepper.py
|
@ -504,6 +504,53 @@ def alloc_globals(gdecls, heap):
|
|||
return global_env
|
||||
|
||||
|
||||
def auto_step(ast, function_name='tigermain', function_args=[1234, 5678]):
|
||||
tdecls = ast.tdecls
|
||||
fdecls = ast.fdecls
|
||||
gdecls = ast.gdecls
|
||||
|
||||
function = fdecls[function_name]
|
||||
body = function.body
|
||||
first_block = body.first_block
|
||||
blocks = body.named_blocks
|
||||
insns = first_block.insns
|
||||
terminator = first_block.terminator
|
||||
stack_frames = []
|
||||
ssa_env = {par[1]: arg for par, arg in zip(function.parameters, function_args)}
|
||||
heap = [None]
|
||||
call_res = []
|
||||
|
||||
global_env = alloc_globals(gdecls, heap)
|
||||
print('Heap after globals are allocated:')
|
||||
print(heap)
|
||||
|
||||
step_cnt = 0
|
||||
while True:
|
||||
(insns, terminator, blocks,
|
||||
stack_frames, ssa_env, heap, call_res) = step(insns, terminator, blocks,
|
||||
stack_frames, ssa_env,
|
||||
global_env, heap, tdecls,
|
||||
fdecls, call_res)
|
||||
step_cnt += 1
|
||||
if terminator is None:
|
||||
print('Stepping done!\nFinal ssa_env: {}'
|
||||
.format(ssa_env))
|
||||
print('Final heap: {}'
|
||||
.format(heap))
|
||||
print('Program resulted in {} after {} steps'.
|
||||
format(insns[0][1].val, step_cnt))
|
||||
break
|
||||
|
||||
if step_cnt % 100 == 0:
|
||||
while True:
|
||||
stop_q = input('We have now done {} steps. Continue? [Y/n]: '
|
||||
.format(step_cnt)).lower()
|
||||
if stop_q in ['y', 'yes', 'n', 'no', '']:
|
||||
break
|
||||
if stop_q in ['n', 'no']:
|
||||
break
|
||||
|
||||
|
||||
def gogo():
|
||||
p = parser.LLVMParser()
|
||||
p.build()
|
||||
|
@ -525,49 +572,9 @@ define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
|
|||
print(data)
|
||||
ast = p.parse(data)
|
||||
|
||||
tdecs = ast.tdecls
|
||||
fdecs = ast.fdecls
|
||||
gdecs = ast.gdecls
|
||||
|
||||
tigermain = ast.fdecls['tigermain']
|
||||
first_block = tigermain.body.first_block
|
||||
blocks = tigermain.body.named_blocks
|
||||
insns = first_block.insns
|
||||
terminator = first_block.terminator
|
||||
stack_frames = []
|
||||
ssa_env = {}
|
||||
heap = [None]
|
||||
call_res = []
|
||||
|
||||
step_cnt = 0
|
||||
|
||||
global_env = alloc_globals(gdecs, heap)
|
||||
|
||||
while True:
|
||||
(insns, terminator, blocks,
|
||||
stack_frames, ssa_env, heap, call_res) = step(insns, terminator, blocks,
|
||||
stack_frames, ssa_env,
|
||||
global_env, heap, tdecs,
|
||||
fdecs, call_res)
|
||||
step_cnt += 1
|
||||
if terminator is None:
|
||||
print('Stepping done!\nFinal ssa_env: {}'
|
||||
.format(ssa_env))
|
||||
print('Final heap: {}'
|
||||
.format(heap))
|
||||
print('Program resulted in {}'.
|
||||
format(insns[0][1].val))
|
||||
break
|
||||
|
||||
if step_cnt % 100 == 0:
|
||||
print(heap)
|
||||
while True:
|
||||
stop_q = input('We have now done {} steps. Continue? [Y/n]: '
|
||||
.format(step_cnt)).lower()
|
||||
if stop_q in ['y', 'yes', 'n', 'no', '']:
|
||||
break
|
||||
if stop_q in ['n', 'no']:
|
||||
break
|
||||
auto_step(ast)
|
||||
if True:
|
||||
return
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in New Issue
Block a user