From a7b3db8c1d06892978eb839e20c79976675e05db Mon Sep 17 00:00:00 2001 From: cfreksen Date: Sun, 29 Oct 2017 18:22:37 +0100 Subject: [PATCH] Add more cases for prettyprinting types. --- ll.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/ll.py b/ll.py index 0c94b1a..acc63c5 100644 --- a/ll.py +++ b/ll.py @@ -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):