annotate python/ir/llvmtype.py @ 149:74241ca312cc

Fixes on parser and semantics
author Windel Bouwman
date Fri, 01 Mar 2013 11:43:52 +0100
parents 4e79484a9d47
children 1b4a85bdd99c
rev   line source
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
1
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
2 def Enum(**enums):
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
3 return type('Enum', (), enums)
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
4
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
5 typeID = Enum(Void=0, Double=3, Integer=10, Function=11, Struct=12, Array=13, Pointer=14, Vector=15)
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
6
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
7 class llvmType:
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
8 def __init__(self, tid):
107
1544e7a4aa98 Improvements
Windel Bouwman
parents: 106
diff changeset
9 self.tid = tid
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
10
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
11 class IntegerType(llvmType):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
12 def __init__(self, bits):
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
13 super().__init__(typeID.Integer)
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
14 self.bits = bits
70
35286e8abd03 Added some llvm classes
windel
parents:
diff changeset
15
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
16 class FunctionType(llvmType):
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
17 def __init__(self, resultType, parameterTypes):
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
18 super().__init__(typeID.Function)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
19 assert type(parameterTypes) is list
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
20 self.resultType = resultType
106
f2d980eef509 improved code generation
Windel Bouwman
parents: 104
diff changeset
21 self.returnType = resultType
104
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
22 self.parameterTypes = parameterTypes
ed230e947dc6 Added hexviewer
windel
parents: 95
diff changeset
23
110
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
24 # Default types:
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
25 i8 = IntegerType(8)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
26 i16 = IntegerType(16)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
27 i32 = IntegerType(32)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
28 void = llvmType(typeID.Void)
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
29
9e552d34bd60 Work on compiler
Windel Bouwman
parents: 107
diff changeset
30