107
|
1
|
|
2 from . import llvmtype
|
|
3 #typeNames[VoidType] = 'void'
|
|
4
|
|
5 class AsmWriter:
|
|
6 def __init__(self):
|
|
7 self.typeNames = {}
|
|
8 self.typeNames[llvmtype.typeID.Void] = 'void'
|
|
9 def printModule(self, module):
|
|
10 if module.Identifier:
|
|
11 print('; ModuleID = {0}'.format(module.Identifier))
|
|
12 #
|
|
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
|
|
24 for bb in f.BasicBlocks:
|
|
25 print(bb)
|
|
26
|
|
27 print('}')
|
|
28
|
|
29 def strType(self, t):
|
|
30 return self.typeNames[t]
|
|
31
|
|
32 def printBasicBlock(self, bb):
|
|
33 if bb.Name:
|
|
34 # print label
|
|
35 print('{0}:'.format(bb.Name))
|
|
36 for instr in bb.Instructions:
|
|
37 self.printInstruction(instr)
|
|
38 def printInstruction(self, i):
|
|
39 pass
|
|
40
|