Add more cases for prettyprinting types.

This commit is contained in:
cfreksen 2017-10-29 18:22:37 +01:00
parent 05be04891b
commit a7b3db8c1d
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

21
ll.py
View File

@ -13,6 +13,20 @@ class SimpleType(Enum):
I32 = 4
I64 = 5
def __repr__(self):
if self == SimpleType.Void:
return 'void'
elif self == SimpleType.I1:
return 'i1'
elif self == SimpleType.I8:
return 'i8'
elif self == SimpleType.I32:
return 'i32'
elif self == SimpleType.I64:
return 'i64'
else:
return str(self)
Program = namedtuple('Program', ['tdecls', 'gdecls', 'fdecls'])
@ -57,12 +71,15 @@ Id = namedtuple('Id', ['val'])
def ty2s(ty):
if ty == SimpleType.I64:
return 'i64'
if isinstance(ty, SimpleType):
return repr(ty)
elif isinstance(ty, PointerType):
return ty2s(ty.inner_ty) + '*'
else:
# TODO
print('Unknown type: {}'
.format(ty))
return str(ty)
def oper2s(operand):