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 Globals = property(lambda self: self.globals_)
|
|
11 Functions = property(lambda self: self.functions)
|
106
|
12 Identifier = property(lambda self: self.identifier)
|
155
|
13
|
|
14 class Argument:
|
|
15 def __init__(self, argtype, name, function):
|
|
16 self.t = argtype
|
|
17 self.name = name
|
|
18 self.function = function
|
|
19
|
|
20 class Function:
|
156
|
21 def __init__(self, name, functiontype):
|
155
|
22 super().__init__()
|
156
|
23 self.name = name
|
155
|
24 self.functiontype = functiontype
|
|
25
|
|
26 self.module.Functions.append(self)
|
|
27 self.basicblocks = []
|
|
28 self.arguments = []
|
|
29 # Construct formal arguments depending on function type
|
|
30 BasicBlocks = property(lambda self: self.basicblocks)
|
|
31 Arguments = property(lambda self: self.arguments)
|
|
32 ReturnType = property(lambda self: self.functiontype.returnType)
|
|
33 FunctionType = property(lambda self: self.functiontype)
|
94
|
34
|
155
|
35 class BasicBlock:
|
|
36 """
|
|
37 A basic block represents a sequence of instructions without
|
|
38 jumps and branches.
|
|
39 """
|
|
40 def __init__(self):
|
|
41 super().__init__()
|
|
42 self.instructions = []
|
|
43 self.name = None
|
|
44 def getInstructions(self):
|
|
45 return self.instructions
|
|
46 Instructions = property(getInstructions)
|
|
47
|