Add size check to Store.

This commit is contained in:
cfreksen 2017-10-29 21:33:57 +01:00
parent 1dc258d26f
commit f04d22c27e
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

View File

@ -65,6 +65,8 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
TODO('Load')
elif isinstance(next_insn, ll.Store):
ty = next_insn.ty
base_ty = ty2base_ty(ty, tdecs)
size = base_ty2size(base_ty)
value = next_insn.value
location = next_insn.location
@ -75,7 +77,12 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
print('heap[{}] <- {}'
.format(location_v, value_v))
if size == 1:
heap[location_v] = value_v
else:
err(('This emulator cannot store objects larger than 1 cell.'
' Current size is {}')
.format(size))
elif isinstance(next_insn, ll.Icmp):
cnd = next_insn.cnd
left = next_insn.left