Mercurial > projects > ldc
comparison gen/declarations.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 | 5ebe8224988b |
children | 48747003a5de |
comparison
equal
deleted
inserted
replaced
1215:08f87d8cd101 | 1228:79758fd2f48a |
---|---|
12 #include "gen/llvmhelpers.h" | 12 #include "gen/llvmhelpers.h" |
13 #include "gen/logger.h" | 13 #include "gen/logger.h" |
14 | 14 |
15 #include "ir/ir.h" | 15 #include "ir/ir.h" |
16 #include "ir/irvar.h" | 16 #include "ir/irvar.h" |
17 #include "ir/irtype.h" | |
18 #include "ir/irtypestruct.h" | |
17 | 19 |
18 /* ================================================================== */ | 20 /* ================================================================== */ |
19 | 21 |
20 void Dsymbol::codegen(Ir*) | 22 void Dsymbol::codegen(Ir*) |
21 { | 23 { |
70 } | 72 } |
71 } | 73 } |
72 | 74 |
73 /* ================================================================== */ | 75 /* ================================================================== */ |
74 | 76 |
77 // FIXME: this is horrible!!! | |
78 | |
75 void VarDeclaration::codegen(Ir* p) | 79 void VarDeclaration::codegen(Ir* p) |
76 { | 80 { |
77 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars()); | 81 Logger::print("VarDeclaration::toObjFile(): %s | %s\n", toChars(), type->toChars()); |
78 LOG_SCOPE; | 82 LOG_SCOPE; |
79 | 83 |
84 // just forward aliases | |
80 if (aliassym) | 85 if (aliassym) |
81 { | 86 { |
82 Logger::println("alias sym"); | 87 Logger::println("alias sym"); |
83 toAlias()->codegen(p); | 88 toAlias()->codegen(p); |
84 return; | 89 return; |
85 } | 90 } |
86 | 91 |
92 // output the parent aggregate first | |
87 if (AggregateDeclaration* ad = isMember()) | 93 if (AggregateDeclaration* ad = isMember()) |
88 ad->codegen(p); | 94 ad->codegen(p); |
89 | 95 |
90 // global variable or magic | 96 // global variable |
91 #if DMDV2 | 97 #if DMDV2 |
92 // taken from dmd2/structs | 98 // taken from dmd2/structs |
93 if (isDataseg() || (storage_class & (STCconst | STCinvariant) && init)) | 99 if (isDataseg() || (storage_class & (STCconst | STCinvariant) && init)) |
94 #else | 100 #else |
95 if (isDataseg()) | 101 if (isDataseg()) |
136 // if this global is used from a nested function, this is necessary or | 142 // if this global is used from a nested function, this is necessary or |
137 // optimization could potentially remove the global (if it's the only use) | 143 // optimization could potentially remove the global (if it's the only use) |
138 if (nakedUse) | 144 if (nakedUse) |
139 gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType())); | 145 gIR->usedArray.push_back(DtoBitCast(gvar, getVoidPtrType())); |
140 | 146 |
141 // don't initialize static struct members yet, they might be of the struct type | 147 // initialize |
142 // which doesn't have a static initializer yet. | 148 DtoConstInitGlobal(this); |
143 if (AggregateDeclaration* ad = isMember()) | |
144 ad->ir.irStruct->staticVars.push_back(this); | |
145 else | |
146 DtoConstInitGlobal(this); | |
147 } | |
148 else | |
149 { | |
150 // might already have its irField, as classes derive each other without getting copies of the VarDeclaration | |
151 if (!ir.irField) | |
152 { | |
153 assert(!ir.isSet()); | |
154 ir.irField = new IrField(this); | |
155 } | |
156 IrStruct* irstruct = gIR->topstruct(); | |
157 irstruct->addVar(this); | |
158 | |
159 Logger::println("added offset %u", offset); | |
160 } | 149 } |
161 } | 150 } |
162 | 151 |
163 /* ================================================================== */ | 152 /* ================================================================== */ |
164 | 153 |
165 void TypedefDeclaration::codegen(Ir*) | 154 void TypedefDeclaration::codegen(Ir*) |
166 { | 155 { |
167 static int tdi = 0; | 156 Logger::print("TypedefDeclaration::toObjFile: %s\n", toChars()); |
168 Logger::print("TypedefDeclaration::toObjFile(%d): %s\n", tdi++, toChars()); | |
169 LOG_SCOPE; | 157 LOG_SCOPE; |
170 | 158 |
171 // generate typeinfo | 159 // generate typeinfo |
172 DtoTypeInfoOf(type, false); | 160 DtoTypeInfoOf(type, false); |
173 } | 161 } |
179 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); | 167 Logger::println("Ignoring EnumDeclaration::toObjFile for %s", toChars()); |
180 } | 168 } |
181 | 169 |
182 /* ================================================================== */ | 170 /* ================================================================== */ |
183 | 171 |
184 void FuncDeclaration::codegen(Ir*) | 172 void FuncDeclaration::codegen(Ir* p) |
185 { | 173 { |
186 DtoResolveDsymbol(this); | 174 // don't touch function aliases, they don't contribute any new symbols |
187 } | 175 if (!isFuncAliasDeclaration()) |
188 | 176 { |
189 /* ================================================================== */ | 177 DtoResolveDsymbol(this); |
190 | |
191 void AnonDeclaration::codegen(Ir* p) | |
192 { | |
193 Array *d = include(NULL, NULL); | |
194 | |
195 if (d) | |
196 { | |
197 // get real aggregate parent | |
198 IrStruct* irstruct = gIR->topstruct(); | |
199 | |
200 // push a block on the stack | |
201 irstruct->pushAnon(isunion); | |
202 | |
203 // go over children | |
204 for (unsigned i = 0; i < d->dim; i++) | |
205 { Dsymbol *s = (Dsymbol *)d->data[i]; | |
206 s->codegen(p); | |
207 } | |
208 | |
209 // finish | |
210 irstruct->popAnon(); | |
211 } | 178 } |
212 } | 179 } |
213 | 180 |
214 /* ================================================================== */ | 181 /* ================================================================== */ |
215 | 182 |