annotate gen/structs.cpp @ 840:a125ada7fd95

more moreatatime fixes
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Tue, 09 Dec 2008 18:45:25 +0100
parents 6c2ff06c4201
children af7a6faf9406
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
97 TypeStruct* ts = (TypeStruct*)si->ad->type;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
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
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
105 // 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
106 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
107 Logger::cout() << "llvm struct type: " << *structtype << '\n';
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
108
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
109 // 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
110 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
111 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
112
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
113 // 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
114 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
115
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
116 // 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
117 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
118
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
119 // 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
120 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
121 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
122
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
123 // 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
124 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
125 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
126 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
127
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
128 // 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
129 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
130 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
131 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
132 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
133 assert(var);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
134 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
135 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
136 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
137 // 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
138 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
139
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
140 // 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
141 // 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
142 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
143 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
144 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
145 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
146 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
147 // 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
148 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
149 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
150
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
151 // 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
152 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
153 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
154 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
155 continue;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
156 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
157 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
158 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
159 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
160 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
161 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
162 }
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 // 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
165 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
166 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
167 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
168
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
169 // 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
170 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
171 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
172 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
173 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
174
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
175 // 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
176 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
177 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
178
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
179 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
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 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
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 // 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
184 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
185 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
186
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
187 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
188 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
189
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
190 // 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
191 Lpadding:
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
192 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
193 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
194 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
195 // 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
196 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
197
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
198 // found
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
199 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
200 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
201 // 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
202 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
203 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
204 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
205 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
206 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
207
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
208 // 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
209 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
210 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
211 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
212 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
213 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
214
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
215 // 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
216 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
217 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
218
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
219 // 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
220 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
221 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
222 // 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
223 else
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
224 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
225 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
226 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
227 // 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
228 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
229 }
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 // 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
232 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
233 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
234 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
235 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
236
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
237 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
238 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
239 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
240
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
241 // there might still be padding after the last one, make sure that is defaulted/zeroed 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
242 size_t structsize = getABITypeSize(structtype);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
243
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
244 // 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
245 // 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
246 Lpadding2:
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
247 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
248 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
249 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
250 // 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
251 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
252
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
253 // found
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
254 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
255 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
256 // 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
257 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
258 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
259 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
260 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
261 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
262
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
263 // 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
264 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
265 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
266 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
267 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
268 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
269
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
270 // 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
271 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
272 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
273
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
274 // 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
275 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
276 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
277 // 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
278 else
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
279 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
280 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
281 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
282 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
283 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
284 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
285 }
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 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
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 // 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
290 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
291 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
292 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
293 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
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 assert(getABITypeSize(c->getType()) == structsize);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
296 return c;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
297 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
298
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
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
301 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
302 {
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
303 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
304 LOG_SCOPE;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
305
840
a125ada7fd95 more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 812
diff changeset
306 DtoResolveStruct(sd);
a125ada7fd95 more moreatatime fixes
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 812
diff changeset
307
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
308 // 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
309 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
310 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
311
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
312 // 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
313 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
314
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
315 // 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
316 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
317
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
318 // 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
319 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
320
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
321 // 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
322 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
323 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
324 // 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
325 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
326 // offset
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
327 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
328 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
329
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
330 // 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
331 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
332
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
333 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
334 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
335
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
336 return val;
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
337 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
338
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
339 void DtoResolveStruct(StructDeclaration* sd)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
340 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
341 // 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
342 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
343 // make sure above works :P
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
344 sd->ir.resolved = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
345
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
346 // 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
347 Logger::println("Resolving struct type: %s (%s)", sd->toChars(), sd->locToChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
348 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
349
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
350 // 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
351 TypeStruct* ts = (TypeStruct*)sd->type;
171
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
352
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
353 // 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
354 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
355 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
356
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
357 // 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
358 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
359
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
360 // 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
361 // 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
362 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
363 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
364 // 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
365 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
366 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
367
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
368 // make this struct current
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
369 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
370
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
371 // 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
372 bool ispacked = (ts->alignsize() == 1);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
373 bool isunion = sd->isUnionDeclaration();
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
374
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
375 // 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
376 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
377
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
378 // defined in this module?
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
379 bool thisModule = false;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
380 if (sd->getModule() == gIR->dmodule)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
381 thisModule = true;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
382
725
3e143b611c1e Fix double field toObjFile for structs with AttribDecls.
Christian Kamm <kamm incasoftware de>
parents: 705
diff changeset
383 // methods, fields
3e143b611c1e Fix double field toObjFile for structs with AttribDecls.
Christian Kamm <kamm incasoftware de>
parents: 705
diff changeset
384 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
385 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
386 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
387 s->toObjFile(0);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
388 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
389
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
390 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
391
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
392 #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
393 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
394
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
395 // 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
396 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
397 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
398 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
399 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
400 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
401 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
402
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
403 unsigned llvmSize = (unsigned)getABITypeSize(ST);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
404 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
405 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
406 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
407
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
408 #endif
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
409
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
410 /*for (int k=0; k < sd->members->dim; k++) {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
411 Dsymbol* dsym = (Dsymbol*)(sd->members->data[k]);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
412 dsym->toObjFile();
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
413 }*/
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
414
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
415 Logger::println("doing struct fields");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
416
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
417 // 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
418 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
419 ST = ts->ir.type->get();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
420
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
421 // name type
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
422 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
423 gIR->module->addTypeName(sd->mangle(),ST);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
424 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
425
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
426 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
427
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
428 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
429 }
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
430
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
431 //////////////////////////////////////////////////////////////////////////////////////////
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
432
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
433 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
434 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
435 if (sd->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
436 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
437
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
438 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
439 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
440
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
441 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
442
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
443 std::string initname("_D");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
444 initname.append(sd->mangle());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
445 initname.append("6__initZ");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
446
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 137
diff changeset
447 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
448 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
449 sd->ir.irStruct->init = initvar;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
450
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
451 gIR->constInitList.push_back(sd);
171
95f07e3f8bb9 [svn r187] Fixed missing definitions of instances of imported struct template declarations.
lindquist
parents: 169
diff changeset
452 if (DtoIsTemplateInstance(sd) || sd->getModule() == gIR->dmodule)
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
453 gIR->defineList.push_back(sd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
454 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
455
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
456 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
457
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
458 void DtoConstInitStruct(StructDeclaration* sd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
459 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
460 if (sd->ir.initialized) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
461 sd->ir.initialized = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
462
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
463 Logger::println("DtoConstInitStruct(%s): %s", sd->toChars(), sd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
464 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
465
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
466 IrStruct* irstruct = sd->ir.irStruct;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
467 gIR->structs.push_back(irstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
468
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
469 const llvm::StructType* structtype = isaStruct(sd->type->ir.type->get());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
470
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
471 // 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
472 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
473 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
474 {
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
475 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
476 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
477 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
478 else
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
479 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
480 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
481
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
482 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
483 irstruct->constInit = c;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
484 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
485
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
486 // 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
487 llvm::cast<llvm::OpaqueType>(irstruct->initOpaque.get())->refineAbstractTypeTo(irstruct->constInit->getType());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
488
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
489 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
490
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
491 // emit typeinfo
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 435
diff changeset
492 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
493 DtoTypeInfoOf(sd->type, false);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
494 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
495
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
496 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
497
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
498 void DtoDefineStruct(StructDeclaration* sd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
499 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
500 if (sd->ir.defined) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
501 sd->ir.defined = true;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
502
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
503 Logger::println("DtoDefineStruct(%s): %s", sd->toChars(), sd->loc.toChars());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
504 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
505
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
506 assert(sd->type->ty == Tstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
507 TypeStruct* ts = (TypeStruct*)sd->type;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
508 sd->ir.irStruct->init->setInitializer(sd->ir.irStruct->constInit);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
509
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 171
diff changeset
510 sd->ir.DModule = gIR->dmodule;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
511 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 96
diff changeset
512
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
diff changeset
513 //////////////////////////////////////////////////////////////////////////////////////////
344
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
514 //////////////////////////// D STRUCT UTILITIES ////////////////////////////////////
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
515 //////////////////////////////////////////////////////////////////////////////////////////
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
516
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
517 LLValue* DtoStructEquals(TOK op, DValue* lhs, DValue* rhs)
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
518 {
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
519 Type* t = lhs->getType()->toBasetype();
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
520 assert(t->ty == Tstruct);
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
521
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
522 // set predicate
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
523 llvm::ICmpInst::Predicate cmpop;
345
5320fe65a65d [svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents: 344
diff changeset
524 if (op == TOKequal || op == TOKidentity)
344
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
525 cmpop = llvm::ICmpInst::ICMP_EQ;
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
526 else
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
527 cmpop = llvm::ICmpInst::ICMP_NE;
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
528
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
529 // call memcmp
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
530 size_t sz = getABITypeSize(DtoType(t));
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 336
diff changeset
531 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
532 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
533 }