annotate gen/toir.cpp @ 1497:d9d50163e1a4

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