diff python/ir/module.py @ 158:9683a4cd848f

Added some functions for code generation
author Windel Bouwman
date Fri, 08 Mar 2013 16:52:44 +0100
parents 8f3924b6076e
children 4348da5ca307
line wrap: on
line diff
--- a/python/ir/module.py	Sun Mar 03 18:14:35 2013 +0100
+++ b/python/ir/module.py	Fri Mar 08 16:52:44 2013 +0100
@@ -33,11 +33,12 @@
    def __init__(self, name):
       self.name = name
       self.functions = [] # Do functions come out of symbol table?
-      self.globals_ = [] # TODO: are globals in symbol table?
+      self.globs = [] # TODO: are globals in symbol table?
       self.symtable = SymbolTable()
-   Globals = property(lambda self: self.globals_)
+   Globals = property(lambda self: self.globs)
    Functions = property(lambda self: self.functions)
-   Identifier = property(lambda self: self.identifier)
+   def __repr__(self):
+      return 'IR-mod {0}'.format(self.name)
 
 class Argument:
    def __init__(self, argtype, name, function):
@@ -57,6 +58,8 @@
    Arguments = property(lambda self: self.arguments)
    ReturnType = property(lambda self: self.functiontype.returnType)
    FunctionType = property(lambda self: self.functiontype)
+   def __repr__(self):
+      return 'FUNC {0}'.format(self.name)
    
 class BasicBlock:
    """ 
@@ -66,8 +69,20 @@
    def __init__(self):
       super().__init__()
       self.instructions = []
-      self.name = None
+      self.label = None
    def getInstructions(self):
       return self.instructions
    Instructions = property(getInstructions)
 
+def printIr(md):
+   print(md)
+   for g in md.Globals:
+      print(g)
+   for f in md.Functions:
+      print(f)
+      for bb in f.BasicBlocks:
+         print('{0}:'.format(bb))
+         for ins in bb.Instructions:
+            print(' {0}'.format(ins))
+      print()
+