annotate gen/tollvm.cpp @ 210:1d6cfdbc97f0 trunk

[svn r226] Fixed: deleting interface. Removed: unused util function for calling class destructors.
author lindquist
date Wed, 14 May 2008 02:00:23 +0200
parents c4c9b4ac021b
children 7816aafeea3c
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 #include <iostream>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
3 #include "gen/llvm.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 #include "dsymbol.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
10 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
11 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
12 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
13 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
14 #include "gen/arrays.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
15 #include "gen/dvalue.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
16 #include "gen/functions.h"
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
17 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
18 #include "gen/classes.h"
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
19 #include "gen/typeinf.h"
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
20 #include "gen/complex.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
22 bool DtoIsPassedByRef(Type* type)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
23 {
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
24 Type* typ = DtoDType(type);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
25 TY t = typ->ty;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
26 return (t == Tstruct || t == Tarray || t == Tdelegate || t == Tsarray || typ->iscomplex());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
27 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
28
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
29 Type* DtoDType(Type* t)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
30 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
31 if (t->ty == Ttypedef) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
32 Type* bt = t->toBasetype();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
33 assert(bt);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
34 return DtoDType(bt);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
35 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
36 return t;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
37 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
38
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
39 const llvm::Type* DtoType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41 assert(t);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
42 switch (t->ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
44 // integers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
45 case Tint8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46 case Tuns8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
47 case Tchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 return (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 case Tint16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 case Tuns16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51 case Twchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52 return (const llvm::Type*)llvm::Type::Int16Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 case Tint32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54 case Tuns32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
55 case Tdchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 return (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 case Tint64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58 case Tuns64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59 return (const llvm::Type*)llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
60
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
61 case Tbool:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62 return (const llvm::Type*)llvm::ConstantInt::getTrue()->getType();
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 // floats
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 case Tfloat32:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
66 case Timaginary32:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67 return llvm::Type::FloatTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 case Tfloat64:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
69 case Timaginary64:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
70 case Tfloat80:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
71 case Timaginary80:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
72 return llvm::Type::DoubleTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
73
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
74 // complex
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
75 case Tcomplex32:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
76 case Tcomplex64:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
77 case Tcomplex80:
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
78 return DtoComplexType(t);
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
79
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 // pointers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81 case Tpointer: {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
82 assert(t->next);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
83 if (t->next->ty == Tvoid)
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
84 return (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
85 else
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
86 return (const llvm::Type*)getPtrToType(DtoType(t->next));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 }
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 // arrays
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90 case Tarray:
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
91 return DtoArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92 case Tsarray:
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
93 return DtoStaticArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 // void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 case Tvoid:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 return llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 // aggregates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 case Tstruct: {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
101 if (!t->ir.type || *t->ir.type == NULL) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 // recursive or cyclic declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
103 if (!gIR->structs.empty())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 {
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: 135
diff changeset
105 IrStruct* found = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
108 if (t == (*i)->type)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
110 return (*i)->recty.get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 }
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 }
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
114 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
116 TypeStruct* ts = (TypeStruct*)t;
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
117 assert(ts->sym);
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
118 DtoResolveDsymbol(ts->sym);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
119 return ts->sym->ir.irStruct->recty.get(); // t->ir.type->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
120 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
121
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
122 case Tclass: {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
123 /*if (!t].type || *gIR->irType[t->ir.type == NULL) {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
124 // recursive or cyclic declaration
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
125 if (!gIR->structs.empty())
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
126 {
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: 135
diff changeset
127 IrStruct* found = 0;
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
128 for (IRState::StructVector::iterator i=gIR->structs.begin(); i!=gIR->structs.end(); ++i)
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
129 {
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
130 if (t == (*i)->type)
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
131 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
132 return getPtrToType((*i)->recty.get());
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
133 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
134 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
135 }
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
136 Logger::println("no type found");
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
137 }*/
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
138
103
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
139 TypeClass* tc = (TypeClass*)t;
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
140 assert(tc->sym);
855adfdb8d38 [svn r107] Getting .classinfo on a class instance now works (classinfo is stored in vtable)
lindquist
parents: 102
diff changeset
141 DtoResolveDsymbol(tc->sym);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
142 return getPtrToType(tc->sym->ir.irStruct->recty.get()); // t->ir.type->get());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
143 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145 // functions
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
146 case Tfunction:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
147 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
148 if (!t->ir.type || *t->ir.type == NULL) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
149 return DtoFunctionType(t,NULL);
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 else {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
152 return t->ir.type->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
153 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
155
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156 // delegates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 case Tdelegate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
158 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
159 if (!t->ir.type || *t->ir.type == NULL) {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
160 return DtoDelegateType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
161 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
162 else {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
163 return t->ir.type->get();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164 }
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 // typedefs
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
168 // enum
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169 case Ttypedef:
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
170 case Tenum:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
172 Type* bt = t->toBasetype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
173 assert(bt);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
174 return DtoType(bt);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
175 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
176
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
177 // associative arrays
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
178 case Taarray:
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
179 {
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
180 TypeAArray* taa = (TypeAArray*)t;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
181 std::vector<const llvm::Type*> types;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
182 types.push_back(DtoType(taa->key));
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
183 types.push_back(DtoType(taa->next));
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
184 return getPtrToType(llvm::StructType::get(types));
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
185 }
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
186
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
187 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
188 printf("trying to convert unknown type with value %d\n", t->ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
189 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
190 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
191 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
192 }
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 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
195
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
196 const llvm::StructType* DtoDelegateType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
197 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
198 const llvm::Type* i8ptr = getPtrToType(llvm::Type::Int8Ty);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
199 const llvm::Type* func = DtoFunctionType(t->next, i8ptr);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
200 const llvm::Type* funcptr = getPtrToType(func);
1
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 std::vector<const llvm::Type*> types;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
203 types.push_back(i8ptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
204 types.push_back(funcptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
205 return llvm::StructType::get(types);
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 //////////////////////////////////////////////////////////////////////////////////////////
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 static llvm::Function* LLVM_DeclareMemIntrinsic(const char* name, int bits, bool set=false)
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 assert(bits == 32 || bits == 64);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
213 const llvm::Type* int8ty = (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
214 const llvm::Type* int32ty = (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 const llvm::Type* int64ty = (const llvm::Type*)llvm::Type::Int64Ty;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
216 const llvm::Type* int8ptrty = (const llvm::Type*)getPtrToType(llvm::Type::Int8Ty);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217 const llvm::Type* voidty = (const llvm::Type*)llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
219 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220 assert(gIR->module);
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 // parameter types
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
223 std::vector<const llvm::Type*> pvec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
224 pvec.push_back(int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
225 pvec.push_back(set?int8ty:int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
226 pvec.push_back(bits==32?int32ty:int64ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
227 pvec.push_back(int32ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
228 llvm::FunctionType* functype = llvm::FunctionType::get(voidty, pvec, false);
141
8f43f5c43c95 [svn r145] fixed some x86 problems
lindquist
parents: 137
diff changeset
229 return llvm::cast<llvm::Function>(gIR->module->getOrInsertFunction(name, functype));
1
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
232 //////////////////////////////////////////////////////////////////////////////////////////
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 // llvm.memset.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
235 llvm::Function* LLVM_DeclareMemSet32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
236 {
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
237 if (gIR->llvm_DeclareMemSet32 == 0) {
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
238 gIR->llvm_DeclareMemSet32 = LLVM_DeclareMemIntrinsic("llvm.memset.i32", 32, true);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
239 }
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
240 return gIR->llvm_DeclareMemSet32;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
241 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
242
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
243 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
244
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
245 llvm::Function* LLVM_DeclareMemSet64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
246 {
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
247 if (gIR->llvm_DeclareMemSet64 == 0) {
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
248 gIR->llvm_DeclareMemSet64 = LLVM_DeclareMemIntrinsic("llvm.memset.i64", 64, true);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
249 }
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
250 return gIR->llvm_DeclareMemSet64;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
251 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
252
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
253 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
254
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
255 // llvm.memcpy.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
256 llvm::Function* LLVM_DeclareMemCpy32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
257 {
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
258 if (gIR->llvm_DeclareMemCpy32 == 0) {
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
259 gIR->llvm_DeclareMemCpy32 = LLVM_DeclareMemIntrinsic("llvm.memcpy.i32", 32);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
260 }
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
261 return gIR->llvm_DeclareMemCpy32;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
262 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
263
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
264 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
265
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
266 // llvm.memcpy.i64
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
267 llvm::Function* LLVM_DeclareMemCpy64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
268 {
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
269 if (gIR->llvm_DeclareMemCpy64 == 0) {
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
270 gIR->llvm_DeclareMemCpy64 = LLVM_DeclareMemIntrinsic("llvm.memcpy.i64", 64);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
271 }
189
3aed08fb64f4 [svn r205] moved some local static variables used for memset and memcpy intrinsics to IrState
ChristianK
parents: 177
diff changeset
272 return gIR->llvm_DeclareMemCpy64;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
273 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
274
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
275 // llvm.memory.barrier
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
276 static llvm::Function* LLVM_DeclareMemBarrier()
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
277 {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
278 if (gIR->llvm_DeclareMemBarrier == 0) {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
279 std::vector<const llvm::Type*> pvec;
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
280 pvec.push_back(llvm::Type::Int1Ty);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
281 pvec.push_back(llvm::Type::Int1Ty);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
282 pvec.push_back(llvm::Type::Int1Ty);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
283 pvec.push_back(llvm::Type::Int1Ty);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
284 pvec.push_back(llvm::Type::Int1Ty);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
285 llvm::FunctionType* functype = llvm::FunctionType::get(llvm::Type::VoidTy, pvec, false);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
286 gIR->llvm_DeclareMemBarrier = llvm::cast<llvm::Function>(gIR->module->getOrInsertFunction("llvm.memory.barrier", functype));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
287 assert(gIR->llvm_DeclareMemBarrier != NULL);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
288 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
289 return gIR->llvm_DeclareMemBarrier;
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
290 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
291
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
292 void DtoMemoryBarrier(bool ll, bool ls, bool sl, bool ss, bool device)
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
293 {
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
294 llvm::Function* fn = LLVM_DeclareMemBarrier();
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
295 assert(fn != NULL);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
296
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
297 llvm::SmallVector<llvm::Value*, 5> llargs;
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
298 llargs.push_back(DtoConstBool(ll));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
299 llargs.push_back(DtoConstBool(ls));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
300 llargs.push_back(DtoConstBool(sl));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
301 llargs.push_back(DtoConstBool(ss));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
302 llargs.push_back(DtoConstBool(device));
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
303
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
304 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
305 }
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
306
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
307 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
308
177
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
309 llvm::Value* DtoDelegateToNull(llvm::Value* v)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
310 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
311 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
312 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
313
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
314 const llvm::Type* i8p_ty = getPtrToType(llvm::Type::Int8Ty);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
315
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
316 llvm::Value* arr = new llvm::BitCastInst(v,i8p_ty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
317
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
318 llvm::Function* fn = LLVM_DeclareMemSet32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
319 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
320 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
321 llargs[0] = arr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
322 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
323 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
324 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
325
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
326 llvm::Value* ret = llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
327
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
328 return ret;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
329 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
330
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
331 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
332
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
333 llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
334 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
335 assert(dst->getType() == src->getType());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
336 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
337
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
338 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
339
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
340 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
341
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
342 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
343 llvm::Value* srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
344
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
345 llvm::Function* fn = LLVM_DeclareMemCpy32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
346 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
347 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
348 llargs[0] = dstarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
349 llargs[1] = srcarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
350 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
351 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
352
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
353 return llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
354 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
355
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
356 //////////////////////////////////////////////////////////////////////////////////////////
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
357
177
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
358 llvm::Value* DtoDelegateCompare(TOK op, llvm::Value* lhs, llvm::Value* rhs)
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
359 {
177
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
360 Logger::println("Doing delegate compare");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
361 llvm::ICmpInst::Predicate pred = (op == TOKequal || op == TOKidentity) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
362 llvm::Value *b1, *b2;
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
363 if (rhs == NULL)
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
364 {
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
365 llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
366 llvm::Value* r = llvm::Constant::getNullValue(l->getType());
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
367 b1 = gIR->ir->CreateICmp(pred,l,r,"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
368 l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
369 r = llvm::Constant::getNullValue(l->getType());
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
370 b2 = gIR->ir->CreateICmp(pred,l,r,"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
371 }
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
372 else
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
373 {
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
374 llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
375 llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
376 b1 = gIR->ir->CreateICmp(pred,l,r,"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
377 l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
378 r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
379 b2 = gIR->ir->CreateICmp(pred,l,r,"tmp");
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
380 }
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
381 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
177
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
382 if (op == TOKnotequal || op == TOKnotidentity)
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
383 return gIR->ir->CreateNot(b,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
384 return b;
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
385 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
386
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
387 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
388
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
389 llvm::GlobalValue::LinkageTypes DtoLinkage(Dsymbol* sym)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
390 {
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
391 // global variable
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
392 if (VarDeclaration* vd = sym->isVarDeclaration())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
393 {
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
394 // template
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
395 if (DtoIsTemplateInstance(sym))
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
396 return llvm::GlobalValue::WeakLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
397 // local static
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
398 else if (sym->parent && sym->parent->isFuncDeclaration())
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
399 return llvm::GlobalValue::InternalLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
400 }
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
401 // function
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
402 else if (FuncDeclaration* fdecl = sym->isFuncDeclaration())
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
403 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
404 assert(fdecl->type->ty == Tfunction);
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
405 TypeFunction* ft = (TypeFunction*)fdecl->type;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
406
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
407 // intrinsics are always external
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
408 if (fdecl->llvmInternal == LLVMintrinsic)
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
409 return llvm::GlobalValue::ExternalLinkage;
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
410 // template instances should have weak linkage
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
411 else if (DtoIsTemplateInstance(fdecl))
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
412 return llvm::GlobalValue::WeakLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
413 // extern(C) functions are always external
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
414 else if (ft->linkage == LINKc)
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
415 return llvm::GlobalValue::ExternalLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
416 }
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
417 // class
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
418 else if (ClassDeclaration* cd = sym->isClassDeclaration())
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
419 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
420 // template
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
421 if (DtoIsTemplateInstance(cd))
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
422 return llvm::GlobalValue::WeakLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
423 }
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
424 else
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
425 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
426 assert(0 && "not global/function");
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
427 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
428
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
429 // default to external linkage
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
430 return llvm::GlobalValue::ExternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
431
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
432 // llvm linkage types
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
433 /* ExternalLinkage = 0, LinkOnceLinkage, WeakLinkage, AppendingLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
434 InternalLinkage, DLLImportLinkage, DLLExportLinkage, ExternalWeakLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
435 GhostLinkage */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
436 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
437
149
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
438 llvm::GlobalValue::LinkageTypes DtoInternalLinkage(Dsymbol* sym)
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
439 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
440 if (DtoIsTemplateInstance(sym))
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
441 return llvm::GlobalValue::WeakLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
442 else
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
443 return llvm::GlobalValue::InternalLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
444 }
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
445
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
446 llvm::GlobalValue::LinkageTypes DtoExternalLinkage(Dsymbol* sym)
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
447 {
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
448 if (DtoIsTemplateInstance(sym))
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
449 return llvm::GlobalValue::WeakLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
450 else
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
451 return llvm::GlobalValue::ExternalLinkage;
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
452 }
4c577c2b7229 [svn r155] Fixed a bunch of linkage problems (especially with templates)
lindquist
parents: 144
diff changeset
453
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
454 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
455
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
456 unsigned DtoCallingConv(LINK l)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
457 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
458 if (l == LINKc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
459 return llvm::CallingConv::C;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
460 else if (l == LINKd || l == LINKdefault)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
461 return llvm::CallingConv::Fast;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
462 else if (l == LINKwindows)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
463 return llvm::CallingConv::X86_StdCall;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
464 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
465 assert(0 && "Unsupported calling convention");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
466 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
467
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
468 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
469
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
470 llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
471 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
472 const llvm::Type* ptrTy = ptr->getType()->getContainedType(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
473 const llvm::Type* valTy = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
474 // ptr points to val's type
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
475 if (ptrTy == valTy)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
476 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
477 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
478 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
479 // ptr is integer pointer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
480 else if (ptrTy->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
481 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
482 // val is integer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
483 assert(valTy->isInteger());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
484 const llvm::IntegerType* pt = llvm::cast<const llvm::IntegerType>(ptrTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
485 const llvm::IntegerType* vt = llvm::cast<const llvm::IntegerType>(valTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
486 if (pt->getBitWidth() < vt->getBitWidth()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
487 return new llvm::TruncInst(val, pt, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
488 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
489 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
490 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
491 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
492 // something else unsupported
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
493 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
494 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
495 Logger::cout() << *ptrTy << '|' << *valTy << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
496 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
497 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
498 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
499 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
500
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
501 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
502
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
503 llvm::Value* DtoBoolean(llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
504 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
505 const llvm::Type* t = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
506 if (t->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
507 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
508 if (t == llvm::Type::Int1Ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
509 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
510 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
511 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
512 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
513 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
514 }
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
515 else if (isaPointer(t)) {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
516 llvm::Value* zero = llvm::Constant::getNullValue(t);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
517 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, val, zero, "tmp", gIR->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
518 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
519 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
520 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
521 Logger::cout() << *t << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
522 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
523 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
524 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
525 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
526
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
527 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
528
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
529 const llvm::Type* DtoSize_t()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
530 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
531 if (global.params.is64bit)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
532 return llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
533 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
534 return llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
535 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
536
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
537 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
538
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
539 llvm::Constant* DtoConstInitializer(Type* type, Initializer* init)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
540 {
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
541 llvm::Constant* _init = 0; // may return zero
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
542 if (!init)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
543 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
544 Logger::println("const default initializer for %s", type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
545 _init = type->defaultInit()->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
547 else if (ExpInitializer* ex = init->isExpInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
548 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
549 Logger::println("const expression initializer");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
550 _init = ex->exp->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
551 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
552 else if (StructInitializer* si = init->isStructInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
553 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
554 Logger::println("const struct initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
555 _init = DtoConstStructInitializer(si);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
556 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
557 else if (ArrayInitializer* ai = init->isArrayInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
558 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
559 Logger::println("const array initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
560 _init = DtoConstArrayInitializer(ai);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
561 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
562 else if (init->isVoidInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
563 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
564 Logger::println("const void initializer");
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
565 const llvm::Type* ty = DtoType(type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
566 _init = llvm::Constant::getNullValue(ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
567 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
568 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
569 Logger::println("unsupported const initializer: %s", init->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
570 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
571 return _init;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
572 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
573
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
574 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
575
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
576 llvm::Constant* DtoConstFieldInitializer(Type* t, Initializer* init)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
577 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
578 Logger::println("DtoConstFieldInitializer");
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
579 LOG_SCOPE;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
580
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
581 const llvm::Type* _type = DtoType(t);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
582
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
583 llvm::Constant* _init = DtoConstInitializer(t, init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
584 assert(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
585 if (_type != _init->getType())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
586 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
587 Logger::cout() << "field init is: " << *_init << " type should be " << *_type << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
588 if (t->ty == Tsarray)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
589 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
590 const llvm::ArrayType* arrty = isaArray(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
591 uint64_t n = arrty->getNumElements();
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
592 std::vector<llvm::Constant*> vals(n,_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
593 _init = llvm::ConstantArray::get(arrty, vals);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
594 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
595 else if (t->ty == Tarray)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
596 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
597 assert(isaStruct(_type));
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
598 _init = llvm::ConstantAggregateZero::get(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
599 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
600 else if (t->ty == Tstruct)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
601 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
602 const llvm::StructType* structty = isaStruct(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
603 TypeStruct* ts = (TypeStruct*)t;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
604 assert(ts);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
605 assert(ts->sym);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
606 assert(ts->sym->ir.irStruct->constInit);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
607 _init = ts->sym->ir.irStruct->constInit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
608 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
609 else if (t->ty == Tclass)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
610 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
611 _init = llvm::Constant::getNullValue(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
612 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
613 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
614 Logger::println("failed for type %s", t->toChars());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
615 assert(0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
616 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
617 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
618
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
619 return _init;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
620 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
621
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
622 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
623
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
624 DValue* DtoInitializer(Initializer* init)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
625 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
626 if (ExpInitializer* ex = init->isExpInitializer())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
627 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
628 Logger::println("expression initializer");
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
629 assert(ex->exp);
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
630 return ex->exp->toElem(gIR);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
631 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
632 else if (init->isVoidInitializer())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
633 {
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
634 // do nothing
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
635 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
636 else {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
637 Logger::println("unsupported initializer: %s", init->toChars());
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
638 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
639 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
640 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
641 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
642
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
643 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
644
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
645 llvm::Value* DtoGEP(llvm::Value* ptr, llvm::Value* i0, llvm::Value* i1, const std::string& var, llvm::BasicBlock* bb)
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
646 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
647 std::vector<llvm::Value*> v(2);
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
648 v[0] = i0;
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
649 v[1] = i1;
163
a8cd9bc1021a [svn r179] lots and lots of fixes, much more of tango now compiles/works.
lindquist
parents: 161
diff changeset
650 Logger::cout() << "DtoGEP: " << *ptr << ", " << *i0 << ", " << *i1 << '\n';
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
651 return llvm::GetElementPtrInst::Create(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
652 }
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
653
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
654 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
655
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
656 llvm::Value* DtoGEP(llvm::Value* ptr, const std::vector<unsigned>& src, const std::string& var, llvm::BasicBlock* bb)
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
657 {
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
658 size_t n = src.size();
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
659 std::vector<llvm::Value*> dst(n, NULL);
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
660 //std::ostream& ostr = Logger::cout();
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
661 //ostr << "indices for '" << *ptr << "':";
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
662 for (size_t i=0; i<n; ++i)
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
663 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
664 //ostr << ' ' << i;
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
665 dst[i] = llvm::ConstantInt::get(llvm::Type::Int32Ty, src[i], false);
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
666 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
667 //ostr << '\n';*/
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
668 return llvm::GetElementPtrInst::Create(ptr, dst.begin(), dst.end(), var, bb?bb:gIR->scopebb());
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
669 }
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
670
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
671 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
672
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
673 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i, const std::string& var, llvm::BasicBlock* bb)
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
674 {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
675 return llvm::GetElementPtrInst::Create(ptr, llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false), var, bb?bb:gIR->scopebb());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
676 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
677
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
678 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
679
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
680 llvm::Value* DtoGEPi(llvm::Value* ptr, unsigned i0, unsigned i1, const std::string& var, llvm::BasicBlock* bb)
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
681 {
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
682 std::vector<llvm::Value*> v(2);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
683 v[0] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i0, false);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
684 v[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i1, false);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
685 return llvm::GetElementPtrInst::Create(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
686 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
687
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
688 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
689
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
690 llvm::Value* DtoNew(Type* newtype)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
691 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
692 // get runtime function
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
693 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocmemoryT");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
694 // get type info
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
695 llvm::Constant* ti = DtoTypeInfoOf(newtype);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
696 assert(isaPointer(ti));
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
697 // call runtime
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
698 llvm::SmallVector<llvm::Value*,1> arg;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
699 arg.push_back(ti);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
700 // allocate
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
701 llvm::Value* mem = gIR->ir->CreateCall(fn, arg.begin(), arg.end(), ".gc_mem");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
702 // cast
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
703 return DtoBitCast(mem, getPtrToType(DtoType(newtype)), ".gc_mem");
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
704 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
705
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
706 void DtoDeleteMemory(llvm::Value* ptr)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
707 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
708 // get runtime function
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
709 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delmemory");
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
710 // build args
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
711 llvm::SmallVector<llvm::Value*,1> arg;
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
712 arg.push_back(DtoBitCast(ptr, getVoidPtrType(), ".tmp"));
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
713 // call
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
714 llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb());
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
715 }
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
716
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
717 void DtoDeleteClass(llvm::Value* inst)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
718 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
719 // get runtime function
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
720 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delclass");
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
721 // build args
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
722 llvm::SmallVector<llvm::Value*,1> arg;
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
723 arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
724 // call
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
725 llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb());
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
726 }
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
727
210
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
728 void DtoDeleteInterface(llvm::Value* inst)
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
729 {
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
730 // get runtime function
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
731 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delinterface");
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
732 // build args
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
733 llvm::SmallVector<llvm::Value*,1> arg;
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
734 arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
735 // call
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
736 llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb());
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
737 }
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
738
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
739 void DtoDeleteArray(DValue* arr)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
740 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
741 // get runtime function
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
742 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delarray");
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
743 // build args
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
744 llvm::SmallVector<llvm::Value*,2> arg;
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
745 arg.push_back(DtoArrayLen(arr));
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
746 arg.push_back(DtoBitCast(DtoArrayPtr(arr), getVoidPtrType(), ".tmp"));
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
747 // call
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
748 llvm::CallInst::Create(fn, arg.begin(), arg.end(), "", gIR->scopebb());
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
749 }
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
750
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
751 //////////////////////////////////////////////////////////////////////////////////////////
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
752
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
753 void DtoAssert(Loc* loc, DValue* msg)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
754 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
755 std::vector<llvm::Value*> args;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
756 llvm::Constant* c;
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
757
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
758 // func
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
759 const char* fname = msg ? "_d_assert_msg" : "_d_assert";
207
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
760 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
761
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
762 c = DtoConstString(loc->filename);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
763
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
764 // msg param
207
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
765 if (msg)
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
766 {
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
767 if (DSliceValue* s = msg->isSlice())
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
768 {
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
769 llvm::AllocaInst* alloc = gIR->func()->msgArg;
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
770 if (!alloc)
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
771 {
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
772 alloc = new llvm::AllocaInst(c->getType(), ".assertmsg", gIR->topallocapoint());
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
773 DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
774 gIR->func()->msgArg = alloc;
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
775 }
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
776 args.push_back(alloc);
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
777 }
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
778 else
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
779 {
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
780 args.push_back(msg->getRVal());
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
781 }
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
782 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
783
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
784 // file param
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
785 llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
786 if (!alloc)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
787 {
207
e0b6040585b4 [svn r223] Fixed: assert with message could be broken.
lindquist
parents: 205
diff changeset
788 alloc = new llvm::AllocaInst(c->getType(), ".srcfile", gIR->topallocapoint());
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
789 gIR->func()->srcfileArg = alloc;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
790 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
791 llvm::Value* ptr = DtoGEPi(alloc, 0,0, "tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
792 DtoStore(c->getOperand(0), ptr);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
793 ptr = DtoGEPi(alloc, 0,1, "tmp");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
794 DtoStore(c->getOperand(1), ptr);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
795 args.push_back(alloc);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
796
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
797 // line param
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
798 c = DtoConstUint(loc->linnum);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
799 args.push_back(c);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
800
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
801 // call
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
802 llvm::CallInst* call = llvm::CallInst::Create(fn, args.begin(), args.end(), "", gIR->scopebb());
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
803 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
804
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
805 //////////////////////////////////////////////////////////////////////////////////////////
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
806
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
807 static const llvm::Type* get_next_frame_ptr_type(Dsymbol* sc)
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
808 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
809 assert(sc->isFuncDeclaration() || sc->isClassDeclaration());
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
810 Dsymbol* p = sc->toParent2();
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
811 if (!p->isFuncDeclaration() && !p->isClassDeclaration())
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
812 Logger::println("unexpected parent symbol found while resolving frame pointer - '%s' kind: '%s'", p->toChars(), p->kind());
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
813 assert(p->isFuncDeclaration() || p->isClassDeclaration());
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
814 if (FuncDeclaration* fd = p->isFuncDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
815 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
816 llvm::Value* v = fd->ir.irFunc->nestedVar;
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
817 assert(v);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
818 return v->getType();
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
819 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
820 else if (ClassDeclaration* cd = p->isClassDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
821 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
822 return DtoType(cd->type);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
823 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
824 else
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
825 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
826 Logger::println("symbol: '%s' kind: '%s'", sc->toChars(), sc->kind());
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
827 assert(0);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
828 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
829 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
830
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
831 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
832
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
833 static llvm::Value* get_frame_ptr_impl(FuncDeclaration* func, Dsymbol* sc, llvm::Value* v)
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
834 {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
835 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
836 if (sc == func)
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
837 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
838 return v;
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
839 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
840 else if (FuncDeclaration* fd = sc->isFuncDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
841 {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
842 Logger::println("scope is function: %s", fd->toChars());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
843
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
844 if (fd->toParent2() == func)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
845 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
846 if (!func->ir.irFunc->nestedVar)
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
847 return NULL;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
848 return DtoBitCast(v, func->ir.irFunc->nestedVar->getType());
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
849 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
850
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
851 v = DtoBitCast(v, get_next_frame_ptr_type(fd));
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
852 Logger::cout() << "v = " << *v << '\n';
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
853
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
854 if (fd->toParent2()->isFuncDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
855 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
856 v = DtoGEPi(v, 0,0, "tmp");
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
857 v = DtoLoad(v);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
858 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
859 else if (ClassDeclaration* cd = fd->toParent2()->isClassDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
860 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
861 size_t idx = 2;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
862 //idx += cd->ir.irStruct->interfaceVec.size();
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
863 v = DtoGEPi(v,0,idx,"tmp");
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
864 v = DtoLoad(v);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
865 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
866 else
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
867 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
868 assert(0);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
869 }
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
870 return get_frame_ptr_impl(func, fd->toParent2(), v);
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
871 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
872 else if (ClassDeclaration* cd = sc->isClassDeclaration())
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
873 {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
874 Logger::println("scope is class: %s", cd->toChars());
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
875 /*size_t idx = 2;
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: 135
diff changeset
876 idx += cd->llvmIrStruct->interfaces.size();
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
877 v = DtoGEPi(v,0,idx,"tmp");
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
878 Logger::cout() << "gep = " << *v << '\n';
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
879 v = DtoLoad(v);*/
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
880 return get_frame_ptr_impl(func, cd->toParent2(), v);
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
881 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
882 else
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
883 {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
884 Logger::println("symbol: '%s'", sc->toPrettyChars());
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
885 assert(0);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
886 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
887 }
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
888
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
889 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
890
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
891 static llvm::Value* get_frame_ptr(FuncDeclaration* func)
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
892 {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
893 Logger::println("Resolving context pointer for nested function: '%s'", func->toPrettyChars());
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
894 LOG_SCOPE;
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: 135
diff changeset
895 IrFunction* irfunc = gIR->func();
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
896
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
897 // in the right scope already
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
898 if (func == irfunc->decl)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
899 return irfunc->decl->ir.irFunc->nestedVar;
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
900
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
901 // use the 'this' pointer
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
902 llvm::Value* ptr = irfunc->decl->ir.irFunc->thisVar;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
903 assert(ptr);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
904
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
905 // return the fully resolved frame pointer
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
906 ptr = get_frame_ptr_impl(func, irfunc->decl, ptr);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
907 if (ptr) Logger::cout() << "Found context!" << *ptr;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
908 else Logger::cout() << "NULL context!\n";
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
909
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
910 return ptr;
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
911 }
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
912
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
913 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
914
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
915 llvm::Value* DtoNestedContext(FuncDeclaration* func)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
916 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
917 // resolve frame ptr
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
918 llvm::Value* ptr = get_frame_ptr(func);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
919 Logger::cout() << "Nested context ptr = ";
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
920 if (ptr) Logger::cout() << *ptr;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
921 else Logger::cout() << "NULL";
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
922 Logger::cout() << '\n';
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
923 return ptr;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
924 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
925
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
926 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
927
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
928 static void print_frame_worker(VarDeclaration* vd, Dsymbol* par)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
929 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
930 if (vd->toParent2() == par)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
931 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
932 Logger::println("found: '%s' kind: '%s'", par->toChars(), par->kind());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
933 return;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
934 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
935
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
936 Logger::println("diving into: '%s' kind: '%s'", par->toChars(), par->kind());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
937 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
938 print_frame_worker(vd, par->toParent2());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
939 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
940
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
941 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
942
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
943 static void print_nested_frame_list(VarDeclaration* vd, Dsymbol* par)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
944 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
945 Logger::println("Frame pointer list for nested var: '%s'", vd->toPrettyChars());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
946 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
947 if (vd->toParent2() != par)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
948 print_frame_worker(vd, par);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
949 else
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
950 Logger::println("Found at level 0");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
951 Logger::println("Done");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
952 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
953
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
954 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
955
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
956 llvm::Value* DtoNestedVariable(VarDeclaration* vd)
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
957 {
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
958 // log the frame list
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: 135
diff changeset
959 IrFunction* irfunc = gIR->func();
135
176bd52b3cf5 [svn r139] Fixed bug #33, thanks for the report :)
lindquist
parents: 133
diff changeset
960 if (Logger::enabled())
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
961 print_nested_frame_list(vd, irfunc->decl);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
962
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
963 // resolve frame ptr
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
964 FuncDeclaration* func = vd->toParent2()->isFuncDeclaration();
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
965 assert(func);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
966 llvm::Value* ptr = DtoNestedContext(func);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
967 assert(ptr && "nested var, but no context");
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
968
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
969 // we must cast here to be sure. nested classes just have a void*
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
970 ptr = DtoBitCast(ptr, func->ir.irFunc->nestedVar->getType());
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
971
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
972 // index nested var and load (if necessary)
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
973 llvm::Value* v = DtoGEPi(ptr, 0, vd->ir.irLocal->nestedIndex, "tmp");
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
974 // references must be loaded, for normal variables this IS already the variable storage!!!
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
975 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type)))
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
976 v = DtoLoad(v);
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
977
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
978 // log and return
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
979 Logger::cout() << "Nested var ptr = " << *v << '\n';
129
8096ba7082db [svn r133] Fixed some problems with inlining not happening :P
lindquist
parents: 121
diff changeset
980 return v;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
981 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
982
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
983 //////////////////////////////////////////////////////////////////////////////////////////
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
984
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
985 void DtoAssign(DValue* lhs, DValue* rhs)
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
986 {
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
987 Logger::cout() << "DtoAssign(...);\n";
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
988 LOG_SCOPE;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
989
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
990 Type* t = DtoDType(lhs->getType());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
991 Type* t2 = DtoDType(rhs->getType());
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
992
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
993 if (t->ty == Tstruct) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
994 if (t2 != t) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
995 // TODO: fix this, use 'rhs' for something
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
996 DtoStructZeroInit(lhs->getLVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
997 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
998 else if (!rhs->inPlace()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
999 DtoStructCopy(lhs->getLVal(),rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1000 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1001 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1002 else if (t->ty == Tarray) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1003 // lhs is slice
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1004 if (DSliceValue* s = lhs->isSlice()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1005 if (DSliceValue* s2 = rhs->isSlice()) {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1006 DtoArrayCopySlices(s, s2);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1007 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1008 else if (t->next == t2) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1009 if (s->len)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1010 DtoArrayInit(s->ptr, s->len, rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1011 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1012 DtoArrayInit(s->ptr, rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1013 }
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1014 else {
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1015 DtoArrayCopyToSlice(s, rhs);
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1016 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1017 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1018 // rhs is slice
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1019 else if (DSliceValue* s = rhs->isSlice()) {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1020 assert(s->getType()->toBasetype() == lhs->getType()->toBasetype());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1021 DtoSetArray(lhs->getLVal(),s->len,s->ptr);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1022 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1023 // null
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1024 else if (rhs->isNull()) {
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
1025 DtoSetArrayToNull(lhs->getLVal());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1026 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1027 // reference assignment
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1028 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1029 DtoArrayAssign(lhs->getLVal(), rhs->getRVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1030 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1031 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1032 else if (t->ty == Tsarray) {
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1033 if (DtoType(lhs->getType()) == DtoType(rhs->getType())) {
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1034 DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal());
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1035 }
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1036 else {
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1037 DtoArrayInit(lhs->getLVal(), rhs->getRVal());
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 142
diff changeset
1038 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1039 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1040 else if (t->ty == Tdelegate) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1041 if (rhs->isNull())
177
cea8dcfa76df [svn r193] Fixed: abstract classes implementing interfaces now output proper Interface info arrays. (null vtables).
lindquist
parents: 173
diff changeset
1042 DtoDelegateToNull(lhs->getLVal());
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1043 else if (!rhs->inPlace()) {
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1044 llvm::Value* l = lhs->getLVal();
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1045 llvm::Value* r = rhs->getRVal();
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1046 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1047 DtoDelegateCopy(l, r);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
1048 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1049 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1050 else if (t->ty == Tclass) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1051 assert(t2->ty == Tclass);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1052 // assignment to this in constructor special case
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1053 if (lhs->isThis()) {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1054 llvm::Value* tmp = rhs->getRVal();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1055 FuncDeclaration* fdecl = gIR->func()->decl;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1056 // respecify the this param
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1057 if (!llvm::isa<llvm::AllocaInst>(fdecl->ir.irFunc->thisVar))
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1058 fdecl->ir.irFunc->thisVar = new llvm::AllocaInst(tmp->getType(), "newthis", gIR->topallocapoint());
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1059 DtoStore(tmp, fdecl->ir.irFunc->thisVar);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1060 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1061 // regular class ref -> class ref assignment
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1062 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1063 DtoStore(rhs->getRVal(), lhs->getLVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1064 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1065 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1066 else if (t->iscomplex()) {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1067 assert(!lhs->isComplex());
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1068
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1069 llvm::Value* dst;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1070 if (DLRValue* lr = lhs->isLRValue()) {
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1071 dst = lr->getLVal();
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1072 rhs = DtoCastComplex(rhs, lr->getLType());
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1073 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1074 else {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1075 dst = lhs->getRVal();
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1076 }
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1077
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1078 if (DComplexValue* cx = rhs->isComplex())
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1079 DtoComplexSet(dst, cx->re, cx->im);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1080 else
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1081 DtoComplexAssign(dst, rhs->getRVal());
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1082 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1083 else {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1084 llvm::Value* l = lhs->getLVal();
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1085 llvm::Value* r = rhs->getRVal();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1086 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1087 const llvm::Type* lit = l->getType()->getContainedType(0);
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1088 if (r->getType() != lit) {
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1089 // handle lvalue cast assignments
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1090 if (DLRValue* lr = lhs->isLRValue()) {
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1091 Logger::println("lvalue cast!");
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1092 r = DtoCast(rhs, lr->getLType())->getRVal();
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1093 }
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1094 else {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1095 r = DtoCast(rhs, lhs->getType())->getRVal();
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1096 }
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1097 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
201
8f9191180c7a [svn r217] Updated: the rebuild profiles.
lindquist
parents: 193
diff changeset
1098 assert(r->getType() == l->getType()->getContainedType(0));
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1099 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1100 gIR->ir->CreateStore(r, l);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1101 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1102 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1103
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1104 //////////////////////////////////////////////////////////////////////////////////////////
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1105 DValue* DtoCastInt(DValue* val, Type* _to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1106 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1107 const llvm::Type* tolltype = DtoType(_to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1108
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1109 Type* to = DtoDType(_to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1110 Type* from = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1111 assert(from->isintegral());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1112
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1113 size_t fromsz = from->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1114 size_t tosz = to->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1115
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1116 llvm::Value* rval = val->getRVal();
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1117 if (rval->getType() == tolltype) {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1118 return new DImValue(_to, rval);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1119 }
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1120
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1121 if (to->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1122 if (fromsz < tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1123 Logger::cout() << "cast to: " << *tolltype << '\n';
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1124 if (from->isunsigned() || from->ty == Tbool) {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1125 rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1126 } else {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1127 rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1128 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1129 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1130 else if (fromsz > tosz) {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1131 rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1132 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1133 else {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1134 rval = new llvm::BitCastInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1135 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1136 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1137 else if (to->isfloating()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1138 if (from->isunsigned()) {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1139 rval = new llvm::UIToFPInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1140 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1141 else {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1142 rval = new llvm::SIToFPInst(rval, tolltype, "tmp", gIR->scopebb());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1143 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1144 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1145 else if (to->ty == Tpointer) {
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1146 Logger::cout() << "cast pointer: " << *tolltype << '\n';
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1147 rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp");
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1148 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1149 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1150 assert(0 && "bad int cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1151 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1152
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1153 return new DImValue(_to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1154 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1155
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1156 DValue* DtoCastPtr(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1157 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1158 const llvm::Type* tolltype = DtoType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1159
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1160 Type* totype = DtoDType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1161 Type* fromtype = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1162 assert(fromtype->ty == Tpointer);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1163
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1164 llvm::Value* rval;
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1165
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1166 if (totype->ty == Tpointer || totype->ty == Tclass) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1167 llvm::Value* src = val->getRVal();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1168 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n';
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1169 rval = new llvm::BitCastInst(src, tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1170 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1171 else if (totype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1172 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1173 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1174 else {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1175 Logger::println("invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1176 assert(0);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1177 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1178
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1179 return new DImValue(to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1180 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1181
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1182 DValue* DtoCastFloat(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1183 {
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1184 if (val->getType() == to)
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1185 return val;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1186
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1187 const llvm::Type* tolltype = DtoType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1188
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1189 Type* totype = DtoDType(to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1190 Type* fromtype = DtoDType(val->getType());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1191 assert(fromtype->isfloating());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1192
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1193 size_t fromsz = fromtype->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1194 size_t tosz = totype->size();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1195
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1196 llvm::Value* rval;
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1197
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1198 if (totype->iscomplex()) {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1199 assert(0);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1200 //return new DImValue(to, DtoComplex(to, val));
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1201 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1202 else if (totype->isfloating()) {
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1203 if ((fromtype->ty == Tfloat80 || fromtype->ty == Tfloat64) && (totype->ty == Tfloat80 || totype->ty == Tfloat64)) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1204 rval = val->getRVal();
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1205 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1206 else if (fromsz < tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1207 rval = new llvm::FPExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1208 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1209 else if (fromsz > tosz) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1210 rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1211 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1212 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1213 assert(0 && "bad float cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1214 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1215 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1216 else if (totype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1217 if (totype->isunsigned()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1218 rval = new llvm::FPToUIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1219 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1220 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1221 rval = new llvm::FPToSIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1222 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1223 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1224 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1225 assert(0 && "bad float cast");
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1226 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1227
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1228 return new DImValue(to, rval);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1229 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1230
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1231 DValue* DtoCastComplex(DValue* val, Type* _to)
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1232 {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1233 Type* to = DtoDType(_to);
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1234 Type* vty = val->getType();
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1235 if (to->iscomplex()) {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1236 if (vty->size() == to->size())
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1237 return val;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1238
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1239 llvm::Value *re, *im;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1240 DtoGetComplexParts(val, re, im);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1241 const llvm::Type* toty = DtoComplexBaseType(to);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1242
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1243 if (to->size() < vty->size()) {
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1244 re = gIR->ir->CreateFPTrunc(re, toty, "tmp");
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1245 im = gIR->ir->CreateFPTrunc(im, toty, "tmp");
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1246 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1247 else if (to->size() > vty->size()) {
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1248 re = gIR->ir->CreateFPExt(re, toty, "tmp");
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1249 im = gIR->ir->CreateFPExt(im, toty, "tmp");
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1250 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1251 else {
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1252 return val;
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1253 }
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1254
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1255 if (val->isComplex())
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1256 return new DComplexValue(_to, re, im);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1257
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1258 // unfortunately at this point, the cast value can show up as the lvalue for += and similar expressions.
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1259 // so we need to give it storage, or fix the system that handles this stuff (DLRValue)
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1260 llvm::Value* mem = new llvm::AllocaInst(DtoType(_to), "castcomplextmp", gIR->topallocapoint());
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1261 DtoComplexSet(mem, re, im);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1262 return new DLRValue(val->getType(), val->getRVal(), _to, mem);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1263 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1264 else if (to->isimaginary()) {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1265 if (val->isComplex())
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1266 return new DImValue(to, val->isComplex()->im);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1267 llvm::Value* v = val->getRVal();
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1268 DImValue* im = new DImValue(to, DtoLoad(DtoGEPi(v,0,1,"tmp")));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1269 return DtoCastFloat(im, to);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1270 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1271 else if (to->isfloating()) {
107
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1272 if (val->isComplex())
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1273 return new DImValue(to, val->isComplex()->re);
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1274 llvm::Value* v = val->getRVal();
3efbcc81ba45 [svn r111] Fixed most problems with complex number support and added typeinfo for them.
lindquist
parents: 106
diff changeset
1275 DImValue* re = new DImValue(to, DtoLoad(DtoGEPi(v,0,0,"tmp")));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1276 return DtoCastFloat(re, to);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1277 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1278 else
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1279 assert(0);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1280 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1281
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1282 DValue* DtoCast(DValue* val, Type* to)
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1283 {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1284 Type* fromtype = DtoDType(val->getType());
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1285 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1286 if (fromtype->isintegral()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1287 return DtoCastInt(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1288 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1289 else if (fromtype->iscomplex()) {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1290 return DtoCastComplex(val, to);
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1291 }
97
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1292 else if (fromtype->isfloating()) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1293 return DtoCastFloat(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1294 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1295 else if (fromtype->ty == Tclass) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1296 return DtoCastClass(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1297 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1298 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1299 return DtoCastArray(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1300 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1301 else if (fromtype->ty == Tpointer) {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1302 return DtoCastPtr(val, to);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1303 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1304 else {
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1305 assert(0);
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1306 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1307 }
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1308
c4e161556a21 [svn r101] Split up CastExp into several smaller utility functions.
lindquist
parents: 96
diff changeset
1309 //////////////////////////////////////////////////////////////////////////////////////////
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1310
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1311 llvm::ConstantInt* DtoConstSize_t(size_t i)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1312 {
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1313 return llvm::ConstantInt::get(DtoSize_t(), i, false);
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1314 }
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1315 llvm::ConstantInt* DtoConstUint(unsigned i)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1316 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1317 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, false);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1318 }
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1319 llvm::ConstantInt* DtoConstInt(int i)
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1320 {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1321 return llvm::ConstantInt::get(llvm::Type::Int32Ty, i, true);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1322 }
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1323 llvm::Constant* DtoConstBool(bool b)
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1324 {
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1325 return llvm::ConstantInt::get(llvm::Type::Int1Ty, b, false);
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1326 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1327
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1328 llvm::ConstantFP* DtoConstFP(Type* t, long double value)
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1329 {
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1330 TY ty = DtoDType(t)->ty;
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1331 if (ty == Tfloat32 || ty == Timaginary32)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1332 return llvm::ConstantFP::get(llvm::APFloat(float(value)));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1333 else if (ty == Tfloat64 || ty == Timaginary64 || ty == Tfloat80 || ty == Timaginary80)
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1334 return llvm::ConstantFP::get(llvm::APFloat(double(value)));
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1335 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1336
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1337
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1338 //////////////////////////////////////////////////////////////////////////////////////////
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1339
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1340 llvm::Constant* DtoConstString(const char* str)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1341 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1342 std::string s(str);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1343 llvm::Constant* init = llvm::ConstantArray::get(s, true);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1344 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1345 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1346 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1347 return DtoConstSlice(
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1348 DtoConstSize_t(s.length()),
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1349 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1350 );
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1351 }
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1352 llvm::Constant* DtoConstStringPtr(const char* str, const char* section)
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1353 {
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1354 std::string s(str);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1355 llvm::Constant* init = llvm::ConstantArray::get(s, true);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1356 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1357 init->getType(), true,llvm::GlobalValue::InternalLinkage, init, "stringliteral", gIR->module);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1358 if (section) gvar->setSection(section);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1359 llvm::Constant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1360 return llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
1361 }
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1362
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1363 //////////////////////////////////////////////////////////////////////////////////////////
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1364
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1365 void DtoMemSetZero(llvm::Value* dst, llvm::Value* nbytes)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1366 {
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1367 const llvm::Type* arrty = getPtrToType(llvm::Type::Int8Ty);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1368 llvm::Value *dstarr;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1369 if (dst->getType() == arrty)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1370 {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1371 dstarr = dst;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1372 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1373 else
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1374 {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1375 dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1376 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1377
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1378 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemSet64() : LLVM_DeclareMemSet32();
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1379 std::vector<llvm::Value*> llargs;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1380 llargs.resize(4);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1381 llargs[0] = dstarr;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1382 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1383 llargs[2] = nbytes;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1384 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1385
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1386 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1387 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1388
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1389 //////////////////////////////////////////////////////////////////////////////////////////
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1390
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1391 void DtoMemCpy(llvm::Value* dst, llvm::Value* src, llvm::Value* nbytes)
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1392 {
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1393 const llvm::Type* arrty = getVoidPtrType();
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1394
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1395 llvm::Value* dstarr;
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1396 if (dst->getType() == arrty)
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1397 dstarr = dst;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1398 else
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1399 dstarr = DtoBitCast(dst, arrty, "tmp");
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1400
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1401 llvm::Value* srcarr;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1402 if (src->getType() == arrty)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1403 srcarr = src;
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1404 else
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1405 srcarr = DtoBitCast(src, arrty, "tmp");
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1406
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1407 llvm::Function* fn = (global.params.is64bit) ? LLVM_DeclareMemCpy64() : LLVM_DeclareMemCpy32();
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1408 std::vector<llvm::Value*> llargs;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1409 llargs.resize(4);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1410 llargs[0] = dstarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1411 llargs[1] = srcarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1412 llargs[2] = nbytes;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1413 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1414
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1415 llvm::CallInst::Create(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1416 }
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1417
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1418 //////////////////////////////////////////////////////////////////////////////////////////
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1419
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1420 llvm::Value* DtoLoad(llvm::Value* src)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1421 {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1422 llvm::Value* ld = gIR->ir->CreateLoad(src,"tmp");
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1423 //ld->setVolatile(gIR->func()->inVolatile);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1424 return ld;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1425 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1426
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1427 void DtoStore(llvm::Value* src, llvm::Value* dst)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1428 {
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1429 llvm::Value* st = gIR->ir->CreateStore(src,dst);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1430 //st->setVolatile(gIR->func()->inVolatile);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1431 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1432
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1433 bool DtoCanLoad(llvm::Value* ptr)
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1434 {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1435 if (isaPointer(ptr->getType())) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1436 return ptr->getType()->getContainedType(0)->isFirstClassType();
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1437 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1438 return false;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1439 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1440
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1441 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1442
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1443 llvm::Value* DtoBitCast(llvm::Value* v, const llvm::Type* t, const char* name)
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1444 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1445 if (v->getType() == t)
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1446 return v;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1447 return gIR->ir->CreateBitCast(v, t, name ? name : "tmp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1448 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1449
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1450 //////////////////////////////////////////////////////////////////////////////////////////
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 103
diff changeset
1451
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1452 const llvm::PointerType* isaPointer(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1453 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1454 return llvm::dyn_cast<llvm::PointerType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1455 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1456
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1457 const llvm::PointerType* isaPointer(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1458 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1459 return llvm::dyn_cast<llvm::PointerType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1460 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1461
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1462 const llvm::ArrayType* isaArray(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1463 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1464 return llvm::dyn_cast<llvm::ArrayType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1465 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1466
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1467 const llvm::ArrayType* isaArray(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1468 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1469 return llvm::dyn_cast<llvm::ArrayType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1470 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1471
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1472 const llvm::StructType* isaStruct(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1473 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1474 return llvm::dyn_cast<llvm::StructType>(v->getType());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1475 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1476
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1477 const llvm::StructType* isaStruct(const llvm::Type* t)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1478 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1479 return llvm::dyn_cast<llvm::StructType>(t);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1480 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1481
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1482 llvm::Constant* isaConstant(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1483 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1484 return llvm::dyn_cast<llvm::Constant>(v);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1485 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1486
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1487 llvm::ConstantInt* isaConstantInt(llvm::Value* v)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1488 {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1489 return llvm::dyn_cast<llvm::ConstantInt>(v);
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1490 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1491
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1492 llvm::Argument* isaArgument(llvm::Value* v)
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1493 {
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1494 return llvm::dyn_cast<llvm::Argument>(v);
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1495 }
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
1496
106
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 104
diff changeset
1497 llvm::GlobalVariable* isaGlobalVar(llvm::Value* v)
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 104
diff changeset
1498 {
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 104
diff changeset
1499 return llvm::dyn_cast<llvm::GlobalVariable>(v);
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 104
diff changeset
1500 }
5b5194b25f33 [svn r110] Fixed typeinfo for classes.
lindquist
parents: 104
diff changeset
1501
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1502 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1503
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1504 const llvm::PointerType* getPtrToType(const llvm::Type* t)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1505 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1506 return llvm::PointerType::get(t, 0);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1507 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1508
193
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 189
diff changeset
1509 const llvm::PointerType* getVoidPtrType()
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 189
diff changeset
1510 {
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 189
diff changeset
1511 return getPtrToType(llvm::Type::Int8Ty);
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 189
diff changeset
1512 }
aca17e55b7a5 [svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents: 189
diff changeset
1513
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1514 llvm::ConstantPointerNull* getNullPtr(const llvm::Type* t)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1515 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1516 const llvm::PointerType* pt = llvm::cast<llvm::PointerType>(t);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1517 return llvm::ConstantPointerNull::get(pt);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1518 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1519
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1520 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1521
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1522 size_t getTypeBitSize(const llvm::Type* t)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1523 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1524 return gTargetData->getTypeSizeInBits(t);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1525 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1526
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1527 size_t getTypeStoreSize(const llvm::Type* t)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1528 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1529 return gTargetData->getTypeStoreSize(t);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1530 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1531
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1532 size_t getABITypeSize(const llvm::Type* t)
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1533 {
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1534 return gTargetData->getABITypeSize(t);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1535 }
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1536
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1537 //////////////////////////////////////////////////////////////////////////////////////////
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1538
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1539 bool DtoIsTemplateInstance(Dsymbol* s)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1540 {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1541 if (!s) return false;
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1542 if (s->isTemplateInstance() && !s->isTemplateMixin())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1543 return true;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1544 else if (s->parent)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1545 return DtoIsTemplateInstance(s->parent);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1546 return false;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1547 }
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1548
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1549 //////////////////////////////////////////////////////////////////////////////////////////
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1550
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1551 void DtoLazyStaticInit(bool istempl, llvm::Value* gvar, Initializer* init, Type* t)
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1552 {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1553 // create a flag to make sure initialization only happens once
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1554 llvm::GlobalValue::LinkageTypes gflaglink = istempl ? llvm::GlobalValue::WeakLinkage : llvm::GlobalValue::InternalLinkage;
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1555 std::string gflagname(gvar->getName());
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1556 gflagname.append("__initflag");
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1557 llvm::GlobalVariable* gflag = new llvm::GlobalVariable(llvm::Type::Int1Ty,false,gflaglink,DtoConstBool(false),gflagname,gIR->module);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1558
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1559 // check flag and do init if not already done
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1560 llvm::BasicBlock* oldend = gIR->scopeend();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1561 llvm::BasicBlock* initbb = llvm::BasicBlock::Create("ifnotinit",gIR->topfunc(),oldend);
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1562 llvm::BasicBlock* endinitbb = llvm::BasicBlock::Create("ifnotinitend",gIR->topfunc(),oldend);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1563 llvm::Value* cond = gIR->ir->CreateICmpEQ(gIR->ir->CreateLoad(gflag,"tmp"),DtoConstBool(false));
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1564 gIR->ir->CreateCondBr(cond, initbb, endinitbb);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1565 gIR->scope() = IRScope(initbb,endinitbb);
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 93
diff changeset
1566 DValue* ie = DtoInitializer(init);
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1567 if (!ie->inPlace()) {
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1568 DValue* dst = new DVarValue(t, gvar, true);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1569 DtoAssign(dst, ie);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1570 }
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1571 gIR->ir->CreateStore(DtoConstBool(true), gflag);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1572 gIR->ir->CreateBr(endinitbb);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1573 gIR->scope() = IRScope(endinitbb,oldend);
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
1574 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1575
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1576 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1577
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
1578 void DtoResolveDsymbol(Dsymbol* dsym)
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1579 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1580 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
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
1581 DtoResolveStruct(sd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1582 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1583 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
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
1584 DtoResolveClass(cd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1585 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1586 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
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
1587 DtoResolveFunction(fd);
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
1588 }
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
1589 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
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
1590 DtoResolveTypeInfo(fd);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1591 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1592 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1593 error(dsym->loc, "unsupported dsymbol: %s", dsym->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
1594 assert(0 && "unsupported dsymbol for DtoResolveDsymbol");
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
1595 }
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
1596 }
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
1597
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
1598 //////////////////////////////////////////////////////////////////////////////////////////
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
1599
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
1600 void DtoDeclareDsymbol(Dsymbol* dsym)
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
1601 {
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
1602 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
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
1603 DtoDeclareStruct(sd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1604 }
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
1605 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
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
1606 DtoDeclareClass(cd);
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
1607 }
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
1608 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
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
1609 DtoDeclareFunction(fd);
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
1610 }
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
1611 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
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
1612 DtoDeclareTypeInfo(fd);
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
1613 }
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
1614 else {
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
1615 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
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
1616 assert(0 && "unsupported dsymbol for DtoDeclareDsymbol");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1617 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1618 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1619
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1620 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1621
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1622 void DtoConstInitDsymbol(Dsymbol* dsym)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1623 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1624 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1625 DtoConstInitStruct(sd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1626 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1627 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1628 DtoConstInitClass(cd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1629 }
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
1630 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
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
1631 DtoConstInitTypeInfo(fd);
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
1632 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1633 else if (VarDeclaration* vd = dsym->isVarDeclaration()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1634 DtoConstInitGlobal(vd);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1635 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1636 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1637 error(dsym->loc, "unsupported dsymbol: %s", dsym->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
1638 assert(0 && "unsupported dsymbol for DtoConstInitDsymbol");
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
1639 }
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
1640 }
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
1641
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
1642 //////////////////////////////////////////////////////////////////////////////////////////
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
1643
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
1644 void DtoDefineDsymbol(Dsymbol* dsym)
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
1645 {
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
1646 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
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
1647 DtoDefineStruct(sd);
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 100
diff changeset
1648 }
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
1649 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
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
1650 DtoDefineClass(cd);
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
1651 }
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
1652 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
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
1653 DtoDefineFunc(fd);
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
1654 }
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
1655 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
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
1656 DtoDefineTypeInfo(fd);
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
1657 }
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
1658 else {
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
1659 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
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
1660 assert(0 && "unsupported dsymbol for DtoDefineDsymbol");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1661 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1662 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1663
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1664 //////////////////////////////////////////////////////////////////////////////////////////
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1665
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1666 void DtoConstInitGlobal(VarDeclaration* vd)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1667 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1668 if (vd->ir.initialized) return;
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1669 vd->ir.initialized = gIR->dmodule;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1670
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
1671 Logger::println("* DtoConstInitGlobal(%s)", vd->toChars());
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
1672 LOG_SCOPE;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1673
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1674 bool emitRTstaticInit = false;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1675
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1676 llvm::Constant* _init = 0;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1677 if (vd->parent && vd->parent->isFuncDeclaration() && vd->init && vd->init->isExpInitializer()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1678 _init = DtoConstInitializer(vd->type, NULL);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1679 emitRTstaticInit = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1680 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1681 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1682 _init = DtoConstInitializer(vd->type, vd->init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1683 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1684
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1685 const llvm::Type* _type = DtoType(vd->type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1686 Type* t = DtoDType(vd->type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1687
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1688 //Logger::cout() << "initializer: " << *_init << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1689 if (_type != _init->getType()) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1690 Logger::cout() << "got type '" << *_init->getType() << "' expected '" << *_type << "'\n";
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1691 // zero initalizer
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1692 if (_init->isNullValue())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1693 _init = llvm::Constant::getNullValue(_type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1694 // pointer to global constant (struct.init)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1695 else if (llvm::isa<llvm::GlobalVariable>(_init))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1696 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1697 assert(_init->getType()->getContainedType(0) == _type);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1698 llvm::GlobalVariable* gv = llvm::cast<llvm::GlobalVariable>(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1699 assert(t->ty == Tstruct);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1700 TypeStruct* ts = (TypeStruct*)t;
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1701 assert(ts->sym->ir.irStruct->constInit);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1702 _init = ts->sym->ir.irStruct->constInit;
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1703 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1704 // array single value init
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1705 else if (isaArray(_type))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1706 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1707 _init = DtoConstStaticArray(_type, _init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1708 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1709 else {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1710 Logger::cout() << "Unexpected initializer type: " << *_type << '\n';
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1711 //assert(0);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1712 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1713 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1714
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1715 bool istempl = false;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1716 if ((vd->storage_class & STCcomdat) || (vd->parent && DtoIsTemplateInstance(vd->parent))) {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1717 istempl = true;
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1718 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1719
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1720 if (_init && _init->getType() != _type)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1721 _type = _init->getType();
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1722 llvm::cast<llvm::OpaqueType>(vd->ir.irGlobal->type.get())->refineAbstractTypeTo(_type);
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1723 _type = vd->ir.irGlobal->type.get();
160
b77664331d06 [svn r176] Fixed a bug with class constructors.
lindquist
parents: 157
diff changeset
1724 //_type->dump();
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1725 assert(!_type->isAbstract());
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1726
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1727 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(vd->ir.irGlobal->value);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1728 if (!(vd->storage_class & STCextern) && (vd->getModule() == gIR->dmodule || istempl))
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1729 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1730 gvar->setInitializer(_init);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1731 }
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1732
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1733 if (emitRTstaticInit)
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1734 DtoLazyStaticInit(istempl, gvar, vd->init, t);
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
1735 }
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
1736
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
1737 //////////////////////////////////////////////////////////////////////////////////////////
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
1738
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
1739 void DtoEmptyResolveList()
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
1740 {
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
1741 //Logger::println("DtoEmptyResolveList()");
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
1742 Dsymbol* dsym;
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
1743 while (!gIR->resolveList.empty()) {
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
1744 dsym = gIR->resolveList.front();
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
1745 gIR->resolveList.pop_front();
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
1746 DtoResolveDsymbol(dsym);
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
1747 }
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
1748 }
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
1749
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
1750 //////////////////////////////////////////////////////////////////////////////////////////
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
1751
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
1752 void DtoEmptyDeclareList()
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
1753 {
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
1754 //Logger::println("DtoEmptyDeclareList()");
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
1755 Dsymbol* dsym;
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
1756 while (!gIR->declareList.empty()) {
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
1757 dsym = gIR->declareList.front();
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
1758 gIR->declareList.pop_front();
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
1759 DtoDeclareDsymbol(dsym);
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
1760 }
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
1761 }
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
1762
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
1763 //////////////////////////////////////////////////////////////////////////////////////////
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
1764
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
1765 void DtoEmptyConstInitList()
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
1766 {
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
1767 //Logger::println("DtoEmptyConstInitList()");
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
1768 Dsymbol* dsym;
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
1769 while (!gIR->constInitList.empty()) {
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
1770 dsym = gIR->constInitList.front();
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
1771 gIR->constInitList.pop_front();
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
1772 DtoConstInitDsymbol(dsym);
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
1773 }
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
1774 }
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
1775
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
1776 //////////////////////////////////////////////////////////////////////////////////////////
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
1777
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
1778 void DtoEmptyDefineList()
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
1779 {
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
1780 //Logger::println("DtoEmptyDefineList()");
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
1781 Dsymbol* dsym;
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
1782 while (!gIR->defineList.empty()) {
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
1783 dsym = gIR->defineList.front();
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
1784 gIR->defineList.pop_front();
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
1785 DtoDefineDsymbol(dsym);
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
1786 }
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
1787 }
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
1788
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
1789 //////////////////////////////////////////////////////////////////////////////////////////
116
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1790 void DtoEmptyAllLists()
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1791 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1792 for(;;)
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1793 {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1794 Dsymbol* dsym;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1795 if (!gIR->resolveList.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1796 dsym = gIR->resolveList.front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1797 gIR->resolveList.pop_front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1798 DtoResolveDsymbol(dsym);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1799 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1800 else if (!gIR->declareList.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1801 dsym = gIR->declareList.front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1802 gIR->declareList.pop_front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1803 DtoDeclareDsymbol(dsym);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1804 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1805 else if (!gIR->constInitList.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1806 dsym = gIR->constInitList.front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1807 gIR->constInitList.pop_front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1808 DtoConstInitDsymbol(dsym);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1809 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1810 else if (!gIR->defineList.empty()) {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1811 dsym = gIR->defineList.front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1812 gIR->defineList.pop_front();
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1813 DtoDefineDsymbol(dsym);
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1814 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1815 else {
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1816 break;
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1817 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1818 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1819 }
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1820
fd7ad91fd713 [svn r120] ModuleInfo implementation is now almost complete.
lindquist
parents: 114
diff changeset
1821 //////////////////////////////////////////////////////////////////////////////////////////
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
1822
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
1823 void DtoForceDeclareDsymbol(Dsymbol* dsym)
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
1824 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1825 if (dsym->ir.declared) return;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1826 Logger::println("DtoForceDeclareDsymbol(%s)", dsym->toPrettyChars());
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
1827 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
1828 DtoResolveDsymbol(dsym);
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
1829
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
1830 DtoEmptyResolveList();
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
1831
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
1832 DtoDeclareDsymbol(dsym);
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
1833 }
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
1834
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
1835 //////////////////////////////////////////////////////////////////////////////////////////
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
1836
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
1837 void DtoForceConstInitDsymbol(Dsymbol* dsym)
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
1838 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1839 if (dsym->ir.initialized) return;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1840 Logger::println("DtoForceConstInitDsymbol(%s)", dsym->toPrettyChars());
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
1841 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
1842 DtoResolveDsymbol(dsym);
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
1843
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
1844 DtoEmptyResolveList();
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
1845 DtoEmptyDeclareList();
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
1846
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
1847 DtoConstInitDsymbol(dsym);
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
1848 }
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
1849
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
1850 //////////////////////////////////////////////////////////////////////////////////////////
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
1851
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
1852 void DtoForceDefineDsymbol(Dsymbol* dsym)
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
1853 {
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1854 if (dsym->ir.defined) return;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1855 Logger::println("DtoForceDefineDsymbol(%s)", dsym->toPrettyChars());
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
1856 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
1857 DtoResolveDsymbol(dsym);
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
1858
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
1859 DtoEmptyResolveList();
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
1860 DtoEmptyDeclareList();
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
1861 DtoEmptyConstInitList();
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
1862
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
1863 DtoDefineDsymbol(dsym);
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
1864 }
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1865
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1866 //////////////////////////////////////////////////////////////////////////////////////////
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1867
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1868 void DtoAnnotation(const char* str)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1869 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1870 std::string s("CODE: ");
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1871 s.append(str);
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1872 char* p = &s[0];
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1873 while (*p)
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1874 {
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1875 if (*p == '"')
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1876 *p = '\'';
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1877 ++p;
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1878 }
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1879 // create a noop with the code as the result name!
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1880 gIR->ir->CreateAnd(DtoConstSize_t(0),DtoConstSize_t(0),s.c_str());
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
1881 }
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: 135
diff changeset
1882
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1883 //////////////////////////////////////////////////////////////////////////////////////////
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1884
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: 135
diff changeset
1885 const llvm::StructType* DtoInterfaceInfoType()
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: 135
diff changeset
1886 {
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 160
diff changeset
1887 if (gIR->interfaceInfoType)
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 160
diff changeset
1888 return gIR->interfaceInfoType;
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: 135
diff changeset
1889
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: 135
diff changeset
1890 // build interface info type
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: 135
diff changeset
1891 std::vector<const llvm::Type*> types;
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: 135
diff changeset
1892 // ClassInfo classinfo
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: 135
diff changeset
1893 ClassDeclaration* cd2 = ClassDeclaration::classinfo;
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: 135
diff changeset
1894 DtoResolveClass(cd2);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 163
diff changeset
1895 types.push_back(getPtrToType(cd2->type->ir.type->get()));
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: 135
diff changeset
1896 // void*[] vtbl
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: 135
diff changeset
1897 std::vector<const llvm::Type*> vtbltypes;
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: 135
diff changeset
1898 vtbltypes.push_back(DtoSize_t());
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: 135
diff changeset
1899 const llvm::Type* byteptrptrty = getPtrToType(getPtrToType(llvm::Type::Int8Ty));
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: 135
diff changeset
1900 vtbltypes.push_back(byteptrptrty);
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: 135
diff changeset
1901 types.push_back(llvm::StructType::get(vtbltypes));
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: 135
diff changeset
1902 // int offset
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: 135
diff changeset
1903 types.push_back(llvm::Type::Int32Ty);
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: 135
diff changeset
1904 // create type
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 160
diff changeset
1905 gIR->interfaceInfoType = llvm::StructType::get(types);
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: 135
diff changeset
1906
161
3a891cfcd249 [svn r177] moved variable for interface info type from being local static to being within IRState
ChristianK
parents: 160
diff changeset
1907 return gIR->interfaceInfoType;
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: 135
diff changeset
1908 }
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1909
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1910 //////////////////////////////////////////////////////////////////////////////////////////
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1911
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1912 llvm::Constant* DtoTypeInfoOf(Type* type)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1913 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1914 const llvm::Type* typeinfotype = DtoType(Type::typeinfo->type);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1915 TypeInfoDeclaration* tidecl = type->getTypeInfoDeclaration();
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1916 DtoForceDeclareDsymbol(tidecl);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1917 assert(tidecl->ir.irGlobal != NULL);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1918 llvm::Constant* c = isaConstant(tidecl->ir.irGlobal->value);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1919 assert(c != NULL);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1920 return llvm::ConstantExpr::getBitCast(c, typeinfotype);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1921 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1922
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1923
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1924
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1925
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1926
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1927
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1928
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1929
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1930
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1931
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1932
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1933