Mercurial > lcfOS
comparison 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 |
comparison
equal
deleted
inserted
replaced
154:81e08e2e7777 | 155:b28a11c01dbe |
---|---|
1 from .value import Value | |
2 from .symboltable import SymbolTable | 1 from .symboltable import SymbolTable |
3 | 2 |
4 class Module(Value): | 3 class Module: |
5 """ | 4 """ Main container for a piece of code. Contains globals and functions. """ |
6 Main container for a piece of code. Contains globals and functions. | 5 def __init__(self, name): |
7 """ | 6 self.name = name |
8 def __init__(self, identifier=None): | |
9 self.identifier = identifier | |
10 self.functions = [] # Do functions come out of symbol table? | 7 self.functions = [] # Do functions come out of symbol table? |
11 self.globals_ = [] # TODO: are globals in symbol table? | 8 self.globals_ = [] # TODO: are globals in symbol table? |
12 self.symtable = SymbolTable() | 9 self.symtable = SymbolTable() |
13 | 10 |
14 Globals = property(lambda self: self.globals_) | 11 Globals = property(lambda self: self.globals_) |
15 Functions = property(lambda self: self.functions) | 12 Functions = property(lambda self: self.functions) |
16 Identifier = property(lambda self: self.identifier) | 13 Identifier = property(lambda self: self.identifier) |
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) | |
17 | 37 |
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 |