annotate gen/tollvm.c @ 85:f869c636a113 trunk

[svn r89] Fixed a bunch of problems with template instance across multiple modules. Fixed initialization of function local static variables, with a non const initializer (now happens on first call using a global to make sure it only happens once.)
author lindquist
date Fri, 02 Nov 2007 06:32:32 +0100
parents 339422268de1
children
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 "mtype.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
6 #include "dsymbol.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 #include "aggregate.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8 #include "declaration.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
9 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
11 #include "gen/tollvm.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
12 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
13 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
14 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
15 #include "gen/elem.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
16 #include "gen/arrays.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17
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
18 bool DtoIsPassedByRef(Type* type)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
19 {
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
20 TY t = DtoDType(type)->ty;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
21 return (t == Tstruct || t == Tarray || t == Tdelegate);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
22 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
23
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
24 Type* DtoDType(Type* t)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
25 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
26 if (t->ty == Ttypedef) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
27 Type* bt = t->toBasetype();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
28 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
29 return DtoDType(bt);
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 return t;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
32 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
33
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 const llvm::Type* DtoType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 assert(t);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 switch (t->ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
38 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
39 // integers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
40 case Tint8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
41 case Tuns8:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
42 case Tchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
43 return (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
44 case Tint16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
45 case Tuns16:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46 case Twchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
47 return (const llvm::Type*)llvm::Type::Int16Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 case Tint32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
49 case Tuns32:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 case Tdchar:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51 return (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
52 case Tint64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
53 case Tuns64:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
54 return (const llvm::Type*)llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
55
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
56 case Tbool:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
57 return (const llvm::Type*)llvm::ConstantInt::getTrue()->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
58
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
59 // floats
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
60 case Tfloat32:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
61 case Timaginary32:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
62 return llvm::Type::FloatTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
63 case Tfloat64:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
64 case Timaginary64:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 case Tfloat80:
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
66 case Timaginary80:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67 return llvm::Type::DoubleTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68
62
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
69 // complex
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
70 case Tcomplex32:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
71 case Tcomplex64:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
72 case Tcomplex80:
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
73 assert(0 && "complex number types not yet implemented");
b86e00b938a5 [svn r66] Added support for imaginary floating point types
lindquist
parents: 58
diff changeset
74
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
75 // pointers
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
76 case Tpointer: {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
77 assert(t->next);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
78 if (t->next->ty == Tvoid)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
79 return (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 else
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
81 return (const llvm::Type*)llvm::PointerType::get(DtoType(t->next));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
82 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
83
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
84 // arrays
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
85 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
86 return DtoArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
87 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
88 return DtoStaticArrayType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
89
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
90 // void
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
91 case Tvoid:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92 return llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
93
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
94 // aggregates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
95 case Tstruct: {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
96 if (t->llvmType == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
97 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
98 // recursive or cyclic declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
99 if (!gIR->structs.empty())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
100 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
101 IRStruct* found = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
102 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
103 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
104 if (t == i->type)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
105 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
106 return i->recty.get();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
107 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
108 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
109 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
110
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
111 // forward declaration
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
112 TypeStruct* ts = (TypeStruct*)t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
113 assert(ts->sym);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
114 ts->sym->toObjFile();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
115 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
116 return t->llvmType;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
117 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
118
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
119 case Tclass: {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
120 if (t->llvmType == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
121 {
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
122 // recursive or cyclic declaration
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
123 if (!gIR->structs.empty())
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
124 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
125 IRStruct* found = 0;
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
126 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
127 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
128 if (t == i->type)
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
129 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
130 return llvm::PointerType::get(i->recty.get());
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
131 }
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
132 }
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 // forward declaration
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
136 TypeClass* tc = (TypeClass*)t;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
137 assert(tc->sym);
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
138 tc->sym->toObjFile();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
139 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
140 return llvm::PointerType::get(t->llvmType);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
141 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
142
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
143 // functions
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
144 case Tfunction:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
145 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
146 if (t->llvmType == 0) {
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
147 return DtoFunctionType(t,NULL);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
148 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
149 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
150 return t->llvmType;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
153
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 // delegates
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
155 case Tdelegate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
156 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
157 if (t->llvmType == 0) {
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
158 return DtoDelegateType(t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
159 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
160 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
161 return t->llvmType;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
162 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
163 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
164
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
165 // typedefs
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
166 // enum
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
167 case Ttypedef:
52
0c77619e803b [svn r56] Initial support for TypeInfo.
lindquist
parents: 51
diff changeset
168 case Tenum:
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
169 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
170 Type* bt = t->toBasetype();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 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
172 return DtoType(bt);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
173 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
174
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
175 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
176 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
177 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
178 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
179 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
180 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
181
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
182 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
183
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
184 const llvm::FunctionType* DtoFunctionType(Type* type, const llvm::Type* thistype, bool ismain)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
185 {
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
186 TypeFunction* f = (TypeFunction*)type;
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
187 assert(f != 0);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
188
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
189 bool typesafeVararg = false;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
190 if (f->linkage == LINKd && f->varargs == 1) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
191 typesafeVararg = true;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
192 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
193
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
194 // return value type
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
195 const llvm::Type* rettype;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
196 const llvm::Type* actualRettype;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
197 Type* rt = f->next;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
198 bool retinptr = false;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
199 bool usesthis = false;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
200
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
201 if (ismain) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
202 rettype = llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
203 actualRettype = rettype;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
204 }
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
205 else {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
206 assert(rt);
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
207 if (DtoIsPassedByRef(rt)) {
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
208 rettype = llvm::PointerType::get(DtoType(rt));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
209 actualRettype = llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
210 f->llvmRetInPtr = retinptr = true;
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 else {
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
213 rettype = DtoType(rt);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
214 actualRettype = rettype;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
216 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218 // parameter types
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
219 std::vector<const llvm::Type*> paramvec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
220
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
221 if (retinptr) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
222 Logger::cout() << "returning through pointer parameter: " << *rettype << '\n';
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
223 paramvec.push_back(rettype);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
224 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
225
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
226 if (thistype) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
227 paramvec.push_back(thistype);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
228 usesthis = true;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
229 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
230
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
231 if (typesafeVararg) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
232 ClassDeclaration* ti = Type::typeinfo;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
233 if (!ti->llvmInitZ)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
234 ti->toObjFile();
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
235 assert(ti->llvmInitZ);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
236 std::vector<const llvm::Type*> types;
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
237 types.push_back(DtoSize_t());
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
238 types.push_back(llvm::PointerType::get(llvm::PointerType::get(ti->llvmInitZ->getType())));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
239 const llvm::Type* t1 = llvm::StructType::get(types);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
240 paramvec.push_back(llvm::PointerType::get(t1));
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
241 paramvec.push_back(llvm::PointerType::get(llvm::Type::Int8Ty));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
242 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
243
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
244 size_t n = Argument::dim(f->parameters);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
245
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
246 for (int i=0; i < n; ++i) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
247 Argument* arg = Argument::getNth(f->parameters, i);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
248 // ensure scalar
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
249 Type* argT = DtoDType(arg->type);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
250 assert(argT);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
251
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
252 if ((arg->storageClass & STCref) || (arg->storageClass & STCout)) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
253 //assert(arg->vardecl);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
254 //arg->vardecl->refparam = true;
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
255 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
256 else
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
257 arg->llvmCopy = true;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
258
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
259 const llvm::Type* at = DtoType(argT);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
260 if (llvm::isa<llvm::StructType>(at)) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
261 Logger::println("struct param");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
262 paramvec.push_back(llvm::PointerType::get(at));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
263 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
264 else if (llvm::isa<llvm::ArrayType>(at)) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
265 Logger::println("sarray param");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
266 assert(argT->ty == Tsarray);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
267 //paramvec.push_back(llvm::PointerType::get(at->getContainedType(0)));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
268 paramvec.push_back(llvm::PointerType::get(at));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
269 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
270 else if (llvm::isa<llvm::OpaqueType>(at)) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
271 Logger::println("opaque param");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
272 if (argT->ty == Tstruct || argT->ty == Tclass)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
273 paramvec.push_back(llvm::PointerType::get(at));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
274 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
275 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
276 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
277 /*if (llvm::isa<llvm::StructType>(at) || argT->ty == Tstruct || argT->ty == Tsarray) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
278 paramvec.push_back(llvm::PointerType::get(at));
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
279 }*/
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
280 else {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
281 if (!arg->llvmCopy) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
282 Logger::println("ref param");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
283 at = llvm::PointerType::get(at);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
284 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
285 else {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
286 Logger::println("in param");
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
287 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
288 paramvec.push_back(at);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
289 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
290 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
291
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
292 // construct function type
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
293 bool isvararg = !typesafeVararg && f->varargs;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
294 llvm::FunctionType* functype = llvm::FunctionType::get(actualRettype, paramvec, isvararg);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
295
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
296 f->llvmRetInPtr = retinptr;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
297 f->llvmUsesThis = usesthis;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
298 return functype;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
299 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
300
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
301 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
302
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
303 static const llvm::FunctionType* DtoVaFunctionType(FuncDeclaration* fdecl)
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
304 {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
305 TypeFunction* f = (TypeFunction*)fdecl->type;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
306 assert(f != 0);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
307
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
308 const llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
309 std::vector<const llvm::Type*> args;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
310
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
311 if (fdecl->llvmInternal == LLVMva_start) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
312 args.push_back(i8pty);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
313 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
314 else if (fdecl->llvmInternal == LLVMva_intrinsic) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
315 size_t n = Argument::dim(f->parameters);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
316 for (size_t i=0; i<n; ++i) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
317 args.push_back(i8pty);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
318 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
319 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
320 else
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
321 assert(0);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
322
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
323 const llvm::FunctionType* fty = llvm::FunctionType::get(llvm::Type::VoidTy, args, false);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
324 f->llvmType = fty;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
325 return fty;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
326 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
327
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
328 //////////////////////////////////////////////////////////////////////////////////////////
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
329
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
330 const llvm::FunctionType* DtoFunctionType(FuncDeclaration* fdecl)
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
331 {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
332 if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) {
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 return DtoVaFunctionType(fdecl);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
334 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
335
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
336 // type has already been resolved
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
337 if (fdecl->type->llvmType != 0) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
338 return llvm::cast<llvm::FunctionType>(fdecl->type->llvmType);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
339 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
340
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
341 const llvm::Type* thisty = NULL;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
342 if (fdecl->needThis()) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
343 if (AggregateDeclaration* ad = fdecl->isMember()) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
344 Logger::print("isMember = this is: %s\n", ad->type->toChars());
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
345 thisty = DtoType(ad->type);
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
346 Logger::cout() << "this llvm type: " << *thisty << '\n';
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
347 if (llvm::isa<llvm::StructType>(thisty) || thisty == gIR->topstruct().recty.get())
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
348 thisty = llvm::PointerType::get(thisty);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
349 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
350 else
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
351 assert(0);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
352 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
353 else if (fdecl->isNested()) {
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
354 thisty = llvm::PointerType::get(llvm::Type::Int8Ty);
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
355 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
356
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
357 const llvm::FunctionType* functype = DtoFunctionType(fdecl->type, thisty, fdecl->isMain());
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
358 fdecl->type->llvmType = functype;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
359 return functype;
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
360 }
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
361
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
362 //////////////////////////////////////////////////////////////////////////////////////////
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 69
diff changeset
363
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
364 const llvm::StructType* DtoDelegateType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
365 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
366 const llvm::Type* i8ptr = llvm::PointerType::get(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
367 const llvm::Type* func = DtoFunctionType(t->next, i8ptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
368 const llvm::Type* funcptr = llvm::PointerType::get(func);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
369
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
370 std::vector<const llvm::Type*> types;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
371 types.push_back(i8ptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
372 types.push_back(funcptr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
373 return llvm::StructType::get(types);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
374 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
375
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
376 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
377
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
378 const llvm::Type* DtoStructType(Type* t)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
379 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
380 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
381 std::vector<const llvm::Type*> types;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
382 return llvm::StructType::get(types);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
383 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
384
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
385
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 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
389 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
390 assert(bits == 32 || bits == 64);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
391 const llvm::Type* int8ty = (const llvm::Type*)llvm::Type::Int8Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
392 const llvm::Type* int32ty = (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
393 const llvm::Type* int64ty = (const llvm::Type*)llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
394 const llvm::Type* int8ptrty = (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
395 const llvm::Type* voidty = (const llvm::Type*)llvm::Type::VoidTy;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
396
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
397 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
398 assert(gIR->module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
399
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
400 // parameter types
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
401 std::vector<const llvm::Type*> pvec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
402 pvec.push_back(int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
403 pvec.push_back(set?int8ty:int8ptrty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
404 pvec.push_back(bits==32?int32ty:int64ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
405 pvec.push_back(int32ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
406 llvm::FunctionType* functype = llvm::FunctionType::get(voidty, pvec, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
407 return new llvm::Function(functype, llvm::GlobalValue::ExternalLinkage, name, gIR->module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
408 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
409
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
410 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
411
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
412 // llvm.memset.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
413 llvm::Function* LLVM_DeclareMemSet32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
414 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
415 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
416 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
417 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i32", 32, true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
418 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
419 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
420 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
421
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
422 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
423
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
424 llvm::Function* LLVM_DeclareMemSet64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
425 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
426 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
427 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
428 _func = LLVM_DeclareMemIntrinsic("llvm.memset.i64", 64, true);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
429 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
430 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
431 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
432
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
433 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
434
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
435 // llvm.memcpy.i32
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
436 llvm::Function* LLVM_DeclareMemCpy32()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
437 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
438 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
439 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
440 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i32", 32);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
441 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
442 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
443 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
444
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
445 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
446
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
447 // llvm.memcpy.i64
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
448 llvm::Function* LLVM_DeclareMemCpy64()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
449 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
450 static llvm::Function* _func = 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
451 if (_func == 0) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
452 _func = LLVM_DeclareMemIntrinsic("llvm.memcpy.i64", 64);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
453 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
454 return _func;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
455 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
456
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
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
459 llvm::Value* DtoStructZeroInit(llvm::Value* v)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
460 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
461 assert(gIR);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
462 uint64_t n = gTargetData->getTypeSize(v->getType()->getContainedType(0));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
463 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
464 llvm::Type* sarrty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
465
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
466 llvm::Value* sarr = new llvm::BitCastInst(v,sarrty,"tmp",gIR->scopebb());
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 llvm::Function* fn = LLVM_DeclareMemSet32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
469 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
470 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
471 llargs[0] = sarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
472 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
473 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
474 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
475
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
476 llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
477
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
478 return ret;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
479 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
480
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
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
483 llvm::Value* DtoStructCopy(llvm::Value* dst, llvm::Value* src)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
484 {
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
485 Logger::cout() << "dst = " << *dst << " src = " << *src << '\n';
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
486 assert(dst->getType() == src->getType());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
487 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
488
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
489 uint64_t n = gTargetData->getTypeSize(dst->getType()->getContainedType(0));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
490 //llvm::Type* sarrty = llvm::PointerType::get(llvm::ArrayType::get(llvm::Type::Int8Ty, n));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
491 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
492
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
493 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
494 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
495
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
496 llvm::Function* fn = LLVM_DeclareMemCpy32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
497 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
498 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
499 llargs[0] = dstarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
500 llargs[1] = srcarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
501 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
502 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
503
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
504 return new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
505 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
506
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
507 //////////////////////////////////////////////////////////////////////////////////////////
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
508 llvm::Constant* DtoConstStructInitializer(StructInitializer* si)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
509 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
510 llvm::StructType* structtype = llvm::cast<llvm::StructType>(si->ad->llvmType);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
511 size_t n = structtype->getNumElements();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
512
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
513 assert(si->value.dim == si->vars.dim);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
514
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
515 std::vector<llvm::Constant*> inits;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
516 inits.resize(n, NULL);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
517 for (int i = 0; i < si->value.dim; ++i)
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 Initializer* ini = (Initializer*)si->value.data[i];
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
520 assert(ini);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
521
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
522 VarDeclaration* vd = (VarDeclaration*)si->vars.data[i];
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
523 Type* vdtype = DtoDType(vd->type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
524 assert(vd);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
525 Logger::println("vars[%d] = %s", i, vd->toChars());
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
526
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
527 llvm::Constant* v = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
528
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
529 assert(vd->llvmFieldIndex >= 0);
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
530 unsigned idx = vd->llvmFieldIndex;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
531
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
532 if (ExpInitializer* ex = ini->isExpInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
533 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
534 v = ex->exp->toConstElem(gIR);
1
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 else if (StructInitializer* si = ini->isStructInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
537 {
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
538 v = DtoConstStructInitializer(si);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
539 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
540 else if (ArrayInitializer* ai = ini->isArrayInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
541 {
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
542 v = DtoConstArrayInitializer(ai);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
543 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
544 else if (ini->isVoidInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
545 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 v = llvm::UndefValue::get(structtype->getElementType(idx));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
547 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
548 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
549 assert(v);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
550
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
551 inits[idx] = v;
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
552 Logger::cout() << "init[" << idx << "] = " << *v << '\n';
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
553 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
554
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
555 // fill out nulls
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
556 assert(si->ad->llvmInitZ);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
557 if (si->ad->llvmInitZ->isNullValue())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
558 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
559 for (int i = 0; i < n; ++i)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
560 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
561 if (inits[i] == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
562 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
563 inits[i] = llvm::Constant::getNullValue(structtype->getElementType(i));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
564 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
565 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
566 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
567 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
568 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
569 for (int i = 0; i < n; ++i)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
570 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
571 if (inits[i] == 0)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
572 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
573 inits[i] = si->ad->llvmInitZ->getOperand(i);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
574 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
575 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
576 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
577
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
578 return llvm::ConstantStruct::get(structtype, inits);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
579 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
580
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
581
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
582
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
583 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
584
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
585 llvm::Value* DtoNullDelegate(llvm::Value* v)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
586 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
587 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
588 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
589
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
590 llvm::Type* i8p_ty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
591
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
592 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
593
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
594 llvm::Function* fn = LLVM_DeclareMemSet32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
595 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
596 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
597 llargs[0] = arr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
598 llargs[1] = llvm::ConstantInt::get(llvm::Type::Int8Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
599 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
600 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
601
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
602 llvm::Value* ret = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
603
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
604 return ret;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
605 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
606
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
607 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
608
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
609 llvm::Value* DtoDelegateCopy(llvm::Value* dst, llvm::Value* src)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
610 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
611 assert(dst->getType() == src->getType());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
612 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
613
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
614 d_uns64 n = (global.params.is64bit) ? 16 : 8;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
615
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
616 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
617
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
618 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
619 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
620
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
621 llvm::Function* fn = LLVM_DeclareMemCpy32();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
622 std::vector<llvm::Value*> llargs;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
623 llargs.resize(4);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
624 llargs[0] = dstarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
625 llargs[1] = srcarr;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
626 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
627 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
628
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
629 return new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
630 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
631
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
632 //////////////////////////////////////////////////////////////////////////////////////////
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
633
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
634 llvm::Value* DtoCompareDelegate(TOK op, llvm::Value* lhs, llvm::Value* rhs)
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
635 {
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
636 llvm::ICmpInst::Predicate pred = (op == TOKequal) ? llvm::ICmpInst::ICMP_EQ : llvm::ICmpInst::ICMP_NE;
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
637 llvm::Value* l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,0,"tmp"),"tmp");
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
638 llvm::Value* r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,0,"tmp"),"tmp");
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
639 llvm::Value* b1 = gIR->ir->CreateICmp(pred,l,r,"tmp");
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
640 l = gIR->ir->CreateLoad(DtoGEPi(lhs,0,1,"tmp"),"tmp");
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
641 r = gIR->ir->CreateLoad(DtoGEPi(rhs,0,1,"tmp"),"tmp");
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
642 llvm::Value* b2 = gIR->ir->CreateICmp(pred,l,r,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
643 llvm::Value* b = gIR->ir->CreateAnd(b1,b2,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
644 if (op == TOKnotequal)
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
645 return gIR->ir->CreateNot(b,"tmp");
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
646 return b;
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
647 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
648
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
649 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
650
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
651 llvm::GlobalValue::LinkageTypes DtoLinkage(PROT prot, uint stc)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
652 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
653 switch(prot)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
654 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
655 case PROTprivate:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
656 return llvm::GlobalValue::InternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
657
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
658 case PROTpublic:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
659 case PROTpackage:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
660 case PROTprotected:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
661 case PROTexport:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
662 return llvm::GlobalValue::ExternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
663
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
664 case PROTundefined:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
665 case PROTnone:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
666 assert(0 && "Unsupported linkage type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
667 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
668 return llvm::GlobalValue::ExternalLinkage;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
669
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
670 /* ExternalLinkage = 0, LinkOnceLinkage, WeakLinkage, AppendingLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
671 InternalLinkage, DLLImportLinkage, DLLExportLinkage, ExternalWeakLinkage,
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
672 GhostLinkage */
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
673 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
674
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
675 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
676
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
677 unsigned DtoCallingConv(LINK l)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
678 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
679 if (l == LINKc)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
680 return llvm::CallingConv::C;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
681 else if (l == LINKd || l == LINKdefault)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
682 return llvm::CallingConv::Fast;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
683 else if (l == LINKwindows)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
684 return llvm::CallingConv::X86_StdCall;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
685 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
686 assert(0 && "Unsupported calling convention");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
687 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
688
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
689 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
690
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
691 llvm::Value* DtoPointedType(llvm::Value* ptr, llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
692 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
693 const llvm::Type* ptrTy = ptr->getType()->getContainedType(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
694 const llvm::Type* valTy = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
695 // ptr points to val's type
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
696 if (ptrTy == valTy)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
697 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
698 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
699 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
700 // ptr is integer pointer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
701 else if (ptrTy->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
702 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
703 // val is integer
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
704 assert(valTy->isInteger());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
705 const llvm::IntegerType* pt = llvm::cast<const llvm::IntegerType>(ptrTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
706 const llvm::IntegerType* vt = llvm::cast<const llvm::IntegerType>(valTy);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
707 if (pt->getBitWidth() < vt->getBitWidth()) {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
708 return new llvm::TruncInst(val, pt, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
709 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
710 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
711 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
712 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
713 // something else unsupported
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
714 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
715 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
716 Logger::cout() << *ptrTy << '|' << *valTy << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
717 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
718 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
719 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
720 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
721
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
722 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
723
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
724 llvm::Value* DtoBoolean(llvm::Value* val)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
725 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
726 const llvm::Type* t = val->getType();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
727 if (t->isInteger())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
728 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
729 if (t == llvm::Type::Int1Ty)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
730 return val;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
731 else {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
732 llvm::Value* zero = llvm::ConstantInt::get(t, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
733 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
734 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
735 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
736 else if (llvm::isa<llvm::PointerType>(t)) {
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
737 const llvm::Type* st = DtoSize_t();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
738 llvm::Value* ptrasint = new llvm::PtrToIntInst(val,st,"tmp",gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
739 llvm::Value* zero = llvm::ConstantInt::get(st, 0, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
740 return new llvm::ICmpInst(llvm::ICmpInst::ICMP_NE, ptrasint, zero, "tmp", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
741 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
742 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
743 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
744 Logger::cout() << *t << '\n';
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
745 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
746 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
747 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
748 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
749
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
750 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
751
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
752 const llvm::Type* DtoSize_t()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
753 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
754 if (global.params.is64bit)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
755 return llvm::Type::Int64Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
756 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
757 return llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
758 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
759
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
760 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
761
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
762 void DtoMain()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
763 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
764 // emit main function llvm style
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
765 // int main(int argc, char**argv, char**env);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
766
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
767 assert(gIR != 0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
768 IRState& ir = *gIR;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
769
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
770 assert(ir.emitMain && ir.mainFunc);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
771
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
772 // parameter types
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
773 std::vector<const llvm::Type*> pvec;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
774 pvec.push_back((const llvm::Type*)llvm::Type::Int32Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
775 const llvm::Type* chPtrType = (const llvm::Type*)llvm::PointerType::get(llvm::Type::Int8Ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
776 pvec.push_back((const llvm::Type*)llvm::PointerType::get(chPtrType));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
777 pvec.push_back((const llvm::Type*)llvm::PointerType::get(chPtrType));
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
778 const llvm::Type* rettype = (const llvm::Type*)llvm::Type::Int32Ty;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
779
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
780 llvm::FunctionType* functype = llvm::FunctionType::get(rettype, pvec, false);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
781 llvm::Function* func = new llvm::Function(functype,llvm::GlobalValue::ExternalLinkage,"main",ir.module);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
782
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
783 llvm::BasicBlock* bb = new llvm::BasicBlock("entry",func);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
784
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
785 // call static ctors
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
786 llvm::Function* fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_ctors");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
787 new llvm::CallInst(fn,"",bb);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
788
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
789 // call user main function
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
790 llvm::CallInst* call = new llvm::CallInst(ir.mainFunc,"ret",bb);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
791 call->setCallingConv(ir.mainFunc->getCallingConv());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
792
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
793 // call static dtors
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
794 fn = LLVM_D_GetRuntimeFunction(ir.module,"_d_run_module_dtors");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
795 new llvm::CallInst(fn,"",bb);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
796
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
797 // return
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
798 new llvm::ReturnInst(call,bb);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
799 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
800
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
801 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
802
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
803 void DtoCallClassDtors(TypeClass* tc, llvm::Value* instance)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
804 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
805 Array* arr = &tc->sym->dtors;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
806 for (size_t i=0; i<arr->dim; i++)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
807 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
808 FuncDeclaration* fd = (FuncDeclaration*)arr->data[i];
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
809 assert(fd->llvmValue);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
810 new llvm::CallInst(fd->llvmValue, instance, "", gIR->scopebb());
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
811 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
812 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
813
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
814 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
815
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
816 void DtoInitClass(TypeClass* tc, llvm::Value* dst)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
817 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
818 assert(gIR);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
819
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
820 assert(tc->llvmType);
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
821 uint64_t size_t_size = gTargetData->getTypeSize(DtoSize_t());
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
822 uint64_t n = gTargetData->getTypeSize(tc->llvmType) - size_t_size;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
823
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
824 // set vtable field
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
825 llvm::Value* vtblvar = DtoGEPi(dst,0,0,"tmp",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
826 assert(tc->sym->llvmVtbl);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
827 new llvm::StoreInst(tc->sym->llvmVtbl, vtblvar, gIR->scopebb());
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
828
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
829 // copy the static initializer
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
830 if (n > 0) {
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
831 assert(tc->llvmInit);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
832 assert(dst->getType() == tc->llvmInit->getType());
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
833
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
834 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
835
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
836 llvm::Value* dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
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
837 dstarr = DtoGEPi(dstarr,size_t_size,"tmp",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
838
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
839 llvm::Value* srcarr = new llvm::BitCastInst(tc->llvmInit,arrty,"tmp",gIR->scopebb());
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
840 srcarr = DtoGEPi(srcarr,size_t_size,"tmp",gIR->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
841
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
842 llvm::Function* fn = LLVM_DeclareMemCpy32();
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
843 std::vector<llvm::Value*> llargs;
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
844 llargs.resize(4);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
845 llargs[0] = dstarr;
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
846 llargs[1] = srcarr;
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
847 llargs[2] = llvm::ConstantInt::get(llvm::Type::Int32Ty, n, false);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
848 llargs[3] = llvm::ConstantInt::get(llvm::Type::Int32Ty, 0, false);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
849
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
850 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
851 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
852 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
853
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
854 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
855
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
856 llvm::Constant* DtoConstInitializer(Type* type, Initializer* init)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
857 {
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
858 llvm::Constant* _init = 0; // may return zero
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
859 if (!init)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
860 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
861 Logger::println("const default initializer for %s", type->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
862 _init = type->defaultInit()->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
863 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
864 else if (ExpInitializer* ex = init->isExpInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
865 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
866 Logger::println("const expression initializer");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
867 _init = ex->exp->toConstElem(gIR);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
868 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
869 else if (StructInitializer* si = init->isStructInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
870 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
871 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
872 _init = DtoConstStructInitializer(si);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
873 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
874 else if (ArrayInitializer* ai = init->isArrayInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
875 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
876 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
877 _init = DtoConstArrayInitializer(ai);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
878 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
879 else if (init->isVoidInitializer())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
880 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
881 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
882 const llvm::Type* ty = DtoType(type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
883 _init = llvm::Constant::getNullValue(ty);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
884 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
885 else {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
886 Logger::println("unsupported const initializer: %s", init->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
887 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
888 return _init;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
889 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
890
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
891 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
892
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
893 elem* DtoInitializer(Initializer* init)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
894 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
895 if (ExpInitializer* ex = init->isExpInitializer())
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
896 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
897 Logger::println("expression initializer");
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
898 return ex->exp->toElem(gIR);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
899 }
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
900 else if (init->isVoidInitializer())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
901 {
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
902 // do nothing
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
903 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
904 else {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
905 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
906 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
907 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
908 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
909 }
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
910
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
911 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
912
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
913 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
914 {
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
915 std::vector<llvm::Value*> v(2);
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
916 v[0] = i0;
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
917 v[1] = i1;
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
918 Logger::cout() << "DtoGEP: " << *ptr << '\n';
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
919 return new llvm::GetElementPtrInst(ptr, v.begin(), v.end(), var, bb?bb:gIR->scopebb());
6
35d93ce68cf4 [svn r10] Updated for LLVM rev. 20070913
lindquist
parents: 4
diff changeset
920 }
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
921
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
922 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
923
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
924 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
925 {
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
926 size_t n = src.size();
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
927 std::vector<llvm::Value*> dst(n);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
928 std::ostream& ostr = Logger::cout();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
929 ostr << "indices for '" << *ptr << "':";
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
930 for (size_t i=0; i<n; ++i)
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
931 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
932 ostr << ' ' << i;
8
5e69b77a5c51 [svn r12] fixed accessing aggregate fields of aggregates
lindquist
parents: 6
diff changeset
933 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
934 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
935 ostr << '\n';
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
936 return new llvm::GetElementPtrInst(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
937 }
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
938
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
939 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
940
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
941 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
942 {
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
943 return new llvm::GetElementPtrInst(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
944 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
945
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
946 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
947
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
948 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
949 {
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
950 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
951 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
952 v[1] = llvm::ConstantInt::get(llvm::Type::Int32Ty, i1, false);
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
953 return new llvm::GetElementPtrInst(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
954 }
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
955
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
956 //////////////////////////////////////////////////////////////////////////////////////////
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
957
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
958 static llvm::Function* DtoDeclareVaFunction(FuncDeclaration* fdecl)
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
959 {
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
960 TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type);
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
961 const llvm::FunctionType* fty = DtoVaFunctionType(fdecl);
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
962 llvm::Constant* fn = 0;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
963
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
964 if (fdecl->llvmInternal == LLVMva_start) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
965 fn = gIR->module->getOrInsertFunction("llvm.va_start", fty);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
966 assert(fn);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
967 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
968 else if (fdecl->llvmInternal == LLVMva_intrinsic) {
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
969 fn = gIR->module->getOrInsertFunction(fdecl->llvmInternal1, fty);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
970 assert(fn);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
971 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
972 else
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
973 assert(0);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
974
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
975 llvm::Function* func = llvm::cast_or_null<llvm::Function>(fn);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
976 assert(func);
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
977 assert(func->isIntrinsic());
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
978 fdecl->llvmValue = func;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
979 return func;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
980 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
981
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
982 //////////////////////////////////////////////////////////////////////////////////////////
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
983
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
984 llvm::Function* DtoDeclareFunction(FuncDeclaration* fdecl)
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
985 {
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
986 if ((fdecl->llvmInternal == LLVMva_start) || (fdecl->llvmInternal == LLVMva_intrinsic)) {
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
987 return DtoDeclareVaFunction(fdecl);
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
988 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
989
27
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
990 // mangled name
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
991 char* mangled_name;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
992 if (fdecl->llvmInternal == LLVMintrinsic)
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
993 mangled_name = fdecl->llvmInternal1;
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
994 else
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
995 mangled_name = fdecl->mangle();
27
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
996
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
997 // unit test special handling
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
998 if (fdecl->isUnitTestDeclaration())
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
999 {
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1000 assert(0 && "no unittests yet");
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1001 /*const llvm::FunctionType* fnty = llvm::FunctionType::get(llvm::Type::VoidTy, std::vector<const llvm::Type*>(), false);
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1002 // make the function
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1003 llvm::Function* func = gIR->module->getFunction(mangled_name);
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1004 if (func == 0)
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1005 func = new llvm::Function(fnty,llvm::GlobalValue::InternalLinkage,mangled_name,gIR->module);
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1006 func->setCallingConv(llvm::CallingConv::Fast);
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1007 fdecl->llvmValue = func;
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1008 return func;
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1009 */
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1010 }
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1011
92408a3a2bac [svn r31] * Fixed returning through hidden pointer was unable to report back the return value
lindquist
parents: 24
diff changeset
1012 // regular function
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
1013 TypeFunction* f = (TypeFunction*)DtoDType(fdecl->type);
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
1014 assert(f != 0);
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
1015
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1016 if (fdecl->llvmValue != 0) {
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1017 if (!llvm::isa<llvm::Function>(fdecl->llvmValue))
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1018 {
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1019 Logger::cout() << *fdecl->llvmValue << '\n';
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1020 assert(0);
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1021 }
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1022 return llvm::cast<llvm::Function>(fdecl->llvmValue);
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1023 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1024
18
c05ef76f1c20 [svn r22] * Forgot to add std.stdio
lindquist
parents: 11
diff changeset
1025 Logger::print("FuncDeclaration::toObjFile(%s): %s\n", fdecl->needThis()?"this":"static",fdecl->toChars());
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1026 LOG_SCOPE;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1027
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1028 if (fdecl->llvmInternal == LLVMintrinsic && fdecl->fbody) {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1029 error("intrinsics cannot have function bodies");
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1030 fatal();
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1031 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1032
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1033 // construct function
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
1034 const llvm::FunctionType* functype = (f->llvmType == 0) ? DtoFunctionType(fdecl) : llvm::cast<llvm::FunctionType>(f->llvmType);
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1035
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1036 // make the function
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1037 llvm::Function* func = gIR->module->getFunction(mangled_name);
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1038 if (func == 0) {
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
1039 func = new llvm::Function(functype,DtoLinkage(fdecl->protection, fdecl->storage_class),mangled_name,gIR->module);
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1040 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1041
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1042 if (fdecl->llvmInternal != LLVMintrinsic)
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
1043 func->setCallingConv(DtoCallingConv(f->linkage));
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1044
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1045 fdecl->llvmValue = func;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1046 f->llvmType = functype;
11
d3ee9efe20e2 [svn r15] * Fixed a bunch problems with virtual calls. Seems I did some rather poor testing.
lindquist
parents: 9
diff changeset
1047 assert(llvm::isa<llvm::FunctionType>(f->llvmType));
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1048
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1049 if (fdecl->isMain()) {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1050 gIR->mainFunc = func;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1051 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1052
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1053 // name parameters
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1054 llvm::Function::arg_iterator iarg = func->arg_begin();
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1055 int k = 0;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1056 if (f->llvmRetInPtr) {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1057 iarg->setName("retval");
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1058 f->llvmRetArg = iarg;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1059 ++iarg;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1060 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1061 if (f->llvmUsesThis) {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1062 iarg->setName("this");
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1063 ++iarg;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1064 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1065 int varargs = -1;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1066 if (f->linkage == LINKd && f->varargs == 1)
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1067 varargs = 0;
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1068 for (; iarg != func->arg_end(); ++iarg)
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1069 {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1070 Argument* arg = Argument::getNth(f->parameters, k++);
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1071 //arg->llvmValue = iarg;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1072 //printf("identifier: '%s' %p\n", arg->ident->toChars(), arg->ident);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1073 if (arg && arg->ident != 0) {
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1074 if (arg->vardecl) {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1075 arg->vardecl->llvmValue = iarg;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1076 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1077 iarg->setName(arg->ident->toChars());
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1078 }
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1079 else if (!arg && varargs >= 0) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1080 if (varargs == 0) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1081 iarg->setName("_arguments");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1082 fdecl->llvmArguments = iarg;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1083 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1084 else if (varargs == 1) {
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1085 iarg->setName("_argptr");
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1086 fdecl->llvmArgPtr = iarg;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1087 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1088 else
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1089 assert(0);
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1090 varargs++;
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1091 }
9
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1092 else {
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1093 iarg->setName("unnamed");
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1094 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1095 }
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1096
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1097 return func;
dafae18f9c08 [svn r13] * Updated for LLVM 2.1
lindquist
parents: 8
diff changeset
1098 }
29
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 27
diff changeset
1099
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 27
diff changeset
1100 //////////////////////////////////////////////////////////////////////////////////////////
253a5fc4033a [svn r33] * Added support for assignment to function arguments
lindquist
parents: 27
diff changeset
1101
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
1102 llvm::Value* DtoRealloc(llvm::Value* ptr, const llvm::Type* ty)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1103 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1104 /*size_t sz = gTargetData->getTypeSize(ty);
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
1105 llvm::ConstantInt* n = llvm::ConstantInt::get(DtoSize_t(), sz, false);
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1106 if (ptr == 0) {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1107 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1108 ptr = llvm::ConstantPointerNull::get(i8pty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1109 }
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
1110 return DtoRealloc(ptr, n);*/
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1111 return NULL;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1112 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1113
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1114 //////////////////////////////////////////////////////////////////////////////////////////
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1115
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
1116 llvm::Value* DtoRealloc(llvm::Value* ptr, llvm::Value* n)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1117 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1118 assert(ptr);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1119 assert(n);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1120
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1121 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_realloc");
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1122 assert(fn);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1123
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1124 llvm::Value* newptr = ptr;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1125
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1126 llvm::PointerType* i8pty = llvm::PointerType::get(llvm::Type::Int8Ty);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1127 if (ptr->getType() != i8pty) {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1128 newptr = new llvm::BitCastInst(ptr,i8pty,"tmp",gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1129 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1130
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1131 std::vector<llvm::Value*> args;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1132 args.push_back(newptr);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1133 args.push_back(n);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1134 llvm::Value* ret = new llvm::CallInst(fn, args.begin(), args.end(), "tmprealloc", gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1135
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1136 return ret->getType() == ptr->getType() ? ret : new llvm::BitCastInst(ret,ptr->getType(),"tmp",gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1137 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1138
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1139 //////////////////////////////////////////////////////////////////////////////////////////
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1140
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
1141 void DtoAssert(llvm::Value* cond, llvm::Value* loc, llvm::Value* msg)
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1142 {
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1143 assert(loc);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1144 std::vector<llvm::Value*> llargs;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1145 llargs.resize(3);
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
1146 llargs[0] = cond ? DtoBoolean(cond) : llvm::ConstantInt::getFalse();
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1147 llargs[1] = loc;
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1148 llargs[2] = msg ? msg : llvm::ConstantPointerNull::get(llvm::PointerType::get(llvm::Type::Int8Ty));
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1149
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1150 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_assert");
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1151 assert(fn);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1152 llvm::CallInst* call = new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1153 call->setCallingConv(llvm::CallingConv::C);
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1154 }
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1155
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1156 //////////////////////////////////////////////////////////////////////////////////////////
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1157
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
1158 llvm::Value* DtoArgument(const llvm::Type* paramtype, Argument* fnarg, Expression* argexp)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1159 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1160 llvm::Value* retval = 0;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1161
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1162 bool haslvals = !gIR->exps.empty();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1163 if (haslvals)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1164 gIR->exps.push_back(IRExp(NULL,NULL,NULL));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1165
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1166 elem* arg = argexp->toElem(gIR);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1167
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1168 if (haslvals)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1169 gIR->exps.pop_back();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1170
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1171 if (arg->inplace) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1172 assert(arg->mem != 0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1173 retval = arg->mem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1174 delete arg;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1175 return retval;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1176 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1177
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
1178 Type* realtype = DtoDType(argexp->type);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1179 TY argty = realtype->ty;
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
1180 if (DtoIsPassedByRef(realtype)) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1181 if (!fnarg || !fnarg->llvmCopy) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1182 retval = arg->getValue();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1183 assert(retval != 0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1184 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1185 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1186 llvm::Value* allocaInst = 0;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1187 llvm::BasicBlock* entryblock = &gIR->topfunc()->front();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1188 //const llvm::PointerType* pty = llvm::cast<llvm::PointerType>(arg->mem->getType());
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
1189 const llvm::Type* realtypell = DtoType(realtype);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1190 const llvm::PointerType* pty = llvm::PointerType::get(realtypell);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1191 if (argty == Tstruct) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1192 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
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
1193 DtoStructCopy(allocaInst,arg->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1194 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1195 else if (argty == Tdelegate) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1196 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
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
1197 DtoDelegateCopy(allocaInst,arg->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1198 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1199 else if (argty == Tarray) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1200 if (arg->type == elem::SLICE) {
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1201 allocaInst = new llvm::AllocaInst(realtypell, "tmpparam", gIR->topallocapoint());
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
1202 DtoSetArray(allocaInst, arg->arg, arg->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1203 }
83
339422268de1 [svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)
lindquist
parents: 82
diff changeset
1204 else if (arg->temp) {
339422268de1 [svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)
lindquist
parents: 82
diff changeset
1205 allocaInst = arg->mem;
339422268de1 [svn r87] Fixed some memory bloat when passing string literals as char[] params (double temporary before)
lindquist
parents: 82
diff changeset
1206 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1207 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1208 allocaInst = new llvm::AllocaInst(pty->getElementType(), "tmpparam", gIR->topallocapoint());
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
1209 DtoArrayAssign(allocaInst,arg->mem);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1210 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1211 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1212 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1213 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1214
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1215 retval = allocaInst;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1216 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1217 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1218 else if (!fnarg || fnarg->llvmCopy) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1219 Logger::println("regular arg");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1220 assert(arg->type != elem::SLICE);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1221 if (arg->mem) Logger::cout() << "mem = " << *arg->mem << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1222 if (arg->val) Logger::cout() << "val = " << *arg->val << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1223 if (arg->arg) Logger::cout() << "arg = " << *arg->arg << '\n';
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1224 retval = arg->arg ? arg->arg : arg->field ? arg->mem : arg->getValue();
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1225 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1226 else {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1227 Logger::println("as ptr arg");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1228 retval = arg->mem ? arg->mem : arg->val;
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
1229 if (paramtype && retval->getType() != paramtype)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1230 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1231 assert(retval->getType() == paramtype->getContainedType(0));
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1232 new llvm::StoreInst(retval, arg->mem, gIR->scopebb());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1233 retval = arg->mem;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1234 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1235 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1236
78
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1237 if (fnarg && paramtype && retval->getType() != paramtype) {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1238 // this is unfortunately needed with the way SymOffExp is overused
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1239 // and static arrays can end up being a pointer to their element type
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1240 if (arg->field) {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1241 retval = gIR->ir->CreateBitCast(retval, paramtype, "tmp");
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1242 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1243 else {
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1244 Logger::cout() << "got '" << *retval->getType() << "' expected '" << *paramtype << "'\n";
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1245 assert(0 && "parameter type that was actually passed is invalid");
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1246 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1247 }
2332006e1fa4 [svn r82] Fixed: Fall-through switch cases were broken.
lindquist
parents: 77
diff changeset
1248
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1249 delete arg;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1250
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1251 return retval;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 34
diff changeset
1252 }
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1253
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1254 //////////////////////////////////////////////////////////////////////////////////////////
34
4648206ca213 [svn r38] * resizing dynamic arrays support
lindquist
parents: 31
diff changeset
1255
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
1256 llvm::Value* DtoNestedVariable(VarDeclaration* vd)
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1257 {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1258 FuncDeclaration* fd = vd->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1259 assert(fd != NULL);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1260
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1261 IRFunction* fcur = &gIR->func();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1262 FuncDeclaration* f = fcur->decl;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1263
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1264 // on this stack
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1265 if (fd == f) {
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
1266 llvm::Value* v = DtoGEPi(vd->llvmValue,0,unsigned(vd->llvmNestedIndex),"tmp");
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
1267 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
1268 Logger::cout() << "1267 loading: " << *v << '\n';
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
1269 v = gIR->ir->CreateLoad(v,"tmp");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
1270 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
1271 return v;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1272 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1273
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1274 // on a caller stack
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1275 llvm::Value* ptr = f->llvmThisVar;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1276 assert(ptr);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1277
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1278 f = f->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1279 assert(f);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1280 assert(f->llvmNested);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1281 const llvm::Type* nesttype = f->llvmNested->getType();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1282 assert(nesttype);
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1283
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1284 ptr = gIR->ir->CreateBitCast(ptr, nesttype, "tmp");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1285
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1286 Logger::cout() << "nested var reference:" << '\n' << *ptr << *nesttype << '\n';
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1287
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1288 while (f) {
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1289 if (fd == f) {
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
1290 llvm::Value* v = DtoGEPi(ptr,0,vd->llvmNestedIndex,"tmp");
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
1291 if (vd->isParameter() && (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type))) {
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
1292 Logger::cout() << "1291 loading: " << *v << '\n';
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
1293 v = gIR->ir->CreateLoad(v,"tmp");
73
b706170e24a9 [svn r77] Fixed foreach on slice.
lindquist
parents: 72
diff changeset
1294 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 62
diff changeset
1295 return v;
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1296 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1297 else {
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
1298 ptr = DtoGEPi(ptr,0,0,"tmp");
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1299 ptr = gIR->ir->CreateLoad(ptr,"tmp");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1300 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1301 f = f->toParent()->isFuncDeclaration();
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1302 }
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1303
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1304 assert(0 && "nested var not found");
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1305 return NULL;
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
1306 }
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1307
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1308 //////////////////////////////////////////////////////////////////////////////////////////
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1309
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
1310 void DtoAssign(Type* t, llvm::Value* lhs, llvm::Value* rhs)
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1311 {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1312 Logger::cout() << "assignment:" << '\n' << *lhs << *rhs << '\n';
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1313
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1314 if (t->ty == Tstruct) {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1315 assert(lhs->getType() == rhs->getType());
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
1316 DtoStructCopy(lhs,rhs);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1317 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1318 else if (t->ty == Tarray) {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1319 assert(lhs->getType() == rhs->getType());
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
1320 DtoArrayAssign(lhs,rhs);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1321 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1322 else if (t->ty == Tsarray) {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1323 assert(lhs->getType() == rhs->getType());
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
1324 DtoStaticArrayCopy(lhs,rhs);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1325 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1326 else if (t->ty == Tdelegate) {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1327 assert(lhs->getType() == rhs->getType());
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
1328 DtoDelegateCopy(lhs,rhs);
51
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1329 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1330 else {
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1331 assert(lhs->getType()->getContainedType(0) == rhs->getType());
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1332 gIR->ir->CreateStore(rhs, lhs);
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1333 }
61bc1b4ad3c4 [svn r55] Foreach was always generating code as if the value variable was 'ref'
lindquist
parents: 50
diff changeset
1334 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1335
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1336 //////////////////////////////////////////////////////////////////////////////////////////
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1337
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
1338 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
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 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
1341 }
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
1342 llvm::ConstantInt* DtoConstUint(unsigned i)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1343 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1344 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
1345 }
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::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
1347 {
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 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
1349 }
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
1350 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
1351 {
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
1352 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
1353 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1354
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1355 //////////////////////////////////////////////////////////////////////////////////////////
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1356
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
1357 llvm::Constant* DtoConstString(const char* str)
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1358 {
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1359 std::string s(str);
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1360 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
1361 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1362 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
1363 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
1364 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
1365 DtoConstSize_t(s.length()),
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1366 llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2)
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1367 );
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
1368 }
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
1369 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
1370 {
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
1371 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
1372 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
1373 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
1374 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
1375 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
1376 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
1377 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
1378 }
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1379
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1380 //////////////////////////////////////////////////////////////////////////////////////////
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1381
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
1382 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
1383 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1384 assert(dst->getType() == src->getType());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1385
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1386 llvm::Type* arrty = llvm::PointerType::get(llvm::Type::Int8Ty);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1387 llvm::Value *dstarr, *srcarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1388 if (dst->getType() == arrty)
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1389 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1390 dstarr = dst;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1391 srcarr = src;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1392 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1393 else
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1394 {
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1395 dstarr = new llvm::BitCastInst(dst,arrty,"tmp",gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1396 srcarr = new llvm::BitCastInst(src,arrty,"tmp",gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1397 }
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1398
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1399 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
1400 std::vector<llvm::Value*> llargs;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1401 llargs.resize(4);
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1402 llargs[0] = dstarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1403 llargs[1] = srcarr;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1404 llargs[2] = nbytes;
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1405 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
1406
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1407 new llvm::CallInst(fn, llargs.begin(), llargs.end(), "", gIR->scopebb());
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1408 }
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1409
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1410 //////////////////////////////////////////////////////////////////////////////////////////
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1411
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
1412 llvm::Value* DtoIndexStruct(llvm::Value* ptr, StructDeclaration* sd, Type* t, unsigned os, std::vector<unsigned>& idxs)
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1413 {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1414 Logger::println("checking for offset %u type %s:", os, t->toChars());
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1415 LOG_SCOPE;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1416
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1417 if (idxs.empty())
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1418 idxs.push_back(0);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1419
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
1420 const llvm::Type* llt = llvm::PointerType::get(DtoType(t));
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1421
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1422 for (unsigned i=0; i<sd->fields.dim; ++i) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1423 VarDeclaration* vd = (VarDeclaration*)sd->fields.data[i];
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
1424 Type* vdtype = DtoDType(vd->type);
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1425 Logger::println("found %u type %s", vd->offset, vdtype->toChars());
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1426 assert(vd->llvmFieldIndex >= 0);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1427 if (os == vd->offset && vdtype == t) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1428 idxs.push_back(vd->llvmFieldIndex);
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
1429 ptr = DtoGEP(ptr, idxs, "tmp");
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1430 if (ptr->getType() != llt)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1431 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1432 if (vd->llvmFieldIndexOffset)
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
1433 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1434 return ptr;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1435 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1436 else if (vdtype->ty == Tstruct && (vd->offset + vdtype->size()) > os) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1437 TypeStruct* ts = (TypeStruct*)vdtype;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1438 StructDeclaration* ssd = ts->sym;
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1439 idxs.push_back(vd->llvmFieldIndex);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1440 if (vd->llvmFieldIndexOffset) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1441 Logger::println("has union field offset");
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
1442 ptr = DtoGEP(ptr, idxs, "tmp");
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1443 if (ptr->getType() != llt)
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1444 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
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
1445 ptr = new llvm::GetElementPtrInst(ptr, DtoConstUint(vd->llvmFieldIndexOffset), "tmp", gIR->scopebb());
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1446 std::vector<unsigned> tmp;
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
1447 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1448 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1449 else {
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
1450 const llvm::Type* sty = llvm::PointerType::get(DtoType(vd->type));
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1451 if (ptr->getType() != sty) {
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1452 ptr = gIR->ir->CreateBitCast(ptr, sty, "tmp");
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1453 std::vector<unsigned> tmp;
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
1454 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, tmp);
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1455 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1456 else {
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
1457 return DtoIndexStruct(ptr, ssd, t, os-vd->offset, idxs);
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1458 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1459 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1460 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1461 }
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1462
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1463 size_t llt_sz = gTargetData->getTypeSize(llt->getContainedType(0));
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1464 assert(os % llt_sz == 0);
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1465 ptr = gIR->ir->CreateBitCast(ptr, llt, "tmp");
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
1466 return new llvm::GetElementPtrInst(ptr, DtoConstUint(os / llt_sz), "tmp", gIR->scopebb());
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 73
diff changeset
1467 }
85
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1468
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1469 //////////////////////////////////////////////////////////////////////////////////////////
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1470
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1471 bool DtoIsTemplateInstance(Dsymbol* s)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1472 {
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1473 assert(s);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1474 if (s->isTemplateInstance() && !s->isTemplateMixin())
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1475 return true;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1476 else if (s->parent)
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1477 return DtoIsTemplateInstance(s->parent);
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1478 return false;
f869c636a113 [svn r89] Fixed a bunch of problems with template instance across multiple modules.
lindquist
parents: 83
diff changeset
1479 }