Add incomplete LLVM pretty printing.

This commit is contained in:
cfreksen 2017-10-29 15:17:45 +01:00
parent 1ffe310f97
commit 1341911459
No known key found for this signature in database
GPG Key ID: EAC13EE101008978

31
ll.py
View File

@ -54,3 +54,34 @@ Null = namedtuple('Null', [])
Const = namedtuple('Const', ['val'])
Gid = namedtuple('Gid', ['val'])
Id = namedtuple('Id', ['val'])
def ty2s(ty):
if ty == SimpleType.I64:
return 'i64'
else:
# TODO
print('Unknown type: {}'
.format(ty))
def oper2s(operand):
if isinstance(operand, Const):
return str(operand.val)
elif isinstance(operand, Id):
return '%' + operand.val
else:
# TODO
print('Unknown operand: {}'
.format(operand))
def insn2s(insn):
if isinstance(insn, Binop):
return ('{} {} {}, {}'
.format(insn.bop, ty2s(insn.ty),
oper2s(insn.left), oper2s(insn.right)))
else:
# TODO
print('Unknown insn: {}'
.format(insn))