annotate python/codegen.py @ 280:02385f62f250

Rework from str interface to Instruction interface
author Windel Bouwman
date Sat, 02 Nov 2013 10:03:26 +0100
parents ea93e0a7a31e
children 7b38782ed496
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)
280
02385f62f250 Rework from str interface to Instruction interface
Windel Bouwman
parents: 274
diff changeset
21 raise Exception() # TODO
210
67b0feafe5ae Added missing file
Windel Bouwman
parents:
diff changeset
22 for f in ircode.Functions:
274
ea93e0a7a31e Move docs
Windel Bouwman
parents: 236
diff changeset
23 for bb in f.Blocks:
210
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