annotate gen/typinf.cpp @ 1529:ad7f2f1862d6

Adjust LDC to work with the LLVMContext LLVM changes. This means we now require a fairly new LLVM revision. I use 75234.
author Christian Kamm <kamm incasoftware de>
date Fri, 10 Jul 2009 21:30:02 +0200
parents d9c5f5a43403
children d1652c8fb4f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 // Copyright (c) 1999-2004 by Digital Mars
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 // All Rights Reserved
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 // written by Walter Bright
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 // www.digitalmars.com
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 // License for redistribution is by either the Artistic License
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 // in artistic.txt, or the GNU General Public License in gnu.txt.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 // See the included readme.txt for details.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10
663
6aaa3d3c1183 First part of rename to LDC.
Christian Kamm <kamm incasoftware de>
parents: 622
diff changeset
11 // Modifications for LDC:
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
12 // Copyright (c) 2007 by Tomas Lindquist Olsen
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
13 // tomas at famolsen dk
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
14
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15 #include <cstdio>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
16 #include <cassert>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
18 #include "gen/llvm.h"
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
19
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 #include "mars.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 #include "module.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 #include "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
23 #include "scope.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
24 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
25 #include "expression.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
26 #include "attrib.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
27 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 #include "template.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 #include "id.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 #include "enum.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
31 #include "import.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
32 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
33
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
34 #include "gen/irstate.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
35 #include "gen/logger.h"
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
36 #include "gen/runtime.h"
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
37 #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: 213
diff changeset
38 #include "gen/llvmhelpers.h"
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
39 #include "gen/arrays.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 98
diff changeset
40 #include "gen/structs.h"
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
41 #include "gen/classes.h"
1064
f0b6549055ab Make LDC work with LLVM trunk (s/LinkOnceLinkage/LinkOnceOdrLinkage/)
Frits van Bommel <fvbommel wxs.nl>
parents: 918
diff changeset
42 #include "gen/linkage.h"
1284
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
43 #include "gen/metadata.h"
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
44 #include "gen/rttibuilder.h"
1482
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1463
diff changeset
45 #include "gen/llvm-version.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46
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
47 #include "ir/irvar.h"
1364
46f6365a50d7 Added IrTypeFunction and IrTypeDelegate and eliminated IrDType. This means the Type::ir field can be removed. It's the final part needed for the move to a slightly more sane type system. Now the whole thing just needs to be cleaned up :P
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1358
diff changeset
48 #include "ir/irtype.h"
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
49
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 /*******************************************
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51 * Get a canonicalized form of the TypeInfo for use with the internal
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52 * runtime library routines. Canonicalized in that static arrays are
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 * represented as dynamic arrays, enums are represented by their
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54 * underlying type, etc. This reduces the number of TypeInfo's needed,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
55 * so we can use the custom internal ones more.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58 Expression *Type::getInternalTypeInfo(Scope *sc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59 { TypeInfoDeclaration *tid;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
60 Expression *e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
61 Type *t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62 static TypeInfoDeclaration *internalTI[TMAX];
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
63
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 //printf("Type::getInternalTypeInfo() %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 t = toBasetype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66 switch (t->ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 case Tsarray:
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
69 #if 0
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
70 // convert to corresponding dynamic array type
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
71 t = t->nextOf()->mutableOf()->arrayOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
72 #endif
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
73 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
74
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
75 case Tclass:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
76 if (((TypeClass *)t)->sym->isInterfaceDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
77 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
78 goto Linternal;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
79
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 case Tarray:
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
81 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
82 // convert to corresponding dynamic array type
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
83 t = t->nextOf()->mutableOf()->arrayOf();
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
84 #endif
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
85 if (t->nextOf()->ty != Tclass)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
86 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 goto Linternal;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
88
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89 case Tfunction:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90 case Tdelegate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
91 case Tpointer:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92 Linternal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
93 tid = internalTI[t->ty];
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94 if (!tid)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 { tid = new TypeInfoDeclaration(t, 1);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 internalTI[t->ty] = tid;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98 e = new VarExp(0, tid);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
99 e = e->addressOf(sc);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 e->type = tid->type; // do this so we don't get redundant dereference
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
101 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 //printf("\tcalling getTypeInfo() %s\n", t->toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 return t->getTypeInfo(sc);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
108 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
110 /****************************************************
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 * Get the exact TypeInfo.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
114 Expression *Type::getTypeInfo(Scope *sc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116 Expression *e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117 Type *t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
118
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
119 //printf("Type::getTypeInfo() %p, %s\n", this, toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
120 t = merge(); // do this since not all Type's are merge'd
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
121 if (!t->vtinfo)
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
122 {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
123 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
124 if (t->isConst())
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
125 t->vtinfo = new TypeInfoConstDeclaration(t);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
126 else if (t->isInvariant())
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
127 t->vtinfo = new TypeInfoInvariantDeclaration(t);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
128 else
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
129 #endif
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
130 t->vtinfo = t->getTypeInfoDeclaration();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
131 assert(t->vtinfo);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
132
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
133 /* If this has a custom implementation in std/typeinfo, then
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
134 * do not generate a COMDAT for it.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
135 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
136 if (!t->builtinTypeInfo())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 { // Generate COMDAT
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
138 if (sc) // if in semantic() pass
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
139 { // Find module that will go all the way to an object file
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
140 Module *m = sc->module->importedFrom;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
141 m->members->push(t->vtinfo);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
142 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
143 else // if in obj generation pass
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144 {
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
145 #if IN_DMD
336
aaade6ded589 [svn r357] Merged DMD 1.033
lindquist
parents: 290
diff changeset
146 t->vtinfo->toObjFile(0); // TODO: multiobj
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
147 #else
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
148 t->vtinfo->codegen(sir);
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
149 #endif
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
150 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
153 e = new VarExp(0, t->vtinfo);
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
154 e = e->addressOf(sc);
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
155 e->type = t->vtinfo->type; // do this so we don't get redundant dereference
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156 return e;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
159 enum RET TypeFunction::retStyle()
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
160 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
161 return RETstack;
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
162 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
163
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164 TypeInfoDeclaration *Type::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
165 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
166 //printf("Type::getTypeInfoDeclaration() %s\n", toChars());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 return new TypeInfoDeclaration(this, 0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
168 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
170 TypeInfoDeclaration *TypeTypedef::getTypeInfoDeclaration()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 {
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
172 return new TypeInfoTypedefDeclaration(this);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
173 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
174
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
175 TypeInfoDeclaration *TypePointer::getTypeInfoDeclaration()
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
176 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
177 return new TypeInfoPointerDeclaration(this);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
178 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
179
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
180 TypeInfoDeclaration *TypeDArray::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
181 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
182 return new TypeInfoArrayDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
183 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
184
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185 TypeInfoDeclaration *TypeSArray::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
186 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
187 return new TypeInfoStaticArrayDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
188 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
189
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
190 TypeInfoDeclaration *TypeAArray::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
191 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
192 return new TypeInfoAssociativeArrayDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
193 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
194
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
195 TypeInfoDeclaration *TypeStruct::getTypeInfoDeclaration()
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
196 {
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
197 return new TypeInfoStructDeclaration(this);
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
198 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
199
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
200 TypeInfoDeclaration *TypeClass::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
201 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
202 if (sym->isInterfaceDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
203 return new TypeInfoInterfaceDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
204 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
205 return new TypeInfoClassDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
206 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
207
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
208 TypeInfoDeclaration *TypeEnum::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
209 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
210 return new TypeInfoEnumDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
211 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
212
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
213 TypeInfoDeclaration *TypeFunction::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
214 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 return new TypeInfoFunctionDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
216 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218 TypeInfoDeclaration *TypeDelegate::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
219 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220 return new TypeInfoDelegateDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
221 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
222
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
223 TypeInfoDeclaration *TypeTuple::getTypeInfoDeclaration()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
224 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
225 return new TypeInfoTupleDeclaration(this);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
226 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
227
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
228
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
229 /* ========================================================================= */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
230
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
231 /* These decide if there's an instance for them already in std.typeinfo,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
232 * because then the compiler doesn't need to build one.
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
233 */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
234
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
235 int Type::builtinTypeInfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
236 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
237 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
238 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
239
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
240 int TypeBasic::builtinTypeInfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
241 {
764
8e7d4ddab66d Forgot D2 versioning on typeinfo change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
242 #if DMDV2
763
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 761
diff changeset
243 return !mod;
764
8e7d4ddab66d Forgot D2 versioning on typeinfo change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
244 #else
8e7d4ddab66d Forgot D2 versioning on typeinfo change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
245 return 1;
8e7d4ddab66d Forgot D2 versioning on typeinfo change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 763
diff changeset
246 #endif
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
247 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
248
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
249 int TypeDArray::builtinTypeInfo()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
250 {
763
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 761
diff changeset
251 #if DMDV2
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 761
diff changeset
252 return !mod && next->isTypeBasic() != NULL && !next->mod;
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 761
diff changeset
253 #else
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
254 return next->isTypeBasic() != NULL;
763
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 761
diff changeset
255 #endif
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
256 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
257
1367
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
258 int TypeClass::builtinTypeInfo()
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
259 {
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
260 /* This is statically put out with the ClassInfo, so
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
261 * claim it is built in so it isn't regenerated by each module.
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
262 */
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
263 #if IN_DMD
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
264 return 1;
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
265 #elif IN_LLVM
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
266 // FIXME if I enable this, the way LDC does typeinfo will cause a bunch
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
267 // of linker errors to missing class typeinfo definitions.
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
268 return 0;
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
269 #endif
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
270 }
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1364
diff changeset
271
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
272 /* ========================================================================= */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
273
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
274 //////////////////////////////////////////////////////////////////////////////
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
275 // MAGIC PLACE
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
276 // (wut?)
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
277 //////////////////////////////////////////////////////////////////////////////
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
278
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
279 void DtoResolveTypeInfo(TypeInfoDeclaration* tid);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
280 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
281
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
282 void TypeInfoDeclaration::codegen(Ir*)
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
283 {
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
284 DtoResolveTypeInfo(this);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
285 }
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
286
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
287 void DtoResolveTypeInfo(TypeInfoDeclaration* tid)
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
288 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
289 if (tid->ir.resolved) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
290 tid->ir.resolved = 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
291
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
292 Logger::println("DtoResolveTypeInfo(%s)", tid->toChars());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
293 LOG_SCOPE;
65
d4a678905d5e [svn r69] forgot std.stdarg
lindquist
parents: 58
diff changeset
294
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
295 IrGlobal* irg = new IrGlobal(tid);
1156
19d4ded7204a Fixed issue with runtime supplied typeinfo generating multiple symbols.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
296
19d4ded7204a Fixed issue with runtime supplied typeinfo generating multiple symbols.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
297 std::string mangle(tid->mangle());
19d4ded7204a Fixed issue with runtime supplied typeinfo generating multiple symbols.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
298
19d4ded7204a Fixed issue with runtime supplied typeinfo generating multiple symbols.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
299 irg->value = gIR->module->getGlobalVariable(mangle);
19d4ded7204a Fixed issue with runtime supplied typeinfo generating multiple symbols.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
300 if (!irg->value)
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1482
diff changeset
301 irg->value = new llvm::GlobalVariable(*gIR->module, irg->type.get(), true,
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1482
diff changeset
302 TYPEINFO_LINKAGE_TYPE, NULL, mangle);
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
303
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
304 tid->ir.irGlobal = irg;
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 96
diff changeset
305
1284
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
306 #ifdef USE_METADATA
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
307 // Add some metadata for use by optimization passes.
1291
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
308 std::string metaname = std::string(TD_PREFIX) + mangle;
1284
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
309 LLGlobalVariable* meta = gIR->module->getGlobalVariable(metaname);
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
310 // Don't generate metadata for non-concrete types
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
311 // (such as tuple types, slice types, typeof(expr), etc.)
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
312 if (!meta && tid->tinfo->toBasetype()->ty < Terror) {
1291
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
313 // Construct the fields
1343
c21a6654cce2 Update for metadata changes in LLVM trunk.
Frits van Bommel <fvbommel wxs.nl>
parents: 1316
diff changeset
314 MDNodeField* mdVals[TD_NumFields];
1316
8c65217be813 Work around an LLVM bug by not referring to globals from metadata. This was
Frits van Bommel <fvbommel wxs.nl>
parents: 1291
diff changeset
315 if (TD_Confirm >= 0)
1344
3297edb697eb Re-enable consistency check for fixed LLVM versions.
Frits van Bommel <fvbommel wxs.nl>
parents: 1343
diff changeset
316 mdVals[TD_Confirm] = llvm::cast<MDNodeField>(irg->value);
1291
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
317 mdVals[TD_Type] = llvm::UndefValue::get(DtoType(tid->tinfo));
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
318 // Construct the metadata
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
319 llvm::MDNode* metadata = llvm::MDNode::get(mdVals, TD_NumFields);
875afb7a93b6 Factor out some constants into the header so producers and consumers of
Frits van Bommel <fvbommel wxs.nl>
parents: 1284
diff changeset
320 // Insert it into the module
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1482
diff changeset
321 new llvm::GlobalVariable(*gIR->module, metadata->getType(), true,
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1482
diff changeset
322 METADATA_LINKAGE_TYPE, metadata, metaname);
1284
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
323 }
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
324 #endif
5851c18e4c6d Add metadata for TypeInfo -> llvm::Type mapping.
Frits van Bommel <fvbommel wxs.nl>
parents: 1283
diff changeset
325
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
326 DtoDeclareTypeInfo(tid);
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
327 }
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
328
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
329 void DtoDeclareTypeInfo(TypeInfoDeclaration* tid)
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
330 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
331 DtoResolveTypeInfo(tid);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
332
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
333 if (tid->ir.declared) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
334 tid->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
335
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 121
diff changeset
336 Logger::println("DtoDeclareTypeInfo(%s)", tid->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
337 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
338
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
339 if (Logger::enabled())
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
340 {
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
341 std::string mangled(tid->mangle());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
342 Logger::println("type = '%s'", tid->tinfo->toChars());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
343 Logger::println("typeinfo mangle: %s", mangled.c_str());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
344 }
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
345
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
346 IrGlobal* irg = tid->ir.irGlobal;
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
347 assert(irg->value != NULL);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
348
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
349 // this is a declaration of a builtin __initZ var
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
350 if (tid->tinfo->builtinTypeInfo()) {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
351 // fixup the global
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
352 const llvm::Type* rty = Type::typeinfo->type->irtype->getPA();
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
353 llvm::cast<llvm::OpaqueType>(irg->type.get())->refineAbstractTypeTo(rty);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
354 LLGlobalVariable* g = isaGlobalVar(irg->value);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
355 g->setLinkage(llvm::GlobalValue::ExternalLinkage);
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
356 return;
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
357 }
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
358
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
359 // define custom typedef
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
360 tid->llvmDefine();
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
361 }
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
362
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
363 /* ========================================================================= */
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
364
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
365 void TypeInfoDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
366 {
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
367 assert(0 && "cannot generate generic typeinfo");
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
368 }
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
369
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
370 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
371
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
372 void TypeInfoTypedefDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
373 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
374 Logger::println("TypeInfoTypedefDeclaration::llvmDefine() %s", toChars());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
375 LOG_SCOPE;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
376
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
377 RTTIBuilder b(Type::typeinfotypedef);
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
378
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
379 assert(tinfo->ty == Ttypedef);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
380 TypeTypedef *tc = (TypeTypedef *)tinfo;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
381 TypedefDeclaration *sd = tc->sym;
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
382
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
383 // TypeInfo base
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
384 sd->basetype = sd->basetype->merge(); // dmd does it ... why?
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
385 b.push_typeinfo(sd->basetype);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
386
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
387 // char[] name
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
388 b.push_string(sd->toPrettyChars());
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
389
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
390 // void[] init
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
391 // emit null array if we should use the basetype, or if the basetype
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
392 // uses default initialization.
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
393 if (!sd->init || tinfo->isZeroInit(0))
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 65
diff changeset
394 {
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
395 b.push_null_void_array();
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 65
diff changeset
396 }
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
397 // otherwise emit a void[] with the default initializer
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 65
diff changeset
398 else
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 65
diff changeset
399 {
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
400 LLConstant* C = DtoConstInitializer(sd->loc, sd->basetype, sd->init);
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
401 b.push_void_array(C, sd->basetype, sd);
69
2b5a2eaa88be [svn r73] Identity expression for dynamic array and null was broken.
lindquist
parents: 65
diff changeset
402 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
403
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
404 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
405 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
406 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 52
diff changeset
407
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
408 /* ========================================================================= */
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
409
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
410 void TypeInfoEnumDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
411 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
412 Logger::println("TypeInfoEnumDeclaration::llvmDefine() %s", toChars());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
413 LOG_SCOPE;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
414
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
415 RTTIBuilder b(Type::typeinfoenum);
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
416
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
417 assert(tinfo->ty == Tenum);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
418 TypeEnum *tc = (TypeEnum *)tinfo;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
419 EnumDeclaration *sd = tc->sym;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
420
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
421 // TypeInfo base
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
422 b.push_typeinfo(sd->memtype);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
423
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
424 // char[] name
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
425 b.push_string(sd->toPrettyChars());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
426
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
427 // void[] init
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
428 // emit void[] with the default initialier, the array is null if the default
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
429 // initializer is zero
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
430 if (!sd->defaultval || tinfo->isZeroInit(0))
71
53d3086b5ad3 [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents: 69
diff changeset
431 {
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
432 b.push_null_void_array();
71
53d3086b5ad3 [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents: 69
diff changeset
433 }
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
434 // otherwise emit a void[] with the default initializer
71
53d3086b5ad3 [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents: 69
diff changeset
435 else
53d3086b5ad3 [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents: 69
diff changeset
436 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
437 const LLType* memty = DtoType(sd->memtype);
1452
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1382
diff changeset
438 #if DMDV2
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1382
diff changeset
439 LLConstant* C = llvm::ConstantInt::get(memty, sd->defaultval->toInteger(), !sd->memtype->isunsigned());
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1382
diff changeset
440 #else
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
441 LLConstant* C = llvm::ConstantInt::get(memty, sd->defaultval, !sd->memtype->isunsigned());
1452
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1382
diff changeset
442 #endif
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
443 b.push_void_array(C, sd->memtype, sd);
71
53d3086b5ad3 [svn r75] Fixed the init member in custom enum typeinfo. I don't see any way this could actually need emmision though :/
lindquist
parents: 69
diff changeset
444 }
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
445
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
446 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
447 b.finalize(ir.irGlobal);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
448 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
449
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
450 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
451
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
452 void TypeInfoPointerDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
453 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
454 Logger::println("TypeInfoPointerDeclaration::llvmDefine() %s", toChars());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
455 LOG_SCOPE;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
456
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
457 RTTIBuilder b(Type::typeinfopointer);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
458 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
459 b.push_typeinfo(tinfo->nextOf());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
460 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
461 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
462 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
463
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
464 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
465
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
466 void TypeInfoArrayDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
467 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
468 Logger::println("TypeInfoArrayDeclaration::llvmDefine() %s", toChars());
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
469 LOG_SCOPE;
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
470
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
471 RTTIBuilder b(Type::typeinfoarray);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
472 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
473 b.push_typeinfo(tinfo->nextOf());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
474 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
475 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
476 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
477
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
478 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
479
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
480 void TypeInfoStaticArrayDeclaration::llvmDefine()
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
481 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
482 Logger::println("TypeInfoStaticArrayDeclaration::llvmDefine() %s", toChars());
105
182b41f56b7f [svn r109] Fixed support for static array TypeInfo
lindquist
parents: 102
diff changeset
483 LOG_SCOPE;
182b41f56b7f [svn r109] Fixed support for static array TypeInfo
lindquist
parents: 102
diff changeset
484
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
485 assert(tinfo->ty == Tsarray);
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
486 TypeSArray *tc = (TypeSArray *)tinfo;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
487
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
488 RTTIBuilder b(Type::typeinfostaticarray);
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
489
105
182b41f56b7f [svn r109] Fixed support for static array TypeInfo
lindquist
parents: 102
diff changeset
490 // value typeinfo
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
491 b.push_typeinfo(tc->nextOf());
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
492
105
182b41f56b7f [svn r109] Fixed support for static array TypeInfo
lindquist
parents: 102
diff changeset
493 // length
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
494 b.push(DtoConstSize_t((size_t)tc->dim->toUInteger()));
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
495
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
496 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
497 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
498 }
105
182b41f56b7f [svn r109] Fixed support for static array TypeInfo
lindquist
parents: 102
diff changeset
499
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
500 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
501
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
502 void TypeInfoAssociativeArrayDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
503 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
504 Logger::println("TypeInfoAssociativeArrayDeclaration::llvmDefine() %s", toChars());
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
505 LOG_SCOPE;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
506
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
507 assert(tinfo->ty == Taarray);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
508 TypeAArray *tc = (TypeAArray *)tinfo;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
509
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
510 RTTIBuilder b(Type::typeinfoassociativearray);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
511
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
512 // value typeinfo
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
513 b.push_typeinfo(tc->nextOf());
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
514
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 106
diff changeset
515 // key typeinfo
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
516 b.push_typeinfo(tc->index);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
517
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
518 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
519 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
520 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
521
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
522 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
523
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
524 void TypeInfoFunctionDeclaration::llvmDefine()
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
525 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
526 Logger::println("TypeInfoFunctionDeclaration::llvmDefine() %s", toChars());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
527 LOG_SCOPE;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
528
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
529 RTTIBuilder b(Type::typeinfofunction);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
530 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
531 b.push_typeinfo(tinfo->nextOf());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
532 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
533 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
534 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
535
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
536 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
537
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
538 void TypeInfoDelegateDeclaration::llvmDefine()
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
539 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
540 Logger::println("TypeInfoDelegateDeclaration::llvmDefine() %s", toChars());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
541 LOG_SCOPE;
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
542
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
543 assert(tinfo->ty == Tdelegate);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
544 Type* ret_type = tinfo->nextOf()->nextOf();
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 4
diff changeset
545
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
546 RTTIBuilder b(Type::typeinfodelegate);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
547 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
548 b.push_typeinfo(ret_type);
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
549 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
550 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
551 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
552
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
553 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
554
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
555 static FuncDeclaration* find_method_overload(AggregateDeclaration* ad, Identifier* id, TypeFunction* tf, Module* mod)
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
556 {
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
557 Dsymbol *s = search_function(ad, id);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
558 FuncDeclaration *fdx = s ? s->isFuncDeclaration() : NULL;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
559 if (fdx)
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
560 {
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
561 FuncDeclaration *fd = fdx->overloadExactMatch(tf, mod);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
562 if (fd)
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
563 {
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
564 return fd;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
565 }
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
566 }
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
567 return NULL;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
568 }
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
569
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
570 void TypeInfoStructDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
571 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
572 Logger::println("TypeInfoStructDeclaration::llvmDefine() %s", toChars());
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
573 LOG_SCOPE;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
574
1245
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
575 // make sure struct is resolved
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
576 assert(tinfo->ty == Tstruct);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
577 TypeStruct *tc = (TypeStruct *)tinfo;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
578 StructDeclaration *sd = tc->sym;
1345
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
579
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
580 // can't emit typeinfo for forward declarations
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
581 if (sd->sizeok != 1)
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
582 {
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
583 sd->error("cannot emit TypeInfo for forward declaration");
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
584 fatal();
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
585 }
712662f45ee4 Added error instead of assertion failure when trying to get !TypeInfo for a forward declared struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1344
diff changeset
586
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
587 sd->codegen(Type::sir);
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
588 IrStruct* irstruct = sd->ir.irStruct;
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
589
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
590 RTTIBuilder b(Type::typeinfostruct);
115
5ba6d286c941 [svn r119] Added the monitor data field that comes after the vtable pointer to all classes. Represented as a void* initialized to zero.
lindquist
parents: 113
diff changeset
591
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
592 // char[] name
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
593 b.push_string(sd->toPrettyChars());
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
594
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
595 // void[] init
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
596 // never emit a null array, even for zero initialized typeinfo
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
597 // the size() method uses this array!
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
598 size_t init_size = getTypeStoreSize(tc->irtype->getPA());
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
599 b.push_void_array(init_size, irstruct->getInitSymbol());
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
600
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
601 // toX functions ground work
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
602 static TypeFunction *tftohash;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
603 static TypeFunction *tftostring;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
604
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
605 if (!tftohash)
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
606 {
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
607 Scope sc;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
608 tftohash = new TypeFunction(NULL, Type::thash_t, 0, LINKd);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
609 tftohash = (TypeFunction *)tftohash->semantic(0, &sc);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
610 tftostring = new TypeFunction(NULL, Type::tchar->arrayOf(), 0, LINKd);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
611 tftostring = (TypeFunction *)tftostring->semantic(0, &sc);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
612 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
613
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
614 // this one takes a parameter, so we need to build a new one each time
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
615 // to get the right type. can we avoid this?
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
616 TypeFunction *tfeqptr;
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
617 {
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
618 Scope sc;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
619 Arguments *arguments = new Arguments;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
620 Argument *arg = new Argument(STCin, tc->pointerTo(), NULL, NULL);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
621 arguments->push(arg);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
622 tfeqptr = new TypeFunction(arguments, Type::tint32, 0, LINKd);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
623 tfeqptr = (TypeFunction *)tfeqptr->semantic(0, &sc);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
624 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
625
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
626 // well use this module for all overload lookups
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
627 Module *gm = getModule();
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
628
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
629 // toHash
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
630 FuncDeclaration* fd = find_method_overload(sd, Id::tohash, tftohash, gm);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
631 b.push_funcptr(fd);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
632
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
633 // opEquals
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
634 fd = find_method_overload(sd, Id::eq, tfeqptr, gm);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
635 b.push_funcptr(fd);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
636
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
637 // opCmp
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
638 fd = find_method_overload(sd, Id::cmp, tfeqptr, gm);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
639 b.push_funcptr(fd);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
640
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
641 // toString
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
642 fd = find_method_overload(sd, Id::tostring, tftostring, gm);
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
643 b.push_funcptr(fd);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
644
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
645 // uint m_flags;
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
646 unsigned hasptrs = tc->hasPointers() ? 1 : 0;
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
647 b.push_uint(hasptrs);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 71
diff changeset
648
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
649 #if DMDV2
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
650 // FIXME: just emit nulls for now
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
651
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
652 ClassDeclaration* tscd = Type::typeinfostruct;
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
653
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
654 assert(tscd->fields.dim == 10);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
655
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
656 // const(MemberInfo[]) function(in char[]) xgetMembers;
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
657 VarDeclaration* xgetMembers = (VarDeclaration*)tscd->fields.data[7];
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
658 b.push_null(xgetMembers->type);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
659
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
660 //void function(void*) xdtor;
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
661 VarDeclaration* xdtor = (VarDeclaration*)tscd->fields.data[8];
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
662 b.push_null(xdtor->type);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
663
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
664 //void function(void*) xpostblit;
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
665 VarDeclaration* xpostblit = (VarDeclaration*)tscd->fields.data[9];
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1452
diff changeset
666 b.push_null(xpostblit->type);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
667 #endif
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
668
1375
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
669 // finish
63f4afd01036 Cleaned up TypeInfo_Struct.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1374
diff changeset
670 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
671 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
672
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
673 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
674
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
675 void TypeInfoClassDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
676 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
677 Logger::println("TypeInfoClassDeclaration::llvmDefine() %s", toChars());
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
678 LOG_SCOPE;
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
679
1245
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
680 // make sure class is resolved
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
681 assert(tinfo->ty == Tclass);
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
682 TypeClass *tc = (TypeClass *)tinfo;
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
683 tc->sym->codegen(Type::sir);
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
684
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
685 RTTIBuilder b(Type::typeinfoclass);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
686
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
687 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
688 b.push_classinfo(tc->sym);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
689
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
690 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
691 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
692 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
693
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
694 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
695
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
696 void TypeInfoInterfaceDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
697 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
698 Logger::println("TypeInfoInterfaceDeclaration::llvmDefine() %s", toChars());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
699 LOG_SCOPE;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
700
1245
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
701 // make sure interface is resolved
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
702 assert(tinfo->ty == Tclass);
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
703 TypeClass *tc = (TypeClass *)tinfo;
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
704 tc->sym->codegen(Type::sir);
465a77c904d4 Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1228
diff changeset
705
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
706 RTTIBuilder b(Type::typeinfointerface);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
707
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
708 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
709 b.push_classinfo(tc->sym);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
710
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
711 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
712 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
713 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
714
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
715 /* ========================================================================= */
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
716
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
717 void TypeInfoTupleDeclaration::llvmDefine()
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
718 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
719 Logger::println("TypeInfoTupleDeclaration::llvmDefine() %s", toChars());
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
720 LOG_SCOPE;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
721
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
722 // create elements array
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
723 assert(tinfo->ty == Ttuple);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
724 TypeTuple *tu = (TypeTuple *)tinfo;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
725
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
726 size_t dim = tu->arguments->dim;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
727 std::vector<LLConstant*> arrInits;
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
728 arrInits.reserve(dim);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
729
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
730 const LLType* tiTy = DtoType(Type::typeinfo->type);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
731
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
732 for (size_t i = 0; i < dim; i++)
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
733 {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
734 Argument *arg = (Argument *)tu->arguments->data[i];
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
735 arrInits.push_back(DtoTypeInfoOf(arg->type, true));
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
736 }
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
737
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
738 // build array
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 213
diff changeset
739 const LLArrayType* arrTy = LLArrayType::get(tiTy, dim);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 173
diff changeset
740 LLConstant* arrC = llvm::ConstantArray::get(arrTy, arrInits);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
741
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
742 RTTIBuilder b(Type::typeinfotypelist);
522
cd4eeb6cc5f6 Fix TypeInfo_Tuple array initialization.
Christian Kamm <kamm incasoftware de>
parents: 508
diff changeset
743
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
744 // push TypeInfo[]
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
745 b.push_array(arrC, dim, Type::typeinfo->type, NULL);
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 110
diff changeset
746
1376
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
747 // finish
a5d0e04298a8 Cleaned up TypeInfo_Tuple generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1375
diff changeset
748 b.finalize(ir.irGlobal);
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
749 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 105
diff changeset
750
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
751 /* ========================================================================= */
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
752
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
753 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
754
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
755 void TypeInfoConstDeclaration::llvmDefine()
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
756 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
757 Logger::println("TypeInfoConstDeclaration::llvmDefine() %s", toChars());
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
758 LOG_SCOPE;
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
759
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
760 RTTIBuilder b(Type::typeinfoconst);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
761 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
762 b.push_typeinfo(tinfo->mutableOf()->merge());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
763 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
764 b.finalize(ir.irGlobal);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
765 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
766
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
767 /* ========================================================================= */
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
768
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
769 void TypeInfoInvariantDeclaration::llvmDefine()
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
770 {
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1064
diff changeset
771 Logger::println("TypeInfoInvariantDeclaration::llvmDefine() %s", toChars());
761
fa306ca8843b Applied fvbommel's patch from #112
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
772 LOG_SCOPE;
fa306ca8843b Applied fvbommel's patch from #112
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
773
1382
a0a4d4dac1a4 Renamed !TypeInfoBuilder to !RTTIBuilder.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1376
diff changeset
774 RTTIBuilder b(Type::typeinfoinvariant);
1374
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
775 // TypeInfo base
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
776 b.push_typeinfo(tinfo->mutableOf()->merge());
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
777 // finish
e630ff79e10d Cleaned up TypeInfo generation, still need to do TypeInfo_Struct/Tuple. Eventually do ClassInfo and ModuleInfo as well using same interface.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1367
diff changeset
778 b.finalize(ir.irGlobal);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
779 }
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 663
diff changeset
780
766
af04bbae8553 D2: Fixed global constants not initialized until module constructor.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 764
diff changeset
781 #endif