changeset 210:67b0feafe5ae

Added missing file
author Windel Bouwman
date Sat, 29 Jun 2013 10:09:50 +0200
parents 07bfea4c1ed7
children 99164160fb0b
files python/codegen.py
diffstat 1 files changed, 31 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/python/codegen.py	Sat Jun 29 10:09:50 2013 +0200
@@ -0,0 +1,31 @@
+import ir, target
+from ppci import CompilerError
+
+class CodeGenerator:
+    """ Target independent code generator """
+    def __init__(self, tg):
+        assert isinstance(tg, target.Target)
+        self.tg = tg
+
+    def tryMap(self, ii):
+        for mi in self.tg.instructions:
+            if mi.irpattern is ii:
+                return mi.FromIr(ii)
+        raise CompilerError('Cannot map {0}'.format(ii))
+        
+    def generate(self, ircode):
+        assert isinstance(ircode, ir.Module)
+        obj = object()
+        for gvar in ircode.Variables:
+            print(gvar)
+            print('TODO')
+        for f in ircode.Functions:
+            for bb in f.BasicBlocks:
+                print(bb)
+                for ins in bb.Instructions:
+                    # Instruction selection:
+                    print(ins)
+                    #mi = self.tryMap(ins)
+        return obj
+                        
+