comparison gen/tollvm.cpp @ 1228:79758fd2f48a

Added Doxygen file. Completely seperated type and symbol generation. Should fix a lot of bugs, but is not yet 100% complete.
author Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
date Wed, 15 Apr 2009 20:06:25 +0200
parents 7e5547d8e59f
children 1e699a4e9759
comparison
equal deleted inserted replaced
1215:08f87d8cd101 1228:79758fd2f48a
21 #include "gen/llvmhelpers.h" 21 #include "gen/llvmhelpers.h"
22 #include "gen/linkage.h" 22 #include "gen/linkage.h"
23 #include "gen/llvm-version.h" 23 #include "gen/llvm-version.h"
24 24
25 #include "ir/irtype.h" 25 #include "ir/irtype.h"
26 #include "ir/irtypeclass.h"
26 27
27 bool DtoIsPassedByRef(Type* type) 28 bool DtoIsPassedByRef(Type* type)
28 { 29 {
29 Type* typ = type->toBasetype(); 30 Type* typ = type->toBasetype();
30 TY t = typ->ty; 31 TY t = typ->ty;
50 return llvm::Attribute::None; 51 return llvm::Attribute::None;
51 } 52 }
52 53
53 const LLType* DtoType(Type* t) 54 const LLType* DtoType(Type* t)
54 { 55 {
56 #if DMDV2
57 t = t->mutableOf();
58 #endif
59
55 if (t->irtype) 60 if (t->irtype)
56 { 61 {
57 return t->irtype->get(); 62 return t->irtype->get();
58 } 63 }
64
65 IF_LOG Logger::println("Building type: %s", t->toChars());
59 66
60 assert(t); 67 assert(t);
61 switch (t->ty) 68 switch (t->ty)
62 { 69 {
63 // basic types 70 // basic types
84 case Tchar: 91 case Tchar:
85 case Twchar: 92 case Twchar:
86 case Tdchar: 93 case Tdchar:
87 { 94 {
88 t->irtype = new IrTypeBasic(t); 95 t->irtype = new IrTypeBasic(t);
89 return t->irtype->get(); 96 return t->irtype->buildType();
90 } 97 }
91 98
92 // pointers 99 // pointers
93 case Tpointer: 100 case Tpointer:
94 { 101 {
95 t->irtype = new IrTypePointer(t); 102 t->irtype = new IrTypePointer(t);
96 return t->irtype->get(); 103 return t->irtype->buildType();
97 } 104 }
98 105
99 // arrays 106 // arrays
100 case Tarray: 107 case Tarray:
101 { 108 {
102 t->irtype = new IrTypeArray(t); 109 t->irtype = new IrTypeArray(t);
103 return t->irtype->get(); 110 return t->irtype->buildType();
104 } 111 }
105 112
106 case Tsarray: 113 case Tsarray:
107 { 114 {
108 t->irtype = new IrTypeSArray(t); 115 t->irtype = new IrTypeSArray(t);
109 return t->irtype->get(); 116 return t->irtype->buildType();
110 } 117 }
111 118
112 // aggregates 119 // aggregates
113 case Tstruct: { 120 case Tstruct: {
114 #if DMDV2
115 TypeStruct* ts = (TypeStruct*)t->mutableOf();
116 #else
117 TypeStruct* ts = (TypeStruct*)t; 121 TypeStruct* ts = (TypeStruct*)t;
118 #endif 122 t->irtype = new IrTypeStruct(ts->sym);
119 assert(ts->sym); 123 return t->irtype->buildType();
120 DtoResolveDsymbol(ts->sym); 124 }
121 return ts->ir.type->get();
122 }
123
124 case Tclass: { 125 case Tclass: {
125 #if DMDV2
126 TypeClass* tc = (TypeClass*)t->mutableOf();
127 #else
128 TypeClass* tc = (TypeClass*)t; 126 TypeClass* tc = (TypeClass*)t;
129 #endif 127 t->irtype = new IrTypeClass(tc->sym);
130 assert(tc->sym); 128 return t->irtype->buildType();
131 DtoResolveDsymbol(tc->sym);
132 return getPtrToType(tc->ir.type->get());
133 } 129 }
134 130
135 // functions 131 // functions
136 case Tfunction: 132 case Tfunction:
137 { 133 {
138 if (!t->ir.type || *t->ir.type == NULL) { 134 if (!t->ir.type || *t->ir.type == NULL) {
139 return DtoFunctionType(t,NULL,NULL); 135 TypeFunction* tf = (TypeFunction*)t;
136 if (tf->funcdecl)
137 return DtoFunctionType(tf->funcdecl);
138 else
139 return DtoFunctionType(tf,NULL,NULL);
140 } 140 }
141 else { 141 else {
142 return t->ir.type->get(); 142 return t->ir.type->get();
143 } 143 }
144 } 144 }
154 } 154 }
155 } 155 }
156 156
157 // typedefs 157 // typedefs
158 // enum 158 // enum
159
160 // FIXME: maybe just call toBasetype first ?
159 case Ttypedef: 161 case Ttypedef:
160 case Tenum: 162 case Tenum:
161 { 163 {
162 Type* bt = t->toBasetype(); 164 Type* bt = t->toBasetype();
163 assert(bt); 165 assert(bt);
164 return DtoType(bt); 166 return DtoType(bt);
165 } 167 }
166 168
167 // associative arrays 169 // associative arrays
168 case Taarray: 170 case Taarray:
169 #if 1
170 return getVoidPtrType(); 171 return getVoidPtrType();
171 #else
172 {
173 TypeAArray* taa = (TypeAArray*)t;
174 // aa key/val can't be void
175 return getPtrToType(LLStructType::get(DtoType(taa->key), DtoType(taa->next), 0));
176 }
177 #endif
178 172
179 /* 173 /*
180 Not needed atm as VarDecls for tuples are rewritten as a string of 174 Not needed atm as VarDecls for tuples are rewritten as a string of
181 VarDecls for the fields (u -> _u_field_0, ...) 175 VarDecls for the fields (u -> _u_field_0, ...)
182 176