comparison python/ir/asmwriter.py @ 147:4e79484a9d47

Moved core to ir folder
author Windel Bouwman
date Fri, 22 Feb 2013 10:33:48 +0100
parents python/ppci/core/asmwriter.py@9e552d34bd60
children
comparison
equal deleted inserted replaced
146:91af0e40f868 147:4e79484a9d47
1
2 from . import llvmtype
3 from .instruction import BinaryOperator
4 #typeNames[VoidType] = 'void'
5
6 class AsmWriter:
7 def __init__(self):
8 self.typeNames = {}
9 self.typeNames[llvmtype.typeID.Void] = 'void'
10 def printModule(self, module):
11 if module.Identifier:
12 print('; ModuleID = {0}'.format(module.Identifier))
13 # Print functions:
14 for f in module.Functions:
15 self.printFunction(f)
16 def printFunction(self, f):
17 # TODO: if definition:
18
19 t = self.strType(f.ReturnType.tid)
20 args = '()'
21 print('define {0} {1}{2}'.format(t, f.name, args))
22 print('{')
23 for bb in f.BasicBlocks:
24 print('basic block!')
25 self.printBasicBlock(bb)
26 print('}')
27
28 def strType(self, t):
29 return self.typeNames[t]
30
31 def printBasicBlock(self, bb):
32 if bb.Name:
33 # print label
34 print('{0}:'.format(bb.Name))
35 for instr in bb.Instructions:
36 self.printInstruction(instr)
37 def printInstruction(self, i):
38 print('Instruction!')
39 if isinstance(i, BinaryOperator):
40 print(i.operation, i.value1.Name, i.value2.Name)
41 else:
42 print(i)
43