Mercurial > lcfOS
comparison python/ir/module.py @ 157:8f3924b6076e
Added some code generator things
author | Windel Bouwman |
---|---|
date | Sun, 03 Mar 2013 18:14:35 +0100 |
parents | 1b4a85bdd99c |
children | 9683a4cd848f |
comparison
equal
deleted
inserted
replaced
156:1b4a85bdd99c | 157:8f3924b6076e |
---|---|
1 from .symboltable import SymbolTable | 1 from .symboltable import SymbolTable |
2 | |
3 # Types: | |
4 class Type: | |
5 def __init__(self): | |
6 pass | |
7 | |
8 class IntegerType(Type): | |
9 def __init__(self, bits): | |
10 super().__init__() | |
11 self.bits = bits | |
12 | |
13 class VoidType(Type): | |
14 pass | |
15 | |
16 class FunctionType(Type): | |
17 def __init__(self, resultType, parameterTypes): | |
18 super().__init__() | |
19 assert type(parameterTypes) is list | |
20 self.resultType = resultType | |
21 self.parameterTypes = parameterTypes | |
22 | |
23 # Default types: | |
24 i8 = IntegerType(8) | |
25 i16 = IntegerType(16) | |
26 i32 = IntegerType(32) | |
27 void = VoidType() | |
28 | |
29 # IR-Structures: | |
2 | 30 |
3 class Module: | 31 class Module: |
4 """ Main container for a piece of code. Contains globals and functions. """ | 32 """ Main container for a piece of code. Contains globals and functions. """ |
5 def __init__(self, name): | 33 def __init__(self, name): |
6 self.name = name | 34 self.name = name |
21 def __init__(self, name, functiontype): | 49 def __init__(self, name, functiontype): |
22 super().__init__() | 50 super().__init__() |
23 self.name = name | 51 self.name = name |
24 self.functiontype = functiontype | 52 self.functiontype = functiontype |
25 | 53 |
26 self.module.Functions.append(self) | |
27 self.basicblocks = [] | 54 self.basicblocks = [] |
28 self.arguments = [] | 55 self.arguments = [] |
29 # Construct formal arguments depending on function type | |
30 BasicBlocks = property(lambda self: self.basicblocks) | 56 BasicBlocks = property(lambda self: self.basicblocks) |
31 Arguments = property(lambda self: self.arguments) | 57 Arguments = property(lambda self: self.arguments) |
32 ReturnType = property(lambda self: self.functiontype.returnType) | 58 ReturnType = property(lambda self: self.functiontype.returnType) |
33 FunctionType = property(lambda self: self.functiontype) | 59 FunctionType = property(lambda self: self.functiontype) |
34 | 60 |