Mercurial > lcfOS
comparison python/ppci/core/asmwriter.py @ 107:1544e7a4aa98
Improvements
author | Windel Bouwman |
---|---|
date | Tue, 01 Jan 2013 17:16:05 +0100 |
parents | |
children | 9e552d34bd60 |
comparison
equal
deleted
inserted
replaced
106:f2d980eef509 | 107:1544e7a4aa98 |
---|---|
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 |