Handle more types for Alloca.
This commit is contained in:
parent
5f7a5bf26c
commit
7deddce45d
5
ll.py
5
ll.py
|
@ -77,6 +77,11 @@ def ty2s(ty):
|
||||||
return repr(ty)
|
return repr(ty)
|
||||||
elif isinstance(ty, PointerType):
|
elif isinstance(ty, PointerType):
|
||||||
return ty2s(ty.inner_ty) + '*'
|
return ty2s(ty.inner_ty) + '*'
|
||||||
|
elif isinstance(ty, StructType):
|
||||||
|
return ('{{{}}}'
|
||||||
|
.format(', '.join(map(ty2s, ty.fields))))
|
||||||
|
if isinstance(ty, NamedType):
|
||||||
|
return '%' + ty.other_name
|
||||||
else:
|
else:
|
||||||
# TODO
|
# TODO
|
||||||
print('ty2s: Unknown type: {}'
|
print('ty2s: Unknown type: {}'
|
||||||
|
|
27
stepper.py
27
stepper.py
|
@ -338,11 +338,25 @@ def eval_icmp(cnd, left, right):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
|
||||||
def ty2base_ty(ty, tdecs):
|
def ty2base_ty(ty, tdecs, seen=[]):
|
||||||
if isinstance(ty, ll.SimpleType):
|
if isinstance(ty, ll.SimpleType):
|
||||||
return ty
|
return ty
|
||||||
elif isinstance(ty, ll.PointerType):
|
elif isinstance(ty, ll.PointerType):
|
||||||
return ll.PointerType(ty2base_ty(ty.inner_ty))
|
return ll.PointerType(ty2base_ty(ty.inner_ty, tdecs, seen))
|
||||||
|
if isinstance(ty, ll.StructType):
|
||||||
|
return ll.StructType([ty2base_ty(t, tdecs, seen)
|
||||||
|
for t in ty.fields])
|
||||||
|
if isinstance(ty, ll.NamedType):
|
||||||
|
other_name = ty.other_name
|
||||||
|
if other_name in seen:
|
||||||
|
err('Cyclic type definition, offender: {}. Seen: {}'
|
||||||
|
.format(other_name, seen))
|
||||||
|
elif other_name in tdecs:
|
||||||
|
return ty2base_ty(tdecs[other_name].body, tdecs, [other_name] + seen)
|
||||||
|
else:
|
||||||
|
err('Could not find type {} in gloval type environment:\n{}'
|
||||||
|
.format(ty2s(ty), tdecs.keys()))
|
||||||
|
return ll.SimpleType.Void
|
||||||
else:
|
else:
|
||||||
# TODO
|
# TODO
|
||||||
err('ty2base_ty: Unknown type: {}'
|
err('ty2base_ty: Unknown type: {}'
|
||||||
|
@ -353,6 +367,10 @@ def ty2base_ty(ty, tdecs):
|
||||||
def base_ty2size(base_ty):
|
def base_ty2size(base_ty):
|
||||||
if isinstance(base_ty, ll.SimpleType):
|
if isinstance(base_ty, ll.SimpleType):
|
||||||
return 1
|
return 1
|
||||||
|
elif isinstance(base_ty, ll.PointerType):
|
||||||
|
return 1
|
||||||
|
elif isinstance(base_ty, ll.StructType):
|
||||||
|
return sum(map(base_ty2size, base_ty.fields))
|
||||||
else:
|
else:
|
||||||
# TODO
|
# TODO
|
||||||
err('base_ty2size: Unknown type or illegal type: {}'
|
err('base_ty2size: Unknown type or illegal type: {}'
|
||||||
|
@ -364,12 +382,13 @@ def gogo():
|
||||||
p = parser.LLVMParser()
|
p = parser.LLVMParser()
|
||||||
p.build()
|
p.build()
|
||||||
data = r'''
|
data = r'''
|
||||||
|
%T_tigermain = type { i64, i64 }
|
||||||
|
|
||||||
define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
|
define i64 @tigermain (i64 %U_mainSL_8, i64 %U_mainDummy_9) {
|
||||||
%a = alloca i64
|
%a = alloca i64
|
||||||
%a_alt = alloca i64
|
%t = alloca %T_tigermain
|
||||||
store i64 9, i64* %a
|
store i64 9, i64* %a
|
||||||
%b = load i64, i64* %a
|
%b = load i64, i64* %a
|
||||||
%b_alt = load i64, i64* %a_alt
|
|
||||||
ret i64 %b
|
ret i64 %b
|
||||||
}
|
}
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user