Mercurial > projects > ldc
annotate gen/toir.cpp @ 1405:a865b81fc961
Oops, didn't mean to change debug info linkage.
author | Frits van Bommel <fvbommel wxs.nl> |
---|---|
date | Thu, 21 May 2009 15:26:46 +0200 |
parents | e2cf1f67ca33 |
children | a6dfd3cb5b99 |
rev | line source |
---|---|
1 | 1 // Backend stubs |
2 | |
3 /* DMDFE backend stubs | |
4 * This file contains the implementations of the backend routines. | |
5 * For dmdfe these do nothing but print a message saying the module | |
6 * has been parsed. Substitute your own behaviors for these routimes. | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <math.h> | |
11 #include <fstream> | |
12 | |
40 | 13 #include "gen/llvm.h" |
1 | 14 |
132 | 15 #include "attrib.h" |
1 | 16 #include "init.h" |
17 #include "mtype.h" | |
321 | 18 #include "template.h" |
1 | 19 #include "hdrgen.h" |
20 #include "port.h" | |
1103
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1036
diff
changeset
|
21 #include "rmem.h" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1036
diff
changeset
|
22 #include "id.h" |
b30fe7e1dbb9
- Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1036
diff
changeset
|
23 #include "enum.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
24 |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
25 #include "gen/irstate.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
26 #include "gen/logger.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
27 #include "gen/tollvm.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
28 #include "gen/llvmhelpers.h" |
4
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
29 #include "gen/runtime.h" |
e116aa1488e6
[svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents:
1
diff
changeset
|
30 #include "gen/arrays.h" |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
31 #include "gen/structs.h" |
100 | 32 #include "gen/classes.h" |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
101
diff
changeset
|
33 #include "gen/typeinf.h" |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
34 #include "gen/complex.h" |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
35 #include "gen/dvalue.h" |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
36 #include "gen/aa.h" |
131 | 37 #include "gen/functions.h" |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
38 #include "gen/todebug.h" |
1207
83d3b25c2213
Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents:
1166
diff
changeset
|
39 #include "gen/nested.h" |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
40 #include "gen/utils.h" |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
41 |
987
73ff89728d85
Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents:
973
diff
changeset
|
42 #include "llvm/Support/ManagedStatic.h" |
73ff89728d85
Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents:
973
diff
changeset
|
43 |
1 | 44 ////////////////////////////////////////////////////////////////////////////////////////// |
45 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
46 void Expression::cacheLvalue(IRState* irs) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
47 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
48 error("expression %s does not mask any l-value", toChars()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
49 fatal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
50 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
51 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
52 ////////////////////////////////////////////////////////////////////////////////////////// |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
53 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
54 DValue* DeclarationExp::toElem(IRState* p) |
1 | 55 { |
56 Logger::print("DeclarationExp::toElem: %s | T=%s\n", toChars(), type->toChars()); | |
57 LOG_SCOPE; | |
58 | |
433
b5f55f471e0b
Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents:
426
diff
changeset
|
59 return DtoDeclarationExp(declaration); |
1 | 60 } |
61 | |
62 ////////////////////////////////////////////////////////////////////////////////////////// | |
63 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
64 void VarExp::cacheLvalue(IRState* p) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
65 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
66 Logger::println("Caching l-value of %s", toChars()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
67 LOG_SCOPE; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
68 cachedLvalue = toElem(p)->getLVal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
69 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
70 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
71 DValue* VarExp::toElem(IRState* p) |
1 | 72 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
73 Logger::print("VarExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 74 LOG_SCOPE; |
75 | |
76 assert(var); | |
834
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
77 |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
78 if (cachedLvalue) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
79 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
80 LLValue* V = cachedLvalue; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
81 cachedLvalue = NULL; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
82 return new DVarValue(type, V); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
83 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
84 |
1 | 85 if (VarDeclaration* vd = var->isVarDeclaration()) |
86 { | |
763
9a9f403ab399
D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
758
diff
changeset
|
87 Logger::println("VarDeclaration ' %s ' of type ' %s '", vd->toChars(), vd->type->toChars()); |
50
6fcc08a4d406
[svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents:
49
diff
changeset
|
88 |
834
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
89 // this is an error! must be accessed with DotVarExp |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
90 if (var->needThis()) |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
91 { |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
92 error("need 'this' to access member %s", toChars()); |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
93 fatal(); |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
94 } |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
95 |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
96 // _arguments |
464
e381e082d5cb
Fixed problem with using the variable names _arguments and _argptr in non D-style vararg functions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
460
diff
changeset
|
97 if (vd->ident == Id::_arguments && p->func()->_arguments) |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
98 { |
72 | 99 Logger::println("Id::_arguments"); |
363 | 100 LLValue* v = p->func()->_arguments; |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
101 return new DVarValue(type, vd, v); |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
102 } |
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
103 // _argptr |
464
e381e082d5cb
Fixed problem with using the variable names _arguments and _argptr in non D-style vararg functions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
460
diff
changeset
|
104 else if (vd->ident == Id::_argptr && p->func()->_argptr) |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
105 { |
72 | 106 Logger::println("Id::_argptr"); |
363 | 107 LLValue* v = p->func()->_argptr; |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
108 return new DVarValue(type, vd, v); |
57
a9d29e9f1fed
[svn r61] Added support for D-style variadic functions :)
lindquist
parents:
55
diff
changeset
|
109 } |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
110 // _dollar |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
111 else if (vd->ident == Id::dollar) |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
112 { |
72 | 113 Logger::println("Id::dollar"); |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
114 assert(!p->arrays.empty()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
115 LLValue* tmp = DtoArrayLen(p->arrays.back()); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
116 return new DImValue(type, tmp); |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
117 } |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
118 // typeinfo |
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
119 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration()) |
1 | 120 { |
121 Logger::println("TypeInfoDeclaration"); | |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
122 tid->codegen(Type::sir); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
123 assert(tid->ir.getIrValue()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
124 const LLType* vartype = DtoType(type); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
125 LLValue* m = tid->ir.getIrValue(); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
126 if (m->getType() != getPtrToType(vartype)) |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
127 m = p->ir->CreateBitCast(m, vartype, "tmp"); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
128 return new DImValue(type, m); |
1 | 129 } |
100 | 130 // classinfo |
131 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration()) | |
132 { | |
133 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars()); | |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
134 cid->cd->codegen(Type::sir);; |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
135 return new DVarValue(type, vd, cid->cd->ir.irStruct->getClassInfoSymbol()); |
100 | 136 } |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
137 // nested variable |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
138 #if DMDV2 |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
139 else if (vd->nestedrefs.dim) { |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
140 #else |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
141 else if (vd->nestedref) { |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
142 #endif |
72 | 143 Logger::println("nested variable"); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
144 return DtoNestedVariable(loc, type, vd); |
1 | 145 } |
146 // function parameter | |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
147 else if (vd->isParameter()) { |
1 | 148 Logger::println("function param"); |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
149 Logger::println("type: %s", vd->type->toChars()); |
339
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
150 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration(); |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
151 if (fd && fd != p->func()->decl) { |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
152 Logger::println("nested parameter"); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
153 return DtoNestedVariable(loc, type, vd); |
339
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
154 } |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
155 else if (vd->storage_class & STClazy) { |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
156 Logger::println("lazy parameter"); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
157 assert(type->ty == Tdelegate); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
158 return new DVarValue(type, vd->ir.getIrValue()); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
159 } |
339
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
160 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) { |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
161 return new DVarValue(type, vd, vd->ir.getIrValue()); |
1 | 162 } |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
163 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) { |
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
164 return new DImValue(type, vd->ir.getIrValue()); |
1 | 165 } |
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
|
166 else assert(0); |
1 | 167 } |
168 else { | |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
169 Logger::println("a normal variable"); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
170 |
67
f918f3e2e99e
[svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents:
66
diff
changeset
|
171 // take care of forward references of global variables |
100 | 172 if (vd->isDataseg() || (vd->storage_class & STCextern)) { |
1147
dbe4af57b240
Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1146
diff
changeset
|
173 vd->codegen(Type::sir); |
100 | 174 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
175 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
176 LLValue* val; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
177 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
178 if (!vd->ir.isSet() || !(val = vd->ir.getIrValue())) { |
834
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
179 // FIXME: this error is bad! |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
180 // We should be VERY careful about adding errors in general, as they have |
f466f475b654
Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
825
diff
changeset
|
181 // a tendency to "mask" out the underlying problems ... |
656
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
643
diff
changeset
|
182 error("variable %s not resolved", vd->toChars()); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
183 if (Logger::enabled()) |
656
a15ccbf7451d
Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
643
diff
changeset
|
184 Logger::cout() << "unresolved variable had type: " << *DtoType(vd->type) << '\n'; |
397
9ec89aad9dbc
Make an unresolved global into an error instead of an assert.
Christian Kamm <kamm incasoftware de>
parents:
384
diff
changeset
|
185 fatal(); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
186 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
187 |
628
e3c46bcce65f
Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents:
624
diff
changeset
|
188 if (vd->isDataseg() || (vd->storage_class & STCextern)) { |
e3c46bcce65f
Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents:
624
diff
changeset
|
189 DtoConstInitGlobal(vd); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
190 val = DtoBitCast(val, DtoType(type->pointerTo())); |
628
e3c46bcce65f
Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents:
624
diff
changeset
|
191 } |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
192 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
193 return new DVarValue(type, vd, val); |
1 | 194 } |
195 } | |
196 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | |
197 { | |
198 Logger::println("FuncDeclaration"); | |
384
3f98d46e05a4
Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
379
diff
changeset
|
199 LLValue* func = 0; |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
200 if (fdecl->llvmInternal == LLVMinline_asm) { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
201 error("special ldc inline asm is not a normal function"); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
202 fatal(); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
203 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
204 else if (fdecl->llvmInternal != LLVMva_arg) { |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
205 fdecl->codegen(Type::sir); |
384
3f98d46e05a4
Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
379
diff
changeset
|
206 func = fdecl->ir.irFunc->func; |
102
027b8d8b71ec
[svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents:
101
diff
changeset
|
207 } |
384
3f98d46e05a4
Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
379
diff
changeset
|
208 return new DFuncValue(fdecl, func); |
1 | 209 } |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
887
diff
changeset
|
210 else if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) |
1 | 211 { |
212 // this seems to be the static initialiser for structs | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
213 Type* sdecltype = sdecl->type->toBasetype(); |
40 | 214 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
215 assert(sdecltype->ty == Tstruct); | |
216 TypeStruct* ts = (TypeStruct*)sdecltype; | |
121
9c79b61fb638
[svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents:
120
diff
changeset
|
217 assert(ts->sym); |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
218 ts->sym->codegen(Type::sir); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
219 |
1270
dd135ff697fa
Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1255
diff
changeset
|
220 LLValue* initsym = ts->sym->ir.irStruct->getInitSymbol(); |
dd135ff697fa
Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1255
diff
changeset
|
221 initsym = DtoBitCast(initsym, DtoType(ts->pointerTo())); |
dd135ff697fa
Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1255
diff
changeset
|
222 return new DVarValue(type, initsym); |
1 | 223 } |
224 else | |
225 { | |
226 assert(0 && "Unimplemented VarExp type"); | |
227 } | |
228 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
229 return 0; |
1 | 230 } |
231 | |
232 ////////////////////////////////////////////////////////////////////////////////////////// | |
233 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
234 LLConstant* VarExp::toConstElem(IRState* p) |
40 | 235 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
236 Logger::print("VarExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 237 LOG_SCOPE; |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
238 |
913
29c0d1194033
Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents:
887
diff
changeset
|
239 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration()) |
40 | 240 { |
241 // this seems to be the static initialiser for structs | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
242 Type* sdecltype = sdecl->type->toBasetype(); |
40 | 243 Logger::print("Sym: type=%s\n", sdecltype->toChars()); |
244 assert(sdecltype->ty == Tstruct); | |
245 TypeStruct* ts = (TypeStruct*)sdecltype; | |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
246 ts->sym->codegen(Type::sir); |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
247 |
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
248 return ts->sym->ir.irStruct->getDefaultInit(); |
40 | 249 } |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
250 |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
251 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration()) |
132 | 252 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
253 const LLType* vartype = DtoType(type); |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
268
diff
changeset
|
254 LLConstant* m = DtoTypeInfoOf(ti->tinfo, false); |
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
268
diff
changeset
|
255 if (m->getType() != getPtrToType(vartype)) |
132 | 256 m = llvm::ConstantExpr::getBitCast(m, vartype); |
257 return m; | |
258 } | |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
259 |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
260 VarDeclaration* vd = var->isVarDeclaration(); |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
261 if (vd && vd->isConst() && vd->init) |
836
14c3319ac1bb
This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
834
diff
changeset
|
262 { |
14c3319ac1bb
This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
834
diff
changeset
|
263 // return the initializer |
14c3319ac1bb
This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
834
diff
changeset
|
264 return DtoConstInitializer(loc, type, vd->init); |
14c3319ac1bb
This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
834
diff
changeset
|
265 } |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
266 |
836
14c3319ac1bb
This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
834
diff
changeset
|
267 // fail |
920
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
268 error("non-constant expression %s", toChars()); |
545f54041d91
Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
918
diff
changeset
|
269 return llvm::UndefValue::get(DtoType(type)); |
40 | 270 } |
271 | |
272 ////////////////////////////////////////////////////////////////////////////////////////// | |
273 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
274 DValue* IntegerExp::toElem(IRState* p) |
1 | 275 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
276 Logger::print("IntegerExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 277 LOG_SCOPE; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
278 LLConstant* c = toConstElem(p); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
279 return new DConstValue(type, c); |
40 | 280 } |
281 | |
282 ////////////////////////////////////////////////////////////////////////////////////////// | |
283 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
284 LLConstant* IntegerExp::toConstElem(IRState* p) |
40 | 285 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
286 Logger::print("IntegerExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 287 LOG_SCOPE; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
288 const LLType* t = DtoType(type); |
96 | 289 if (isaPointer(t)) { |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
290 Logger::println("pointer"); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
291 LLConstant* i = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)value,false); |
40 | 292 return llvm::ConstantExpr::getIntToPtr(i, t); |
1 | 293 } |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
294 assert(llvm::isa<LLIntegerType>(t)); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
295 LLConstant* c = llvm::ConstantInt::get(t,(uint64_t)value,!type->isunsigned()); |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
296 assert(c); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
297 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
298 Logger::cout() << "value = " << *c << '\n'; |
88
058d3925950e
[svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents:
86
diff
changeset
|
299 return c; |
1 | 300 } |
301 | |
302 ////////////////////////////////////////////////////////////////////////////////////////// | |
303 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
304 DValue* RealExp::toElem(IRState* p) |
1 | 305 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
306 Logger::print("RealExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 307 LOG_SCOPE; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
308 LLConstant* c = toConstElem(p); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
309 return new DConstValue(type, c); |
40 | 310 } |
311 | |
312 ////////////////////////////////////////////////////////////////////////////////////////// | |
313 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
314 LLConstant* RealExp::toConstElem(IRState* p) |
40 | 315 { |
1378
5575e0c07e1a
Use %La to hex-format a real instead of pretending it's an integer.
Frits van Bommel <fvbommel wxs.nl>
parents:
1377
diff
changeset
|
316 Logger::print("RealExp::toConstElem: %s @ %s | %La\n", toChars(), type->toChars(), value); |
40 | 317 LOG_SCOPE; |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
318 Type* t = type->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
319 return DtoConstFP(t, value); |
1 | 320 } |
321 | |
322 ////////////////////////////////////////////////////////////////////////////////////////// | |
323 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
324 DValue* NullExp::toElem(IRState* p) |
1 | 325 { |
326 Logger::print("NullExp::toElem(type=%s): %s\n", type->toChars(),toChars()); | |
327 LOG_SCOPE; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
328 LLConstant* c = toConstElem(p); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
329 return new DNullValue(type, c); |
40 | 330 } |
331 | |
332 ////////////////////////////////////////////////////////////////////////////////////////// | |
333 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
334 LLConstant* NullExp::toConstElem(IRState* p) |
40 | 335 { |
336 Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars()); | |
337 LOG_SCOPE; | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
338 const LLType* t = DtoType(type); |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
27
diff
changeset
|
339 if (type->ty == Tarray) { |
96 | 340 assert(isaStruct(t)); |
40 | 341 return llvm::ConstantAggregateZero::get(t); |
28
1c80c18f3c82
[svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents:
27
diff
changeset
|
342 } |
40 | 343 else { |
344 return llvm::Constant::getNullValue(t); | |
345 } | |
346 assert(0); | |
347 return NULL; | |
1 | 348 } |
349 | |
350 ////////////////////////////////////////////////////////////////////////////////////////// | |
351 | |
90 | 352 DValue* ComplexExp::toElem(IRState* p) |
353 { | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
354 Logger::print("ComplexExp::toElem(): %s @ %s\n", toChars(), type->toChars()); |
90 | 355 LOG_SCOPE; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
356 LLConstant* c = toConstElem(p); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
357 LLValue* res; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
358 |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
359 if (c->isNullValue()) { |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
360 Type* t = type->toBasetype(); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
361 if (t->ty == Tcomplex32) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
362 c = DtoConstFP(Type::tfloat32, 0); |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
363 else if (t->ty == Tcomplex64) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
364 c = DtoConstFP(Type::tfloat64, 0); |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
365 else if (t->ty == Tcomplex80) |
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
366 c = DtoConstFP(Type::tfloat80, 0); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
367 else |
445
cc40db549aea
Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
443
diff
changeset
|
368 assert(0); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
369 res = DtoAggrPair(DtoType(type), c, c); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
370 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
371 else { |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
372 res = DtoAggrPair(DtoType(type), c->getOperand(0), c->getOperand(1)); |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
373 } |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
374 |
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
375 return new DImValue(type, res); |
90 | 376 } |
377 | |
378 ////////////////////////////////////////////////////////////////////////////////////////// | |
379 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
380 LLConstant* ComplexExp::toConstElem(IRState* p) |
90 | 381 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
382 Logger::print("ComplexExp::toConstElem(): %s @ %s\n", toChars(), type->toChars()); |
90 | 383 LOG_SCOPE; |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
384 return DtoConstComplex(type, value.re, value.im); |
90 | 385 } |
386 | |
387 ////////////////////////////////////////////////////////////////////////////////////////// | |
388 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
389 DValue* StringExp::toElem(IRState* p) |
1 | 390 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
391 Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 392 LOG_SCOPE; |
393 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
394 Type* dtype = type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
395 Type* cty = dtype->nextOf()->toBasetype(); |
1 | 396 |
328
7086a84ab3d6
[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents:
321
diff
changeset
|
397 const LLType* ct = DtoTypeNotVoid(cty); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
398 //printf("ct = %s\n", type->nextOf()->toChars()); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
399 const LLArrayType* at = LLArrayType::get(ct,len+1); |
1 | 400 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
401 LLConstant* _init; |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
402 if (cty->size() == 1) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
403 uint8_t* str = (uint8_t*)string; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
404 std::string cont((char*)str, len); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
405 _init = llvm::ConstantArray::get(cont,true); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
406 } |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
407 else if (cty->size() == 2) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
408 uint16_t* str = (uint16_t*)string; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
409 std::vector<LLConstant*> vals; |
1395
6063ddfcf27d
Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1378
diff
changeset
|
410 vals.reserve(len+1); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
411 for(size_t i=0; i<len; ++i) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
412 vals.push_back(llvm::ConstantInt::get(ct, str[i], false));; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
413 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
414 vals.push_back(llvm::ConstantInt::get(ct, 0, false)); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
415 _init = llvm::ConstantArray::get(at,vals); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
416 } |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
417 else if (cty->size() == 4) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
418 uint32_t* str = (uint32_t*)string; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
419 std::vector<LLConstant*> vals; |
1395
6063ddfcf27d
Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1378
diff
changeset
|
420 vals.reserve(len+1); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
421 for(size_t i=0; i<len; ++i) { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
422 vals.push_back(llvm::ConstantInt::get(ct, str[i], false));; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
423 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
424 vals.push_back(llvm::ConstantInt::get(ct, 0, false)); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
425 _init = llvm::ConstantArray::get(at,vals); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
426 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
427 else |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
428 assert(0); |
1 | 429 |
918
a4fcc13da3cd
Changed templates and typeinfo to use linkonce linkage instead of weak linkage, this should fix inlining problems, fixing bug #197 . If problems show up, it's easy to change it back by changing the define in mars.h . I'm 95% sure this is safe, given how we handle templates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
915
diff
changeset
|
430 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
431 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
432 Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n'; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
433 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(at,true,_linkage,_init,".str",gIR->module); |
1 | 434 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
435 llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
436 LLConstant* idxs[2] = { zero, zero }; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
437 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
1 | 438 |
40 | 439 if (dtype->ty == Tarray) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
440 LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); |
720
e177ae483f8e
Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
719
diff
changeset
|
441 return new DImValue(type, DtoConstSlice(clen, arrptr)); |
1 | 442 } |
40 | 443 else if (dtype->ty == Tsarray) { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
444 const LLType* dstType = getPtrToType(LLArrayType::get(ct, len)); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
445 LLValue* emem = (gvar->getType() == dstType) ? gvar : DtoBitCast(gvar, dstType); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
446 return new DVarValue(type, emem); |
21
8d45266bbabe
[svn r25] * Fixed a lot of problems with string literals
lindquist
parents:
18
diff
changeset
|
447 } |
40 | 448 else if (dtype->ty == Tpointer) { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
449 return new DImValue(type, arrptr); |
1 | 450 } |
451 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
452 assert(0); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
453 return 0; |
1 | 454 } |
455 | |
456 ////////////////////////////////////////////////////////////////////////////////////////// | |
457 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
458 LLConstant* StringExp::toConstElem(IRState* p) |
40 | 459 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
460 Logger::print("StringExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 461 LOG_SCOPE; |
462 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
463 Type* t = type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
464 Type* cty = t->nextOf()->toBasetype(); |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
465 |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
466 bool nullterm = (t->ty != Tsarray); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
467 size_t endlen = nullterm ? len+1 : len; |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
468 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
469 const LLType* ct = DtoType(cty); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
470 const LLArrayType* at = LLArrayType::get(ct,endlen); |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
471 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
472 LLConstant* _init; |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
473 if (cty->size() == 1) { |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
474 uint8_t* str = (uint8_t*)string; |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
475 std::string cont((char*)str, len); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
476 _init = llvm::ConstantArray::get(cont, nullterm); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
477 } |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
478 else if (cty->size() == 2) { |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
479 uint16_t* str = (uint16_t*)string; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
480 std::vector<LLConstant*> vals; |
1395
6063ddfcf27d
Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1378
diff
changeset
|
481 vals.reserve(len+1); |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
482 for(size_t i=0; i<len; ++i) { |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
483 vals.push_back(llvm::ConstantInt::get(ct, str[i], false));; |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
484 } |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
485 if (nullterm) |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
486 vals.push_back(llvm::ConstantInt::get(ct, 0, false)); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
487 _init = llvm::ConstantArray::get(at,vals); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
488 } |
183
3cdf4b0c75a1
[svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents:
178
diff
changeset
|
489 else if (cty->size() == 4) { |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
490 uint32_t* str = (uint32_t*)string; |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
491 std::vector<LLConstant*> vals; |
1395
6063ddfcf27d
Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1378
diff
changeset
|
492 vals.reserve(len+1); |
176
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
493 for(size_t i=0; i<len; ++i) { |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
494 vals.push_back(llvm::ConstantInt::get(ct, str[i], false));; |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
495 } |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
496 if (nullterm) |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
497 vals.push_back(llvm::ConstantInt::get(ct, 0, false)); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
498 _init = llvm::ConstantArray::get(at,vals); |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
499 } |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
500 else |
a074a5ff709c
[svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents:
175
diff
changeset
|
501 assert(0); |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
502 |
178
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
503 if (t->ty == Tsarray) |
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
504 { |
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
505 return _init; |
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
506 } |
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
507 |
918
a4fcc13da3cd
Changed templates and typeinfo to use linkonce linkage instead of weak linkage, this should fix inlining problems, fixing bug #197 . If problems show up, it's easy to change it back by changing the define in mars.h . I'm 95% sure this is safe, given how we handle templates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
915
diff
changeset
|
508 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
509 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(_init->getType(),true,_linkage,_init,".str",gIR->module); |
40 | 510 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
511 llvm::ConstantInt* zero = llvm::ConstantInt::get(LLType::Int32Ty, 0, false); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
512 LLConstant* idxs[2] = { zero, zero }; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
513 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2); |
40 | 514 |
515 if (t->ty == Tpointer) { | |
516 return arrptr; | |
517 } | |
178
8873b7f1457e
[svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents:
177
diff
changeset
|
518 else if (t->ty == Tarray) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
519 LLConstant* clen = llvm::ConstantInt::get(DtoSize_t(),len,false); |
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
|
520 return DtoConstSlice(clen, arrptr); |
40 | 521 } |
522 | |
523 assert(0); | |
524 return NULL; | |
525 } | |
526 | |
527 ////////////////////////////////////////////////////////////////////////////////////////// | |
528 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
529 DValue* AssignExp::toElem(IRState* p) |
1 | 530 { |
467
261b05cf4d1c
Fixed problem in AssignExp where the result value might be uninitialized. see mini/assign1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
464
diff
changeset
|
531 Logger::print("AssignExp::toElem: %s | (%s)(%s = %s)\n", toChars(), type->toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0); |
1 | 532 LOG_SCOPE; |
533 | |
335
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
534 if (e1->op == TOKarraylength) |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
535 { |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
536 Logger::println("performing array.length assignment"); |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
537 ArrayLengthExp *ale = (ArrayLengthExp *)e1; |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
538 DValue* arr = ale->e1->toElem(p); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
539 DVarValue arrval(ale->e1->type, arr->getLVal()); |
335
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
540 DValue* newlen = e2->toElem(p); |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
541 DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
542 DtoAssign(loc, &arrval, slice); |
335
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
543 return newlen; |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
544 } |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
545 |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
546 Logger::println("performing normal assignment"); |
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
547 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
548 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
549 DValue* r = e2->toElem(p); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
550 DtoAssign(loc, l, r); |
92 | 551 |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
552 if (l->isSlice()) |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
553 return l; |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
554 |
468
45a67b6f1310
Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
467
diff
changeset
|
555 return r; |
1 | 556 } |
557 | |
558 ////////////////////////////////////////////////////////////////////////////////////////// | |
559 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
560 /// Finds the proper lvalue for a binassign expressions. |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
561 /// Makes sure the given LHS expression is only evaluated once. |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
562 static Expression* findLvalue(IRState* irs, Expression* exp) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
563 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
564 Expression* e = exp; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
565 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
566 // skip past any casts |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
567 while(e->op == TOKcast) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
568 e = ((CastExp*)e)->e1; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
569 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
570 // cache lvalue and return |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
571 e->cacheLvalue(irs); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
572 return e; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
573 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
574 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
575 #define BIN_ASSIGN(X) \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
576 DValue* X##AssignExp::toElem(IRState* p) \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
577 { \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
578 Logger::print(#X"AssignExp::toElem: %s @ %s\n", toChars(), type->toChars()); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
579 LOG_SCOPE; \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
580 X##Exp e3(loc, e1, e2); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
581 e3.type = e1->type; \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
582 DValue* dst = findLvalue(p, e1)->toElem(p); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
583 DValue* res = e3.toElem(p); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
584 DValue* stval = DtoCast(loc, res, dst->getType()); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
585 DtoAssign(loc, dst, stval); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
586 return DtoCast(loc, res, type); \ |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
587 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
588 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
589 BIN_ASSIGN(Add) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
590 BIN_ASSIGN(Min) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
591 BIN_ASSIGN(Mul) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
592 BIN_ASSIGN(Div) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
593 BIN_ASSIGN(Mod) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
594 BIN_ASSIGN(And) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
595 BIN_ASSIGN(Or) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
596 BIN_ASSIGN(Xor) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
597 BIN_ASSIGN(Shl) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
598 BIN_ASSIGN(Shr) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
599 BIN_ASSIGN(Ushr) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
600 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
601 #undef BIN_ASSIGN |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
602 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
603 ////////////////////////////////////////////////////////////////////////////////////////// |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
604 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
605 static void errorOnIllegalArrayOp(Expression* base, Expression* e1, Expression* e2) |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
606 { |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
607 Type* t1 = e1->type->toBasetype(); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
608 Type* t2 = e2->type->toBasetype(); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
609 |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
610 // valid array ops would have been transformed by optimize |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
611 if ((t1->ty == Tarray || t1->ty == Tsarray) && |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
612 (t2->ty == Tarray || t2->ty == Tsarray) |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
613 ) |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
614 { |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
615 error("Array operation %s not recognized", base->toChars()); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
616 fatal(); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
617 } |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
618 } |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
619 |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
620 ////////////////////////////////////////////////////////////////////////////////////////// |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
621 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
622 DValue* AddExp::toElem(IRState* p) |
1 | 623 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
624 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 625 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
626 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
627 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
628 DValue* r = e2->toElem(p); |
1 | 629 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
630 Type* t = type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
631 Type* e1type = e1->type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
632 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL; |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
633 Type* e2type = e2->type->toBasetype(); |
40 | 634 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
635 errorOnIllegalArrayOp(this, e1, e2); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
636 |
40 | 637 if (e1type != e2type) { |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
638 if (e1type->ty == Tpointer) { |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
639 Logger::println("add to pointer"); |
1166
c6f39553b702
Clean up some suspicious code.
Frits van Bommel <fvbommel wxs.nl>
parents:
1161
diff
changeset
|
640 if (DConstValue* cv = r->isConst()) { |
c6f39553b702
Clean up some suspicious code.
Frits van Bommel <fvbommel wxs.nl>
parents:
1161
diff
changeset
|
641 if (cv->c->isNullValue()) { |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
642 Logger::println("is zero"); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
643 return new DImValue(type, l->getRVal()); |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
644 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
645 } |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
646 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
647 return new DImValue(type, v); |
1 | 648 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
649 else if (t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
650 return DtoComplexAdd(loc, type, l, r); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
651 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
652 assert(0); |
1 | 653 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
654 else if (t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
655 return DtoComplexAdd(loc, type, l, r); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
656 } |
1 | 657 else { |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
658 return DtoBinAdd(l,r); |
1 | 659 } |
660 } | |
661 | |
662 ////////////////////////////////////////////////////////////////////////////////////////// | |
663 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
664 DValue* MinExp::toElem(IRState* p) |
1 | 665 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
666 Logger::print("MinExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 667 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
668 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
669 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
670 DValue* r = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
671 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
672 Type* t = type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
673 Type* t1 = e1->type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
674 Type* t2 = e2->type->toBasetype(); |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
675 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
676 errorOnIllegalArrayOp(this, e1, e2); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
677 |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
678 if (t1->ty == Tpointer && t2->ty == Tpointer) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
679 LLValue* lv = l->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
680 LLValue* rv = r->getRVal(); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
681 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
682 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n'; |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
683 lv = p->ir->CreatePtrToInt(lv, DtoSize_t(), "tmp"); |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
684 rv = p->ir->CreatePtrToInt(rv, DtoSize_t(), "tmp"); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
685 LLValue* diff = p->ir->CreateSub(lv,rv,"tmp"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
686 if (diff->getType() != DtoType(type)) |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
687 diff = p->ir->CreateIntToPtr(diff, DtoType(type), "tmp"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
688 return new DImValue(type, diff); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
689 } |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
690 else if (t1->ty == Tpointer) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
691 LLValue* idx = p->ir->CreateNeg(r->getRVal(), "tmp"); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
692 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), idx, "tmp", p->scopebb()); |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
693 return new DImValue(type, v); |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
694 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
695 else if (t->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
696 return DtoComplexSub(loc, type, l, r); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
697 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
698 else { |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
699 return DtoBinSub(l,r); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
700 } |
1 | 701 } |
702 | |
703 ////////////////////////////////////////////////////////////////////////////////////////// | |
704 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
705 DValue* MulExp::toElem(IRState* p) |
1 | 706 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
707 Logger::print("MulExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 708 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
709 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
710 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
711 DValue* r = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
712 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
713 errorOnIllegalArrayOp(this, e1, e2); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
714 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
715 if (type->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
716 return DtoComplexMul(loc, type, l, r); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
717 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
718 |
524
ca2dfe98036c
Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents:
521
diff
changeset
|
719 return DtoBinMul(type, l, r); |
1 | 720 } |
721 | |
722 ////////////////////////////////////////////////////////////////////////////////////////// | |
723 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
724 DValue* DivExp::toElem(IRState* p) |
1 | 725 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
726 Logger::print("DivExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 727 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
728 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
729 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
730 DValue* r = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
731 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
732 errorOnIllegalArrayOp(this, e1, e2); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
733 |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
734 if (type->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
735 return DtoComplexDiv(loc, type, l, r); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
736 } |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
737 |
524
ca2dfe98036c
Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents:
521
diff
changeset
|
738 return DtoBinDiv(type, l, r); |
1 | 739 } |
740 | |
741 ////////////////////////////////////////////////////////////////////////////////////////// | |
742 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
743 DValue* ModExp::toElem(IRState* p) |
1 | 744 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
745 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 746 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
747 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
748 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
749 DValue* r = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
750 |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
751 errorOnIllegalArrayOp(this, e1, e2); |
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
752 |
524
ca2dfe98036c
Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents:
521
diff
changeset
|
753 return DtoBinRem(type, l, r); |
1 | 754 } |
755 | |
756 ////////////////////////////////////////////////////////////////////////////////////////// | |
757 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
758 DValue* CallExp::toElem(IRState* p) |
1 | 759 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
760 Logger::print("CallExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 761 LOG_SCOPE; |
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
|
762 |
1152
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
763 // handle magic inline asm |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
764 if (e1->op == TOKvar) |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
765 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
766 VarExp* ve = (VarExp*)e1; |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
767 if (FuncDeclaration* fd = ve->var->isFuncDeclaration()) |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
768 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
769 if (fd->llvmInternal == LLVMinline_asm) |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
770 { |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
771 return DtoInlineAsmExpr(loc, fd, arguments); |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
772 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
773 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
774 } |
521dd1626d76
Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1151
diff
changeset
|
775 |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
776 // get the callee value |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
777 DValue* fnval = e1->toElem(p); |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
778 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
779 // get func value if any |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
780 DFuncValue* dfnval = fnval->isFunc(); |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
781 |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
782 // handle magic intrinsics (mapping to instructions) |
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
|
783 bool va_intrinsic = false; |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
784 if (dfnval && dfnval->func) |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
785 { |
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
786 FuncDeclaration* fndecl = dfnval->func; |
215
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
213
diff
changeset
|
787 // va_start instruction |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
788 if (fndecl->llvmInternal == LLVMva_start) { |
443
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
440
diff
changeset
|
789 // llvm doesn't need the second param hence the override |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
440
diff
changeset
|
790 Expression* exp = (Expression*)arguments->data[0]; |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
440
diff
changeset
|
791 DValue* expv = exp->toElem(p); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
440
diff
changeset
|
792 LLValue* arg = DtoBitCast(expv->getLVal(), getVoidPtrType()); |
44f08170f4ef
Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
440
diff
changeset
|
793 return new DImValue(type, gIR->ir->CreateCall(GET_INTRINSIC_DECL(vastart), arg, "")); |
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
|
794 } |
215
a58d8f4b84df
[svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents:
213
diff
changeset
|
795 // va_arg instruction |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
796 else if (fndecl->llvmInternal == LLVMva_arg) { |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
797 return DtoVaArg(loc, type, (Expression*)arguments->data[0]); |
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
|
798 } |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
799 // C alloca |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
800 else if (fndecl->llvmInternal == LLVMalloca) { |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
801 Expression* exp = (Expression*)arguments->data[0]; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
802 DValue* expv = exp->toElem(p); |
132 | 803 if (expv->getType()->toBasetype()->ty != Tint32) |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
804 expv = DtoCast(loc, expv, Type::tint32); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
805 return new DImValue(type, p->ir->CreateAlloca(LLType::Int8Ty, expv->getRVal(), ".alloca")); |
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
|
806 } |
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
|
807 } |
414
ac1fcc138e42
Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
399
diff
changeset
|
808 |
422
fa91b03d9cd7
Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents:
414
diff
changeset
|
809 return DtoCallFunction(loc, type, fnval, arguments); |
1 | 810 } |
811 | |
812 ////////////////////////////////////////////////////////////////////////////////////////// | |
813 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
814 DValue* CastExp::toElem(IRState* p) |
1 | 815 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
816 Logger::print("CastExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 817 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
818 |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
819 // get the value to cast |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
820 DValue* u = e1->toElem(p); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
821 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
822 // cast it to the 'to' type, if necessary |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
823 DValue* v = u; |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
824 if (!to->equals(e1->type)) |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
825 v = DtoCast(loc, u, to); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
826 |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
827 // paint the type, if necessary |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
828 if (!type->equals(to)) |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
829 v = DtoPaintType(loc, v, type); |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
830 |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
831 // return the new rvalue |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
832 return v; |
1 | 833 } |
834 | |
835 ////////////////////////////////////////////////////////////////////////////////////////// | |
836 | |
619
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
837 LLConstant* CastExp::toConstElem(IRState* p) |
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
838 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
839 Logger::print("CastExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
619
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
840 LOG_SCOPE; |
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
841 |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
842 LLConstant* res; |
619
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
843 const LLType* lltype = DtoType(type); |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
844 Type* tb = to->toBasetype(); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
845 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
846 // string literal to dyn array: |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
847 // reinterpret the string data as an array, calculate the length |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
848 if (e1->op == TOKstring && tb->ty == Tarray) { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
849 /* StringExp *strexp = (StringExp*)e1; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
850 size_t datalen = strexp->sz * strexp->len; |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
851 Type* eltype = tb->nextOf()->toBasetype(); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
852 if (datalen % eltype->size() != 0) { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
853 error("the sizes don't line up"); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
854 return e1->toConstElem(p); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
855 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
856 size_t arrlen = datalen / eltype->size();*/ |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
857 error("ct cast of string to dynamic array not fully implemented"); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
858 return e1->toConstElem(p); |
624
eb444ed4a2d3
Make invalid compile time casts an error instead of asserting.
Christian Kamm <kamm incasoftware de>
parents:
622
diff
changeset
|
859 } |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
860 // pointer to pointer |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
861 else if (tb->ty == Tpointer && e1->type->toBasetype()->ty == Tpointer) { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
862 res = llvm::ConstantExpr::getBitCast(e1->toConstElem(p), lltype); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
863 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
864 else { |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
865 error("can not cast %s to %s at compile time", e1->type->toChars(), type->toChars()); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
866 return e1->toConstElem(p); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
867 } |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
868 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
869 return res; |
619
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
870 } |
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
871 |
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
872 ////////////////////////////////////////////////////////////////////////////////////////// |
722630261d62
Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents:
616
diff
changeset
|
873 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
874 DValue* SymOffExp::toElem(IRState* p) |
1 | 875 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
876 Logger::print("SymOffExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 877 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
878 |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
879 assert(0 && "SymOffExp::toElem should no longer be called :/"); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
880 return 0; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
881 } |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
882 |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
883 ////////////////////////////////////////////////////////////////////////////////////////// |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
884 |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
885 DValue* AddrExp::toElem(IRState* p) |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
886 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
887 Logger::println("AddrExp::toElem: %s @ %s", toChars(), type->toChars()); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
888 LOG_SCOPE; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
889 DValue* v = e1->toElem(p); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
890 if (v->isField()) { |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
891 Logger::println("is field"); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
892 return v; |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
893 } |
100 | 894 else if (DFuncValue* fv = v->isFunc()) { |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
895 Logger::println("is func"); |
100 | 896 //Logger::println("FuncDeclaration"); |
94
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
897 FuncDeclaration* fd = fv->func; |
61615fa85940
[svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents:
92
diff
changeset
|
898 assert(fd); |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
899 fd->codegen(Type::sir); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
900 return new DFuncValue(fd, fd->ir.irFunc->func); |
1 | 901 } |
101
169fda3a77d4
[svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents:
100
diff
changeset
|
902 else if (DImValue* im = v->isIm()) { |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
903 Logger::println("is immediate"); |
101
169fda3a77d4
[svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents:
100
diff
changeset
|
904 return v; |
169fda3a77d4
[svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents:
100
diff
changeset
|
905 } |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
906 Logger::println("is nothing special"); |
820
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
907 |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
908 // we special case here, since apparently taking the address of a slice is ok |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
909 LLValue* lval; |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
910 if (v->isLVal()) |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
911 lval = v->getLVal(); |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
912 else |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
913 { |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
914 assert(v->isSlice()); |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
915 LLValue* rval = v->getRVal(); |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
916 lval = DtoRawAlloca(rval->getType(), 0, ".tmp_slice_storage"); |
820
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
917 DtoStore(rval, lval); |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
918 } |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
919 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
920 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
921 Logger::cout() << "lval: " << *lval << '\n'; |
820
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
922 |
bb4a81e68ddb
Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
819
diff
changeset
|
923 return new DImValue(type, DtoBitCast(lval, DtoType(type))); |
1 | 924 } |
925 | |
459
9db9099583ca
Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents:
452
diff
changeset
|
926 LLConstant* AddrExp::toConstElem(IRState* p) |
9db9099583ca
Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents:
452
diff
changeset
|
927 { |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
928 // FIXME: this should probably be generalized more so we don't |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
929 // need to have a case for each thing we can take the address of |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
930 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
931 // address of global variable |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
932 if (e1->op == TOKvar) |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
933 { |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
934 VarExp* vexp = (VarExp*)e1; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
935 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
936 // make sure 'this' isn't needed |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
937 if (vexp->var->needThis()) |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
938 { |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
939 error("need 'this' to access %s", vexp->var->toChars()); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
940 fatal(); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
941 } |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
942 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
943 // global variable |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
944 if (VarDeclaration* vd = vexp->var->isVarDeclaration()) |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
945 { |
1149
5ebe8224988b
Fixed problems introduced by previous commits that prevented Tango from compiling.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1148
diff
changeset
|
946 vd->codegen(Type::sir); |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
947 LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue()); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
948 assert(llc); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
949 return llc; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
950 } |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
951 // static function |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
952 else if (FuncDeclaration* fd = vexp->var->isFuncDeclaration()) |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
953 { |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
954 fd->codegen(Type::sir); |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
955 IrFunction* irfunc = fd->ir.irFunc; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
956 return irfunc->func; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
957 } |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
958 // something else |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
959 else |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
960 { |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
961 // fail |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
962 goto Lerr; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
963 } |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
964 } |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
965 // address of indexExp |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
966 else if (e1->op == TOKindex) |
469
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
967 { |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
968 IndexExp* iexp = (IndexExp*)e1; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
969 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
970 // indexee must be global static array var |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
971 assert(iexp->e1->op == TOKvar); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
972 VarExp* vexp = (VarExp*)iexp->e1; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
973 VarDeclaration* vd = vexp->var->isVarDeclaration(); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
974 assert(vd); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
975 assert(vd->type->toBasetype()->ty == Tsarray); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
976 assert(vd->ir.irGlobal); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
977 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
978 // get index |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
979 LLConstant* index = iexp->e2->toConstElem(p); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
980 assert(index->getType() == DtoSize_t()); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
981 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
982 // gep |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
983 LLConstant* idxs[2] = { DtoConstSize_t(0), index }; |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
984 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(isaConstant(vd->ir.irGlobal->value), idxs, 2); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
985 |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
986 // bitcast to requested type |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
987 assert(type->toBasetype()->ty == Tpointer); |
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
988 return DtoBitCast(gep, DtoType(type)); |
469
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
989 } |
857
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
990 else if (e1->op == TOKstructliteral) |
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
991 { |
1231
212ec2d9d176
Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
992 // FIXME: is this right? |
857
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
993 StructLiteralExp* slexp = (StructLiteralExp*)e1; |
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
994 LLConstant* lit = slexp->toConstElem(p); |
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
995 return lit; |
217e8c719a2f
Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents:
837
diff
changeset
|
996 } |
469
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
997 // not yet supported |
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
998 else |
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
999 { |
819
446263a8a30d
Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
809
diff
changeset
|
1000 Lerr: |
469
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
1001 error("constant expression '%s' not yet implemented", toChars()); |
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
1002 fatal(); |
d0dad1fe0f45
Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
468
diff
changeset
|
1003 } |
459
9db9099583ca
Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents:
452
diff
changeset
|
1004 } |
9db9099583ca
Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents:
452
diff
changeset
|
1005 |
1 | 1006 ////////////////////////////////////////////////////////////////////////////////////////// |
1007 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1008 void PtrExp::cacheLvalue(IRState* p) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1009 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1010 Logger::println("Caching l-value of %s", toChars()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1011 LOG_SCOPE; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1012 cachedLvalue = e1->toElem(p)->getRVal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1013 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1014 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1015 DValue* PtrExp::toElem(IRState* p) |
1 | 1016 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1017 Logger::println("PtrExp::toElem: %s @ %s", toChars(), type->toChars()); |
1 | 1018 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1019 |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1020 // function pointers are special |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1021 if (type->toBasetype()->ty == Tfunction) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1022 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1023 assert(!cachedLvalue); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1024 return new DImValue(type, e1->toElem(p)->getRVal()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1025 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1026 |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1027 // get the rvalue and return it as an lvalue |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1028 LLValue* V; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1029 if (cachedLvalue) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1030 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1031 V = cachedLvalue; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1032 cachedLvalue = NULL; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1033 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1034 else |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1035 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1036 V = e1->toElem(p)->getRVal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1037 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1038 return new DVarValue(type, V); |
1 | 1039 } |
1040 | |
1041 ////////////////////////////////////////////////////////////////////////////////////////// | |
1042 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1043 void DotVarExp::cacheLvalue(IRState* p) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1044 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1045 Logger::println("Caching l-value of %s", toChars()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1046 LOG_SCOPE; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1047 cachedLvalue = toElem(p)->getLVal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1048 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1049 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1050 DValue* DotVarExp::toElem(IRState* p) |
1 | 1051 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1052 Logger::print("DotVarExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1053 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1054 |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1055 if (cachedLvalue) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1056 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1057 LLValue *V = cachedLvalue; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1058 cachedLvalue = NULL; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1059 VarDeclaration* vd = var->isVarDeclaration(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1060 assert(vd); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1061 return new DVarValue(type, vd, V); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1062 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1063 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1064 DValue* l = e1->toElem(p); |
1 | 1065 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1066 Type* t = type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1067 Type* e1type = e1->type->toBasetype(); |
40 | 1068 |
172
68a7dd38c03c
[svn r188] Fixed using a dereferenced pointer argument as both l- and r-value. fixes tango.io.FileRoots.
lindquist
parents:
170
diff
changeset
|
1069 //Logger::println("e1type=%s", e1type->toChars()); |
68a7dd38c03c
[svn r188] Fixed using a dereferenced pointer argument as both l- and r-value. fixes tango.io.FileRoots.
lindquist
parents:
170
diff
changeset
|
1070 //Logger::cout() << *DtoType(e1type) << '\n'; |
1 | 1071 |
1072 if (VarDeclaration* vd = var->isVarDeclaration()) { | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1073 LLValue* arrptr; |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1074 // indexing struct pointer |
40 | 1075 if (e1type->ty == Tpointer) { |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
1076 assert(e1type->nextOf()->ty == Tstruct); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
1077 TypeStruct* ts = (TypeStruct*)e1type->nextOf(); |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1078 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); |
1 | 1079 } |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1080 // indexing normal struct |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1081 else if (e1type->ty == Tstruct) { |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1082 TypeStruct* ts = (TypeStruct*)e1type; |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1083 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1084 } |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1085 // indexing class |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1086 else if (e1type->ty == Tclass) { |
40 | 1087 TypeClass* tc = (TypeClass*)e1type; |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1088 arrptr = DtoIndexClass(l->getRVal(), tc->sym, vd); |
1 | 1089 } |
77
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
76
diff
changeset
|
1090 else |
714057ff2dbb
[svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents:
76
diff
changeset
|
1091 assert(0); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1092 |
123
7f9a0a58394b
[svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents:
122
diff
changeset
|
1093 //Logger::cout() << "mem: " << *arrptr << '\n'; |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1094 return new DVarValue(type, vd, arrptr); |
1 | 1095 } |
1096 else if (FuncDeclaration* fdecl = var->isFuncDeclaration()) | |
1097 { | |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1098 DtoResolveDsymbol(fdecl); |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1099 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1100 LLValue* funcval; |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1101 LLValue* vthis2 = 0; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1102 if (e1type->ty == Tclass) { |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1103 TypeClass* tc = (TypeClass*)e1type; |
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1104 if (tc->sym->isInterfaceDeclaration()) { |
114 | 1105 vthis2 = DtoCastInterfaceToObject(l, NULL)->getRVal(); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1106 } |
1 | 1107 } |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1108 LLValue* vthis = l->getRVal(); |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1109 if (!vthis2) vthis2 = vthis; |
1 | 1110 |
1136 | 1111 // |
1112 // decide whether this function needs to be looked up in the vtable | |
1113 // | |
1114 bool vtbllookup = fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual()); | |
1115 | |
1116 // even virtual functions are looked up directly if super or DotTypeExp | |
1117 // are used, thus we need to walk through the this expression and check | |
1118 Expression* e = e1; | |
1119 while (e && vtbllookup) { | |
1120 if (e->op == TOKsuper || e->op == TOKdottype) | |
1121 vtbllookup = false; | |
1122 else if (e->op == TOKcast) | |
1123 e = ((CastExp*)e)->e1; | |
1124 else | |
1125 break; | |
1126 } | |
1127 | |
1128 // | |
1129 // look up function | |
1130 // | |
1131 if (!vtbllookup) { | |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1132 fdecl->codegen(Type::sir); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
1133 funcval = fdecl->ir.irFunc->func; |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1134 assert(funcval); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1135 } |
1136 | 1136 else { |
1 | 1137 assert(fdecl->vtblIndex > 0); |
40 | 1138 assert(e1type->ty == Tclass); |
1 | 1139 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
1140 LLValue* zero = DtoConstUint(0); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
1141 size_t vtblidx = fdecl->vtblIndex; |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1142 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1143 Logger::cout() << "vthis: " << *vthis << '\n'; |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
1144 funcval = DtoGEP(vthis, zero, zero); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1145 funcval = DtoLoad(funcval); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
1146 Logger::println("vtblidx = %lu", vtblidx); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
1147 funcval = DtoGEP(funcval, zero, DtoConstUint(vtblidx), toChars()); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1148 funcval = DtoLoad(funcval); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
1149 |
193
aca17e55b7a5
[svn r209] Fixed: exotic array to pointer casts were broken.
lindquist
parents:
183
diff
changeset
|
1150 funcval = DtoBitCast(funcval, getPtrToType(DtoType(fdecl->type))); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1151 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1152 Logger::cout() << "funcval casted: " << *funcval << '\n'; |
1 | 1153 } |
1136 | 1154 |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1155 return new DFuncValue(fdecl, funcval, vthis2); |
1 | 1156 } |
1157 else { | |
123
7f9a0a58394b
[svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents:
122
diff
changeset
|
1158 printf("unsupported dotvarexp: %s\n", var->toChars()); |
1 | 1159 } |
1160 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1161 assert(0); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1162 return 0; |
1 | 1163 } |
1164 | |
1165 ////////////////////////////////////////////////////////////////////////////////////////// | |
1166 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1167 DValue* ThisExp::toElem(IRState* p) |
1 | 1168 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1169 Logger::print("ThisExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1170 LOG_SCOPE; |
1171 | |
328
7086a84ab3d6
[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents:
321
diff
changeset
|
1172 // regular this expr |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1173 if (VarDeclaration* vd = var->isVarDeclaration()) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1174 LLValue* v; |
452
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1175 if (vd->toParent2() != p->func()->decl) { |
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1176 Logger::println("nested this exp"); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1177 return DtoNestedVariable(loc, type, vd); |
452
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1178 } |
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1179 else { |
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1180 Logger::println("normal this exp"); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1181 v = p->func()->thisArg; |
452
30ef3c7bddca
Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
445
diff
changeset
|
1182 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1183 return new DVarValue(type, vd, v); |
1 | 1184 } |
1185 | |
328
7086a84ab3d6
[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents:
321
diff
changeset
|
1186 // anything we're not yet handling ? |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1187 assert(0 && "no var in ThisExp"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1188 return 0; |
1 | 1189 } |
1190 | |
1191 ////////////////////////////////////////////////////////////////////////////////////////// | |
1192 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1193 void IndexExp::cacheLvalue(IRState* p) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1194 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1195 Logger::println("Caching l-value of %s", toChars()); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1196 LOG_SCOPE; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1197 cachedLvalue = toElem(p)->getLVal(); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1198 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1199 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1200 DValue* IndexExp::toElem(IRState* p) |
1 | 1201 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1202 Logger::print("IndexExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1203 LOG_SCOPE; |
1204 | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1205 if (cachedLvalue) |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1206 { |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1207 LLValue* V = cachedLvalue; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1208 cachedLvalue = NULL; |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1209 return new DVarValue(type, V); |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1210 } |
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1211 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1212 DValue* l = e1->toElem(p); |
1 | 1213 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1214 Type* e1type = e1->type->toBasetype(); |
40 | 1215 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1216 p->arrays.push_back(l); // if $ is used it must be an array so this is fine. |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1217 DValue* r = e2->toElem(p); |
1 | 1218 p->arrays.pop_back(); |
1219 | |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1220 LLValue* zero = DtoConstUint(0); |
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1221 LLValue* one = DtoConstUint(1); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1222 |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1223 LLValue* arrptr = 0; |
40 | 1224 if (e1type->ty == Tpointer) { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1225 arrptr = DtoGEP1(l->getRVal(),r->getRVal()); |
1 | 1226 } |
40 | 1227 else if (e1type->ty == Tsarray) { |
439
47b64d06eb9f
Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents:
435
diff
changeset
|
1228 if(global.params.useArrayBounds) |
440
d8dc221d3db7
Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents:
439
diff
changeset
|
1229 DtoArrayBoundsCheck(loc, l, r, false); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1230 arrptr = DtoGEP(l->getRVal(), zero, r->getRVal()); |
1 | 1231 } |
40 | 1232 else if (e1type->ty == Tarray) { |
439
47b64d06eb9f
Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents:
435
diff
changeset
|
1233 if(global.params.useArrayBounds) |
440
d8dc221d3db7
Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents:
439
diff
changeset
|
1234 DtoArrayBoundsCheck(loc, l, r, false); |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
268
diff
changeset
|
1235 arrptr = DtoArrayPtr(l); |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1236 arrptr = DtoGEP1(arrptr,r->getRVal()); |
1 | 1237 } |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1238 else if (e1type->ty == Taarray) { |
458
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
452
diff
changeset
|
1239 return DtoAAIndex(loc, type, l, r, modifiable); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1240 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1241 else { |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1242 Logger::println("invalid index exp! e1type: %s", e1type->toChars()); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1243 assert(0); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
1244 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1245 return new DVarValue(type, arrptr); |
1 | 1246 } |
1247 | |
1248 ////////////////////////////////////////////////////////////////////////////////////////// | |
1249 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1250 DValue* SliceExp::toElem(IRState* p) |
1 | 1251 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1252 Logger::print("SliceExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1253 LOG_SCOPE; |
1254 | |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1255 // this is the new slicing code, it's different in that a full slice will no longer retain the original pointer. |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1256 // but this was broken if there *was* no original pointer, ie. a slice of a slice... |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1257 // now all slices have *both* the 'len' and 'ptr' fields set to != null. |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1258 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1259 // value being sliced |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1260 LLValue* elen; |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1261 LLValue* eptr; |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1262 DValue* e = e1->toElem(p); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1263 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1264 // handle pointer slicing |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1265 Type* etype = e1->type->toBasetype(); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1266 if (etype->ty == Tpointer) |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1267 { |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1268 assert(lwr); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1269 eptr = e->getRVal(); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1270 } |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1271 // array slice |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1272 else |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1273 { |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1274 eptr = DtoArrayPtr(e); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1275 } |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1276 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1277 // has lower bound, pointer needs adjustment |
1 | 1278 if (lwr) |
1279 { | |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1280 // must have upper bound too then |
1 | 1281 assert(upr); |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1282 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1283 // get bounds (make sure $ works) |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1284 p->arrays.push_back(e); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1285 DValue* lo = lwr->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1286 DValue* up = upr->toElem(p); |
1 | 1287 p->arrays.pop_back(); |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1288 LLValue* vlo = lo->getRVal(); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1289 LLValue* vup = up->getRVal(); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1290 |
440
d8dc221d3db7
Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents:
439
diff
changeset
|
1291 if(global.params.useArrayBounds && (etype->ty == Tsarray || etype->ty == Tarray)) |
d8dc221d3db7
Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents:
439
diff
changeset
|
1292 DtoArrayBoundsCheck(loc, e, up, true); |
d8dc221d3db7
Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents:
439
diff
changeset
|
1293 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1294 // offset by lower |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1295 eptr = DtoGEP1(eptr, vlo); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1296 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1297 // adjust length |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1298 elen = p->ir->CreateSub(vup, vlo, "tmp"); |
1 | 1299 } |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1300 // no bounds or full slice -> just convert to slice |
1 | 1301 else |
1302 { | |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1303 assert(e1->type->toBasetype()->ty != Tpointer); |
339
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1304 // if the sliceee is a static array, we use the length of that as DMD seems |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1305 // to give contrary inconsistent sizesin some multidimensional static array cases. |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1306 // (namely default initialization, int[16][16] arr; -> int[256] arr = 0;) |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1307 if (etype->ty == Tsarray) |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1308 { |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1309 TypeSArray* tsa = (TypeSArray*)etype; |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1310 elen = DtoConstSize_t(tsa->dim->toUInteger()); |
825
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
823
diff
changeset
|
1311 |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
823
diff
changeset
|
1312 // in this case, we also need to make sure the pointer is cast to the innermost element type |
a70ddd449e7d
Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
823
diff
changeset
|
1313 eptr = DtoBitCast(eptr, DtoType(tsa->nextOf()->pointerTo())); |
339
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1314 } |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1315 // for normal code the actual array length is what we want! |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1316 else |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1317 { |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1318 elen = DtoArrayLen(e); |
385a18242485
[svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents:
336
diff
changeset
|
1319 } |
1 | 1320 } |
1321 | |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
1322 return new DSliceValue(type, elen, eptr); |
1 | 1323 } |
1324 | |
1325 ////////////////////////////////////////////////////////////////////////////////////////// | |
1326 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1327 DValue* CmpExp::toElem(IRState* p) |
1 | 1328 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1329 Logger::print("CmpExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1330 LOG_SCOPE; |
1331 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1332 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1333 DValue* r = e2->toElem(p); |
1 | 1334 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1335 Type* t = e1->type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1336 Type* e2t = e2->type->toBasetype(); |
1 | 1337 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1338 LLValue* eval = 0; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1339 |
58
2c3cd3596187
[svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents:
57
diff
changeset
|
1340 if (t->isintegral() || t->ty == Tpointer) |
1 | 1341 { |
1342 llvm::ICmpInst::Predicate cmpop; | |
40 | 1343 bool skip = false; |
575
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1344 // pointers don't report as being unsigned |
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1345 bool uns = (t->isunsigned() || t->ty == Tpointer); |
1 | 1346 switch(op) |
1347 { | |
1348 case TOKlt: | |
40 | 1349 case TOKul: |
575
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1350 cmpop = uns ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT; |
1 | 1351 break; |
1352 case TOKle: | |
40 | 1353 case TOKule: |
575
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1354 cmpop = uns ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE; |
1 | 1355 break; |
1356 case TOKgt: | |
40 | 1357 case TOKug: |
575
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1358 cmpop = uns ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT; |
1 | 1359 break; |
1360 case TOKge: | |
40 | 1361 case TOKuge: |
575
f0c20d50d4b3
Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
574
diff
changeset
|
1362 cmpop = uns ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE; |
1 | 1363 break; |
40 | 1364 case TOKue: |
1365 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1366 break; | |
1367 case TOKlg: | |
1368 cmpop = llvm::ICmpInst::ICMP_NE; | |
1369 break; | |
1370 case TOKleg: | |
1371 skip = true; | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1372 eval = llvm::ConstantInt::getTrue(); |
40 | 1373 break; |
1374 case TOKunord: | |
1375 skip = true; | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1376 eval = llvm::ConstantInt::getFalse(); |
40 | 1377 break; |
1378 | |
1 | 1379 default: |
1380 assert(0); | |
1381 } | |
40 | 1382 if (!skip) |
1383 { | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1384 LLValue* a = l->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1385 LLValue* b = r->getRVal(); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1386 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1387 { |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1388 Logger::cout() << "type 1: " << *a << '\n'; |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1389 Logger::cout() << "type 2: " << *b << '\n'; |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
1390 } |
574
aee6217b4084
Fixed pointer comparisons with differing types.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
554
diff
changeset
|
1391 if (a->getType() != b->getType()) |
aee6217b4084
Fixed pointer comparisons with differing types.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
554
diff
changeset
|
1392 b = DtoBitCast(b, a->getType()); |
365 | 1393 eval = p->ir->CreateICmp(cmpop, a, b, "tmp"); |
40 | 1394 } |
1 | 1395 } |
1396 else if (t->isfloating()) | |
1397 { | |
1398 llvm::FCmpInst::Predicate cmpop; | |
1399 switch(op) | |
1400 { | |
1401 case TOKlt: | |
1402 cmpop = llvm::FCmpInst::FCMP_OLT;break; | |
1403 case TOKle: | |
1404 cmpop = llvm::FCmpInst::FCMP_OLE;break; | |
1405 case TOKgt: | |
1406 cmpop = llvm::FCmpInst::FCMP_OGT;break; | |
1407 case TOKge: | |
1408 cmpop = llvm::FCmpInst::FCMP_OGE;break; | |
1409 case TOKunord: | |
1410 cmpop = llvm::FCmpInst::FCMP_UNO;break; | |
1411 case TOKule: | |
1412 cmpop = llvm::FCmpInst::FCMP_ULE;break; | |
1413 case TOKul: | |
1414 cmpop = llvm::FCmpInst::FCMP_ULT;break; | |
1415 case TOKuge: | |
1416 cmpop = llvm::FCmpInst::FCMP_UGE;break; | |
1417 case TOKug: | |
1418 cmpop = llvm::FCmpInst::FCMP_UGT;break; | |
1419 case TOKue: | |
1420 cmpop = llvm::FCmpInst::FCMP_UEQ;break; | |
1421 case TOKlg: | |
1422 cmpop = llvm::FCmpInst::FCMP_ONE;break; | |
1423 case TOKleg: | |
1424 cmpop = llvm::FCmpInst::FCMP_ORD;break; | |
1425 | |
1426 default: | |
1427 assert(0); | |
1428 } | |
365 | 1429 eval = p->ir->CreateFCmp(cmpop, l->getRVal(), r->getRVal(), "tmp"); |
1 | 1430 } |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1431 else if (t->ty == Tsarray || t->ty == Tarray) |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1432 { |
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1433 Logger::println("static or dynamic array"); |
424
c8d98ccad0cc
Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents:
422
diff
changeset
|
1434 eval = DtoArrayCompare(loc,op,l,r); |
99
a676a7743642
[svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents:
98
diff
changeset
|
1435 } |
1 | 1436 else |
1437 { | |
1438 assert(0 && "Unsupported CmpExp type"); | |
1439 } | |
1440 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1441 return new DImValue(type, eval); |
1 | 1442 } |
1443 | |
1444 ////////////////////////////////////////////////////////////////////////////////////////// | |
1445 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1446 DValue* EqualExp::toElem(IRState* p) |
1 | 1447 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1448 Logger::print("EqualExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1449 LOG_SCOPE; |
1450 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1451 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1452 DValue* r = e2->toElem(p); |
1 | 1453 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1454 Type* t = e1->type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1455 Type* e2t = e2->type->toBasetype(); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
1456 //assert(t == e2t); |
1 | 1457 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1458 LLValue* eval = 0; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1459 |
512
0d286cd9fd08
Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents:
487
diff
changeset
|
1460 // the Tclass catches interface comparisons, regular |
0d286cd9fd08
Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents:
487
diff
changeset
|
1461 // class equality should be rewritten as a.opEquals(b) by this time |
0d286cd9fd08
Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents:
487
diff
changeset
|
1462 if (t->isintegral() || t->ty == Tpointer || t->ty == Tclass) |
1 | 1463 { |
512
0d286cd9fd08
Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents:
487
diff
changeset
|
1464 Logger::println("integral or pointer or interface"); |
1 | 1465 llvm::ICmpInst::Predicate cmpop; |
1466 switch(op) | |
1467 { | |
1468 case TOKequal: | |
1469 cmpop = llvm::ICmpInst::ICMP_EQ; | |
1470 break; | |
1471 case TOKnotequal: | |
1472 cmpop = llvm::ICmpInst::ICMP_NE; | |
1473 break; | |
1474 default: | |
1475 assert(0); | |
1476 } | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1477 LLValue* lv = l->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1478 LLValue* rv = r->getRVal(); |
108
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
1479 if (rv->getType() != lv->getType()) { |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
1480 rv = DtoBitCast(rv, lv->getType()); |
288fe1029e1f
[svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents:
107
diff
changeset
|
1481 } |
705
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1482 if (Logger::enabled()) |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1483 { |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1484 Logger::cout() << "lv: " << *lv << '\n'; |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1485 Logger::cout() << "rv: " << *rv << '\n'; |
5a2983f97498
Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
704
diff
changeset
|
1486 } |
365 | 1487 eval = p->ir->CreateICmp(cmpop, lv, rv, "tmp"); |
1 | 1488 } |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
1489 else if (t->iscomplex()) |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
1490 { |
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
1491 Logger::println("complex"); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
1492 eval = DtoComplexEquals(loc, op, l, r); |
104
4d1e9eb001e0
[svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents:
102
diff
changeset
|
1493 } |
1 | 1494 else if (t->isfloating()) |
1495 { | |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1496 Logger::println("floating"); |
1 | 1497 llvm::FCmpInst::Predicate cmpop; |
1498 switch(op) | |
1499 { | |
1500 case TOKequal: | |
1501 cmpop = llvm::FCmpInst::FCMP_OEQ; | |
1502 break; | |
1503 case TOKnotequal: | |
1504 cmpop = llvm::FCmpInst::FCMP_UNE; | |
1505 break; | |
1506 default: | |
1507 assert(0); | |
1508 } | |
365 | 1509 eval = p->ir->CreateFCmp(cmpop, l->getRVal(), r->getRVal(), "tmp"); |
1 | 1510 } |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
1511 else if (t->ty == Tsarray || t->ty == Tarray) |
40 | 1512 { |
98
6789050b5ad1
[svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents:
97
diff
changeset
|
1513 Logger::println("static or dynamic array"); |
424
c8d98ccad0cc
Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents:
422
diff
changeset
|
1514 eval = DtoArrayEquals(loc,op,l,r); |
1 | 1515 } |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1516 else if (t->ty == Tdelegate) |
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1517 { |
64
b688ad419f8c
[svn r68] Added support for multi-dimensional static arrays.
lindquist
parents:
62
diff
changeset
|
1518 Logger::println("delegate"); |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1519 eval = DtoDelegateEquals(op,l->getRVal(),r->getRVal()); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1520 } |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1521 else if (t->ty == Tstruct) |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1522 { |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1523 Logger::println("struct"); |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1524 // when this is reached it means there is no opEquals overload. |
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
1525 eval = DtoStructEquals(op,l,r); |
53
06ccc817acd4
[svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents:
52
diff
changeset
|
1526 } |
1 | 1527 else |
1528 { | |
1529 assert(0 && "Unsupported EqualExp type"); | |
1530 } | |
1531 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1532 return new DImValue(type, eval); |
1 | 1533 } |
1534 | |
1535 ////////////////////////////////////////////////////////////////////////////////////////// | |
1536 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1537 DValue* PostExp::toElem(IRState* p) |
1 | 1538 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1539 Logger::print("PostExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1540 LOG_SCOPE; |
1541 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1542 DValue* l = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1543 DValue* r = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1544 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1545 LLValue* val = l->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1546 LLValue* post = 0; |
1 | 1547 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1548 Type* e1type = e1->type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1549 Type* e2type = e2->type->toBasetype(); |
40 | 1550 |
1551 if (e1type->isintegral()) | |
1 | 1552 { |
40 | 1553 assert(e2type->isintegral()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1554 LLValue* one = llvm::ConstantInt::get(val->getType(), 1, !e2type->isunsigned()); |
1 | 1555 if (op == TOKplusplus) { |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
1556 post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb()); |
1 | 1557 } |
1558 else if (op == TOKminusminus) { | |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
1559 post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb()); |
1 | 1560 } |
1561 } | |
40 | 1562 else if (e1type->ty == Tpointer) |
1 | 1563 { |
40 | 1564 assert(e2type->isintegral()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1565 LLConstant* minusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)-1,true); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1566 LLConstant* plusone = llvm::ConstantInt::get(DtoSize_t(),(uint64_t)1,false); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1567 LLConstant* whichone = (op == TOKplusplus) ? plusone : minusone; |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1568 post = llvm::GetElementPtrInst::Create(val, whichone, "tmp", p->scopebb()); |
1 | 1569 } |
40 | 1570 else if (e1type->isfloating()) |
1 | 1571 { |
40 | 1572 assert(e2type->isfloating()); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1573 LLValue* one = DtoConstFP(e1type, 1.0); |
1 | 1574 if (op == TOKplusplus) { |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
1575 post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb()); |
1 | 1576 } |
1577 else if (op == TOKminusminus) { | |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
1578 post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb()); |
1 | 1579 } |
1580 } | |
1581 else | |
1582 assert(post); | |
1583 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1584 DtoStore(post,l->getLVal()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1585 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1586 return new DImValue(type,val); |
1 | 1587 } |
1588 | |
1589 ////////////////////////////////////////////////////////////////////////////////////////// | |
1590 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1591 DValue* NewExp::toElem(IRState* p) |
1 | 1592 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1593 Logger::print("NewExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1594 LOG_SCOPE; |
1595 | |
1596 assert(newtype); | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1597 Type* ntype = newtype->toBasetype(); |
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
|
1598 |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1599 // new class |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1600 if (ntype->ty == Tclass) { |
169
2df270e1ba59
[svn r185] Fixed broken nested classes with data members, did DMD change the class layout? tango.text.Regex now compiles.
lindquist
parents:
167
diff
changeset
|
1601 Logger::println("new class"); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1602 return DtoNewClass(loc, (TypeClass*)ntype, this); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1603 } |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1604 // new dynamic array |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1605 else if (ntype->ty == Tarray) |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1606 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1607 Logger::println("new dynamic array: %s", newtype->toChars()); |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1608 // get dim |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1609 assert(arguments); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1610 assert(arguments->dim >= 1); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1611 if (arguments->dim == 1) |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1612 { |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1613 DValue* sz = ((Expression*)arguments->data[0])->toElem(p); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1614 // allocate & init |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
587
diff
changeset
|
1615 return DtoNewDynArray(loc, newtype, sz, true); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1616 } |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1617 else |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1618 { |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1619 size_t ndims = arguments->dim; |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1620 std::vector<DValue*> dims(ndims); |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1621 for (size_t i=0; i<ndims; ++i) |
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1622 dims[i] = ((Expression*)arguments->data[i])->toElem(p); |
591
e6bcc4d9e5ff
Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents:
587
diff
changeset
|
1623 return DtoNewMulDimDynArray(loc, newtype, &dims[0], ndims, true); |
286
a3b7c19c866c
[svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents:
284
diff
changeset
|
1624 } |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1625 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1626 // new static array |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1627 else if (ntype->ty == Tsarray) |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1628 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1629 assert(0); |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1630 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1631 // new struct |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1632 else if (ntype->ty == Tstruct) |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1633 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1634 Logger::println("new struct on heap: %s\n", newtype->toChars()); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1635 // allocate |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1636 LLValue* mem = DtoNew(newtype); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1637 // init |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1638 TypeStruct* ts = (TypeStruct*)ntype; |
1367
8026319762be
Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1351
diff
changeset
|
1639 if (ts->isZeroInit(ts->sym->loc)) { |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1640 DtoAggrZeroInit(mem); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1641 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1642 else { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1643 assert(ts->sym); |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
1644 ts->sym->codegen(Type::sir); |
1270
dd135ff697fa
Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1255
diff
changeset
|
1645 DtoAggrCopy(mem, ts->sym->ir.irStruct->getInitSymbol()); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1646 } |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1647 return new DImValue(type, mem); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1648 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1649 // new basic type |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1650 else |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1651 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1652 // allocate |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1653 LLValue* mem = DtoNew(newtype); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1654 DVarValue tmpvar(newtype, mem); |
212
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1655 |
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1656 // default initialize |
1228
79758fd2f48a
Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1211
diff
changeset
|
1657 // static arrays never appear here, so using the defaultInit is ok! |
212
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1658 Expression* exp = newtype->defaultInit(loc); |
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1659 DValue* iv = exp->toElem(gIR); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
1660 DtoAssign(loc, &tmpvar, iv); |
212
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1661 |
4c2689d57ba4
[svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents:
210
diff
changeset
|
1662 // return as pointer-to |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1663 return new DImValue(type, mem); |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1664 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1665 |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
1666 assert(0); |
1 | 1667 } |
1668 | |
1669 ////////////////////////////////////////////////////////////////////////////////////////// | |
1670 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1671 DValue* DeleteExp::toElem(IRState* p) |
1 | 1672 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1673 Logger::print("DeleteExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1674 LOG_SCOPE; |
1675 | |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1676 DValue* dval = e1->toElem(p); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
1677 Type* et = e1->type->toBasetype(); |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1678 |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1679 // simple pointer |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1680 if (et->ty == Tpointer) |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1681 { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1682 LLValue* rval = dval->getRVal(); |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1683 DtoDeleteMemory(rval); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1684 if (dval->isVar()) |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1685 DtoStore(llvm::Constant::getNullValue(rval->getType()), dval->getLVal()); |
1 | 1686 } |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1687 // class |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1688 else if (et->ty == Tclass) |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1689 { |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1690 bool onstack = false; |
210 | 1691 TypeClass* tc = (TypeClass*)et; |
1692 if (tc->sym->isInterfaceDeclaration()) | |
1693 { | |
1694 DtoDeleteInterface(dval->getRVal()); | |
1695 onstack = true; | |
1696 } | |
1697 else if (DVarValue* vv = dval->isVar()) { | |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1698 if (vv->var && vv->var->onstack) { |
554
1b702422451c
Always call finalizer for stack classes. Checking for the number of
Christian Kamm <kamm incasoftware de>
parents:
553
diff
changeset
|
1699 DtoFinalizeClass(dval->getRVal()); |
275
665b81613475
[svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents:
268
diff
changeset
|
1700 onstack = true; |
113
27b9f749d9fe
[svn r117] Initial working implementation of interfaces.
lindquist
parents:
109
diff
changeset
|
1701 } |
1 | 1702 } |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1703 if (!onstack) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1704 LLValue* rval = dval->getRVal(); |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1705 DtoDeleteClass(rval); |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1706 } |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
1707 if (dval->isVar()) { |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1708 LLValue* lval = dval->getLVal(); |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1709 DtoStore(llvm::Constant::getNullValue(lval->getType()->getContainedType(0)), lval); |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1710 } |
1 | 1711 } |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1712 // dyn array |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1713 else if (et->ty == Tarray) |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1714 { |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1715 DtoDeleteArray(dval); |
715
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
1716 if (dval->isLVal()) |
30b42a283c8e
Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
705
diff
changeset
|
1717 DtoSetArrayToNull(dval->getLVal()); |
1 | 1718 } |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1719 // unknown/invalid |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1720 else |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1721 { |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1722 assert(0 && "invalid delete"); |
1 | 1723 } |
1724 | |
209
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1725 // no value to return |
c4c9b4ac021b
[svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents:
207
diff
changeset
|
1726 return NULL; |
1 | 1727 } |
1728 | |
1729 ////////////////////////////////////////////////////////////////////////////////////////// | |
1730 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1731 DValue* ArrayLengthExp::toElem(IRState* p) |
1 | 1732 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1733 Logger::print("ArrayLengthExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1734 LOG_SCOPE; |
1735 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1736 DValue* u = e1->toElem(p); |
335
17b844102023
[svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents:
334
diff
changeset
|
1737 return new DImValue(type, DtoArrayLen(u)); |
1 | 1738 } |
1739 | |
1740 ////////////////////////////////////////////////////////////////////////////////////////// | |
1741 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1742 DValue* AssertExp::toElem(IRState* p) |
1 | 1743 { |
328
7086a84ab3d6
[svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents:
321
diff
changeset
|
1744 Logger::print("AssertExp::toElem: %s\n", toChars()); |
1 | 1745 LOG_SCOPE; |
1746 | |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1747 if(!global.params.useAssert) |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1748 return NULL; |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1749 |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1750 // condition |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1751 DValue* cond; |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1752 Type* condty; |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1753 |
1272
dd4766851b37
Forgot the special case part in last !ThisExp change.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1271
diff
changeset
|
1754 // special case for dmd generated assert(this); when not in -release mode |
dd4766851b37
Forgot the special case part in last !ThisExp change.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1271
diff
changeset
|
1755 if (e1->op == TOKthis && ((ThisExp*)e1)->var == NULL) |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1756 { |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1757 LLValue* thisarg = p->func()->thisArg; |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1758 assert(thisarg && "null thisarg, but we're in assert(this) exp;"); |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1759 LLValue* thisptr = DtoLoad(p->func()->thisArg); |
1326
a41a40deff73
Fixed dmdfe generated class invariant calls. Also insert proper "this !is null" check before it. Fixed invariant* dstress regressions and generally seems like a good idea. Hope I didn't break anything.. minitests run fine!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
1760 condty = e1->type->toBasetype(); |
a41a40deff73
Fixed dmdfe generated class invariant calls. Also insert proper "this !is null" check before it. Fixed invariant* dstress regressions and generally seems like a good idea. Hope I didn't break anything.. minitests run fine!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1292
diff
changeset
|
1761 cond = new DImValue(condty, thisptr); |
1271
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1762 } |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1763 else |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1764 { |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1765 cond = e1->toElem(p); |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1766 condty = e1->type->toBasetype(); |
0686701178d3
Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1270
diff
changeset
|
1767 } |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1768 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1769 InvariantDeclaration* invdecl; |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1770 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1771 // class invariants |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1772 if( |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1773 global.params.useInvariants && |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1774 condty->ty == Tclass && |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1775 !((TypeClass*)condty)->sym->isInterfaceDeclaration()) |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1776 { |
1401
e2cf1f67ca33
Don't print the entire declaration of the alliassee when `->toChars()` is
Frits van Bommel <fvbommel wxs.nl>
parents:
1395
diff
changeset
|
1777 Logger::println("calling class invariant"); |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1778 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_invariant"); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1779 LLValue* arg = DtoBitCast(cond->getRVal(), fn->getFunctionType()->getParamType(0)); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1780 gIR->CreateCallOrInvoke(fn, arg); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1781 } |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1782 // struct invariants |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1783 else if( |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1784 global.params.useInvariants && |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
1785 condty->ty == Tpointer && condty->nextOf()->ty == Tstruct && |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
1786 (invdecl = ((TypeStruct*)condty->nextOf())->sym->inv) != NULL) |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1787 { |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1788 Logger::print("calling struct invariant"); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1789 DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal()); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1790 DtoCallFunction(loc, NULL, &invfunc, NULL); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1791 } |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1792 else |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1793 { |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1794 // create basic blocks |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1795 llvm::BasicBlock* oldend = p->scopeend(); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1796 llvm::BasicBlock* assertbb = llvm::BasicBlock::Create("assert", p->topfunc(), oldend); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1797 llvm::BasicBlock* endbb = llvm::BasicBlock::Create("noassert", p->topfunc(), oldend); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1798 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1799 // test condition |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
1800 LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal(); |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1801 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1802 // branch |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1803 llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb()); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1804 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1805 // call assert runtime functions |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1806 p->scope() = IRScope(assertbb,endbb); |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1136
diff
changeset
|
1807 DtoAssert(p->func()->decl->getModule(), loc, msg ? msg->toElem(p) : NULL); |
530
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1808 |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1809 // rewrite the scope |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1810 p->scope() = IRScope(endbb,oldend); |
d30c40f1128d
Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents:
525
diff
changeset
|
1811 } |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1812 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1813 // no meaningful return value |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
1814 return NULL; |
1 | 1815 } |
1816 | |
1817 ////////////////////////////////////////////////////////////////////////////////////////// | |
1818 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1819 DValue* NotExp::toElem(IRState* p) |
1 | 1820 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1821 Logger::print("NotExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1822 LOG_SCOPE; |
1823 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1824 DValue* u = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1825 |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
1826 LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal(); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
1827 |
611
83ca663ecc20
Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents:
610
diff
changeset
|
1828 LLConstant* zero = DtoConstBool(false); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1829 b = p->ir->CreateICmpEQ(b,zero); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1830 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1831 return new DImValue(type, b); |
1 | 1832 } |
1833 | |
1834 ////////////////////////////////////////////////////////////////////////////////////////// | |
1835 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1836 DValue* AndAndExp::toElem(IRState* p) |
1 | 1837 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1838 Logger::print("AndAndExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1839 LOG_SCOPE; |
1840 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1841 DValue* u = e1->toElem(p); |
1 | 1842 |
1843 llvm::BasicBlock* oldend = p->scopeend(); | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1844 llvm::BasicBlock* andand = llvm::BasicBlock::Create("andand", gIR->topfunc(), oldend); |
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1845 llvm::BasicBlock* andandend = llvm::BasicBlock::Create("andandend", gIR->topfunc(), oldend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1846 |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
1847 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1848 |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1849 llvm::BasicBlock* oldblock = p->scopebb(); |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1850 llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1851 |
1 | 1852 p->scope() = IRScope(andand, andandend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1853 DValue* v = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1854 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1855 LLValue* vbool = 0; |
859
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1856 if (!v->isFunc() && v->getType() != Type::tvoid) |
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1857 { |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1858 vbool = DtoCast(loc, v, Type::tbool)->getRVal(); |
859
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1859 } |
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1860 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1861 llvm::BasicBlock* newblock = p->scopebb(); |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1862 llvm::BranchInst::Create(andandend,p->scopebb()); |
1 | 1863 p->scope() = IRScope(andandend, oldend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1864 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1865 LLValue* resval = 0; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1866 if (ubool == vbool || !vbool) { |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1867 // No need to create a PHI node. |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1868 resval = ubool; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1869 } else { |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1870 llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "andandval"); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1871 // If we jumped over evaluation of the right-hand side, |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1872 // the result is false. Otherwise it's the value of the right-hand side. |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1873 phi->addIncoming(LLConstantInt::getFalse(), oldblock); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1874 phi->addIncoming(vbool, newblock); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1875 resval = phi; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1876 } |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1877 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1878 return new DImValue(type, resval); |
1 | 1879 } |
1880 | |
1881 ////////////////////////////////////////////////////////////////////////////////////////// | |
1882 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1883 DValue* OrOrExp::toElem(IRState* p) |
1 | 1884 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1885 Logger::print("OrOrExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1886 LOG_SCOPE; |
1887 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1888 DValue* u = e1->toElem(p); |
1 | 1889 |
1890 llvm::BasicBlock* oldend = p->scopeend(); | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1891 llvm::BasicBlock* oror = llvm::BasicBlock::Create("oror", gIR->topfunc(), oldend); |
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1892 llvm::BasicBlock* ororend = llvm::BasicBlock::Create("ororend", gIR->topfunc(), oldend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1893 |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
1894 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal(); |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1895 |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1896 llvm::BasicBlock* oldblock = p->scopebb(); |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1897 llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1898 |
1 | 1899 p->scope() = IRScope(oror, ororend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1900 DValue* v = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1901 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1902 LLValue* vbool = 0; |
859
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1903 if (!v->isFunc() && v->getType() != Type::tvoid) |
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1904 { |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1905 vbool = DtoCast(loc, v, Type::tbool)->getRVal(); |
859
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1906 } |
a719f2ca3e92
Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents:
858
diff
changeset
|
1907 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1908 llvm::BasicBlock* newblock = p->scopebb(); |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
1909 llvm::BranchInst::Create(ororend,p->scopebb()); |
1 | 1910 p->scope() = IRScope(ororend, oldend); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1911 |
1225
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1912 LLValue* resval = 0; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1913 if (ubool == vbool || !vbool) { |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1914 // No need to create a PHI node. |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1915 resval = ubool; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1916 } else { |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1917 llvm::PHINode* phi = p->ir->CreatePHI(LLType::Int1Ty, "ororval"); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1918 // If we jumped over evaluation of the right-hand side, |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1919 // the result is true. Otherwise, it's the value of the right-hand side. |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1920 phi->addIncoming(LLConstantInt::getTrue(), oldblock); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1921 phi->addIncoming(vbool, newblock); |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1922 resval = phi; |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1923 } |
837f48560863
No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents:
1211
diff
changeset
|
1924 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1925 return new DImValue(type, resval); |
1 | 1926 } |
1927 | |
1928 ////////////////////////////////////////////////////////////////////////////////////////// | |
1929 | |
1930 #define BinBitExp(X,Y) \ | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1931 DValue* X##Exp::toElem(IRState* p) \ |
1 | 1932 { \ |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1933 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \ |
1 | 1934 LOG_SCOPE; \ |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1935 DValue* u = e1->toElem(p); \ |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1936 DValue* v = e2->toElem(p); \ |
1202
7c7072437a89
Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents:
1166
diff
changeset
|
1937 errorOnIllegalArrayOp(this, e1, e2); \ |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
1938 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \ |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1939 return new DImValue(type, x); \ |
1 | 1940 } |
1941 | |
1942 BinBitExp(And,And); | |
1943 BinBitExp(Or,Or); | |
1944 BinBitExp(Xor,Xor); | |
1945 BinBitExp(Shl,Shl); | |
1946 BinBitExp(Ushr,LShr); | |
1947 | |
268
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1948 DValue* ShrExp::toElem(IRState* p) |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1949 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1950 Logger::print("ShrExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
268
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1951 LOG_SCOPE; |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1952 DValue* u = e1->toElem(p); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1953 DValue* v = e2->toElem(p); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1954 LLValue* x; |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1955 if (e1->type->isunsigned()) |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1956 x = p->ir->CreateLShr(u->getRVal(), v->getRVal(), "tmp"); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1957 else |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1958 x = p->ir->CreateAShr(u->getRVal(), v->getRVal(), "tmp"); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1959 return new DImValue(type, x); |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1960 } |
23d0d9855cad
[svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents:
264
diff
changeset
|
1961 |
1 | 1962 ////////////////////////////////////////////////////////////////////////////////////////// |
1963 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1964 DValue* HaltExp::toElem(IRState* p) |
1 | 1965 { |
262
88252a1af660
[svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents:
259
diff
changeset
|
1966 Logger::print("HaltExp::toElem: %s\n", toChars()); |
1 | 1967 LOG_SCOPE; |
1968 | |
363 | 1969 // FIXME: DMD inserts a trap here... we probably should as well !?! |
1970 | |
281
f5f97ca47b33
[svn r302] Make HaltExps and assert(0) generate an assert message again instead of using llvm's trap intrinsic.
ChristianK
parents:
275
diff
changeset
|
1971 #if 1 |
1141
f99a3b393c03
Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents:
1136
diff
changeset
|
1972 DtoAssert(p->func()->decl->getModule(), loc, NULL); |
258
8dbddae09152
[svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents:
245
diff
changeset
|
1973 #else |
217
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
1974 // call the new (?) trap intrinsic |
0806379a5eca
[svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents:
215
diff
changeset
|
1975 p->ir->CreateCall(GET_INTRINSIC_DECL(trap),""); |
291
068cb3c60afb
[svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents:
286
diff
changeset
|
1976 new llvm::UnreachableInst(p->scopebb()); |
258
8dbddae09152
[svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents:
245
diff
changeset
|
1977 #endif |
36
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
1978 |
282
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1979 // this terminated the basicblock, start a new one |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1980 // this is sensible, since someone might goto behind the assert |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1981 // and prevents compiler errors if a terminator follows the assert |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1982 llvm::BasicBlock* oldend = gIR->scopeend(); |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1983 llvm::BasicBlock* bb = llvm::BasicBlock::Create("afterhalt", p->topfunc(), oldend); |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1984 p->scope() = IRScope(bb,oldend); |
74348f162225
[svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents:
281
diff
changeset
|
1985 |
1 | 1986 return 0; |
1987 } | |
1988 | |
1989 ////////////////////////////////////////////////////////////////////////////////////////// | |
1990 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
1991 DValue* DelegateExp::toElem(IRState* p) |
1 | 1992 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
1993 Logger::print("DelegateExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 1994 LOG_SCOPE; |
1995 | |
426
e763821ab244
Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents:
424
diff
changeset
|
1996 if(func->isStatic()) |
e763821ab244
Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents:
424
diff
changeset
|
1997 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars()); |
e763821ab244
Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents:
424
diff
changeset
|
1998 |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
1999 const LLPointerType* int8ptrty = getPtrToType(LLType::Int8Ty); |
1 | 2000 |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2001 assert(type->toBasetype()->ty == Tdelegate); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2002 const LLType* dgty = DtoType(type); |
1 | 2003 |
143
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2004 DValue* u = e1->toElem(p); |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2005 LLValue* uval; |
119
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
118
diff
changeset
|
2006 if (DFuncValue* f = u->isFunc()) { |
634
0084d2c76b74
Fixed problem with taking the delegate of a nested function of the current function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
629
diff
changeset
|
2007 assert(f->func); |
0084d2c76b74
Fixed problem with taking the delegate of a nested function of the current function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
629
diff
changeset
|
2008 LLValue* contextptr = DtoNestedContext(loc, f->func); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2009 uval = DtoBitCast(contextptr, getVoidPtrType()); |
119
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
118
diff
changeset
|
2010 } |
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
118
diff
changeset
|
2011 else { |
143
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2012 DValue* src = u; |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2013 if (ClassDeclaration* cd = u->getType()->isClassHandle()) |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2014 { |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2015 Logger::println("context type is class handle"); |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2016 if (cd->isInterfaceDeclaration()) |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2017 { |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2018 Logger::println("context type is interface"); |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2019 src = DtoCastInterfaceToObject(u, ClassDeclaration::object->type); |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2020 } |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2021 } |
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2022 uval = src->getRVal(); |
119
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
118
diff
changeset
|
2023 } |
79c9ac745fbc
[svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents:
118
diff
changeset
|
2024 |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2025 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2026 Logger::cout() << "context = " << *uval << '\n'; |
143
336ec4f4bbb3
[svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents:
137
diff
changeset
|
2027 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2028 LLValue* castcontext = DtoBitCast(uval, int8ptrty); |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2029 |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2030 Logger::println("func: '%s'", func->toPrettyChars()); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2031 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2032 LLValue* castfptr; |
837
331a176c1f4f
Removed error on naked, not fully complete, but I'll be doing more work on it during this Christmas, and some things do work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
836
diff
changeset
|
2033 if (func->isVirtual() && !func->isFinal()) |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2034 castfptr = DtoVirtualFunctionPointer(u, func); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2035 else if (func->isAbstract()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2036 assert(0 && "TODO delegate to abstract method"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2037 else if (func->toParent()->isInterfaceDeclaration()) |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2038 assert(0 && "TODO delegate to interface method"); |
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2039 else |
150
2c336566ffed
[svn r156] added a testcase for the most annoying bug ever
lindquist
parents:
144
diff
changeset
|
2040 { |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
2041 func->codegen(Type::sir); |
173
db9890b3fb64
[svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents:
172
diff
changeset
|
2042 castfptr = func->ir.irFunc->func; |
150
2c336566ffed
[svn r156] added a testcase for the most annoying bug ever
lindquist
parents:
144
diff
changeset
|
2043 } |
133
44a95ac7368a
[svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents:
132
diff
changeset
|
2044 |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2045 castfptr = DtoBitCast(castfptr, dgty->getContainedType(1)); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2046 |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2047 return new DImValue(type, DtoAggrPair(castcontext, castfptr, ".dg")); |
1 | 2048 } |
2049 | |
2050 ////////////////////////////////////////////////////////////////////////////////////////// | |
2051 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2052 DValue* IdentityExp::toElem(IRState* p) |
1 | 2053 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2054 Logger::print("IdentityExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 2055 LOG_SCOPE; |
2056 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2057 DValue* u = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2058 DValue* v = e2->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2059 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2060 Type* t1 = e1->type->toBasetype(); |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2061 |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2062 // handle dynarray specially |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2063 if (t1->ty == Tarray) |
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2064 return new DImValue(type, DtoDynArrayIs(op,u,v)); |
345
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
2065 // also structs |
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
2066 else if (t1->ty == Tstruct) |
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
2067 return new DImValue(type, DtoStructEquals(op,u,v)); |
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
2068 |
5320fe65a65d
[svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents:
344
diff
changeset
|
2069 // FIXME this stuff isn't pretty |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2070 LLValue* l = u->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2071 LLValue* r = v->getRVal(); |
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2072 LLValue* eval = 0; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2073 |
308
6b62e8cdf970
[svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents:
295
diff
changeset
|
2074 if (t1->ty == Tdelegate) { |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2075 if (v->isNull()) { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2076 r = NULL; |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2077 } |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2078 else { |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2079 assert(l->getType() == r->getType()); |
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2080 } |
344
e20ce6d8d374
[svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents:
340
diff
changeset
|
2081 eval = DtoDelegateEquals(op,l,r); |
162
1856c62af24b
[svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents:
156
diff
changeset
|
2082 } |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
143
diff
changeset
|
2083 else if (t1->isfloating()) |
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
143
diff
changeset
|
2084 { |
365 | 2085 eval = (op == TOKidentity) |
2086 ? p->ir->CreateFCmpOEQ(l,r,"tmp") | |
2087 : p->ir->CreateFCmpONE(l,r,"tmp"); | |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
143
diff
changeset
|
2088 } |
629
607b6b5819a7
Fixed issue with IsExpression and potential type mismatch for classes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
628
diff
changeset
|
2089 else if (t1->ty == Tpointer || t1->ty == Tclass) |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2090 { |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2091 if (l->getType() != r->getType()) { |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2092 if (v->isNull()) |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2093 r = llvm::ConstantPointerNull::get(isaPointer(l->getType())); |
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2094 else |
244
a95056b3c996
[svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
243
diff
changeset
|
2095 r = DtoBitCast(r, l->getType()); |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2096 } |
365 | 2097 eval = (op == TOKidentity) |
2098 ? p->ir->CreateICmpEQ(l,r,"tmp") | |
2099 : p->ir->CreateICmpNE(l,r,"tmp"); | |
167
adca7f32fb6d
[svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents:
164
diff
changeset
|
2100 } |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2101 else { |
629
607b6b5819a7
Fixed issue with IsExpression and potential type mismatch for classes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
628
diff
changeset
|
2102 assert(l->getType() == r->getType()); |
365 | 2103 eval = (op == TOKidentity) |
2104 ? p->ir->CreateICmpEQ(l,r,"tmp") | |
2105 : p->ir->CreateICmpNE(l,r,"tmp"); | |
54
28e99b04a132
[svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents:
53
diff
changeset
|
2106 } |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2107 return new DImValue(type, eval); |
1 | 2108 } |
2109 | |
2110 ////////////////////////////////////////////////////////////////////////////////////////// | |
2111 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2112 DValue* CommaExp::toElem(IRState* p) |
1 | 2113 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2114 Logger::print("CommaExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 2115 LOG_SCOPE; |
2116 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2117 DValue* u = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2118 DValue* v = e2->toElem(p); |
144
a27941d00351
[svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents:
143
diff
changeset
|
2119 assert(e2->type == type); |
1 | 2120 return v; |
2121 } | |
2122 | |
2123 ////////////////////////////////////////////////////////////////////////////////////////// | |
2124 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2125 DValue* CondExp::toElem(IRState* p) |
1 | 2126 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2127 Logger::print("CondExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 2128 LOG_SCOPE; |
2129 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2130 Type* dtype = type->toBasetype(); |
1 | 2131 |
887 | 2132 DValue* dvv; |
2133 // voids returns will need no storage | |
2134 if (dtype->ty != Tvoid) { | |
2135 // allocate a temporary for the final result. failed to come up with a better way :/ | |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
2136 LLValue* resval = DtoAlloca(dtype,"condtmp"); |
887 | 2137 dvv = new DVarValue(type, resval); |
2138 } else { | |
2139 dvv = new DConstValue(type, getNullValue(DtoTypeNotVoid(dtype))); | |
2140 } | |
1 | 2141 |
2142 llvm::BasicBlock* oldend = p->scopeend(); | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2143 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create("condtrue", gIR->topfunc(), oldend); |
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2144 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create("condfalse", gIR->topfunc(), oldend); |
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2145 llvm::BasicBlock* condend = llvm::BasicBlock::Create("condend", gIR->topfunc(), oldend); |
1 | 2146 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2147 DValue* c = econd->toElem(p); |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
2148 LLValue* cond_val = DtoCast(loc, c, Type::tbool)->getRVal(); |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2149 llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb()); |
1 | 2150 |
2151 p->scope() = IRScope(condtrue, condfalse); | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2152 DValue* u = e1->toElem(p); |
887 | 2153 if (dtype->ty != Tvoid) |
2154 DtoAssign(loc, dvv, u); | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2155 llvm::BranchInst::Create(condend,p->scopebb()); |
1 | 2156 |
2157 p->scope() = IRScope(condfalse, condend); | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2158 DValue* v = e2->toElem(p); |
887 | 2159 if (dtype->ty != Tvoid) |
2160 DtoAssign(loc, dvv, v); | |
205
9d44ec83acd1
[svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents:
203
diff
changeset
|
2161 llvm::BranchInst::Create(condend,p->scopebb()); |
1 | 2162 |
2163 p->scope() = IRScope(condend, oldend); | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2164 return dvv; |
1 | 2165 } |
2166 | |
2167 ////////////////////////////////////////////////////////////////////////////////////////// | |
2168 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2169 DValue* ComExp::toElem(IRState* p) |
1 | 2170 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2171 Logger::print("ComExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
1 | 2172 LOG_SCOPE; |
2173 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2174 DValue* u = e1->toElem(p); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2175 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2176 LLValue* value = u->getRVal(); |
809
69a5e4a6fc0f
Changed some hardcoded offset/alignment for classes in DMD, broke offsets for 64bits.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
802
diff
changeset
|
2177 LLValue* minusone = llvm::ConstantInt::get(value->getType(), (uint64_t)-1, true); |
704
43165a082535
Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
703
diff
changeset
|
2178 value = llvm::BinaryOperator::Create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2179 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2180 return new DImValue(type, value); |
1 | 2181 } |
2182 | |
2183 ////////////////////////////////////////////////////////////////////////////////////////// | |
2184 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2185 DValue* NegExp::toElem(IRState* p) |
23 | 2186 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2187 Logger::print("NegExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
23 | 2188 LOG_SCOPE; |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2189 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2190 DValue* l = e1->toElem(p); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
163
diff
changeset
|
2191 |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
163
diff
changeset
|
2192 if (type->iscomplex()) { |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2193 return DtoComplexNeg(loc, type, l); |
164
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
163
diff
changeset
|
2194 } |
a64becf2a702
[svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents:
163
diff
changeset
|
2195 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2196 LLValue* val = l->getRVal(); |
616
5ced42a55aa9
Fix NegExp not to use substraction.
Christian Kamm <kamm incasoftware de>
parents:
611
diff
changeset
|
2197 |
5ced42a55aa9
Fix NegExp not to use substraction.
Christian Kamm <kamm incasoftware de>
parents:
611
diff
changeset
|
2198 val = gIR->ir->CreateNeg(val,"negval"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2199 return new DImValue(type, val); |
23 | 2200 } |
2201 | |
2202 ////////////////////////////////////////////////////////////////////////////////////////// | |
2203 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2204 DValue* CatExp::toElem(IRState* p) |
36
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2205 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2206 Logger::print("CatExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
36
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2207 LOG_SCOPE; |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2208 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2209 Type* t = type->toBasetype(); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2210 |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2211 bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype(); |
132 | 2212 |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2213 // array ~ array |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2214 if (arrNarr) |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2215 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2216 return DtoCatArrays(type, e1, e2); |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2217 } |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2218 // array ~ element |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2219 // element ~ array |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2220 else |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2221 { |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2222 return DtoCatArrayElement(type, e1, e2); |
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2223 } |
36
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2224 } |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2225 |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2226 ////////////////////////////////////////////////////////////////////////////////////////// |
c0967c4b2a74
[svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents:
34
diff
changeset
|
2227 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2228 DValue* CatAssignExp::toElem(IRState* p) |
40 | 2229 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2230 Logger::print("CatAssignExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 2231 LOG_SCOPE; |
2232 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2233 DValue* l = e1->toElem(p); |
40 | 2234 |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2235 Type* e1type = e1->type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2236 Type* elemtype = e1type->nextOf()->toBasetype(); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2237 Type* e2type = e2->type->toBasetype(); |
40 | 2238 |
2239 if (e2type == elemtype) { | |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2240 DSliceValue* slice = DtoCatAssignElement(l,e2); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2241 DtoAssign(loc, l, slice); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2242 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2243 else if (e1type == e2type) { |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2244 DSliceValue* slice = DtoCatAssignArray(l,e2); |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2245 DtoAssign(loc, l, slice); |
40 | 2246 } |
2247 else | |
2248 assert(0 && "only one element at a time right now"); | |
2249 | |
203
e881c9b1c738
[svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents:
201
diff
changeset
|
2250 return l; |
40 | 2251 } |
2252 | |
2253 ////////////////////////////////////////////////////////////////////////////////////////// | |
2254 | |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2255 DValue* FuncExp::toElem(IRState* p) |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2256 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2257 Logger::print("FuncExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2258 LOG_SCOPE; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2259 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2260 assert(fd); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2261 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2262 if (fd->isNested()) Logger::println("nested"); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2263 Logger::println("kind = %s\n", fd->kind()); |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2264 |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
2265 fd->codegen(Type::sir); |
521
99e95dae90d5
Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents:
520
diff
changeset
|
2266 assert(fd->ir.irFunc->func); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2267 |
520
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2268 if(fd->tok == TOKdelegate) { |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2269 const LLType* dgty = DtoType(type); |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2270 |
520
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2271 LLValue* cval; |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2272 IrFunction* irfn = p->func(); |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2273 if (irfn->nestedVar) |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2274 cval = irfn->nestedVar; |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2275 else if (irfn->nestArg) |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2276 cval = irfn->nestArg; |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2277 else |
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2278 cval = getNullPtr(getVoidPtrType()); |
719
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2279 cval = DtoBitCast(cval, dgty->getContainedType(0)); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2280 |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2281 LLValue* castfptr = DtoBitCast(fd->ir.irFunc->func, dgty->getContainedType(1)); |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2282 |
7261ff0f95ff
Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
715
diff
changeset
|
2283 return new DImValue(type, DtoAggrPair(cval, castfptr, ".func")); |
521
99e95dae90d5
Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents:
520
diff
changeset
|
2284 |
520
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2285 } else if(fd->tok == TOKfunction) { |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
2286 return new DImValue(type, fd->ir.irFunc->func); |
520
73e41129b7f3
Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents:
512
diff
changeset
|
2287 } |
521
99e95dae90d5
Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents:
520
diff
changeset
|
2288 |
99e95dae90d5
Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents:
520
diff
changeset
|
2289 assert(0 && "fd->tok must be TOKfunction or TOKdelegate"); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2290 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2291 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2292 ////////////////////////////////////////////////////////////////////////////////////////// |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2293 |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2294 LLConstant* FuncExp::toConstElem(IRState* p) |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2295 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2296 Logger::print("FuncExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2297 LOG_SCOPE; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2298 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2299 assert(fd); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2300 assert(fd->tok == TOKfunction); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2301 |
1148
3d1b16dabd25
Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1147
diff
changeset
|
2302 fd->codegen(Type::sir); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2303 assert(fd->ir.irFunc->func); |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2304 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2305 return fd->ir.irFunc->func; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2306 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2307 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2308 ////////////////////////////////////////////////////////////////////////////////////////// |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2309 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2310 DValue* ArrayLiteralExp::toElem(IRState* p) |
40 | 2311 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2312 Logger::print("ArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 2313 LOG_SCOPE; |
2314 | |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2315 // D types |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2316 Type* arrayType = type->toBasetype(); |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2317 Type* elemType = arrayType->nextOf()->toBasetype(); |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2318 |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2319 // is dynamic ? |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2320 bool dyn = (arrayType->ty == Tarray); |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2321 // length |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2322 size_t len = elements->dim; |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2323 |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2324 // llvm target type |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2325 const LLType* llType = DtoType(arrayType); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2326 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2327 Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n"; |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2328 |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2329 // llvm storage type |
587
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2330 const LLType* llElemType = DtoTypeNotVoid(elemType); |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2331 const LLType* llStoType = LLArrayType::get(llElemType, len); |
622
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2332 if (Logger::enabled()) |
26fce59fe80a
Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
619
diff
changeset
|
2333 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n"; |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2334 |
587
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2335 // don't allocate storage for zero length dynamic array literals |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2336 if (dyn && len == 0) |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2337 { |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2338 // dmd seems to just make them null... |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2339 return new DSliceValue(type, DtoConstSize_t(0), getNullPtr(getPtrToType(llElemType))); |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2340 } |
23538d0f0d5b
Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
585
diff
changeset
|
2341 |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2342 // dst pointer |
592
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2343 LLValue* dstMem; |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2344 DSliceValue* dynSlice = NULL; |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2345 if(dyn) |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2346 { |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2347 dynSlice = DtoNewDynArray(loc, arrayType, new DConstValue(Type::tsize_t, DtoConstSize_t(len)), false); |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2348 dstMem = dynSlice->ptr; |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2349 } |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2350 else |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
2351 dstMem = DtoRawAlloca(llStoType, 0, "arrayliteral"); |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2352 |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2353 // store elements |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2354 for (size_t i=0; i<len; ++i) |
40 | 2355 { |
2356 Expression* expr = (Expression*)elements->data[i]; | |
592
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2357 LLValue* elemAddr; |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2358 if(dyn) |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2359 elemAddr = DtoGEPi1(dstMem, i, "tmp", p->scopebb()); |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2360 else |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2361 elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb()); |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2362 |
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2363 // emulate assignment |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
2364 DVarValue* vv = new DVarValue(expr->type, elemAddr); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2365 DValue* e = expr->toElem(p); |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2366 DtoAssign(loc, vv, e); |
40 | 2367 } |
2368 | |
175
c44e6a711885
[svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents:
173
diff
changeset
|
2369 // return storage directly ? |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2370 if (!dyn) |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2371 return new DImValue(type, dstMem); |
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2372 |
592
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2373 // return slice |
5fb7ed0ac580
Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents:
591
diff
changeset
|
2374 return dynSlice; |
40 | 2375 } |
2376 | |
2377 ////////////////////////////////////////////////////////////////////////////////////////// | |
2378 | |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2379 LLConstant* ArrayLiteralExp::toConstElem(IRState* p) |
40 | 2380 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2381 Logger::print("ArrayLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
40 | 2382 LOG_SCOPE; |
2383 | |
602
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2384 // extract D types |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2385 Type* bt = type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2386 Type* elemt = bt->nextOf(); |
602
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2387 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2388 // build llvm array type |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2389 const LLArrayType* arrtype = LLArrayType::get(DtoType(elemt), elements->dim); |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2390 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2391 // dynamic arrays can occur here as well ... |
603
10bc9eb9e262
Fix typo in ArrayLiteralExp::toConstElem.
Christian Kamm <kamm incasoftware de>
parents:
602
diff
changeset
|
2392 bool dyn = (bt->ty == Tarray); |
602
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2393 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2394 // build the initializer |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2395 std::vector<LLConstant*> vals(elements->dim, NULL); |
40 | 2396 for (unsigned i=0; i<elements->dim; ++i) |
2397 { | |
2398 Expression* expr = (Expression*)elements->data[i]; | |
2399 vals[i] = expr->toConstElem(p); | |
2400 } | |
2401 | |
602
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2402 // build the constant array initializer |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2403 LLConstant* initval = llvm::ConstantArray::get(arrtype, vals); |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2404 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2405 // if static array, we're done |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2406 if (!dyn) |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2407 return initval; |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2408 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2409 // for dynamic arrays we need to put the initializer in a global, and build a constant dynamic array reference with the .ptr field pointing into this global |
1292
ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents:
1272
diff
changeset
|
2410 // Important: don't make the global constant, since this const initializer might |
ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents:
1272
diff
changeset
|
2411 // be used as an initializer for a static T[] - where modifying contents is allowed. |
ad41053c336e
Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents:
1272
diff
changeset
|
2412 LLConstant* globalstore = new LLGlobalVariable(arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage", p->module); |
602
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2413 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) }; |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2414 LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2); |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2415 |
48f079b4fe0f
Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
600
diff
changeset
|
2416 return DtoConstSlice(DtoConstSize_t(elements->dim), globalstorePtr); |
40 | 2417 } |
2418 | |
2419 ////////////////////////////////////////////////////////////////////////////////////////// | |
2420 | |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2421 // building a struct literal is pretty much the same as building a default initializer. |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2422 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2423 extern size_t add_zeros(std::vector<llvm::Value*>& values, size_t diff); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2424 extern LLConstant* get_default_initializer(VarDeclaration* vd, Initializer* init); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2425 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2426 DValue* StructLiteralExp::toElem(IRState* p) |
49
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2427 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2428 Logger::print("StructLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
49
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2429 LOG_SCOPE; |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2430 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2431 // make sure the struct is fully resolved |
1245
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1231
diff
changeset
|
2432 sd->codegen(Type::sir); |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1231
diff
changeset
|
2433 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2434 // final list of values to put in the struct |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2435 std::vector<LLValue*> initvalues; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2436 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2437 // offset tracker |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2438 size_t offset = 0; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2439 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2440 // align(1) struct S { ... } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2441 bool packed = sd->type->alignsize() == 1; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2442 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2443 // ready elements data |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2444 assert(elements && "struct literal has null elements"); |
823
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2445 size_t nexprs = elements->dim;; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2446 Expression** exprs = (Expression**)elements->data; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2447 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2448 // go through fields |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2449 ArrayIter<VarDeclaration> it(sd->fields); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2450 for (; !it.done(); it.next()) |
823
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2451 { |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2452 VarDeclaration* vd = it.get(); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2453 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2454 if (vd->offset < offset) |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2455 { |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2456 IF_LOG Logger::println("skipping field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2457 continue; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2458 } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2459 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2460 IF_LOG Logger::println("using field: %s %s (+%u)", vd->type->toChars(), vd->toChars(), vd->offset); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2461 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2462 // get next aligned offset for this field |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2463 size_t alignedoffset = offset; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2464 if (!packed) |
823
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2465 { |
1351
8d501abecd24
Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1350
diff
changeset
|
2466 alignedoffset = realignOffset(alignedoffset, vd->type); |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2467 } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2468 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2469 // insert explicit padding? |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2470 if (alignedoffset < vd->offset) |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2471 { |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2472 add_zeros(initvalues, vd->offset - alignedoffset); |
823
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2473 } |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2474 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2475 // add initializer |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2476 Expression* expr = (it.index < nexprs) ? exprs[it.index] : NULL; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2477 IF_LOG Logger::println("expr: %p", expr); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2478 if (expr) |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2479 { |
1372
229e02867307
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
2480 IF_LOG Logger::println("expr %zu = %s", it.index, expr->toChars()); |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2481 LLValue* v = DtoExprValue(vd->type, expr); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2482 initvalues.push_back(v); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2483 } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2484 else |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2485 { |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2486 IF_LOG Logger::println("using default initializer"); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2487 initvalues.push_back(get_default_initializer(vd, NULL)); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2488 } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2489 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2490 // advance offset to right past this field |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2491 offset = vd->offset + vd->type->size(); |
823
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2492 } |
794c8af186ce
Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
820
diff
changeset
|
2493 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2494 // tail padding? |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2495 if (offset < sd->structsize) |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2496 { |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2497 add_zeros(initvalues, sd->structsize - offset); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2498 } |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2499 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2500 // build type |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2501 std::vector<const LLType*> valuetypes; |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2502 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2503 size_t n = initvalues.size(); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2504 valuetypes.reserve(n); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2505 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2506 for (size_t i = 0; i < n; i++) |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2507 { |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2508 valuetypes.push_back(initvalues[i]->getType()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2509 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2510 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2511 const LLType* st = llvm::StructType::get(valuetypes, packed); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2512 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2513 // alloca a stack slot |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
2514 LLValue* mem = DtoRawAlloca(st, 0, ".structliteral"); |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2515 |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2516 // fill in values |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2517 for (size_t i = 0; i < n; i++) |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2518 { |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2519 LLValue* addr = DtoGEPi(mem, 0, i); |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2520 p->ir->CreateStore(initvalues[i], addr); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2521 } |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2522 |
1255
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2523 // cast to default struct type |
9014d7f0433f
Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1248
diff
changeset
|
2524 mem = DtoBitCast(mem, DtoType(sd->type->pointerTo())); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2525 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2526 // return as a var |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2527 return new DVarValue(type, mem); |
49
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2528 } |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2529 |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2530 ////////////////////////////////////////////////////////////////////////////////////////// |
e5c4bece7fa1
[svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents:
48
diff
changeset
|
2531 |
213
7816aafeea3c
[svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents:
212
diff
changeset
|
2532 LLConstant* StructLiteralExp::toConstElem(IRState* p) |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2533 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2534 Logger::print("StructLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars()); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2535 LOG_SCOPE; |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2536 |
1245
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1231
diff
changeset
|
2537 // make sure the struct is resolved |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1231
diff
changeset
|
2538 sd->codegen(Type::sir); |
465a77c904d4
Fixed all issues preventing Tango 0.99.8 to compile with `sh build-tango.sh --verbose ldc'.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1231
diff
changeset
|
2539 |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2540 // get inits |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2541 std::vector<LLValue*> inits(sd->fields.dim, NULL); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2542 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2543 size_t nexprs = elements->dim;; |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2544 Expression** exprs = (Expression**)elements->data; |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2545 |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2546 for (size_t i = 0; i < nexprs; i++) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2547 if (exprs[i]) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2548 inits[i] = exprs[i]->toConstElem(p); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2549 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2550 // vector of values to build aggregate from |
1231
212ec2d9d176
Fixed some minitest regressions.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1228
diff
changeset
|
2551 std::vector<LLValue*> values = DtoStructLiteralValues(sd, inits); |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2552 |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2553 // we know those values are constants.. cast them |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2554 std::vector<LLConstant*> constvals(values.size(), NULL); |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2555 for (size_t i = 0; i < values.size(); ++i) |
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2556 constvals[i] = llvm::cast<LLConstant>(values[i]); |
797
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2557 |
340acf1535d0
Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
778
diff
changeset
|
2558 // return constant struct |
870
af7a6faf9406
Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents:
864
diff
changeset
|
2559 return LLConstantStruct::get(constvals, sd->ir.irStruct->packed); |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2560 } |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2561 |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2562 ////////////////////////////////////////////////////////////////////////////////////////// |
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2563 |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2564 DValue* InExp::toElem(IRState* p) |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2565 { |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2566 Logger::print("InExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2567 LOG_SCOPE; |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2568 |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2569 DValue* key = e1->toElem(p); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2570 DValue* aa = e2->toElem(p); |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2571 |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2572 return DtoAAIn(loc, type, aa, key); |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2573 } |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2574 |
127 | 2575 DValue* RemoveExp::toElem(IRState* p) |
2576 { | |
2577 Logger::print("RemoveExp::toElem: %s\n", toChars()); | |
2578 LOG_SCOPE; | |
2579 | |
2580 DValue* aa = e1->toElem(p); | |
2581 DValue* key = e2->toElem(p); | |
2582 | |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2583 DtoAARemove(loc, aa, key); |
127 | 2584 |
2585 return NULL; // does not produce anything useful | |
2586 } | |
2587 | |
109
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2588 ////////////////////////////////////////////////////////////////////////////////////////// |
5ab8e92611f9
[svn r113] Added initial support for associative arrays (AAs).
lindquist
parents:
108
diff
changeset
|
2589 |
125 | 2590 DValue* AssocArrayLiteralExp::toElem(IRState* p) |
2591 { | |
1151
3cf0066e6faf
- Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1149
diff
changeset
|
2592 Logger::print("AssocArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars()); |
125 | 2593 LOG_SCOPE; |
2594 | |
2595 assert(keys); | |
2596 assert(values); | |
2597 assert(keys->dim == values->dim); | |
2598 | |
486
a34078905d01
Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
485
diff
changeset
|
2599 Type* aatype = type->toBasetype(); |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2600 Type* vtype = aatype->nextOf(); |
283
9bb48fb57a7d
[svn r304] Fix associative array literals by always reserving a zero inited temporary for them.
ChristianK
parents:
282
diff
changeset
|
2601 |
9bb48fb57a7d
[svn r304] Fix associative array literals by always reserving a zero inited temporary for them.
ChristianK
parents:
282
diff
changeset
|
2602 // it should be possible to avoid the temporary in some cases |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
2603 LLValue* tmp = DtoAlloca(type,"aaliteral"); |
585
fbb1a366cfbc
Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
575
diff
changeset
|
2604 DValue* aa = new DVarValue(type, tmp); |
1350
15e9762bb620
Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents:
1326
diff
changeset
|
2605 DtoStore(LLConstant::getNullValue(DtoType(type)), tmp); |
127 | 2606 |
125 | 2607 const size_t n = keys->dim; |
2608 for (size_t i=0; i<n; ++i) | |
2609 { | |
2610 Expression* ekey = (Expression*)keys->data[i]; | |
2611 Expression* eval = (Expression*)values->data[i]; | |
2612 | |
1372
229e02867307
Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents:
1367
diff
changeset
|
2613 Logger::println("(%zu) aa[%s] = %s", i, ekey->toChars(), eval->toChars()); |
127 | 2614 |
2615 // index | |
2616 DValue* key = ekey->toElem(p); | |
458
121624c14053
Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
452
diff
changeset
|
2617 DValue* mem = DtoAAIndex(loc, vtype, aa, key, true); |
127 | 2618 |
2619 // store | |
2620 DValue* val = eval->toElem(p); | |
399
0e6b4d65d3f8
Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents:
397
diff
changeset
|
2621 DtoAssign(loc, mem, val); |
125 | 2622 } |
2623 | |
127 | 2624 return aa; |
125 | 2625 } |
2626 | |
2627 ////////////////////////////////////////////////////////////////////////////////////////// | |
2628 | |
599
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2629 DValue* GEPExp::toElem(IRState* p) |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2630 { |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2631 // this should be good enough for now! |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2632 DValue* val = e1->toElem(p); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2633 assert(val->isLVal()); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2634 LLValue* v = DtoGEPi(val->getLVal(), 0, index); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2635 return new DVarValue(type, DtoBitCast(v, getPtrToType(DtoType(type)))); |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2636 } |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2637 |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2638 ////////////////////////////////////////////////////////////////////////////////////////// |
4435f57956e7
Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
594
diff
changeset
|
2639 |
666 | 2640 DValue* BoolExp::toElem(IRState* p) |
2641 { | |
778
4adf0f742896
Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents:
770
diff
changeset
|
2642 return new DImValue(type, DtoCast(loc, e1->toElem(p), Type::tbool)->getRVal()); |
666 | 2643 } |
2644 | |
2645 ////////////////////////////////////////////////////////////////////////////////////////// | |
2646 | |
667 | 2647 DValue* DotTypeExp::toElem(IRState* p) |
2648 { | |
2649 Type* t = sym->getType(); | |
2650 assert(t); | |
2651 return e1->toElem(p); | |
2652 } | |
2653 | |
2654 ////////////////////////////////////////////////////////////////////////////////////////// | |
2655 | |
973
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2656 DValue* TypeExp::toElem(IRState *p) |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2657 { |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2658 error("type %s is not an expression", toChars()); |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2659 //TODO: Improve error handling. DMD just returns some value here and hopes |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2660 // some more sensible error messages will be triggered. |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2661 fatal(); |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2662 return NULL; |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2663 } |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2664 |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2665 ////////////////////////////////////////////////////////////////////////////////////////// |
d96471e8b5e5
Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents:
936
diff
changeset
|
2666 |
86
fd32135dca3e
[svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents:
85
diff
changeset
|
2667 #define STUB(x) DValue *x::toElem(IRState * p) {error("Exp type "#x" not implemented: %s", toChars()); fatal(); return 0; } |
1 | 2668 STUB(Expression); |
2669 STUB(ScopeExp); | |
92 | 2670 STUB(TupleExp); |
1 | 2671 |
758
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2672 #if DMDV2 |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2673 STUB(SymbolExp); |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2674 #endif |
f04dde6e882c
Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
720
diff
changeset
|
2675 |
1036
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2676 #define CONSTSTUB(x) LLConstant* x::toConstElem(IRState * p) { \ |
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2677 error("expression '%s' is not a constant", toChars()); \ |
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2678 fatal(); \ |
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2679 return NULL; \ |
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2680 } |
40 | 2681 CONSTSTUB(Expression); |
860
7edce7e58ab1
Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents:
859
diff
changeset
|
2682 CONSTSTUB(GEPExp); |
7edce7e58ab1
Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents:
859
diff
changeset
|
2683 CONSTSTUB(SliceExp); |
7edce7e58ab1
Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents:
859
diff
changeset
|
2684 CONSTSTUB(IndexExp); |
40 | 2685 CONSTSTUB(AssocArrayLiteralExp); |
2686 | |
1146
1860414bf3b7
* Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents:
1141
diff
changeset
|
2687 ////////////////////////////////////////////////////////////////////////////////////////// |
1 | 2688 |
659
43d2ab9833bf
Forgot a change from DMD update.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
656
diff
changeset
|
2689 void obj_includelib(const char* lib) |
340 | 2690 { |
1036
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2691 size_t n = strlen(lib)+3; |
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2692 char *arg = (char *)mem.malloc(n); |
594
e096a1502428
Fix #88 : pragma(lib, "str") is now converted to -lstr in the linker command line.
Christian Kamm <kamm incasoftware de>
parents:
592
diff
changeset
|
2693 strcpy(arg, "-l"); |
1036
01544da4cdd8
Added ~{memory} clobber when a jump_target is generated in inline asm (branch out of inline asm)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents:
1031
diff
changeset
|
2694 strncat(arg, lib, n); |
594
e096a1502428
Fix #88 : pragma(lib, "str") is now converted to -lstr in the linker command line.
Christian Kamm <kamm incasoftware de>
parents:
592
diff
changeset
|
2695 global.params.linkswitches->push(arg); |
340 | 2696 } |
2697 | |
2698 void backend_init() | |
1 | 2699 { |
1161
f528e55fb32f
Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents:
1152
diff
changeset
|
2700 // LLVM_D_InitRuntime is done in Module::genLLVMModule |
f528e55fb32f
Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents:
1152
diff
changeset
|
2701 // since it requires the semantic pass to be done |
1 | 2702 } |
2703 | |
340 | 2704 void backend_term() |
1 | 2705 { |
2706 LLVM_D_FreeRuntime(); | |
987
73ff89728d85
Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents:
973
diff
changeset
|
2707 llvm::llvm_shutdown(); |
1 | 2708 } |