Add conditional branching.
This commit is contained in:
parent
344609e54b
commit
4aeb986d75
35
stepper.py
35
stepper.py
|
@ -12,6 +12,11 @@ def err(msg):
|
|||
.format(msg))
|
||||
|
||||
|
||||
def warn(msg):
|
||||
print('WARNING: {}'
|
||||
.format(msg))
|
||||
|
||||
|
||||
def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||
tdecs, fdecs, call_res):
|
||||
if len(insns) == 0:
|
||||
|
@ -108,6 +113,30 @@ def terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory):
|
|||
print('Jumping unconditionally to {}'
|
||||
.format(label))
|
||||
|
||||
return (new_insns, new_terminator, blocks, stack_frames,
|
||||
ssa_env, memory, None)
|
||||
elif isinstance(terminator, ll.Cbr):
|
||||
ty = terminator.ty
|
||||
if ty != ll.SimpleType.I1:
|
||||
warn('Branching based on value of type {}. You ought to branch on {}'
|
||||
.format(ll.ty2s(ty), ll.ty2s(ll.SimpleType.I1)))
|
||||
operand = terminator.oper
|
||||
operand_v = eval_oper(operand, ssa_env, global_env)
|
||||
|
||||
if operand_v:
|
||||
label = terminator.then_label
|
||||
else:
|
||||
label = terminator.else_label
|
||||
|
||||
next_block = blocks[label]
|
||||
new_insns = next_block.insns
|
||||
new_terminator = next_block.terminator
|
||||
clear_block_from_ssa_env(new_insns, ssa_env)
|
||||
|
||||
# TODO
|
||||
print('Operand was {}. Branching to {}'
|
||||
.format(operand_v, label))
|
||||
|
||||
return (new_insns, new_terminator, blocks, stack_frames,
|
||||
ssa_env, memory, None)
|
||||
else:
|
||||
|
@ -182,14 +211,14 @@ def gogo():
|
|||
data = r'''
|
||||
define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
|
||||
%a = add i64 3, 5 ; please be 8
|
||||
br label %L1
|
||||
%c = icmp eq i64 %a, 9
|
||||
br i1 %c, label %L1, label %L2
|
||||
L1:
|
||||
%b = add i64 %a, %a
|
||||
%c = icmp eq i64 %a, %b
|
||||
ret i1 %c
|
||||
L2:
|
||||
%d = add i64 %a, 1
|
||||
%e = add i64 10, %b
|
||||
%e = add i64 10, %d
|
||||
ret i64 %e
|
||||
}
|
||||
'''
|
||||
|
|
Loading…
Reference in New Issue
Block a user