210
|
1 import ir, target
|
|
2 from ppci import CompilerError
|
|
3
|
|
4 class CodeGenerator:
|
|
5 """ Target independent code generator """
|
|
6 def __init__(self, tg):
|
|
7 assert isinstance(tg, target.Target)
|
|
8 self.tg = tg
|
|
9
|
|
10 def tryMap(self, ii):
|
|
11 for mi in self.tg.instructions:
|
|
12 if mi.irpattern is ii:
|
|
13 return mi.FromIr(ii)
|
|
14 raise CompilerError('Cannot map {0}'.format(ii))
|
|
15
|
|
16 def generate(self, ircode):
|
|
17 assert isinstance(ircode, ir.Module)
|
|
18 obj = object()
|
|
19 for gvar in ircode.Variables:
|
|
20 print(gvar)
|
|
21 print('TODO')
|
|
22 for f in ircode.Functions:
|
|
23 for bb in f.BasicBlocks:
|
|
24 for ins in bb.Instructions:
|
|
25 # Instruction selection:
|
|
26 #mi = self.tryMap(ins)
|
236
|
27 pass
|
210
|
28 return obj
|
|
29
|
|
30
|