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