Rename memory to heap.
This commit is contained in:
parent
6b6dd9cf68
commit
46f5bf9fc7
36
stepper.py
36
stepper.py
|
@ -23,10 +23,10 @@ class Garbage(Enum):
|
||||||
GARBAGE = '<<Unitialized memory>>'
|
GARBAGE = '<<Unitialized memory>>'
|
||||||
|
|
||||||
|
|
||||||
def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
|
||||||
tdecs, fdecs, call_res):
|
tdecs, fdecs, call_res):
|
||||||
if len(insns) == 0:
|
if len(insns) == 0:
|
||||||
return terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
return terminate(terminator, blocks, stack_frames, ssa_env, global_env, heap,
|
||||||
call_res)
|
call_res)
|
||||||
ssa_target, next_insn = insns[0]
|
ssa_target, next_insn = insns[0]
|
||||||
insns_rest = insns[1:]
|
insns_rest = insns[1:]
|
||||||
|
@ -56,9 +56,9 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||||
print('alloca {} --> allocating {} cells'
|
print('alloca {} --> allocating {} cells'
|
||||||
.format(ll.ty2s(base_ty), size))
|
.format(ll.ty2s(base_ty), size))
|
||||||
|
|
||||||
ptr = len(memory)
|
ptr = len(heap)
|
||||||
for i in range(max(size, 1)):
|
for i in range(max(size, 1)):
|
||||||
memory.append(Garbage.GARBAGE)
|
heap.append(Garbage.GARBAGE)
|
||||||
|
|
||||||
res = ptr
|
res = ptr
|
||||||
elif isinstance(next_insn, ll.Load):
|
elif isinstance(next_insn, ll.Load):
|
||||||
|
@ -83,7 +83,7 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||||
if not isinstance(callee, ll.Gid):
|
if not isinstance(callee, ll.Gid):
|
||||||
err('Cannot call anything but global identifiers: {}'
|
err('Cannot call anything but global identifiers: {}'
|
||||||
.format(ll.oper2s(callee)))
|
.format(ll.oper2s(callee)))
|
||||||
return insns_rest, terminator, blocks, stack_frames, ssa_env, memory, call_res
|
return insns_rest, terminator, blocks, stack_frames, ssa_env, heap, call_res
|
||||||
|
|
||||||
arguments_v = [eval_oper(oper, ssa_env, global_env)
|
arguments_v = [eval_oper(oper, ssa_env, global_env)
|
||||||
for ty, oper in arguments]
|
for ty, oper in arguments]
|
||||||
|
@ -93,7 +93,7 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||||
except KeyError:
|
except KeyError:
|
||||||
err('Could not find function {} in environment:\n{}'
|
err('Could not find function {} in environment:\n{}'
|
||||||
.format(callee.val, fdecs.keys()))
|
.format(callee.val, fdecs.keys()))
|
||||||
return insns_rest, terminator, blocks, stack_frames, ssa_env, memory, call_res
|
return insns_rest, terminator, blocks, stack_frames, ssa_env, heap, call_res
|
||||||
|
|
||||||
parameters = function.parameters
|
parameters = function.parameters
|
||||||
print('call @{} ({})'
|
print('call @{} ({})'
|
||||||
|
@ -105,10 +105,10 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||||
child_blocks = function.body.named_blocks
|
child_blocks = function.body.named_blocks
|
||||||
child_stack_frames = [(insns_rest, terminator, blocks, ssa_env)] + stack_frames
|
child_stack_frames = [(insns_rest, terminator, blocks, ssa_env)] + stack_frames
|
||||||
child_ssa_env = {par[1]: arg for par, arg in zip(parameters, arguments_v)}
|
child_ssa_env = {par[1]: arg for par, arg in zip(parameters, arguments_v)}
|
||||||
child_memory = memory
|
child_heap = heap
|
||||||
child_call_res = [ssa_target] + call_res
|
child_call_res = [ssa_target] + call_res
|
||||||
return (child_insns, child_terminator, child_blocks, child_stack_frames,
|
return (child_insns, child_terminator, child_blocks, child_stack_frames,
|
||||||
child_ssa_env, child_memory, child_call_res)
|
child_ssa_env, child_heap, child_call_res)
|
||||||
|
|
||||||
elif isinstance(next_insn, ll.Bitcast):
|
elif isinstance(next_insn, ll.Bitcast):
|
||||||
oper = next_insn.oper
|
oper = next_insn.oper
|
||||||
|
@ -161,10 +161,10 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, memory,
|
||||||
.format(ssa_target, res))
|
.format(ssa_target, res))
|
||||||
ssa_env[ssa_target] = res
|
ssa_env[ssa_target] = res
|
||||||
|
|
||||||
return insns_rest, terminator, blocks, stack_frames, ssa_env, memory, call_res
|
return insns_rest, terminator, blocks, stack_frames, ssa_env, heap, call_res
|
||||||
|
|
||||||
|
|
||||||
def terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory, call_res):
|
def terminate(terminator, blocks, stack_frames, ssa_env, global_env, heap, call_res):
|
||||||
def clear_block_from_ssa_env(insns, ssa_env):
|
def clear_block_from_ssa_env(insns, ssa_env):
|
||||||
for (id, insn) in insns:
|
for (id, insn) in insns:
|
||||||
if id is not None and id in ssa_env:
|
if id is not None and id in ssa_env:
|
||||||
|
@ -197,7 +197,7 @@ def terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory, cal
|
||||||
new_stack_frames = stack_frames[1:]
|
new_stack_frames = stack_frames[1:]
|
||||||
new_call_res = call_res[1:]
|
new_call_res = call_res[1:]
|
||||||
return (new_insns, new_terminator, new_blocks, new_stack_frames,
|
return (new_insns, new_terminator, new_blocks, new_stack_frames,
|
||||||
new_ssa_env, memory, new_call_res)
|
new_ssa_env, heap, new_call_res)
|
||||||
elif isinstance(terminator, ll.Br):
|
elif isinstance(terminator, ll.Br):
|
||||||
label = terminator.label
|
label = terminator.label
|
||||||
next_block = blocks[label]
|
next_block = blocks[label]
|
||||||
|
@ -214,7 +214,7 @@ def terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory, cal
|
||||||
.format(label))
|
.format(label))
|
||||||
|
|
||||||
return (new_insns, new_terminator, blocks, stack_frames,
|
return (new_insns, new_terminator, blocks, stack_frames,
|
||||||
ssa_env, memory, call_res)
|
ssa_env, heap, call_res)
|
||||||
elif isinstance(terminator, ll.Cbr):
|
elif isinstance(terminator, ll.Cbr):
|
||||||
ty = terminator.ty
|
ty = terminator.ty
|
||||||
if ty != ll.SimpleType.I1:
|
if ty != ll.SimpleType.I1:
|
||||||
|
@ -238,7 +238,7 @@ def terminate(terminator, blocks, stack_frames, ssa_env, global_env, memory, cal
|
||||||
.format(operand_v, label))
|
.format(operand_v, label))
|
||||||
|
|
||||||
return (new_insns, new_terminator, blocks, stack_frames,
|
return (new_insns, new_terminator, blocks, stack_frames,
|
||||||
ssa_env, memory, call_res)
|
ssa_env, heap, call_res)
|
||||||
else:
|
else:
|
||||||
err('Unknown LLVM terminator: {}'
|
err('Unknown LLVM terminator: {}'
|
||||||
.format(terminator))
|
.format(terminator))
|
||||||
|
@ -353,15 +353,15 @@ define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
|
||||||
stack_frames = []
|
stack_frames = []
|
||||||
ssa_env = {}
|
ssa_env = {}
|
||||||
# TODO: memory structure has not been decided yet
|
# TODO: memory structure has not been decided yet
|
||||||
memory = [None]
|
heap = [None]
|
||||||
call_res = []
|
call_res = []
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
(insns, terminator, blocks,
|
(insns, terminator, blocks,
|
||||||
stack_frames, ssa_env, memory, call_res) = step(insns, terminator, blocks,
|
stack_frames, ssa_env, heap, call_res) = step(insns, terminator, blocks,
|
||||||
stack_frames, ssa_env,
|
stack_frames, ssa_env,
|
||||||
global_env, memory, tdecs,
|
global_env, heap, tdecs,
|
||||||
fdecs, call_res)
|
fdecs, call_res)
|
||||||
|
|
||||||
if terminator is None:
|
if terminator is None:
|
||||||
print('Stepping done! Final ssa_env:\n{}'
|
print('Stepping done! Final ssa_env:\n{}'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user