From 5f7a5bf26c8e30251734350db784a5a56f37dca9 Mon Sep 17 00:00:00 2001 From: cfreksen Date: Sun, 29 Oct 2017 21:40:26 +0100 Subject: [PATCH] Implement load. --- ll.py | 4 ++++ stepper.py | 22 ++++++++++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/ll.py b/ll.py index b34838e..4477e78 100644 --- a/ll.py +++ b/ll.py @@ -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), diff --git a/stepper.py b/stepper.py index aee0c88..77c5a12 100644 --- a/stepper.py +++ b/stepper.py @@ -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 } '''