annotate python/ir/module.py @ 156:1b4a85bdd99c

change types
author Windel Bouwman
date Sun, 03 Mar 2013 15:50:34 +0100
parents b28a11c01dbe
children 8f3924b6076e
rev   line source
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
1 from .symboltable import SymbolTable
104
ed230e947dc6 Added hexviewer
windel
parents: 102
diff changeset
2
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
3 class Module:
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
4 """ Main container for a piece of code. Contains globals and functions. """
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
5 def __init__(self, name):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
6 self.name = name
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
7 self.functions = [] # Do functions come out of symbol table?
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
8 self.globals_ = [] # TODO: are globals in symbol table?
105
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
9 self.symtable = SymbolTable()
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
10 Globals = property(lambda self: self.globals_)
6a303f835c6d Removed compilers directory
Windel Bouwman
parents: 104
diff changeset
11 Functions = property(lambda self: self.functions)
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 105
diff changeset
12 Identifier = property(lambda self: self.identifier)
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
13
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
14 class Argument:
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
15 def __init__(self, argtype, name, function):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
16 self.t = argtype
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
17 self.name = name
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
18 self.function = function
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
19
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
20 class Function:
156
1b4a85bdd99c change types
Windel Bouwman
parents: 155
diff changeset
21 def __init__(self, name, functiontype):
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
22 super().__init__()
156
1b4a85bdd99c change types
Windel Bouwman
parents: 155
diff changeset
23 self.name = name
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
24 self.functiontype = functiontype
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
25
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
26 self.module.Functions.append(self)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
27 self.basicblocks = []
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
28 self.arguments = []
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
29 # Construct formal arguments depending on function type
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
30 BasicBlocks = property(lambda self: self.basicblocks)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
31 Arguments = property(lambda self: self.arguments)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
32 ReturnType = property(lambda self: self.functiontype.returnType)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
33 FunctionType = property(lambda self: self.functiontype)
94
1be00bcfaabb Last parts before movage
windel
parents:
diff changeset
34
155
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
35 class BasicBlock:
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
36 """
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
37 A basic block represents a sequence of instructions without
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
38 jumps and branches.
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
39 """
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
40 def __init__(self):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
41 super().__init__()
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
42 self.instructions = []
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
43 self.name = None
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
44 def getInstructions(self):
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
45 return self.instructions
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
46 Instructions = property(getInstructions)
b28a11c01dbe Simplified IR classes
Windel Bouwman
parents: 147
diff changeset
47