annotate python/codegen.py @ 225:1c7364bd74c7

Fixed pointer deref
author Windel Bouwman
date Thu, 11 Jul 2013 07:42:30 +0200
parents 67b0feafe5ae
children 8786811a5a59
rev   line source
210
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
1 import ir, target
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
2 from ppci import CompilerError
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
3
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
4 class CodeGenerator:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
5 """ Target independent code generator """
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
6 def __init__(self, tg):
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
7 assert isinstance(tg, target.Target)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
8 self.tg = tg
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
9
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
10 def tryMap(self, ii):
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
11 for mi in self.tg.instructions:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
12 if mi.irpattern is ii:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
13 return mi.FromIr(ii)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
14 raise CompilerError('Cannot map {0}'.format(ii))
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
15
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
16 def generate(self, ircode):
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
17 assert isinstance(ircode, ir.Module)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
18 obj = object()
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
19 for gvar in ircode.Variables:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
20 print(gvar)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
21 print('TODO')
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
22 for f in ircode.Functions:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
23 for bb in f.BasicBlocks:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
24 print(bb)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
25 for ins in bb.Instructions:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
26 # Instruction selection:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
27 print(ins)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
28 #mi = self.tryMap(ins)
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
29 return obj
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
30
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
31