diff python/ir/module.py @ 155:b28a11c01dbe

Simplified IR classes
author Windel Bouwman
date Sun, 03 Mar 2013 13:20:03 +0100
parents 4e79484a9d47
children 1b4a85bdd99c
line wrap: on
line diff
--- a/python/ir/module.py	Sat Mar 02 10:19:38 2013 +0100
+++ b/python/ir/module.py	Sun Mar 03 13:20:03 2013 +0100
@@ -1,12 +1,9 @@
-from .value import Value
 from .symboltable import SymbolTable
 
-class Module(Value):
-   """
-      Main container for a piece of code. Contains globals and functions.
-   """
-   def __init__(self, identifier=None):
-      self.identifier = identifier
+class Module:
+   """ Main container for a piece of code. Contains globals and functions. """
+   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.symtable = SymbolTable()
@@ -14,4 +11,40 @@
    Globals = property(lambda self: self.globals_)
    Functions = property(lambda self: self.functions)
    Identifier = property(lambda self: self.identifier)
+
+class Argument:
+   def __init__(self, argtype, name, function):
+      self.t = argtype
+      self.name = name
+      self.function = function
+
+class Function:
+   def __init__(self, functiontype, name, module):
+      super().__init__()
+      self.functiontype = functiontype
+      self.name = name
+      self.module = module
+
+      self.module.Functions.append(self)
+      self.basicblocks = []
+      self.arguments = []
+      # Construct formal arguments depending on function type
+
+   BasicBlocks = property(lambda self: self.basicblocks)
+   Arguments = property(lambda self: self.arguments)
+   ReturnType = property(lambda self: self.functiontype.returnType)
+   FunctionType = property(lambda self: self.functiontype)
    
+class BasicBlock:
+   """ 
+     A basic block represents a sequence of instructions without
+     jumps and branches.
+   """
+   def __init__(self):
+      super().__init__()
+      self.instructions = []
+      self.name = None
+   def getInstructions(self):
+      return self.instructions
+   Instructions = property(getInstructions)
+