comparison ir/irtype.cpp @ 1192:3251ce06c820

Started seperating type resolution from the rest of codegen again, the merge had too many regressions.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Fri, 03 Apr 2009 16:34:11 +0200
parents
children 79758fd2f48a
comparison
equal deleted inserted replaced
1191:d68796be59fd 1192:3251ce06c820
1 #include "llvm/DerivedTypes.h"
2 #include "ir/irtype.h"
3
4 #include "mars.h"
5 #include "mtype.h"
6
7 IrType::IrType(Type* dt, const llvm::Type* lt)
8 : dtype(dt),
9 pa(lt)
10 {
11 assert(dt && "null D Type");
12 assert(lt && "null LLVM Type");
13 }
14
15 //////////////////////////////////////////////////////////////////////////////
16 //////////////////////////////////////////////////////////////////////////////
17 //////////////////////////////////////////////////////////////////////////////
18
19 IrTypeBasic::IrTypeBasic(Type * dt)
20 : IrType(dt, basic2llvm(dt))
21 {
22 }
23
24 //////////////////////////////////////////////////////////////////////////////
25
26 const llvm::Type * IrTypeBasic::basic2llvm(Type* t)
27 {
28 const llvm::Type* t2;
29
30 switch(t->ty)
31 {
32 case Tvoid:
33 return llvm::Type::VoidTy;
34
35 case Tint8:
36 case Tuns8:
37 case Tchar:
38 return llvm::Type::Int8Ty;
39
40 case Tint16:
41 case Tuns16:
42 case Twchar:
43 return llvm::Type::Int16Ty;
44
45 case Tint32:
46 case Tuns32:
47 case Tdchar:
48 return llvm::Type::Int32Ty;
49
50 case Tint64:
51 case Tuns64:
52 return llvm::Type::Int64Ty;
53
54 /*
55 case Tint128:
56 case Tuns128:
57 return llvm::IntegerType::get(128);
58 */
59
60 case Tfloat32:
61 case Timaginary32:
62 return llvm::Type::FloatTy;
63
64 case Tfloat64:
65 case Timaginary64:
66 return llvm::Type::DoubleTy;
67
68 case Tfloat80:
69 case Timaginary80:
70 // only x86 has 80bit float
71 if (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64)
72 return llvm::Type::X86_FP80Ty;
73 // other platforms use 64bit reals
74 else
75 return llvm::Type::DoubleTy;
76
77 case Tcomplex32:
78 t2 = llvm::Type::FloatTy;
79 return llvm::StructType::get(t2, t2, NULL);
80
81 case Tcomplex64:
82 t2 = llvm::Type::DoubleTy;
83 return llvm::StructType::get(t2, t2, NULL);
84
85 case Tcomplex80:
86 t2 = (global.params.cpu == ARCHx86 || global.params.cpu == ARCHx86_64)
87 ? llvm::Type::X86_FP80Ty
88 : llvm::Type::DoubleTy;
89 return llvm::StructType::get(t2, t2, NULL);
90
91 case Tbool:
92 return llvm::Type::Int1Ty;
93 }
94
95 assert(0 && "not basic type");
96 return NULL;
97 }
98
99 //////////////////////////////////////////////////////////////////////////////
100 //////////////////////////////////////////////////////////////////////////////
101 //////////////////////////////////////////////////////////////////////////////
102
103 IrTypePointer::IrTypePointer(Type * dt)
104 : IrType(dt, pointer2llvm(dt))
105 {
106 }
107
108 //////////////////////////////////////////////////////////////////////////////
109
110 extern const llvm::Type* DtoType(Type* dt);
111
112 const llvm::Type * IrTypePointer::pointer2llvm(Type * t)
113 {
114 assert(t->ty == Tpointer && "not pointer type");
115
116 const llvm::Type* elemType = DtoType(t->nextOf());
117 if (elemType == llvm::Type::VoidTy)
118 elemType = llvm::Type::Int8Ty;
119 return llvm::PointerType::get(elemType, 0);
120 }
121
122 //////////////////////////////////////////////////////////////////////////////
123 //////////////////////////////////////////////////////////////////////////////
124 //////////////////////////////////////////////////////////////////////////////
125
126 IrTypeSArray::IrTypeSArray(Type * dt)
127 : IrType(dt, sarray2llvm(dt))
128 {
129 TypeSArray* tsa = (TypeSArray*)dt;
130 uint64_t d = (uint64_t)tsa->dim->toUInteger();
131 assert(d == dim);
132 }
133
134 //////////////////////////////////////////////////////////////////////////////
135
136 const llvm::Type * IrTypeSArray::sarray2llvm(Type * t)
137 {
138 assert(t->ty == Tsarray && "not static array type");
139
140 TypeSArray* tsa = (TypeSArray*)t;
141 dim = (uint64_t)tsa->dim->toUInteger();
142 const llvm::Type* elemType = DtoType(t->nextOf());
143 if (elemType == llvm::Type::VoidTy)
144 elemType = llvm::Type::Int8Ty;
145 return llvm::ArrayType::get(elemType, dim);
146 }
147
148 //////////////////////////////////////////////////////////////////////////////
149 //////////////////////////////////////////////////////////////////////////////
150 //////////////////////////////////////////////////////////////////////////////
151
152 IrTypeArray::IrTypeArray(Type * dt)
153 : IrType(dt, array2llvm(dt))
154 {
155 }
156
157 //////////////////////////////////////////////////////////////////////////////
158
159 extern const llvm::Type* DtoSize_t();
160
161 const llvm::Type * IrTypeArray::array2llvm(Type * t)
162 {
163 assert(t->ty == Tarray && "not dynamic array type");
164
165 const llvm::Type* elemType = DtoType(t->nextOf());
166 if (elemType == llvm::Type::VoidTy)
167 elemType = llvm::Type::Int8Ty;
168 elemType = llvm::PointerType::get(elemType, 0);
169 return llvm::StructType::get(DtoSize_t(), elemType, NULL);
170 }
171
172 //////////////////////////////////////////////////////////////////////////////
173