From 134191145989b423bf7f82bc085102a1ca087455 Mon Sep 17 00:00:00 2001 From: cfreksen Date: Sun, 29 Oct 2017 15:17:45 +0100 Subject: [PATCH] Add incomplete LLVM pretty printing. --- ll.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/ll.py b/ll.py index ecfff99..0c94b1a 100644 --- a/ll.py +++ b/ll.py @@ -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))