Implement load.

This commit is contained in:
cfreksen 2017-10-29 21:40:26 +01:00
parent f04d22c27e
commit 5f7a5bf26c
No known key found for this signature in database
GPG Key ID: EAC13EE101008978
2 changed files with 24 additions and 2 deletions

4
ll.py
View File

@ -110,6 +110,10 @@ def insn2s(insn):
if isinstance(insn, Alloca):
return ('alloca {}'
.format(ty2s(insn.ty)))
if isinstance(insn, Load):
return ('load {}, {}* {}'
.format(ty2s(insn.ty), ty2s(insn.ty),
oper2s(insn.location)))
if isinstance(insn, Store):
return ('store {} {}, {}* {}'
.format(ty2s(insn.ty),

View File

@ -62,7 +62,22 @@ def step(insns, terminator, blocks, stack_frames, ssa_env, global_env, heap,
res = ptr
elif isinstance(next_insn, ll.Load):
TODO('Load')
ty = next_insn.ty
base_ty = ty2base_ty(ty, tdecs)
size = base_ty2size(base_ty)
location = next_insn.location
location_v = eval_oper(location, ssa_env, global_env)
# TODO
print('load heap[{}]'
.format(location_v))
if size != 1:
err(('This emulator cannot load objects larger than 1 cell.'
' Current size is {}')
.format(size))
res = heap[location_v]
elif isinstance(next_insn, ll.Store):
ty = next_insn.ty
base_ty = ty2base_ty(ty, tdecs)
@ -351,8 +366,11 @@ def gogo():
data = r'''
define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
%a = alloca i64
%a_alt = alloca i64
store i64 9, i64* %a
ret i64 77
%b = load i64, i64* %a
%b_alt = load i64, i64* %a_alt
ret i64 %b
}
'''