105
|
1 from .symboltable import SymbolTable
|
104
|
2
|
155
|
3 class Module:
|
|
4 """ Main container for a piece of code. Contains globals and functions. """
|
|
5 def __init__(self, name):
|
|
6 self.name = name
|
106
|
7 self.functions = [] # Do functions come out of symbol table?
|
|
8 self.globals_ = [] # TODO: are globals in symbol table?
|
105
|
9 self.symtable = SymbolTable()
|
|
10
|
|
11 Globals = property(lambda self: self.globals_)
|
|
12 Functions = property(lambda self: self.functions)
|
106
|
13 Identifier = property(lambda self: self.identifier)
|
155
|
14
|
|
15 class Argument:
|
|
16 def __init__(self, argtype, name, function):
|
|
17 self.t = argtype
|
|
18 self.name = name
|
|
19 self.function = function
|
|
20
|
|
21 class Function:
|
|
22 def __init__(self, functiontype, name, module):
|
|
23 super().__init__()
|
|
24 self.functiontype = functiontype
|
|
25 self.name = name
|
|
26 self.module = module
|
|
27
|
|
28 self.module.Functions.append(self)
|
|
29 self.basicblocks = []
|
|
30 self.arguments = []
|
|
31 # Construct formal arguments depending on function type
|
|
32
|
|
33 BasicBlocks = property(lambda self: self.basicblocks)
|
|
34 Arguments = property(lambda self: self.arguments)
|
|
35 ReturnType = property(lambda self: self.functiontype.returnType)
|
|
36 FunctionType = property(lambda self: self.functiontype)
|
94
|
37
|
155
|
38 class BasicBlock:
|
|
39 """
|
|
40 A basic block represents a sequence of instructions without
|
|
41 jumps and branches.
|
|
42 """
|
|
43 def __init__(self):
|
|
44 super().__init__()
|
|
45 self.instructions = []
|
|
46 self.name = None
|
|
47 def getInstructions(self):
|
|
48 return self.instructions
|
|
49 Instructions = property(getInstructions)
|
|
50
|