annotate python/codegen.py @ 268:5ec7580976d9

Op naar tree-IR
author Windel Bouwman
date Wed, 14 Aug 2013 20:12:40 +0200
parents 8786811a5a59
children ea93e0a7a31e
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 for ins in bb.Instructions:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
25 # Instruction selection:
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
26 #mi = self.tryMap(ins)
236
8786811a5a59 Fix pcrel
Windel Bouwman
parents: 210
diff changeset
27 pass
210
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
28 return obj
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
29
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
30