Implement global identifiers.

This commit is contained in:
cfreksen 2017-10-30 01:09:36 +01:00
parent 6f64647852
commit 7cd2560956
No known key found for this signature in database
GPG Key ID: EAC13EE101008978
1 changed files with 9 additions and 1 deletions

View File

@ -317,7 +317,13 @@ def eval_oper(operand, ssa_env, global_env):
elif isinstance(operand, ll.Const):
return operand.val
elif isinstance(operand, ll.Gid):
TODO('eval_oper Gid')
gid = operand.val
try:
return global_env[gid]
except KeyError:
err('Unable to find @{} in environment:\n{}'
.format(global_env))
return 0
elif isinstance(operand, ll.Id):
id = operand.val
try:
@ -325,6 +331,7 @@ def eval_oper(operand, ssa_env, global_env):
except KeyError:
err('Unable to find %{} in environment:\n{}'
.format(id, ssa_env))
return 0
def eval_binop(bop, left, right):
@ -464,6 +471,7 @@ def base_ty2size(base_ty):
.format(ll.ty2s(base_ty)))
return 1
def alloc_globals(gdecls, heap):
def alloc_global(ginit):
next_idx = len(heap)