Mercurial > projects > ldc
annotate gen/structs.cpp @ 1063:40d7f9b7357f
Fixed some #includes to be correct for both D1 and D2
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Sun, 08 Mar 2009 12:13:22 +0100 |
parents | 3ead5c40b7d6 |
children | dbe4af57b240 |
rev | line source |
---|---|
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
1 #include <algorithm> |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
2 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
3 #include "gen/llvm.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
4 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
5 #include "mtype.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
6 #include "aggregate.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
7 #include "init.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
8 #include "declaration.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
9 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
10 #include "gen/irstate.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
11 #include "gen/tollvm.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
217
diff
changeset
|
12 #include "gen/llvmhelpers.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
13 #include "gen/arrays.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
14 #include "gen/logger.h" |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
15 #include "gen/structs.h" |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
16 #include "gen/dvalue.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
17 |
136
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
18 #include "ir/irstruct.h" |
0e28624814e8
[svn r140] did a lot of the work towards being able to pass multiple modules on the command line. not complete yet though
lindquist
parents:
133
diff
changeset
|
19 |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
20 ////////////////////////////////////////////////////////////////////////////////////////// |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
21 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
22 // pair of var and its init |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
23 typedef std::pair<VarDeclaration*,Initializer*> VarInitPair; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
24 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
25 // comparison func for qsort |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
26 static int varinit_offset_cmp_func(const void* p1, const void* p2) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
27 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
28 VarDeclaration* v1 = ((VarInitPair*)p1)->first; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
29 VarDeclaration* v2 = ((VarInitPair*)p2)->first; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
30 if (v1->offset < v2->offset) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
31 return -1; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
32 else if (v1->offset > v2->offset) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
33 return 1; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
34 else |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
35 return 0; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
36 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
37 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
38 /* |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
39 this uses a simple algorithm to build the correct constant |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
40 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
41 (1) first sort the explicit initializers by offset... well, DMD doesn't :) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
42 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
43 (2) if there is NO space before the next explicit initializeer, goto (9) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
44 (3) find the next default initializer that fits before it, if NOT found goto (7) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
45 (4) insert zero padding up to the next default initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
46 (5) insert the next default initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
47 (6) goto (2) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
48 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
49 (7) insert zero padding up to the next explicit initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
50 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
51 (9) insert the next explicit initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
52 (10) goto (2) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
53 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
54 (11) done |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
55 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
56 (next can be the end too) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
57 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
58 */ |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
59 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
60 // return the next default initializer to use or null |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
61 static VarDeclaration* nextDefault(IrStruct* irstruct, size_t& idx, size_t pos, size_t offset) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
62 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
63 IrStruct::VarDeclVector& defaults = irstruct->defVars; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
64 size_t ndefaults = defaults.size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
65 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
66 // for each valid index |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
67 while(idx < ndefaults) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
68 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
69 VarDeclaration* v = defaults[idx]; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
70 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
71 // skip defaults before pos |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
72 if (v->offset < pos) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
73 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
74 idx++; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
75 continue; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
76 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
77 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
78 // this var default fits |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
79 if (v->offset >= pos && v->offset + v->type->size() <= offset) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
80 return v; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
81 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
82 // not usable |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
83 break; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
84 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
85 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
86 // not usable |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
87 return NULL; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
88 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
89 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
205
diff
changeset
|
90 LLConstant* DtoConstStructInitializer(StructInitializer* si) |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
91 { |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
92 Logger::println("DtoConstStructInitializer: %s", si->toChars()); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
93 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
94 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
95 // get TypeStruct |
449
56265fa07c7d
Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
96 assert(si->ad); |
100 | 97 TypeStruct* ts = (TypeStruct*)si->ad->type; |
98 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
99 // force constant initialization of the symbol |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
100 DtoForceConstInitDsymbol(si->ad); |
449
56265fa07c7d
Fixed problem where global variables did not resolve type before using it.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
101 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
102 // get formal type |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
103 const llvm::StructType* structtype = isaStruct(ts->ir.type->get()); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
104 |
1030
3ead5c40b7d6
Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
955
diff
changeset
|
105 #if 0 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
106 // log it |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
107 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
108 Logger::cout() << "llvm struct type: " << *structtype << '\n'; |
1030
3ead5c40b7d6
Disabled some extensive LLVM value logging with -vv that dramatically increases -vv output length for little value.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
955
diff
changeset
|
109 #endif |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
110 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
111 // sanity check |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
112 assert(si->value.dim > 0); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
113 assert(si->value.dim == si->vars.dim); |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
114 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
115 // vector of final initializer constants |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
116 std::vector<LLConstant*> inits; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
117 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
118 // get the ir struct |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
119 IrStruct* irstruct = si->ad->ir.irStruct; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
120 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
121 // get default fields |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
122 IrStruct::VarDeclVector& defaults = irstruct->defVars; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
123 size_t ndefaults = defaults.size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
124 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
125 // make sure si->vars is sorted by offset |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
126 std::vector<VarInitPair> vars; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
127 size_t nvars = si->vars.dim; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
128 vars.resize(nvars); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
129 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
130 // fill pair vector |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
131 for (size_t i = 0; i < nvars; i++) |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
132 { |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
133 VarDeclaration* var = (VarDeclaration*)si->vars.data[i]; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
134 Initializer* ini = (Initializer*)si->value.data[i]; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
135 assert(var); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
136 assert(ini); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
137 vars[i] = std::make_pair(var, ini); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
138 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
139 // sort it |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
140 qsort(&vars[0], nvars, sizeof(VarInitPair), &varinit_offset_cmp_func); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
141 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
142 // check integrity |
809
69a5e4a6fc0f
Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
803
diff
changeset
|
143 // and do error checking, since the frontend does not verify static struct initializers |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
144 size_t lastoffset = 0; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
145 size_t lastsize = 0; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
146 bool overlap = false; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
147 for (size_t i=0; i < nvars; i++) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
148 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
149 // next explicit init var |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
150 VarDeclaration* var = vars[i].first; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
151 Logger::println("var = %s : +%u", var->toChars(), var->offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
152 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
153 // I would have thought this to be a frontend check |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
154 for (size_t j=i+1; j<nvars; j++) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
155 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
156 if (j == i) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
157 continue; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
158 VarDeclaration* var2 = vars[j].first; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
159 if (var2->offset >= var->offset && var2->offset < var->offset + var->type->size()) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
160 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
161 fprintf(stdmsg, "Error: %s: initializer '%s' overlaps with '%s'\n", si->loc.toChars(), var->toChars(), var2->toChars()); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
162 overlap = true; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
163 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
164 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
165 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
166 // update offsets |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
167 lastoffset = var->offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
168 lastsize = var->type->size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
169 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
170 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
171 // error handling, report all overlaps before aborting |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
172 if (overlap) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
173 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
174 error("%s: overlapping union initializers", si->loc.toChars()); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
175 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
176 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
177 // go through each explicit initalizer, falling back to defaults or zeros when necessary |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
178 lastoffset = 0; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
179 lastsize = 0; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
180 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
181 size_t j=0; // defaults |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
182 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
183 for (size_t i=0; i < nvars; i++) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
184 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
185 // get var and init |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
186 VarDeclaration* var = vars[i].first; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
187 Initializer* ini = vars[i].second; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
188 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
189 size_t offset = var->offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
190 size_t size = var->type->size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
191 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
192 // if there is space before the next explicit initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
193 Lpadding: |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
194 size_t pos = lastoffset+lastsize; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
195 if (offset > pos) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
196 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
197 // find the the next default initializer that fits in this space |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
198 VarDeclaration* nextdef = nextDefault(irstruct, j, lastoffset+lastsize, offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
199 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
200 // found |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
201 if (nextdef) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
202 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
203 // need zeros before the default |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
204 if (nextdef->offset > pos) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
205 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
206 Logger::println("inserting %lu byte padding at %lu", nextdef->offset - pos, pos); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
207 addZeros(inits, pos, nextdef->offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
208 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
209 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
210 // do the default |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
211 Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset); |
800
d14e4594c7d7
Changed aggregate field initializers to be created lazily, fixes problem with static void arrays in aggregates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
212 if (!nextdef->ir.irField->constInit) |
803
c62c6936635b
Removed DtoConstFieldInitializer, it's no longer needed and was buggy.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
802
diff
changeset
|
213 nextdef->ir.irField->constInit = DtoConstInitializer(nextdef->loc, nextdef->type, nextdef->init); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
214 LLConstant* c = nextdef->ir.irField->constInit; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
215 inits.push_back(c); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
216 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
217 // update offsets |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
218 lastoffset = nextdef->offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
219 lastsize = nextdef->type->size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
220 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
221 // check if more defaults would fit |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
222 goto Lpadding; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
223 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
224 // not found, pad with zeros |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
225 else |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
226 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
227 Logger::println("inserting %lu byte padding at %lu", offset - pos, pos); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
228 addZeros(inits, pos, offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
229 // offsets are updated by the explicit initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
230 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
231 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
232 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
233 // insert next explicit |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
234 Logger::println("adding explicit field: %s : +%lu", var->toChars(), offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
235 LOG_SCOPE; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
236 LLConstant* c = DtoConstInitializer(var->loc, var->type, ini); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
237 inits.push_back(c); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
238 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
239 lastoffset = offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
240 lastsize = size; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
241 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
242 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
243 // there might still be padding after the last one, make sure that is defaulted/zeroed as well |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
940
diff
changeset
|
244 size_t structsize = getTypePaddedSize(structtype); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
245 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
246 // if there is space before the next explicit initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
247 // FIXME: this should be handled in the loop above as well |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
248 Lpadding2: |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
249 size_t pos = lastoffset+lastsize; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
250 if (structsize > pos) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
251 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
252 // find the the next default initializer that fits in this space |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
253 VarDeclaration* nextdef = nextDefault(irstruct, j, lastoffset+lastsize, structsize); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
254 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
255 // found |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
256 if (nextdef) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
257 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
258 // need zeros before the default |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
259 if (nextdef->offset > pos) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
260 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
261 Logger::println("inserting %lu byte padding at %lu", nextdef->offset - pos, pos); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
262 addZeros(inits, pos, nextdef->offset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
263 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
264 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
265 // do the default |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
266 Logger::println("adding default field: %s : +%u", nextdef->toChars(), nextdef->offset); |
800
d14e4594c7d7
Changed aggregate field initializers to be created lazily, fixes problem with static void arrays in aggregates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
797
diff
changeset
|
267 if (!nextdef->ir.irField->constInit) |
803
c62c6936635b
Removed DtoConstFieldInitializer, it's no longer needed and was buggy.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
802
diff
changeset
|
268 nextdef->ir.irField->constInit = DtoConstInitializer(nextdef->loc, nextdef->type, nextdef->init); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
269 LLConstant* c = nextdef->ir.irField->constInit; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
270 inits.push_back(c); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
271 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
272 // update offsets |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
273 lastoffset = nextdef->offset; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
274 lastsize = nextdef->type->size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
275 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
276 // check if more defaults would fit |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
277 goto Lpadding2; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
278 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
279 // not found, pad with zeros |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
280 else |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
281 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
282 Logger::println("inserting %lu byte padding at %lu", structsize - pos, pos); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
283 addZeros(inits, pos, structsize); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
284 lastoffset = pos; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
285 lastsize = structsize - pos; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
286 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
287 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
288 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
289 assert(lastoffset+lastsize == structsize); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
290 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
291 // make the constant struct |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
292 LLConstant* c = LLConstantStruct::get(inits, si->ad->ir.irStruct->packed); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
293 if (Logger::enabled()) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
294 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
295 Logger::cout() << "constant struct initializer: " << *c << '\n'; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
296 } |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
940
diff
changeset
|
297 assert(getTypePaddedSize(c->getType()) == structsize); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
298 return c; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
299 } |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
300 |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
301 ////////////////////////////////////////////////////////////////////////////////////////// |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
302 |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
303 std::vector<llvm::Value*> DtoStructLiteralValues(const StructDeclaration* sd, const std::vector<llvm::Value*>& inits) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
304 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
305 // get arrays |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
306 size_t nvars = sd->fields.dim; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
307 VarDeclaration** vars = (VarDeclaration**)sd->fields.data; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
308 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
309 assert(inits.size() == nvars); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
310 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
311 // first locate all explicit initializers |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
312 std::vector<VarDeclaration*> explicitInits; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
313 for (size_t i=0; i < nvars; i++) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
314 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
315 if (inits[i]) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
316 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
317 explicitInits.push_back(vars[i]); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
318 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
319 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
320 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
321 // vector of values to build aggregate from |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
322 std::vector<llvm::Value*> values; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
323 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
324 // offset trackers |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
325 size_t lastoffset = 0; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
326 size_t lastsize = 0; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
327 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
328 // index of next explicit init |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
329 size_t exidx = 0; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
330 // number of explicit inits |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
331 size_t nex = explicitInits.size(); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
332 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
333 // for through each field and build up the struct, padding with zeros |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
334 size_t i; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
335 for (i=0; i<nvars; i++) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
336 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
337 VarDeclaration* var = vars[i]; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
338 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
339 // get var info |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
340 size_t os = var->offset; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
341 size_t sz = var->type->size(); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
342 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
343 // get next explicit |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
344 VarDeclaration* nextVar = NULL; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
345 size_t nextOs = 0; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
346 if (exidx < nex) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
347 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
348 nextVar = explicitInits[exidx]; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
349 nextOs = nextVar->offset; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
350 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
351 // none, rest is defaults |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
352 else |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
353 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
354 break; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
355 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
356 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
357 // not explicit initializer, default initialize if there is room, otherwise skip |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
358 if (!inits[i]) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
359 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
360 // default init if there is room |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
361 // (past current offset) and (small enough to fit before next explicit) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
362 if ((os >= lastoffset + lastsize) && (os+sz <= nextOs)) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
363 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
364 // add any 0 padding needed before this field |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
365 if (os > lastoffset + lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
366 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
367 //printf("1added %lu zeros\n", os - lastoffset - lastsize); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
368 addZeros(values, lastoffset + lastsize, os); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
369 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
370 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
371 // get field default init |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
372 IrField* f = var->ir.irField; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
373 assert(f); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
374 if (!f->constInit) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
375 f->constInit = DtoConstInitializer(var->loc, var->type, var->init); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
376 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
377 values.push_back(f->constInit); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
378 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
379 lastoffset = os; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
380 lastsize = sz; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
381 //printf("added default: %s : %lu (%lu)\n", var->toChars(), os, sz); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
382 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
383 // skip |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
384 continue; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
385 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
386 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
387 assert(nextVar == var); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
388 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
389 // add any 0 padding needed before this field |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
390 if (os > lastoffset + lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
391 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
392 //printf("added %lu zeros\n", os - lastoffset - lastsize); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
393 addZeros(values, lastoffset + lastsize, os); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
394 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
395 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
396 // add the expression value |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
397 values.push_back(inits[i]); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
398 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
399 // update offsets |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
400 lastoffset = os; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
401 lastsize = sz; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
402 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
403 // go to next explicit init |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
404 exidx++; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
405 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
406 //printf("added field: %s : %lu (%lu)\n", var->toChars(), os, sz); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
407 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
408 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
409 // fill out rest with default initializers |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
410 const LLType* structtype = DtoType(sd->type); |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
940
diff
changeset
|
411 size_t structsize = getTypePaddedSize(structtype); |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
412 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
413 // FIXME: this could probably share some code with the above |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
414 if (structsize > lastoffset+lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
415 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
416 for (/*continue from first loop*/; i < nvars; i++) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
417 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
418 VarDeclaration* var = vars[i]; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
419 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
420 // get var info |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
421 size_t os = var->offset; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
422 size_t sz = var->type->size(); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
423 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
424 // skip? |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
425 if (os < lastoffset + lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
426 continue; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
427 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
428 // add any 0 padding needed before this field |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
429 if (os > lastoffset + lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
430 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
431 //printf("2added %lu zeros\n", os - lastoffset - lastsize); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
432 addZeros(values, lastoffset + lastsize, os); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
433 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
434 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
435 // get field default init |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
436 IrField* f = var->ir.irField; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
437 assert(f); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
438 if (!f->constInit) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
439 f->constInit = DtoConstInitializer(var->loc, var->type, var->init); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
440 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
441 values.push_back(f->constInit); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
442 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
443 lastoffset = os; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
444 lastsize = sz; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
445 //printf("2added default: %s : %lu (%lu)\n", var->toChars(), os, sz); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
446 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
447 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
448 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
449 // add any 0 padding needed at the end of the literal |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
450 if (structsize > lastoffset+lastsize) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
451 { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
452 //printf("3added %lu zeros\n", structsize - lastoffset - lastsize); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
453 addZeros(values, lastoffset + lastsize, structsize); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
454 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
455 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
456 return values; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
457 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
458 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
459 ////////////////////////////////////////////////////////////////////////////////////////// |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
840
diff
changeset
|
460 |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
461 LLValue* DtoIndexStruct(LLValue* src, StructDeclaration* sd, VarDeclaration* vd) |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
462 { |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
463 Logger::println("indexing struct field %s:", vd->toPrettyChars()); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
464 LOG_SCOPE; |
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
465 |
840
a125ada7fd95
more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
812
diff
changeset
|
466 DtoResolveStruct(sd); |
a125ada7fd95
more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
812
diff
changeset
|
467 |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
468 // vd must be a field |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
469 IrField* field = vd->ir.irField; |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
470 assert(field); |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
471 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
472 // get the start pointer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
473 const LLType* st = getPtrToType(DtoType(sd->type)); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
474 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
475 // cast to the formal struct type |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
476 src = DtoBitCast(src, st); |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
477 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
478 // gep to the index |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
479 LLValue* val = DtoGEPi(src, 0, field->index); |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
480 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
481 // do we need to offset further? (union area) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
482 if (field->unionOffset) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
483 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
484 // cast to void* |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
485 val = DtoBitCast(val, getVoidPtrType()); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
486 // offset |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
487 val = DtoGEPi1(val, field->unionOffset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
488 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
489 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
490 // cast it to the right type |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
491 val = DtoBitCast(val, getPtrToType(DtoType(vd->type))); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
486
diff
changeset
|
492 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
493 if (Logger::enabled()) |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
494 Logger::cout() << "value: " << *val << '\n'; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
495 |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
496 return val; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
497 } |
100 | 498 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
499 void DtoResolveStruct(StructDeclaration* sd) |
100 | 500 { |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
501 // don't do anything if already been here |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
502 if (sd->ir.resolved) return; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
503 // make sure above works :P |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
504 sd->ir.resolved = true; |
100 | 505 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
506 // log what we're doing |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
507 Logger::println("Resolving struct type: %s (%s)", sd->toChars(), sd->locToChars()); |
100 | 508 LOG_SCOPE; |
509 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
510 // get the DMD TypeStruct |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
511 TypeStruct* ts = (TypeStruct*)sd->type; |
171
95f07e3f8bb9
[svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents:
169
diff
changeset
|
512 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
513 // create the IrStruct |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
514 IrStruct* irstruct = new IrStruct(sd); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
515 sd->ir.irStruct = irstruct; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
516 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
517 // create the type |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
518 ts->ir.type = new LLPATypeHolder(llvm::OpaqueType::get()); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
519 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
520 // handle forward declaration structs (opaques) |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
725
diff
changeset
|
521 // didn't even know D had those ... |
656
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
622
diff
changeset
|
522 if (sd->sizeok != 1) |
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
622
diff
changeset
|
523 { |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
524 // nothing more to do |
656
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
622
diff
changeset
|
525 return; |
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
622
diff
changeset
|
526 } |
100 | 527 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
528 // make this struct current |
100 | 529 gIR->structs.push_back(irstruct); |
530 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
531 // get some info |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
532 bool ispacked = (ts->alignsize() == 1); |
737
041c1596d217
Removed warnings on ignored aligns. Only do aligment on packed structs, align(1) struct Packed { ... }
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
725
diff
changeset
|
533 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
534 // set irstruct info |
435
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
535 irstruct->packed = ispacked; |
74101be2a553
Added type param to DVarValue as DMD sometimes overrides the type of the VarDeclaration.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
351
diff
changeset
|
536 |
725
3e143b611c1e
Fix double field toObjFile for structs with AttribDecls.
Christian Kamm <kamm incasoftware de>
parents:
705
diff
changeset
|
537 // methods, fields |
3e143b611c1e
Fix double field toObjFile for structs with AttribDecls.
Christian Kamm <kamm incasoftware de>
parents:
705
diff
changeset
|
538 Array* arr = sd->members; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
539 for (int k=0; k < arr->dim; k++) { |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
540 Dsymbol* s = (Dsymbol*)arr->data[k]; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
541 s->toObjFile(0); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
542 } |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
543 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
544 const LLType* ST = irstruct->build(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
545 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
546 #if 0 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
547 std::cout << sd->kind() << ' ' << sd->toPrettyChars() << " type: " << *ST << '\n'; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
548 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
549 // add fields |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
550 for (int k=0; k < fields->dim; k++) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
551 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
552 VarDeclaration* v = (VarDeclaration*)fields->data[k]; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
553 printf(" field: %s %s\n", v->type->toChars(), v->toChars()); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
554 printf(" index: %u offset: %u\n", v->ir.irField->index, v->ir.irField->unionOffset); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
555 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
556 |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
940
diff
changeset
|
557 unsigned llvmSize = (unsigned)getTypePaddedSize(ST); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
558 unsigned dmdSize = (unsigned)sd->type->size(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
559 printf(" llvm size: %u dmd size: %u\n", llvmSize, dmdSize); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
560 assert(llvmSize == dmdSize); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
561 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
562 #endif |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
563 |
132 | 564 /*for (int k=0; k < sd->members->dim; k++) { |
100 | 565 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]); |
566 dsym->toObjFile(); | |
132 | 567 }*/ |
100 | 568 |
569 Logger::println("doing struct fields"); | |
570 | |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
571 // refine abstract types for stuff like: struct S{S* next;} |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
572 llvm::cast<llvm::OpaqueType>(ts->ir.type->get())->refineAbstractTypeTo(ST); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
573 ST = ts->ir.type->get(); |
100 | 574 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
575 // name type |
100 | 576 if (sd->parent->isModule()) { |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
577 gIR->module->addTypeName(sd->mangle(),ST); |
100 | 578 } |
579 | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
580 gIR->structs.pop_back(); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
581 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
582 gIR->declareList.push_back(sd); |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
583 } |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
584 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
585 ////////////////////////////////////////////////////////////////////////////////////////// |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
586 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
587 void DtoDeclareStruct(StructDeclaration* sd) |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
588 { |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
589 if (sd->ir.declared) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
590 sd->ir.declared = true; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
591 |
132 | 592 Logger::println("DtoDeclareStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
593 LOG_SCOPE; |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
594 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
449
diff
changeset
|
595 TypeStruct* ts = (TypeStruct*)sd->type->toBasetype(); |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
596 |
100 | 597 std::string initname("_D"); |
598 initname.append(sd->mangle()); | |
599 initname.append("6__initZ"); | |
600 | |
149
4c577c2b7229
[svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents:
137
diff
changeset
|
601 llvm::GlobalValue::LinkageTypes _linkage = DtoExternalLinkage(sd); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
602 llvm::GlobalVariable* initvar = new llvm::GlobalVariable(sd->ir.irStruct->initOpaque.get(), true, _linkage, NULL, initname, gIR->module); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
603 sd->ir.irStruct->init = initvar; |
100 | 604 |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
605 gIR->constInitList.push_back(sd); |
940
39519a1ff603
Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
870
diff
changeset
|
606 if (mustDefineSymbol(sd)) |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
607 gIR->defineList.push_back(sd); |
100 | 608 } |
609 | |
610 ////////////////////////////////////////////////////////////////////////////////////////// | |
611 | |
612 void DtoConstInitStruct(StructDeclaration* sd) | |
613 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
614 if (sd->ir.initialized) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
615 sd->ir.initialized = true; |
100 | 616 |
132 | 617 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 618 LOG_SCOPE; |
619 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
620 IrStruct* irstruct = sd->ir.irStruct; |
100 | 621 gIR->structs.push_back(irstruct); |
622 | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
623 const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get()); |
100 | 624 |
625 // always generate the constant initalizer | |
812
6c2ff06c4201
Fixed a nasty bug with how interface vtables for class initializers were output, causing some class fields to be skipped.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
626 assert(!irstruct->constInit); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
627 if (sd->zeroInit) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
628 { |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
629 Logger::println("Zero initialized"); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
630 irstruct->constInit = llvm::ConstantAggregateZero::get(structtype); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
631 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
632 else |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
633 { |
100 | 634 Logger::println("Not zero initialized"); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
635 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
636 LLConstant* c = irstruct->buildDefaultConstInit(); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
637 irstruct->constInit = c; |
100 | 638 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
639 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
640 // refine __initZ global type to the one of the initializer |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
796
diff
changeset
|
641 llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType()); |
100 | 642 |
643 gIR->structs.pop_back(); | |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
644 |
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
100
diff
changeset
|
645 // emit typeinfo |
955
8a70b4381369
Make sure debug info uses the right compilation units - in particular the
Christian Kamm <kamm incasoftware de>
parents:
947
diff
changeset
|
646 if (sd->getModule() == gIR->dmodule && sd->llvmInternal != LLVMno_typeinfo) |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
244
diff
changeset
|
647 DtoTypeInfoOf(sd->type, false); |
100 | 648 } |
649 | |
650 ////////////////////////////////////////////////////////////////////////////////////////// | |
651 | |
652 void DtoDefineStruct(StructDeclaration* sd) | |
653 { | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
654 if (sd->ir.defined) return; |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
655 sd->ir.defined = true; |
100 | 656 |
132 | 657 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars()); |
100 | 658 LOG_SCOPE; |
659 | |
660 assert(sd->type->ty == Tstruct); | |
661 TypeStruct* ts = (TypeStruct*)sd->type; | |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
662 sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit); |
100 | 663 |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
171
diff
changeset
|
664 sd->ir.DModule = gIR->dmodule; |
100 | 665 } |
666 | |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff
changeset
|
667 ////////////////////////////////////////////////////////////////////////////////////////// |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
668 //////////////////////////// D STRUCT UTILITIES //////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
669 ////////////////////////////////////////////////////////////////////////////////////////// |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
670 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
671 LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs) |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
672 { |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
673 Type* t = lhs->getType()->toBasetype(); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
674 assert(t->ty == Tstruct); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
675 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
676 // set predicate |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
677 llvm::ICmpInst::Predicate cmpop; |
345
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
678 if (op == TOKequal || op == TOKidentity) |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
679 cmpop = llvm::ICmpInst::ICMP_EQ; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
680 else |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
681 cmpop = llvm::ICmpInst::ICMP_NE; |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
682 |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
683 // call memcmp |
945
03d7c4aac654
SWITCHED TO LLVM 2.5 !
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
940
diff
changeset
|
684 size_t sz = getTypePaddedSize(DtoType(t)); |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
685 LLValue* val = DtoMemCmp(lhs->getRVal(), rhs->getRVal(), DtoConstSize_t(sz)); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
686 return gIR->ir->CreateICmp(cmpop, val, LLConstantInt::get(val->getType(), 0, false), "tmp"); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
336
diff
changeset
|
687 } |