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