annotate gen/toir.cpp @ 1633:5c0cebff9be8

Improve array append performance. Actually use the appropriate runtime function, instead of just growing the array by one!
author Christian Kamm <kamm incasoftware de>
date Sun, 14 Feb 2010 10:11:05 +0100
parents 628433c343b4
children 8f121883bce8
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"
1567
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
14 #include "llvm/Support/CommandLine.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
15
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
16 #include "attrib.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 #include "init.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 #include "mtype.h"
321
571959608194 [svn r342] Fix DMD bug 2206.
ChristianK
parents: 315
diff changeset
19 #include "template.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 #include "hdrgen.h"
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 #include "port.h"
1103
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1036
diff changeset
22 #include "rmem.h"
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1036
diff changeset
23 #include "id.h"
b30fe7e1dbb9 - Updated to DMD frontend 1.041.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1036
diff changeset
24 #include "enum.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
25
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
26 #include "gen/irstate.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
27 #include "gen/logger.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
28 #include "gen/tollvm.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
29 #include "gen/llvmhelpers.h"
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
30 #include "gen/runtime.h"
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
31 #include "gen/arrays.h"
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
32 #include "gen/structs.h"
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
33 #include "gen/classes.h"
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 101
diff changeset
34 #include "gen/typeinf.h"
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
35 #include "gen/complex.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
36 #include "gen/dvalue.h"
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
37 #include "gen/aa.h"
131
5825d48b27d1 [svn r135] * Merged DMD 1.025 *
lindquist
parents: 129
diff changeset
38 #include "gen/functions.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
39 #include "gen/todebug.h"
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1166
diff changeset
40 #include "gen/nested.h"
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
41 #include "gen/utils.h"
1567
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
42 #include "gen/warnings.h"
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
43
987
73ff89728d85 Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents: 973
diff changeset
44 #include "llvm/Support/ManagedStatic.h"
73ff89728d85 Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents: 973
diff changeset
45
1567
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
46 llvm::cl::opt<bool> checkPrintf("check-printf-calls",
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
47 llvm::cl::desc("Validate printf call format strings against arguments"),
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
48 llvm::cl::ZeroOrMore);
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
49
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
50 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
51
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
52 void Expression::cacheLvalue(IRState* irs)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
53 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
54 error("expression %s does not mask any l-value", toChars());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
55 fatal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
56 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
57
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
58 //////////////////////////////////////////////////////////////////////////////////////////
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
59
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
60 DValue* DeclarationExp::toElem(IRState* p)
1
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 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
63 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 426
diff changeset
65 return DtoDeclarationExp(declaration);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
67
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
68 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
69
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
70 void VarExp::cacheLvalue(IRState* p)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
71 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
72 Logger::println("Caching l-value of %s", toChars());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
73 LOG_SCOPE;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
74 cachedLvalue = toElem(p)->getLVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
75 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
76
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
77 DValue* VarExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
78 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
79 Logger::print("VarExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
80 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
81
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
82 assert(var);
834
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
83
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
84 if (cachedLvalue)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
85 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
86 LLValue* V = cachedLvalue;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
87 cachedLvalue = NULL;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
88 return new DVarValue(type, V);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
89 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
90
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
91 if (VarDeclaration* vd = var->isVarDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
92 {
763
9a9f403ab399 D2 changes!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 758
diff changeset
93 Logger::println("VarDeclaration ' %s ' of type ' %s '", vd->toChars(), vd->type->toChars());
50
6fcc08a4d406 [svn r54] Added support for nested delegates referencing parent's stack variables.
lindquist
parents: 49
diff changeset
94
834
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
95 // this is an error! must be accessed with DotVarExp
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
96 if (var->needThis())
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
97 {
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
98 error("need 'this' to access member %s", toChars());
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
99 fatal();
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
100 }
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
101
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
102 // _arguments
464
e381e082d5cb Fixed problem with using the variable names _arguments and _argptr in non D-style vararg functions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 460
diff changeset
103 if (vd->ident == Id::_arguments && p->func()->_arguments)
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
104 {
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 70
diff changeset
105 Logger::println("Id::_arguments");
363
4d7495038ae8 [svn r384] Some minor code cleanups.
lindquist
parents: 361
diff changeset
106 LLValue* v = p->func()->_arguments;
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
107 return new DVarValue(type, vd, v);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
108 }
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
109 // _argptr
464
e381e082d5cb Fixed problem with using the variable names _arguments and _argptr in non D-style vararg functions.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 460
diff changeset
110 else if (vd->ident == Id::_argptr && p->func()->_argptr)
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
111 {
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 70
diff changeset
112 Logger::println("Id::_argptr");
363
4d7495038ae8 [svn r384] Some minor code cleanups.
lindquist
parents: 361
diff changeset
113 LLValue* v = p->func()->_argptr;
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
114 return new DVarValue(type, vd, v);
57
a9d29e9f1fed [svn r61] Added support for D-style variadic functions :)
lindquist
parents: 55
diff changeset
115 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
116 // _dollar
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
117 else if (vd->ident == Id::dollar)
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
118 {
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 70
diff changeset
119 Logger::println("Id::dollar");
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
120 assert(!p->arrays.empty());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
121 LLValue* tmp = DtoArrayLen(p->arrays.back());
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
122 return new DImValue(type, tmp);
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
123 }
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
124 // typeinfo
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
125 else if (TypeInfoDeclaration* tid = vd->isTypeInfoDeclaration())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
126 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
127 Logger::println("TypeInfoDeclaration");
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
128 tid->codegen(Type::sir);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
129 assert(tid->ir.getIrValue());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
130 const LLType* vartype = DtoType(type);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
131 LLValue* m = tid->ir.getIrValue();
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
132 if (m->getType() != getPtrToType(vartype))
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
133 m = p->ir->CreateBitCast(m, vartype, "tmp");
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
134 return new DImValue(type, m);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
135 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
136 // classinfo
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
137 else if (ClassInfoDeclaration* cid = vd->isClassInfoDeclaration())
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
138 {
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
139 Logger::println("ClassInfoDeclaration: %s", cid->cd->toChars());
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
140 cid->cd->codegen(Type::sir);;
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1211
diff changeset
141 return new DVarValue(type, vd, cid->cd->ir.irStruct->getClassInfoSymbol());
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
142 }
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
143 // nested variable
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
144 #if DMDV2
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
145 else if (vd->nestedrefs.dim) {
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
146 #else
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
147 else if (vd->nestedref) {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
148 #endif
72
d7e764e62462 [svn r76] Fixed: TypeInfo for structs.
lindquist
parents: 70
diff changeset
149 Logger::println("nested variable");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
150 return DtoNestedVariable(loc, type, vd);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
151 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
152 // function parameter
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
153 else if (vd->isParameter()) {
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
154 Logger::println("function param");
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
155 Logger::println("type: %s", vd->type->toChars());
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
156 FuncDeclaration* fd = vd->toParent2()->isFuncDeclaration();
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
157 if (fd && fd != p->func()->decl) {
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
158 Logger::println("nested parameter");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
159 return DtoNestedVariable(loc, type, vd);
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
160 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
161 else if (vd->storage_class & STClazy) {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
162 Logger::println("lazy parameter");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
163 assert(type->ty == Tdelegate);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
164 return new DVarValue(type, vd->ir.getIrValue());
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
165 }
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
166 else if (vd->isRef() || vd->isOut() || DtoIsPassedByRef(vd->type) || llvm::isa<llvm::AllocaInst>(vd->ir.getIrValue())) {
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
167 return new DVarValue(type, vd, vd->ir.getIrValue());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
168 }
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
169 else if (llvm::isa<llvm::Argument>(vd->ir.getIrValue())) {
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
170 return new DImValue(type, vd->ir.getIrValue());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
171 }
82
d8dd47ef3973 [svn r86] Changed the way arguments are given storage. It is now detected if they will need it during semantic passes.
lindquist
parents: 81
diff changeset
172 else assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
173 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
174 else {
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
175 Logger::println("a normal variable");
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
176
67
f918f3e2e99e [svn r71] Fixed accessing parent function arguments from inside nested delegates.
lindquist
parents: 66
diff changeset
177 // take care of forward references of global variables
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
178 if (vd->isDataseg() || (vd->storage_class & STCextern)) {
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1146
diff changeset
179 vd->codegen(Type::sir);
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
180 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
181
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
182 LLValue* val;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
183
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
184 if (!vd->ir.isSet() || !(val = vd->ir.getIrValue())) {
834
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
185 // FIXME: this error is bad!
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
186 // We should be VERY careful about adding errors in general, as they have
f466f475b654 Added proper "need 'this' to access member foo" errors instead of "variable foo not resolved" for some cases, added FIXME for the old error!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 825
diff changeset
187 // a tendency to "mask" out the underlying problems ...
656
a15ccbf7451d Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 643
diff changeset
188 error("variable %s not resolved", vd->toChars());
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
189 if (Logger::enabled())
656
a15ccbf7451d Support structs that are merely a forward reference. See mini/forwdecl1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 643
diff changeset
190 Logger::cout() << "unresolved variable had type: " << *DtoType(vd->type) << '\n';
397
9ec89aad9dbc Make an unresolved global into an error instead of an assert.
Christian Kamm <kamm incasoftware de>
parents: 384
diff changeset
191 fatal();
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
192 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
193
628
e3c46bcce65f Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents: 624
diff changeset
194 if (vd->isDataseg() || (vd->storage_class & STCextern)) {
e3c46bcce65f Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents: 624
diff changeset
195 DtoConstInitGlobal(vd);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
196 val = DtoBitCast(val, DtoType(type->pointerTo()));
628
e3c46bcce65f Detect a missing global before trying to const init it.
Christian Kamm <kamm incasoftware de>
parents: 624
diff changeset
197 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
198
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
199 return new DVarValue(type, vd, val);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
200 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
201 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
202 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
203 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
204 Logger::println("FuncDeclaration");
384
3f98d46e05a4 Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 379
diff changeset
205 LLValue* func = 0;
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
206 if (fdecl->llvmInternal == LLVMinline_asm) {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
207 error("special ldc inline asm is not a normal function");
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
208 fatal();
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
209 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
210 else if (fdecl->llvmInternal != LLVMva_arg) {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
211 fdecl->codegen(Type::sir);
384
3f98d46e05a4 Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 379
diff changeset
212 func = fdecl->ir.irFunc->func;
102
027b8d8b71ec [svn r106] Turns out the last commit wasn't enough, now the D->LLVM process is even more split up.
lindquist
parents: 101
diff changeset
213 }
384
3f98d46e05a4 Fixed segfault when using va_arg.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 379
diff changeset
214 return new DFuncValue(fdecl, func);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
215 }
913
29c0d1194033 Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents: 887
diff changeset
216 else if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
217 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
218 // this seems to be the static initialiser for structs
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
219 Type* sdecltype = sdecl->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
220 Logger::print("Sym: type=%s\n", sdecltype->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
221 assert(sdecltype->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
222 TypeStruct* ts = (TypeStruct*)sdecltype;
121
9c79b61fb638 [svn r125] Renamed/moved a few backend member inside DMD structures for consistency.
lindquist
parents: 120
diff changeset
223 assert(ts->sym);
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
224 ts->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1211
diff changeset
225
1270
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
226 LLValue* initsym = ts->sym->ir.irStruct->getInitSymbol();
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
227 initsym = DtoBitCast(initsym, DtoType(ts->pointerTo()));
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
228 return new DVarValue(type, initsym);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
229 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
230 else
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 assert(0 && "Unimplemented VarExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
233 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
234
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
235 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
236 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
237
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
238 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
239
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
240 LLConstant* VarExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
241 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
242 Logger::print("VarExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
243 LOG_SCOPE;
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
244
913
29c0d1194033 Fix #198 and #199 by making CTFE on static struct initializers work.
Christian Kamm <kamm incasoftware de>
parents: 887
diff changeset
245 if (StaticStructInitDeclaration* sdecl = var->isStaticStructInitDeclaration())
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
246 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
247 // this seems to be the static initialiser for structs
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
248 Type* sdecltype = sdecl->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
249 Logger::print("Sym: type=%s\n", sdecltype->toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
250 assert(sdecltype->ty == Tstruct);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
251 TypeStruct* ts = (TypeStruct*)sdecltype;
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
252 ts->sym->codegen(Type::sir);
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1211
diff changeset
253
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1211
diff changeset
254 return ts->sym->ir.irStruct->getDefaultInit();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
255 }
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
256
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
257 if (TypeInfoDeclaration* ti = var->isTypeInfoDeclaration())
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
258 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
259 const LLType* vartype = DtoType(type);
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 268
diff changeset
260 LLConstant* m = DtoTypeInfoOf(ti->tinfo, false);
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 268
diff changeset
261 if (m->getType() != getPtrToType(vartype))
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
262 m = llvm::ConstantExpr::getBitCast(m, vartype);
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
263 return m;
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
264 }
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
265
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
266 VarDeclaration* vd = var->isVarDeclaration();
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
267 if (vd && vd->isConst() && vd->init)
836
14c3319ac1bb This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 834
diff changeset
268 {
1595
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
269 if (vd->inuse)
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
270 {
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
271 error("recursive reference %s", toChars());
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
272 return llvm::UndefValue::get(DtoType(type));
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
273 }
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
274 vd->inuse++;
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
275 LLConstant* ret = DtoConstInitializer(loc, type, vd->init);
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
276 vd->inuse--;
836
14c3319ac1bb This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 834
diff changeset
277 // return the initializer
1595
628433c343b4 Fixed DStress tests nocompile/c/{const_32_B.d,const_32_C.d}.
Robert Clipsham <robert@octarineparrot.com>
parents: 1580
diff changeset
278 return ret;
836
14c3319ac1bb This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 834
diff changeset
279 }
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
280
836
14c3319ac1bb This ''should'' fix #139 , I failed to produce a testcase, but I would imagine this to be correct, and it removes '''that''' error when building Hybrid.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 834
diff changeset
281 // fail
920
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
282 error("non-constant expression %s", toChars());
545f54041d91 Implemented proper support for naked asm using llvm module level asm. Still not 100% complete, but already 1000 times better that what we had before. Don's BignumX86 implementation from Tango (when turned into a standalone unittest) seems to fully work with no changes, and great performance :)
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 918
diff changeset
283 return llvm::UndefValue::get(DtoType(type));
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
284 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
285
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
286 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
287
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
288 DValue* IntegerExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
289 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
290 Logger::print("IntegerExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
291 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
292 LLConstant* c = toConstElem(p);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
293 return new DConstValue(type, c);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
294 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
295
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
296 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
297
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
298 LLConstant* IntegerExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
299 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
300 Logger::print("IntegerExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
301 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
302 const LLType* t = DtoType(type);
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
303 if (isaPointer(t)) {
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
304 Logger::println("pointer");
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
305 LLConstant* i = LLConstantInt::get(DtoSize_t(),(uint64_t)value,false);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
306 return llvm::ConstantExpr::getIntToPtr(i, t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
307 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
308 assert(llvm::isa<LLIntegerType>(t));
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
309 LLConstant* c = LLConstantInt::get(t,(uint64_t)value,!type->isunsigned());
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
310 assert(c);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
311 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
312 Logger::cout() << "value = " << *c << '\n';
88
058d3925950e [svn r92] Fixed support for statically initialized unions. lots of bugfixes as cleanups too.
lindquist
parents: 86
diff changeset
313 return c;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
314 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
315
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
316 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
317
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
318 DValue* RealExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
319 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
320 Logger::print("RealExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
321 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
322 LLConstant* c = toConstElem(p);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
323 return new DConstValue(type, c);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
324 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
325
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
326 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
327
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
328 LLConstant* RealExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
329 {
1378
5575e0c07e1a Use %La to hex-format a real instead of pretending it's an integer.
Frits van Bommel <fvbommel wxs.nl>
parents: 1377
diff changeset
330 Logger::print("RealExp::toConstElem: %s @ %s | %La\n", toChars(), type->toChars(), value);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
331 LOG_SCOPE;
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
332 Type* t = type->toBasetype();
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
333 return DtoConstFP(t, value);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
334 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
335
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
336 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
337
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
338 DValue* NullExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
339 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
340 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
341 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
342 LLConstant* c = toConstElem(p);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
343 return new DNullValue(type, c);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
344 }
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 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
347
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
348 LLConstant* NullExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
349 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
350 Logger::print("NullExp::toConstElem(type=%s): %s\n", type->toChars(),toChars());
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
351 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
352 const LLType* t = DtoType(type);
28
1c80c18f3c82 [svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents: 27
diff changeset
353 if (type->ty == Tarray) {
96
ce7ed8f59b99 [svn r100] Moved test/ray.d to demos/ray.d.
lindquist
parents: 94
diff changeset
354 assert(isaStruct(t));
1556
4897323d47b5 ConstantAggregateZero moved back to LLVM 2.5-style API
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
355 return llvm::ConstantAggregateZero::get(t);
28
1c80c18f3c82 [svn r32] * Fixed problems with arrays members of aggregates
lindquist
parents: 27
diff changeset
356 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
357 else {
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1559
diff changeset
358 return LLConstant::getNullValue(t);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
359 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
360 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
361 return NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
362 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
363
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
364 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
365
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
366 DValue* ComplexExp::toElem(IRState* p)
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
367 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
368 Logger::print("ComplexExp::toElem(): %s @ %s\n", toChars(), type->toChars());
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
369 LOG_SCOPE;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
370 LLConstant* c = toConstElem(p);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
371 LLValue* res;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
372
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
373 if (c->isNullValue()) {
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
374 Type* t = type->toBasetype();
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
375 if (t->ty == Tcomplex32)
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
376 c = DtoConstFP(Type::tfloat32, 0);
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
377 else if (t->ty == Tcomplex64)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
378 c = DtoConstFP(Type::tfloat64, 0);
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
379 else if (t->ty == Tcomplex80)
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
380 c = DtoConstFP(Type::tfloat80, 0);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
381 else
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 443
diff changeset
382 assert(0);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
383 res = DtoAggrPair(DtoType(type), c, c);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
384 }
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
385 else {
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
386 res = DtoAggrPair(DtoType(type), c->getOperand(0), c->getOperand(1));
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
387 }
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
388
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
389 return new DImValue(type, res);
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
390 }
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
391
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
392 //////////////////////////////////////////////////////////////////////////////////////////
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
393
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
394 LLConstant* ComplexExp::toConstElem(IRState* p)
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
395 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
396 Logger::print("ComplexExp::toConstElem(): %s @ %s\n", toChars(), type->toChars());
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
397 LOG_SCOPE;
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
398 return DtoConstComplex(type, value.re, value.im);
90
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
399 }
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
400
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
401 //////////////////////////////////////////////////////////////////////////////////////////
16e88334bba7 [svn r94] started on complex support
lindquist
parents: 88
diff changeset
402
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
403 DValue* StringExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
404 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
405 Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
406 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
407
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
408 Type* dtype = type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
409 Type* cty = dtype->nextOf()->toBasetype();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
410
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 321
diff changeset
411 const LLType* ct = DtoTypeNotVoid(cty);
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
412 //printf("ct = %s\n", type->nextOf()->toChars());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
413 const LLArrayType* at = LLArrayType::get(ct,len+1);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
414
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
415 LLConstant* _init;
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
416 if (cty->size() == 1) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
417 uint8_t* str = (uint8_t*)string;
1572
30bdcfb8299e Avoid some unecessary heap allocations by using llvm's StringRef class.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1571
diff changeset
418 llvm::StringRef cont((char*)str, len);
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
419 _init = LLConstantArray::get(p->context(), cont, true);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
420 }
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
421 else if (cty->size() == 2) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
422 uint16_t* str = (uint16_t*)string;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
423 std::vector<LLConstant*> vals;
1395
6063ddfcf27d Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1378
diff changeset
424 vals.reserve(len+1);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
425 for(size_t i=0; i<len; ++i) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
426 vals.push_back(LLConstantInt::get(ct, str[i], false));;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
427 }
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
428 vals.push_back(LLConstantInt::get(ct, 0, false));
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
429 _init = LLConstantArray::get(at,vals);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
430 }
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
431 else if (cty->size() == 4) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
432 uint32_t* str = (uint32_t*)string;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
433 std::vector<LLConstant*> vals;
1395
6063ddfcf27d Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1378
diff changeset
434 vals.reserve(len+1);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
435 for(size_t i=0; i<len; ++i) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
436 vals.push_back(LLConstantInt::get(ct, str[i], false));;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
437 }
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
438 vals.push_back(LLConstantInt::get(ct, 0, false));
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
439 _init = LLConstantArray::get(at,vals);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
440 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
441 else
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
442 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
443
918
a4fcc13da3cd Changed templates and typeinfo to use linkonce linkage instead of weak linkage, this should fix inlining problems, fixing bug #197 . If problems show up, it's easy to change it back by changing the define in mars.h . I'm 95% sure this is safe, given how we handle templates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 915
diff changeset
444 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
445 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
446 Logger::cout() << "type: " << *at << "\ninit: " << *_init << '\n';
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1513
diff changeset
447 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,at,true,_linkage,_init,".str");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
448
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
449 llvm::ConstantInt* zero = LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
450 LLConstant* idxs[2] = { zero, zero };
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
451 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
452
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
453 if (dtype->ty == Tarray) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
454 LLConstant* clen = LLConstantInt::get(DtoSize_t(),len,false);
720
e177ae483f8e Added inreg attribute where appropriate on x86 to follow ABI docs.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
455 return new DImValue(type, DtoConstSlice(clen, arrptr));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
456 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
457 else if (dtype->ty == Tsarray) {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
458 const LLType* dstType = getPtrToType(LLArrayType::get(ct, len));
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
459 LLValue* emem = (gvar->getType() == dstType) ? gvar : DtoBitCast(gvar, dstType);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
460 return new DVarValue(type, emem);
21
8d45266bbabe [svn r25] * Fixed a lot of problems with string literals
lindquist
parents: 18
diff changeset
461 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
462 else if (dtype->ty == Tpointer) {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
463 return new DImValue(type, arrptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
464 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
465
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
466 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
467 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
468 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
469
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
470 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
471
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
472 LLConstant* StringExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
473 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
474 Logger::print("StringExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
475 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
476
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
477 Type* t = type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
478 Type* cty = t->nextOf()->toBasetype();
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
479
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
480 bool nullterm = (t->ty != Tsarray);
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
481 size_t endlen = nullterm ? len+1 : len;
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
482
1496
b4fc62f047cd More DtoType -> DtoTypeNotVoid for getting the array element llvm type.
Christian Kamm <kamm incasoftware de>
parents: 1479
diff changeset
483 const LLType* ct = DtoTypeNotVoid(cty);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
484 const LLArrayType* at = LLArrayType::get(ct,endlen);
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
485
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
486 LLConstant* _init;
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
487 if (cty->size() == 1) {
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
488 uint8_t* str = (uint8_t*)string;
1572
30bdcfb8299e Avoid some unecessary heap allocations by using llvm's StringRef class.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1571
diff changeset
489 llvm::StringRef cont((char*)str, len);
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
490 _init = LLConstantArray::get(p->context(), cont, nullterm);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
491 }
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
492 else if (cty->size() == 2) {
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
493 uint16_t* str = (uint16_t*)string;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
494 std::vector<LLConstant*> vals;
1395
6063ddfcf27d Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1378
diff changeset
495 vals.reserve(len+1);
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
496 for(size_t i=0; i<len; ++i) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
497 vals.push_back(LLConstantInt::get(ct, str[i], false));;
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
498 }
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
499 if (nullterm)
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
500 vals.push_back(LLConstantInt::get(ct, 0, false));
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
501 _init = LLConstantArray::get(at,vals);
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
502 }
183
3cdf4b0c75a1 [svn r199] Fixed: still some small issues with string literals implicitly converting to different pointer types. Should be fixed now!
lindquist
parents: 178
diff changeset
503 else if (cty->size() == 4) {
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
504 uint32_t* str = (uint32_t*)string;
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
505 std::vector<LLConstant*> vals;
1395
6063ddfcf27d Try to cut down reallocations when building string literals.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1378
diff changeset
506 vals.reserve(len+1);
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
507 for(size_t i=0; i<len; ++i) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
508 vals.push_back(LLConstantInt::get(ct, str[i], false));;
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
509 }
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
510 if (nullterm)
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
511 vals.push_back(LLConstantInt::get(ct, 0, false));
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
512 _init = LLConstantArray::get(at,vals);
176
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
513 }
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
514 else
a074a5ff709c [svn r192] Fixed: String literals as constant expression was broken for utf16/32.
lindquist
parents: 175
diff changeset
515 assert(0);
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
516
178
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
517 if (t->ty == Tsarray)
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
518 {
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
519 return _init;
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
520 }
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
521
918
a4fcc13da3cd Changed templates and typeinfo to use linkonce linkage instead of weak linkage, this should fix inlining problems, fixing bug #197 . If problems show up, it's easy to change it back by changing the define in mars.h . I'm 95% sure this is safe, given how we handle templates.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 915
diff changeset
522 llvm::GlobalValue::LinkageTypes _linkage = llvm::GlobalValue::InternalLinkage;
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1513
diff changeset
523 llvm::GlobalVariable* gvar = new llvm::GlobalVariable(*gIR->module,_init->getType(),true,_linkage,_init,".str");
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
524
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
525 llvm::ConstantInt* zero = LLConstantInt::get(LLType::getInt32Ty(gIR->context()), 0, false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
526 LLConstant* idxs[2] = { zero, zero };
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
527 LLConstant* arrptr = llvm::ConstantExpr::getGetElementPtr(gvar,idxs,2);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
528
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
529 if (t->ty == Tpointer) {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
530 return arrptr;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
531 }
178
8873b7f1457e [svn r194] Fixed: string literal constant expressions with static array type was broken.
lindquist
parents: 177
diff changeset
532 else if (t->ty == Tarray) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
533 LLConstant* clen = LLConstantInt::get(DtoSize_t(),len,false);
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
534 return DtoConstSlice(clen, arrptr);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
535 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
536
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
537 assert(0);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
538 return NULL;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
539 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
540
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
541 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
542
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
543 DValue* AssignExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
544 {
467
261b05cf4d1c Fixed problem in AssignExp where the result value might be uninitialized. see mini/assign1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 464
diff changeset
545 Logger::print("AssignExp::toElem: %s | (%s)(%s = %s)\n", toChars(), type->toChars(), e1->type->toChars(), e2->type ? e2->type->toChars() : 0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
546 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
547
335
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
548 if (e1->op == TOKarraylength)
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
549 {
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
550 Logger::println("performing array.length assignment");
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
551 ArrayLengthExp *ale = (ArrayLengthExp *)e1;
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
552 DValue* arr = ale->e1->toElem(p);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
553 DVarValue arrval(ale->e1->type, arr->getLVal());
335
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
554 DValue* newlen = e2->toElem(p);
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
555 DSliceValue* slice = DtoResizeDynArray(arrval.getType(), &arrval, newlen);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
556 DtoAssign(loc, &arrval, slice);
335
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
557 return newlen;
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
558 }
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
559
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
560 Logger::println("performing normal assignment");
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
561
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
562 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
563 DValue* r = e2->toElem(p);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
564 DtoAssign(loc, l, r);
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
565
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
566 if (l->isSlice())
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
567 return l;
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
568
468
45a67b6f1310 Removed the 'needsstorage' thing from Dsymbol. Arguments are not always given storage when applicable. This is not longer treat specially
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 467
diff changeset
569 return r;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
570 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
571
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
572 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
573
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
574 /// Finds the proper lvalue for a binassign expressions.
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
575 /// Makes sure the given LHS expression is only evaluated once.
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
576 static Expression* findLvalue(IRState* irs, Expression* exp)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
577 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
578 Expression* e = exp;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
579
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
580 // skip past any casts
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
581 while(e->op == TOKcast)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
582 e = ((CastExp*)e)->e1;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
583
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
584 // cache lvalue and return
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
585 e->cacheLvalue(irs);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
586 return e;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
587 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
588
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
589 #define BIN_ASSIGN(X) \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
590 DValue* X##AssignExp::toElem(IRState* p) \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
591 { \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
592 Logger::print(#X"AssignExp::toElem: %s @ %s\n", toChars(), type->toChars()); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
593 LOG_SCOPE; \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
594 X##Exp e3(loc, e1, e2); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
595 e3.type = e1->type; \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
596 DValue* dst = findLvalue(p, e1)->toElem(p); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
597 DValue* res = e3.toElem(p); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
598 DValue* stval = DtoCast(loc, res, dst->getType()); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
599 DtoAssign(loc, dst, stval); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
600 return DtoCast(loc, res, type); \
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
601 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
602
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
603 BIN_ASSIGN(Add)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
604 BIN_ASSIGN(Min)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
605 BIN_ASSIGN(Mul)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
606 BIN_ASSIGN(Div)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
607 BIN_ASSIGN(Mod)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
608 BIN_ASSIGN(And)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
609 BIN_ASSIGN(Or)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
610 BIN_ASSIGN(Xor)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
611 BIN_ASSIGN(Shl)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
612 BIN_ASSIGN(Shr)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
613 BIN_ASSIGN(Ushr)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
614
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
615 #undef BIN_ASSIGN
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
616
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
617 //////////////////////////////////////////////////////////////////////////////////////////
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
618
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
619 static void errorOnIllegalArrayOp(Expression* base, Expression* e1, Expression* e2)
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
620 {
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
621 Type* t1 = e1->type->toBasetype();
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
622 Type* t2 = e2->type->toBasetype();
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
623
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
624 // valid array ops would have been transformed by optimize
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
625 if ((t1->ty == Tarray || t1->ty == Tsarray) &&
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
626 (t2->ty == Tarray || t2->ty == Tsarray)
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
627 )
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
628 {
1513
8a5570ddad25 Emit file and line info for 'Array operation ... not recognized' error.
Christian Kamm <kamm incasoftware de>
parents: 1512
diff changeset
629 base->error("Array operation %s not recognized", base->toChars());
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
630 fatal();
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
631 }
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
632 }
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
633
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
634 //////////////////////////////////////////////////////////////////////////////////////////
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
635
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
636 DValue* AddExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
637 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
638 Logger::print("AddExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
639 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
640
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
641 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
642 DValue* r = e2->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
643
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
644 Type* t = type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
645 Type* e1type = e1->type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
646 Type* e1next = e1type->nextOf() ? e1type->nextOf()->toBasetype() : NULL;
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
647 Type* e2type = e2->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
648
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
649 errorOnIllegalArrayOp(this, e1, e2);
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
650
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
651 if (e1type != e2type) {
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
652 if (e1type->ty == Tpointer) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
653 Logger::println("add to pointer");
1166
c6f39553b702 Clean up some suspicious code.
Frits van Bommel <fvbommel wxs.nl>
parents: 1161
diff changeset
654 if (DConstValue* cv = r->isConst()) {
c6f39553b702 Clean up some suspicious code.
Frits van Bommel <fvbommel wxs.nl>
parents: 1161
diff changeset
655 if (cv->c->isNullValue()) {
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
656 Logger::println("is zero");
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
657 return new DImValue(type, l->getRVal());
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
658 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
659 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
660 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), r->getRVal(), "tmp", p->scopebb());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
661 return new DImValue(type, v);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
662 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
663 else if (t->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
664 return DtoComplexAdd(loc, type, l, r);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
665 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
666 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
667 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
668 else if (t->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
669 return DtoComplexAdd(loc, type, l, r);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
670 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
671 else {
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
672 return DtoBinAdd(l,r);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
673 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
674 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
675
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
676 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
677
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
678 DValue* MinExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
679 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
680 Logger::print("MinExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
681 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
682
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
683 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
684 DValue* r = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
685
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
686 Type* t = type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
687 Type* t1 = e1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
688 Type* t2 = e2->type->toBasetype();
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
689
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
690 errorOnIllegalArrayOp(this, e1, e2);
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
691
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
692 if (t1->ty == Tpointer && t2->ty == Tpointer) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
693 LLValue* lv = l->getRVal();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
694 LLValue* rv = r->getRVal();
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
695 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
696 Logger::cout() << "lv: " << *lv << " rv: " << *rv << '\n';
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
697 lv = p->ir->CreatePtrToInt(lv, DtoSize_t(), "tmp");
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
698 rv = p->ir->CreatePtrToInt(rv, DtoSize_t(), "tmp");
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
699 LLValue* diff = p->ir->CreateSub(lv,rv,"tmp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
700 if (diff->getType() != DtoType(type))
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
701 diff = p->ir->CreateIntToPtr(diff, DtoType(type), "tmp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
702 return new DImValue(type, diff);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
703 }
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
704 else if (t1->ty == Tpointer) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
705 LLValue* idx = p->ir->CreateNeg(r->getRVal(), "tmp");
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
706 LLValue* v = llvm::GetElementPtrInst::Create(l->getRVal(), idx, "tmp", p->scopebb());
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
707 return new DImValue(type, v);
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
708 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
709 else if (t->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
710 return DtoComplexSub(loc, type, l, r);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
711 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
712 else {
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
713 return DtoBinSub(l,r);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
714 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
715 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
716
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
717 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
718
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
719 DValue* MulExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
720 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
721 Logger::print("MulExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
722 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
723
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
724 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
725 DValue* r = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
726
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
727 errorOnIllegalArrayOp(this, e1, e2);
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
728
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
729 if (type->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
730 return DtoComplexMul(loc, type, l, r);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
731 }
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
732
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 521
diff changeset
733 return DtoBinMul(type, l, r);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
734 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
735
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
736 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
737
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
738 DValue* DivExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
739 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
740 Logger::print("DivExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
741 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
742
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
743 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
744 DValue* r = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
745
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
746 errorOnIllegalArrayOp(this, e1, e2);
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
747
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
748 if (type->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
749 return DtoComplexDiv(loc, type, l, r);
104
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
750 }
4d1e9eb001e0 [svn r108] Now basic suppport for complex types. =,+,-,*,/ are supported.
lindquist
parents: 102
diff changeset
751
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 521
diff changeset
752 return DtoBinDiv(type, l, r);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
753 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
754
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
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
757 DValue* ModExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
758 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
759 Logger::print("ModExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
760 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
761
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
762 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
763 DValue* r = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
764
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
765 errorOnIllegalArrayOp(this, e1, e2);
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
766
524
ca2dfe98036c Binary ops had the wrong result type for real op imaginary.
Christian Kamm <kamm incasoftware de>
parents: 521
diff changeset
767 return DtoBinRem(type, l, r);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
768 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
769
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
770 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
771
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
772 DValue* CallExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
773 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
774 Logger::print("CallExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
775 LOG_SCOPE;
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
776
1152
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
777 // handle magic inline asm
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
778 if (e1->op == TOKvar)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
779 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
780 VarExp* ve = (VarExp*)e1;
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
781 if (FuncDeclaration* fd = ve->var->isFuncDeclaration())
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
782 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
783 if (fd->llvmInternal == LLVMinline_asm)
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
784 {
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
785 return DtoInlineAsmExpr(loc, fd, arguments);
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
786 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
787 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
788 }
521dd1626d76 Added initial support for raw LLVM inline asm.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1151
diff changeset
789
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
790 // get the callee value
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
791 DValue* fnval = e1->toElem(p);
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
792
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
793 // get func value if any
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
794 DFuncValue* dfnval = fnval->isFunc();
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
795
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
796 // handle magic intrinsics (mapping to instructions)
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
797 bool va_intrinsic = false;
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
798 if (dfnval && dfnval->func)
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
799 {
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
800 FuncDeclaration* fndecl = dfnval->func;
1567
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
801
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
802 // as requested by bearophile, see if it's a C printf call and that it's valid.
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
803 if (global.params.warnings && checkPrintf)
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
804 {
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
805 if (fndecl->linkage == LINKc && strcmp(fndecl->ident->string, "printf") == 0)
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
806 {
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
807 warnInvalidPrintfCall(loc, (Expression*)arguments->data[0], arguments->dim);
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
808 }
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
809 }
f1f33c8dcd90 Added framework for writing a static printf call checker for bearophile to implement.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1560
diff changeset
810
215
a58d8f4b84df [svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents: 213
diff changeset
811 // va_start instruction
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
812 if (fndecl->llvmInternal == LLVMva_start) {
443
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 440
diff changeset
813 // llvm doesn't need the second param hence the override
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 440
diff changeset
814 Expression* exp = (Expression*)arguments->data[0];
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 440
diff changeset
815 DValue* expv = exp->toElem(p);
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 440
diff changeset
816 LLValue* arg = DtoBitCast(expv->getLVal(), getVoidPtrType());
44f08170f4ef Removed tango from the repository and instead added a runtime dir with the files needed to patch and build tango from svn.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 440
diff changeset
817 return new DImValue(type, gIR->ir->CreateCall(GET_INTRINSIC_DECL(vastart), arg, ""));
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
818 }
215
a58d8f4b84df [svn r231] Changed: warnings are no longer treated as an error.
lindquist
parents: 213
diff changeset
819 // va_arg instruction
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
820 else if (fndecl->llvmInternal == LLVMva_arg) {
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
821 return DtoVaArg(loc, type, (Expression*)arguments->data[0]);
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
822 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
823 // C alloca
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
824 else if (fndecl->llvmInternal == LLVMalloca) {
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
825 Expression* exp = (Expression*)arguments->data[0];
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
826 DValue* expv = exp->toElem(p);
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
827 if (expv->getType()->toBasetype()->ty != Tint32)
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
828 expv = DtoCast(loc, expv, Type::tint32);
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
829 return new DImValue(type, p->ir->CreateAlloca(LLType::getInt8Ty(gIR->context()), expv->getRVal(), ".alloca"));
55
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
830 }
0ccfae271c45 [svn r59] Added support for C-style variadic functions. Currently only works on x86, x86-64 va_arg is broken in LLVM 2.1. PPC and PPC64 unknown.
lindquist
parents: 54
diff changeset
831 }
414
ac1fcc138e42 Fixed issue with internal real representation, incorrect for non x86-32 architectures.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
832
422
fa91b03d9cd7 Error message for calling a function with a missing 'this' arg.
Christian Kamm <kamm incasoftware de>
parents: 414
diff changeset
833 return DtoCallFunction(loc, type, fnval, arguments);
1
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 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
837
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
838 DValue* CastExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
839 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
840 Logger::print("CastExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
841 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
842
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
843 // get the value to cast
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
844 DValue* u = e1->toElem(p);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
845
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
846 // cast it to the 'to' type, if necessary
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
847 DValue* v = u;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
848 if (!to->equals(e1->type))
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
849 v = DtoCast(loc, u, to);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
850
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
851 // paint the type, if necessary
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
852 if (!type->equals(to))
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
853 v = DtoPaintType(loc, v, type);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
854
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
855 // return the new rvalue
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
856 return v;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
857 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
858
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
859 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
860
619
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
861 LLConstant* CastExp::toConstElem(IRState* p)
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
862 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
863 Logger::print("CastExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
619
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
864 LOG_SCOPE;
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
865
870
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
866 LLConstant* res;
619
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
867 const LLType* lltype = DtoType(type);
870
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
868 Type* tb = to->toBasetype();
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
869
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
870 // string literal to dyn array:
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
871 // reinterpret the string data as an array, calculate the length
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
872 if (e1->op == TOKstring && tb->ty == Tarray) {
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
873 /* StringExp *strexp = (StringExp*)e1;
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
874 size_t datalen = strexp->sz * strexp->len;
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
875 Type* eltype = tb->nextOf()->toBasetype();
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
876 if (datalen % eltype->size() != 0) {
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
877 error("the sizes don't line up");
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
878 return e1->toConstElem(p);
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
879 }
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
880 size_t arrlen = datalen / eltype->size();*/
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
881 error("ct cast of string to dynamic array not fully implemented");
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
882 return e1->toConstElem(p);
624
eb444ed4a2d3 Make invalid compile time casts an error instead of asserting.
Christian Kamm <kamm incasoftware de>
parents: 622
diff changeset
883 }
870
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
884 // pointer to pointer
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
885 else if (tb->ty == Tpointer && e1->type->toBasetype()->ty == Tpointer) {
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
886 res = llvm::ConstantExpr::getBitCast(e1->toConstElem(p), lltype);
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
887 }
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
888 else {
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
889 error("can not cast %s to %s at compile time", e1->type->toChars(), type->toChars());
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
890 return e1->toConstElem(p);
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
891 }
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
892
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
893 return res;
619
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
894 }
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
895
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
896 //////////////////////////////////////////////////////////////////////////////////////////
722630261d62 Implemented constant pointer casts (like casting function pointer to void* as a constant global initializer)
tomas@myhost
parents: 616
diff changeset
897
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
898 DValue* SymOffExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
899 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
900 Logger::print("SymOffExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
901 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
902
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
903 assert(0 && "SymOffExp::toElem should no longer be called :/");
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
904 return 0;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
905 }
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
906
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
907 //////////////////////////////////////////////////////////////////////////////////////////
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
908
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
909 DValue* AddrExp::toElem(IRState* p)
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
910 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
911 Logger::println("AddrExp::toElem: %s @ %s", toChars(), type->toChars());
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
912 LOG_SCOPE;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
913 DValue* v = e1->toElem(p);
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
914 if (v->isField()) {
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
915 Logger::println("is field");
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
916 return v;
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
917 }
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
918 else if (DFuncValue* fv = v->isFunc()) {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
919 Logger::println("is func");
100
5071469303d4 [svn r104] TONS OF FIXES.
lindquist
parents: 99
diff changeset
920 //Logger::println("FuncDeclaration");
94
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
921 FuncDeclaration* fd = fv->func;
61615fa85940 [svn r98] Added support for std.c.stdlib.alloca via pragma(LLVM_internal, "alloca").
lindquist
parents: 92
diff changeset
922 assert(fd);
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
923 fd->codegen(Type::sir);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
924 return new DFuncValue(fd, fd->ir.irFunc->func);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
925 }
101
169fda3a77d4 [svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents: 100
diff changeset
926 else if (DImValue* im = v->isIm()) {
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
927 Logger::println("is immediate");
101
169fda3a77d4 [svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents: 100
diff changeset
928 return v;
169fda3a77d4 [svn r105] -inline does nothing for now, the -On setting can already be used to trigger it.
lindquist
parents: 100
diff changeset
929 }
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
930 Logger::println("is nothing special");
820
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
931
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
932 // we special case here, since apparently taking the address of a slice is ok
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
933 LLValue* lval;
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
934 if (v->isLVal())
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
935 lval = v->getLVal();
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
936 else
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
937 {
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
938 assert(v->isSlice());
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
939 LLValue* rval = v->getRVal();
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1326
diff changeset
940 lval = DtoRawAlloca(rval->getType(), 0, ".tmp_slice_storage");
820
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
941 DtoStore(rval, lval);
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
942 }
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
943
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
944 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
945 Logger::cout() << "lval: " << *lval << '\n';
820
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
946
bb4a81e68ddb Implemented allocating storage for a slice if its address is taken, fixes #115
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 819
diff changeset
947 return new DImValue(type, DtoBitCast(lval, DtoType(type)));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
948 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
949
459
9db9099583ca Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents: 452
diff changeset
950 LLConstant* AddrExp::toConstElem(IRState* p)
9db9099583ca Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents: 452
diff changeset
951 {
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
952 // FIXME: this should probably be generalized more so we don't
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
953 // need to have a case for each thing we can take the address of
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
954
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
955 // address of global variable
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
956 if (e1->op == TOKvar)
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
957 {
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
958 VarExp* vexp = (VarExp*)e1;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
959
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
960 // make sure 'this' isn't needed
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
961 if (vexp->var->needThis())
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
962 {
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
963 error("need 'this' to access %s", vexp->var->toChars());
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
964 fatal();
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
965 }
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
966
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
967 // global variable
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
968 if (VarDeclaration* vd = vexp->var->isVarDeclaration())
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
969 {
1149
5ebe8224988b Fixed problems introduced by previous commits that prevented Tango from compiling.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
970 vd->codegen(Type::sir);
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
971 LLConstant* llc = llvm::dyn_cast<LLConstant>(vd->ir.getIrValue());
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
972 assert(llc);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
973 return llc;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
974 }
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
975 // static function
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
976 else if (FuncDeclaration* fd = vexp->var->isFuncDeclaration())
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
977 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
978 fd->codegen(Type::sir);
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
979 IrFunction* irfunc = fd->ir.irFunc;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
980 return irfunc->func;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
981 }
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
982 // something else
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
983 else
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
984 {
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
985 // fail
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
986 goto Lerr;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
987 }
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
988 }
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
989 // address of indexExp
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
990 else if (e1->op == TOKindex)
469
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
991 {
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
992 IndexExp* iexp = (IndexExp*)e1;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
993
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
994 // indexee must be global static array var
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
995 assert(iexp->e1->op == TOKvar);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
996 VarExp* vexp = (VarExp*)iexp->e1;
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
997 VarDeclaration* vd = vexp->var->isVarDeclaration();
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
998 assert(vd);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
999 assert(vd->type->toBasetype()->ty == Tsarray);
1580
b4616536dc04 allow forward referencing, fix #361
Moritz Warning <moritzwarning@web.de>
parents: 1572
diff changeset
1000 vd->codegen(Type::sir);
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1001 assert(vd->ir.irGlobal);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1002
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1003 // get index
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1004 LLConstant* index = iexp->e2->toConstElem(p);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1005 assert(index->getType() == DtoSize_t());
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1006
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1007 // gep
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1008 LLConstant* idxs[2] = { DtoConstSize_t(0), index };
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1009 LLConstant* gep = llvm::ConstantExpr::getGetElementPtr(isaConstant(vd->ir.irGlobal->value), idxs, 2);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1010
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1011 // bitcast to requested type
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1012 assert(type->toBasetype()->ty == Tpointer);
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1013 return DtoBitCast(gep, DtoType(type));
469
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1014 }
1497
d9d50163e1a4 Cannot take the address of a slice or struct literal as a constant expression.
Christian Kamm <kamm incasoftware de>
parents: 1496
diff changeset
1015 else if (
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1016 e1->op == TOKstructliteral ||
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
1017 e1->op == TOKslice)
857
217e8c719a2f Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents: 837
diff changeset
1018 {
1497
d9d50163e1a4 Cannot take the address of a slice or struct literal as a constant expression.
Christian Kamm <kamm incasoftware de>
parents: 1496
diff changeset
1019 error("non-constant expression '%s'", toChars());
d9d50163e1a4 Cannot take the address of a slice or struct literal as a constant expression.
Christian Kamm <kamm incasoftware de>
parents: 1496
diff changeset
1020 fatal();
857
217e8c719a2f Apply wilsonk's patch to AddrExp::toConstElem for struct literals.
Christian Kamm <kamm incasoftware de>
parents: 837
diff changeset
1021 }
469
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1022 // not yet supported
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1023 else
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1024 {
819
446263a8a30d Fixed taking address of global static array element as constant expression.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 809
diff changeset
1025 Lerr:
469
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1026 error("constant expression '%s' not yet implemented", toChars());
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1027 fatal();
d0dad1fe0f45 Fixed constant expression taking address of function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 468
diff changeset
1028 }
459
9db9099583ca Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents: 452
diff changeset
1029 }
9db9099583ca Implement a rough AddrExp::toConstElem()
Christian Kamm <kamm incasoftware de>
parents: 452
diff changeset
1030
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1031 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1032
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1033 void PtrExp::cacheLvalue(IRState* p)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1034 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1035 Logger::println("Caching l-value of %s", toChars());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1036 LOG_SCOPE;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1037 cachedLvalue = e1->toElem(p)->getRVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1038 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1039
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1040 DValue* PtrExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1041 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1042 Logger::println("PtrExp::toElem: %s @ %s", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1043 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1044
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1045 // function pointers are special
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1046 if (type->toBasetype()->ty == Tfunction)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1047 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1048 assert(!cachedLvalue);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1049 return new DImValue(type, e1->toElem(p)->getRVal());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1050 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1051
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1052 // get the rvalue and return it as an lvalue
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1053 LLValue* V;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1054 if (cachedLvalue)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1055 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1056 V = cachedLvalue;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1057 cachedLvalue = NULL;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1058 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1059 else
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1060 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1061 V = e1->toElem(p)->getRVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1062 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1063 return new DVarValue(type, V);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1064 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1065
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1066 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1067
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1068 void DotVarExp::cacheLvalue(IRState* p)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1069 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1070 Logger::println("Caching l-value of %s", toChars());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1071 LOG_SCOPE;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1072 cachedLvalue = toElem(p)->getLVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1073 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1074
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1075 DValue* DotVarExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1076 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1077 Logger::print("DotVarExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1078 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1079
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1080 if (cachedLvalue)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1081 {
1465
dd72f56ad211 Added missing initializer of (LDC introduced) Expression::cachedLvalue in D2 frontend.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1434
diff changeset
1082 Logger::println("using cached lvalue");
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1083 LLValue *V = cachedLvalue;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1084 cachedLvalue = NULL;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1085 VarDeclaration* vd = var->isVarDeclaration();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1086 assert(vd);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1087 return new DVarValue(type, vd, V);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1088 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1089
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1090 DValue* l = e1->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1091
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1092 Type* t = type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1093 Type* e1type = e1->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1094
172
68a7dd38c03c [svn r188] Fixed using a dereferenced pointer argument as both l- and r-value. fixes tango.io.FileRoots.
lindquist
parents: 170
diff changeset
1095 //Logger::println("e1type=%s", e1type->toChars());
68a7dd38c03c [svn r188] Fixed using a dereferenced pointer argument as both l- and r-value. fixes tango.io.FileRoots.
lindquist
parents: 170
diff changeset
1096 //Logger::cout() << *DtoType(e1type) << '\n';
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1097
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1098 if (VarDeclaration* vd = var->isVarDeclaration()) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1099 LLValue* arrptr;
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1100 // indexing struct pointer
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1101 if (e1type->ty == Tpointer) {
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
1102 assert(e1type->nextOf()->ty == Tstruct);
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
1103 TypeStruct* ts = (TypeStruct*)e1type->nextOf();
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1104 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1105 }
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1106 // indexing normal struct
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1107 else if (e1type->ty == Tstruct) {
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1108 TypeStruct* ts = (TypeStruct*)e1type;
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1109 arrptr = DtoIndexStruct(l->getRVal(), ts->sym, vd);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1110 }
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1111 // indexing class
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1112 else if (e1type->ty == Tclass) {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1113 TypeClass* tc = (TypeClass*)e1type;
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1114 arrptr = DtoIndexClass(l->getRVal(), tc->sym, vd);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1115 }
77
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 76
diff changeset
1116 else
714057ff2dbb [svn r81] Fixed: Union support was very buggy. Should be fairly solid now.
lindquist
parents: 76
diff changeset
1117 assert(0);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1118
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 122
diff changeset
1119 //Logger::cout() << "mem: " << *arrptr << '\n';
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1120 return new DVarValue(type, vd, arrptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1121 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1122 else if (FuncDeclaration* fdecl = var->isFuncDeclaration())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1123 {
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1124 DtoResolveDsymbol(fdecl);
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1125
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1126 LLValue* funcval;
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1127 LLValue* vthis2 = 0;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1128 if (e1type->ty == Tclass) {
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1129 TypeClass* tc = (TypeClass*)e1type;
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1130 if (tc->sym->isInterfaceDeclaration()) {
114
5880c12dba83 [svn r118] Fixed dynamic casts.
lindquist
parents: 113
diff changeset
1131 vthis2 = DtoCastInterfaceToObject(l, NULL)->getRVal();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1132 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1133 }
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1134 LLValue* vthis = l->getRVal();
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1135 if (!vthis2) vthis2 = vthis;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1136
1136
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1137 //
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1138 // decide whether this function needs to be looked up in the vtable
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1139 //
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1140 bool vtbllookup = fdecl->isAbstract() || (!fdecl->isFinal() && fdecl->isVirtual());
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1141
1136
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1142 // even virtual functions are looked up directly if super or DotTypeExp
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1143 // 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
1144 Expression* e = e1;
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1145 while (e && vtbllookup) {
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1146 if (e->op == TOKsuper || e->op == TOKdottype)
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1147 vtbllookup = false;
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1148 else if (e->op == TOKcast)
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1149 e = ((CastExp*)e)->e1;
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1150 else
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1151 break;
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1152 }
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1153
1136
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1154 //
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1155 // look up function
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1156 //
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1157 if (!vtbllookup) {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
1158 fdecl->codegen(Type::sir);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
1159 funcval = fdecl->ir.irFunc->func;
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1160 assert(funcval);
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1161 }
1136
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1162 else {
1434
5d0c043ff131 Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents: 1419
diff changeset
1163 DImValue vthis3(e1type, vthis);
5d0c043ff131 Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents: 1419
diff changeset
1164 funcval = DtoVirtualFunctionPointer(&vthis3, fdecl, toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1165 }
1136
9d308feaec27 Fix #239.
Christian Kamm <kamm incasoftware de>
parents: 1103
diff changeset
1166
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1167 return new DFuncValue(fdecl, funcval, vthis2);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1168 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1169 else {
123
7f9a0a58394b [svn r127] Updated the lphobos build scripts a little. Created a new rebuild profile.
lindquist
parents: 122
diff changeset
1170 printf("unsupported dotvarexp: %s\n", var->toChars());
1
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
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1173 assert(0);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1174 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1175 }
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
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1179 DValue* ThisExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1180 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1181 Logger::print("ThisExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1182 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1183
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 321
diff changeset
1184 // regular this expr
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1185 if (VarDeclaration* vd = var->isVarDeclaration()) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1186 LLValue* v;
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1187 if (vd->toParent2() != p->func()->decl) {
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1188 Logger::println("nested this exp");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1189 return DtoNestedVariable(loc, type, vd);
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1190 }
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1191 else {
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1192 Logger::println("normal this exp");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1193 v = p->func()->thisArg;
452
30ef3c7bddca Fixed problems with nested 'this'. Fixes #39 .
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 445
diff changeset
1194 }
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1195 return new DVarValue(type, vd, v);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1196 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1197
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 321
diff changeset
1198 // anything we're not yet handling ?
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1199 assert(0 && "no var in ThisExp");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1200 return 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1201 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1202
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1203 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1204
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1205 void IndexExp::cacheLvalue(IRState* p)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1206 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1207 Logger::println("Caching l-value of %s", toChars());
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1208 LOG_SCOPE;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1209 cachedLvalue = toElem(p)->getLVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1210 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1211
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1212 DValue* IndexExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1213 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1214 Logger::print("IndexExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1215 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1216
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1217 if (cachedLvalue)
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1218 {
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1219 LLValue* V = cachedLvalue;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1220 cachedLvalue = NULL;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1221 return new DVarValue(type, V);
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1222 }
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1223
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1224 DValue* l = e1->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1225
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1226 Type* e1type = e1->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1227
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1228 p->arrays.push_back(l); // if $ is used it must be an array so this is fine.
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1229 DValue* r = e2->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1230 p->arrays.pop_back();
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1231
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1232 LLValue* zero = DtoConstUint(0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1233 LLValue* one = DtoConstUint(1);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1234
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1235 LLValue* arrptr = 0;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1236 if (e1type->ty == Tpointer) {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1237 arrptr = DtoGEP1(l->getRVal(),r->getRVal());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1238 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1239 else if (e1type->ty == Tsarray) {
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1240 if(global.params.useArrayBounds)
440
d8dc221d3db7 Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents: 439
diff changeset
1241 DtoArrayBoundsCheck(loc, l, r, false);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1242 arrptr = DtoGEP(l->getRVal(), zero, r->getRVal());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1243 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1244 else if (e1type->ty == Tarray) {
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1245 if(global.params.useArrayBounds)
440
d8dc221d3db7 Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents: 439
diff changeset
1246 DtoArrayBoundsCheck(loc, l, r, false);
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 268
diff changeset
1247 arrptr = DtoArrayPtr(l);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1248 arrptr = DtoGEP1(arrptr,r->getRVal());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1249 }
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1250 else if (e1type->ty == Taarray) {
458
121624c14053 Fixed AA Rvalue-only access (like indexing an AA return value immediately).
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 452
diff changeset
1251 return DtoAAIndex(loc, type, l, r, modifiable);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1252 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1253 else {
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1254 Logger::println("invalid index exp! e1type: %s", e1type->toChars());
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1255 assert(0);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
1256 }
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1257 return new DVarValue(type, arrptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1258 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1259
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1260 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1261
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1262 DValue* SliceExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1263 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1264 Logger::print("SliceExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1265 LOG_SCOPE;
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 // this is the new slicing code, it's different in that a full slice will no longer retain the original pointer.
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1268 // but this was broken if there *was* no original pointer, ie. a slice of a slice...
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1269 // now all slices have *both* the 'len' and 'ptr' fields set to != null.
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1270
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1271 // value being sliced
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1272 LLValue* elen;
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1273 LLValue* eptr;
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1274 DValue* e = e1->toElem(p);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1275
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1276 // handle pointer slicing
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1277 Type* etype = e1->type->toBasetype();
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1278 if (etype->ty == Tpointer)
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1279 {
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1280 assert(lwr);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1281 eptr = e->getRVal();
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1282 }
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1283 // array slice
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1284 else
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1285 {
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1286 eptr = DtoArrayPtr(e);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1287 }
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1288
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1289 // has lower bound, pointer needs adjustment
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1290 if (lwr)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1291 {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1292 // must have upper bound too then
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1293 assert(upr);
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1294
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1295 // get bounds (make sure $ works)
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1296 p->arrays.push_back(e);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1297 DValue* lo = lwr->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1298 DValue* up = upr->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1299 p->arrays.pop_back();
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1300 LLValue* vlo = lo->getRVal();
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1301 LLValue* vup = up->getRVal();
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1302
440
d8dc221d3db7 Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents: 439
diff changeset
1303 if(global.params.useArrayBounds && (etype->ty == Tsarray || etype->ty == Tarray))
d8dc221d3db7 Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents: 439
diff changeset
1304 DtoArrayBoundsCheck(loc, e, up, true);
d8dc221d3db7 Insert array bound checks for slices.
Christian Kamm <kamm incasoftware de>
parents: 439
diff changeset
1305
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1306 // offset by lower
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1307 eptr = DtoGEP1(eptr, vlo);
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1309 // adjust length
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1310 elen = p->ir->CreateSub(vup, vlo, "tmp");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1311 }
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1312 // no bounds or full slice -> just convert to slice
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1313 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1314 {
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1315 assert(e1->type->toBasetype()->ty != Tpointer);
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1316 // if the sliceee is a static array, we use the length of that as DMD seems
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1317 // to give contrary inconsistent sizesin some multidimensional static array cases.
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1318 // (namely default initialization, int[16][16] arr; -> int[256] arr = 0;)
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1319 if (etype->ty == Tsarray)
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1320 {
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1321 TypeSArray* tsa = (TypeSArray*)etype;
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1322 elen = DtoConstSize_t(tsa->dim->toUInteger());
825
a70ddd449e7d Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 823
diff changeset
1323
a70ddd449e7d Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 823
diff changeset
1324 // in this case, we also need to make sure the pointer is cast to the innermost element type
a70ddd449e7d Commented some logging that could be '''very''' long, cuts -vv output size of a gtkd gl sample down 1.2GB by 3/4.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 823
diff changeset
1325 eptr = DtoBitCast(eptr, DtoType(tsa->nextOf()->pointerTo()));
339
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1326 }
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1327 // for normal code the actual array length is what we want!
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1328 else
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1329 {
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1330 elen = DtoArrayLen(e);
385a18242485 [svn r360] Another mostly rewrite of DtoArrayInit. Should be much more robust now, and probably faster code generated for the most common cases too!
lindquist
parents: 336
diff changeset
1331 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1332 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1333
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
1334 return new DSliceValue(type, elen, eptr);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1335 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1336
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1337 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1338
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1339 DValue* CmpExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1340 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1341 Logger::print("CmpExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1342 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1343
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1344 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1345 DValue* r = e2->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1346
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1347 Type* t = e1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1348 Type* e2t = e2->type->toBasetype();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1349
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1350 LLValue* eval = 0;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1351
58
2c3cd3596187 [svn r62] Added support for TypeInfo _Array, _Function, _Pointer, _Delegate, _Enum
lindquist
parents: 57
diff changeset
1352 if (t->isintegral() || t->ty == Tpointer)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1353 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1354 llvm::ICmpInst::Predicate cmpop;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1355 bool skip = false;
575
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1356 // pointers don't report as being unsigned
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1357 bool uns = (t->isunsigned() || t->ty == Tpointer);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1358 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1359 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1360 case TOKlt:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1361 case TOKul:
575
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1362 cmpop = uns ? llvm::ICmpInst::ICMP_ULT : llvm::ICmpInst::ICMP_SLT;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1363 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1364 case TOKle:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1365 case TOKule:
575
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1366 cmpop = uns ? llvm::ICmpInst::ICMP_ULE : llvm::ICmpInst::ICMP_SLE;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1367 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1368 case TOKgt:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1369 case TOKug:
575
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1370 cmpop = uns ? llvm::ICmpInst::ICMP_UGT : llvm::ICmpInst::ICMP_SGT;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1371 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1372 case TOKge:
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1373 case TOKuge:
575
f0c20d50d4b3 Pointer comparisons were being treated as signed integers. Now they are handled as unsigned integers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 574
diff changeset
1374 cmpop = uns ? llvm::ICmpInst::ICMP_UGE : llvm::ICmpInst::ICMP_SGE;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1375 break;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1376 case TOKue:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1377 cmpop = llvm::ICmpInst::ICMP_EQ;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1378 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1379 case TOKlg:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1380 cmpop = llvm::ICmpInst::ICMP_NE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1381 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1382 case TOKleg:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1383 skip = true;
1559
06d5cc873350 getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents: 1556
diff changeset
1384 eval = LLConstantInt::getTrue(gIR->context());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1385 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1386 case TOKunord:
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1387 skip = true;
1559
06d5cc873350 getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents: 1556
diff changeset
1388 eval = LLConstantInt::getFalse(gIR->context());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1389 break;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1390
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1391 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1392 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1393 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1394 if (!skip)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1395 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1396 LLValue* a = l->getRVal();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1397 LLValue* b = r->getRVal();
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
1398 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
1399 {
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
1400 Logger::cout() << "type 1: " << *a << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
1401 Logger::cout() << "type 2: " << *b << '\n';
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
1402 }
574
aee6217b4084 Fixed pointer comparisons with differing types.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 554
diff changeset
1403 if (a->getType() != b->getType())
aee6217b4084 Fixed pointer comparisons with differing types.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 554
diff changeset
1404 b = DtoBitCast(b, a->getType());
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1405 eval = p->ir->CreateICmp(cmpop, a, b, "tmp");
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1406 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1407 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1408 else if (t->isfloating())
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1409 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1410 llvm::FCmpInst::Predicate cmpop;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1411 switch(op)
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 case TOKlt:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1414 cmpop = llvm::FCmpInst::FCMP_OLT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1415 case TOKle:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1416 cmpop = llvm::FCmpInst::FCMP_OLE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1417 case TOKgt:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1418 cmpop = llvm::FCmpInst::FCMP_OGT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1419 case TOKge:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1420 cmpop = llvm::FCmpInst::FCMP_OGE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1421 case TOKunord:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1422 cmpop = llvm::FCmpInst::FCMP_UNO;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1423 case TOKule:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1424 cmpop = llvm::FCmpInst::FCMP_ULE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1425 case TOKul:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1426 cmpop = llvm::FCmpInst::FCMP_ULT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1427 case TOKuge:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1428 cmpop = llvm::FCmpInst::FCMP_UGE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1429 case TOKug:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1430 cmpop = llvm::FCmpInst::FCMP_UGT;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1431 case TOKue:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1432 cmpop = llvm::FCmpInst::FCMP_UEQ;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1433 case TOKlg:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1434 cmpop = llvm::FCmpInst::FCMP_ONE;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1435 case TOKleg:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1436 cmpop = llvm::FCmpInst::FCMP_ORD;break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1437
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1438 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1439 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1440 }
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1441 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
1442 }
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1443 else if (t->ty == Tsarray || t->ty == Tarray)
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1444 {
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1445 Logger::println("static or dynamic array");
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 422
diff changeset
1446 eval = DtoArrayCompare(loc,op,l,r);
99
a676a7743642 [svn r103] Array comparisons are now fully implemented, that is - to the extent that TypeInfo is.
lindquist
parents: 98
diff changeset
1447 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1448 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1449 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1450 assert(0 && "Unsupported CmpExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1451 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1452
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1453 return new DImValue(type, eval);
1
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
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1456 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1457
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1458 DValue* EqualExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1459 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1460 Logger::print("EqualExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1461 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1462
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1463 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1464 DValue* r = e2->toElem(p);
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
1465 LLValue* lv = l->getRVal();
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
1466 LLValue* rv = r->getRVal();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1467
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1468 Type* t = e1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1469 Type* e2t = e2->type->toBasetype();
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1470 //assert(t == e2t);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1471
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1472 LLValue* eval = 0;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1473
512
0d286cd9fd08 Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents: 487
diff changeset
1474 // the Tclass catches interface comparisons, regular
0d286cd9fd08 Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents: 487
diff changeset
1475 // class equality should be rewritten as a.opEquals(b) by this time
1512
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1476 if (t->isintegral() || t->ty == Tpointer || t->ty == Tclass)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1477 {
512
0d286cd9fd08 Add interface comparison to EqualExp: just do pointer comparison.
Christian Kamm <kamm incasoftware de>
parents: 487
diff changeset
1478 Logger::println("integral or pointer or interface");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1479 llvm::ICmpInst::Predicate cmpop;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1480 switch(op)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1481 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1482 case TOKequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1483 cmpop = llvm::ICmpInst::ICMP_EQ;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1484 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1485 case TOKnotequal:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1486 cmpop = llvm::ICmpInst::ICMP_NE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1487 break;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1488 default:
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1489 assert(0);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1490 }
108
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1491 if (rv->getType() != lv->getType()) {
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1492 rv = DtoBitCast(rv, lv->getType());
288fe1029e1f [svn r112] Fixed 'case 1,2,3:' style case statements.
lindquist
parents: 107
diff changeset
1493 }
705
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1494 if (Logger::enabled())
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1495 {
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1496 Logger::cout() << "lv: " << *lv << '\n';
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1497 Logger::cout() << "rv: " << *rv << '\n';
5a2983f97498 Fixed weird struct problem from downs, see mini/compile_structs1.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 704
diff changeset
1498 }
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
1499 eval = p->ir->CreateICmp(cmpop, lv, rv, "tmp");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1500 }
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
1501 else if (t->isfloating()) // includes iscomplex
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1502 {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
1503 eval = DtoBinNumericEquals(loc, l, r, op);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1504 }
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1505 else if (t->ty == Tsarray || t->ty == Tarray)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1506 {
98
6789050b5ad1 [svn r102] Further delayed emission of function bodies to avoid problems with circular-forward-references.
lindquist
parents: 97
diff changeset
1507 Logger::println("static or dynamic array");
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 422
diff changeset
1508 eval = DtoArrayEquals(loc,op,l,r);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1509 }
1512
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1510 else if (t->ty == Taarray)
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1511 {
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1512 Logger::println("associative array");
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1513 eval = DtoAAEquals(loc,op,l,r);
09734fb929c0 Make == for associative arrays test for equality, not identity.
Christian Kamm <kamm incasoftware de>
parents: 1511
diff changeset
1514 }
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1515 else if (t->ty == Tdelegate)
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1516 {
64
b688ad419f8c [svn r68] Added support for multi-dimensional static arrays.
lindquist
parents: 62
diff changeset
1517 Logger::println("delegate");
344
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1518 eval = DtoDelegateEquals(op,l->getRVal(),r->getRVal());
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1519 }
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1520 else if (t->ty == Tstruct)
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1521 {
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1522 Logger::println("struct");
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1523 // when this is reached it means there is no opEquals overload.
e20ce6d8d374 [svn r365] Implemented raw struct equality comparison, uses C memcmp.
lindquist
parents: 340
diff changeset
1524 eval = DtoStructEquals(op,l,r);
53
06ccc817acd4 [svn r57] Added most basic TypeInfo (rebuild lphobos).
lindquist
parents: 52
diff changeset
1525 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1526 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1527 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1528 assert(0 && "Unsupported EqualExp type");
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1529 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1530
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1531 return new DImValue(type, eval);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1532 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1533
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1534 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1535
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1536 DValue* PostExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1537 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1538 Logger::print("PostExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1539 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1540
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1541 DValue* l = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1542 DValue* r = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1543
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1544 LLValue* val = l->getRVal();
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1545 LLValue* post = 0;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1546
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1547 Type* e1type = e1->type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1548 Type* e2type = e2->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1549
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1550 if (e1type->isintegral())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1551 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1552 assert(e2type->isintegral());
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
1553 LLValue* one = LLConstantInt::get(val->getType(), 1, !e2type->isunsigned());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1554 if (op == TOKplusplus) {
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
1555 post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1556 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1557 else if (op == TOKminusminus) {
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
1558 post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1559 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1560 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1561 else if (e1type->ty == Tpointer)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1562 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1563 assert(e2type->isintegral());
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
1564 LLConstant* minusone = LLConstantInt::get(DtoSize_t(),(uint64_t)-1,true);
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
1565 LLConstant* plusone = LLConstantInt::get(DtoSize_t(),(uint64_t)1,false);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1566 LLConstant* whichone = (op == TOKplusplus) ? plusone : minusone;
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1567 post = llvm::GetElementPtrInst::Create(val, whichone, "tmp", p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1568 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1569 else if (e1type->isfloating())
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1570 {
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
1571 assert(e2type->isfloating());
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1572 LLValue* one = DtoConstFP(e1type, 1.0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1573 if (op == TOKplusplus) {
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
1574 post = llvm::BinaryOperator::CreateAdd(val,one,"tmp",p->scopebb());
1
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 else if (op == TOKminusminus) {
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
1577 post = llvm::BinaryOperator::CreateSub(val,one,"tmp",p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1578 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1579 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1580 else
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1581 assert(post);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1582
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1583 DtoStore(post,l->getLVal());
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1584
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1585 return new DImValue(type,val);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1586 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1587
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1588 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1589
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1590 DValue* NewExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1591 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1592 Logger::print("NewExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1593 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1594
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1595 assert(newtype);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1596 Type* ntype = newtype->toBasetype();
81
3587401b6eeb [svn r85] Fixed: if a return statement appeared in the try block of a nested try-finally, only the inner-most finally block would be executed.
lindquist
parents: 78
diff changeset
1597
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1598 // new class
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1599 if (ntype->ty == Tclass) {
169
2df270e1ba59 [svn r185] Fixed broken nested classes with data members, did DMD change the class layout? tango.text.Regex now compiles.
lindquist
parents: 167
diff changeset
1600 Logger::println("new class");
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1601 return DtoNewClass(loc, (TypeClass*)ntype, this);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1602 }
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1603 // new dynamic array
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1604 else if (ntype->ty == Tarray)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1605 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1606 Logger::println("new dynamic array: %s", newtype->toChars());
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1607 // get dim
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1608 assert(arguments);
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1609 assert(arguments->dim >= 1);
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1610 if (arguments->dim == 1)
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1611 {
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1612 DValue* sz = ((Expression*)arguments->data[0])->toElem(p);
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1613 // allocate & init
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 587
diff changeset
1614 return DtoNewDynArray(loc, newtype, sz, true);
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1615 }
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1616 else
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1617 {
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1618 size_t ndims = arguments->dim;
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1619 std::vector<DValue*> dims(ndims);
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1620 for (size_t i=0; i<ndims; ++i)
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1621 dims[i] = ((Expression*)arguments->data[i])->toElem(p);
591
e6bcc4d9e5ff Add _d_newarrayvT and _d_newarraymvT to create arrays without initialization.
Christian Kamm <kamm incasoftware de>
parents: 587
diff changeset
1622 return DtoNewMulDimDynArray(loc, newtype, &dims[0], ndims, true);
286
a3b7c19c866c [svn r307] Fixed: multidimensional new expressions now work. Eg.:
lindquist
parents: 284
diff changeset
1623 }
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1624 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1625 // new static array
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1626 else if (ntype->ty == Tsarray)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1627 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1628 assert(0);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1629 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1630 // new struct
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1631 else if (ntype->ty == Tstruct)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1632 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1633 Logger::println("new struct on heap: %s\n", newtype->toChars());
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1634 // allocate
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1635 LLValue* mem = DtoNew(newtype);
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1636 // init
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1637 TypeStruct* ts = (TypeStruct*)ntype;
1367
8026319762be Merged DMD 1.045 !!!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1351
diff changeset
1638 if (ts->isZeroInit(ts->sym->loc)) {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents: 243
diff changeset
1639 DtoAggrZeroInit(mem);
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1640 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1641 else {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1642 assert(ts->sym);
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
1643 ts->sym->codegen(Type::sir);
1270
dd135ff697fa Fixed class default initializers and type generation. Bug #260 is fixed.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1644 DtoAggrCopy(mem, ts->sym->ir.irStruct->getInitSymbol());
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1645 }
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1646 return new DImValue(type, mem);
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1647 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1648 // new basic type
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1649 else
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1650 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1651 // allocate
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1652 LLValue* mem = DtoNew(newtype);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1653 DVarValue tmpvar(newtype, mem);
212
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1654
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1655 // default initialize
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1211
diff changeset
1656 // static arrays never appear here, so using the defaultInit is ok!
212
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1657 Expression* exp = newtype->defaultInit(loc);
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1658 DValue* iv = exp->toElem(gIR);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
1659 DtoAssign(loc, &tmpvar, iv);
212
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1660
4c2689d57ba4 [svn r228] Fixed: when new'ing basic types, the storage was not default initialized.
lindquist
parents: 210
diff changeset
1661 // return as pointer-to
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1662 return new DImValue(type, mem);
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1663 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1664
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
1665 assert(0);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1666 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1667
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1668 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1669
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1670 DValue* DeleteExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1671 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1672 Logger::print("DeleteExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1673 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1674
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1675 DValue* dval = e1->toElem(p);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
1676 Type* et = e1->type->toBasetype();
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1677
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1678 // simple pointer
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1679 if (et->ty == Tpointer)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1680 {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1681 LLValue* rval = dval->getRVal();
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1682 DtoDeleteMemory(rval);
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1683 if (dval->isVar())
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1559
diff changeset
1684 DtoStore(LLConstant::getNullValue(rval->getType()), dval->getLVal());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1685 }
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1686 // class
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1687 else if (et->ty == Tclass)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1688 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1689 bool onstack = false;
210
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1690 TypeClass* tc = (TypeClass*)et;
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1691 if (tc->sym->isInterfaceDeclaration())
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1692 {
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1693 DtoDeleteInterface(dval->getRVal());
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1694 onstack = true;
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1695 }
1d6cfdbc97f0 [svn r226] Fixed: deleting interface.
lindquist
parents: 209
diff changeset
1696 else if (DVarValue* vv = dval->isVar()) {
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1697 if (vv->var && vv->var->onstack) {
554
1b702422451c Always call finalizer for stack classes. Checking for the number of
Christian Kamm <kamm incasoftware de>
parents: 553
diff changeset
1698 DtoFinalizeClass(dval->getRVal());
275
665b81613475 [svn r296] Removed: the 'suite' dir, it never took off!
lindquist
parents: 268
diff changeset
1699 onstack = true;
113
27b9f749d9fe [svn r117] Initial working implementation of interfaces.
lindquist
parents: 109
diff changeset
1700 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1701 }
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1702 if (!onstack) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1703 LLValue* rval = dval->getRVal();
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1704 DtoDeleteClass(rval);
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1705 }
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
1706 if (dval->isVar()) {
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1707 LLValue* lval = dval->getLVal();
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1559
diff changeset
1708 DtoStore(LLConstant::getNullValue(lval->getType()->getContainedType(0)), lval);
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1709 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1710 }
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1711 // dyn array
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1712 else if (et->ty == Tarray)
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1713 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1714 DtoDeleteArray(dval);
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
1715 if (dval->isLVal())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 705
diff changeset
1716 DtoSetArrayToNull(dval->getLVal());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1717 }
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1718 // unknown/invalid
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1719 else
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1720 {
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1721 assert(0 && "invalid delete");
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1722 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1723
209
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1724 // no value to return
c4c9b4ac021b [svn r225] Fixed: delete expressions no longer use llvm's free instruction, which crashes on a GC provided pointer.
lindquist
parents: 207
diff changeset
1725 return NULL;
1
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 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1729
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1730 DValue* ArrayLengthExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1731 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1732 Logger::print("ArrayLengthExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1733 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1734
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1735 DValue* u = e1->toElem(p);
335
17b844102023 [svn r356] Fixed problem with array length assignment introduced in [355]
lindquist
parents: 334
diff changeset
1736 return new DImValue(type, DtoArrayLen(u));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1737 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1738
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1739 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1740
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1741 DValue* AssertExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1742 {
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 321
diff changeset
1743 Logger::print("AssertExp::toElem: %s\n", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1744 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1745
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1746 if(!global.params.useAssert)
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1747 return NULL;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1748
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1749 // condition
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1750 DValue* cond;
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1751 Type* condty;
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1752
1272
dd4766851b37 Forgot the special case part in last !ThisExp change.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
1753 // special case for dmd generated assert(this); when not in -release mode
dd4766851b37 Forgot the special case part in last !ThisExp change.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
1754 if (e1->op == TOKthis && ((ThisExp*)e1)->var == NULL)
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1755 {
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1756 LLValue* thisarg = p->func()->thisArg;
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1757 assert(thisarg && "null thisarg, but we're in assert(this) exp;");
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1758 LLValue* thisptr = DtoLoad(p->func()->thisArg);
1326
a41a40deff73 Fixed dmdfe generated class invariant calls. Also insert proper "this !is null" check before it. Fixed invariant* dstress regressions and generally seems like a good idea. Hope I didn't break anything.. minitests run fine!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1292
diff changeset
1759 condty = e1->type->toBasetype();
a41a40deff73 Fixed dmdfe generated class invariant calls. Also insert proper "this !is null" check before it. Fixed invariant* dstress regressions and generally seems like a good idea. Hope I didn't break anything.. minitests run fine!
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1292
diff changeset
1760 cond = new DImValue(condty, thisptr);
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1761 }
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1762 else
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1763 {
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1764 cond = e1->toElem(p);
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1765 condty = e1->type->toBasetype();
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1270
diff changeset
1766 }
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1767
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1768 InvariantDeclaration* invdecl;
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1769
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1770 // class invariants
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1771 if(
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1772 global.params.useInvariants &&
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1773 condty->ty == Tclass &&
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1774 !((TypeClass*)condty)->sym->isInterfaceDeclaration())
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1775 {
1401
e2cf1f67ca33 Don't print the entire declaration of the alliassee when `->toChars()` is
Frits van Bommel <fvbommel wxs.nl>
parents: 1395
diff changeset
1776 Logger::println("calling class invariant");
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1777 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_invariant");
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1778 LLValue* arg = DtoBitCast(cond->getRVal(), fn->getFunctionType()->getParamType(0));
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1779 gIR->CreateCallOrInvoke(fn, arg);
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1780 }
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1781 // struct invariants
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1782 else if(
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
1783 global.params.useInvariants &&
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
1784 condty->ty == Tpointer && condty->nextOf()->ty == Tstruct &&
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
1785 (invdecl = ((TypeStruct*)condty->nextOf())->sym->inv) != NULL)
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1786 {
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1787 Logger::print("calling struct invariant");
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1788 DFuncValue invfunc(invdecl, invdecl->ir.irFunc->func, cond->getRVal());
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1789 DtoCallFunction(loc, NULL, &invfunc, NULL);
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1790 }
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1791 else
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1792 {
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1793 // create basic blocks
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1794 llvm::BasicBlock* oldend = p->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1795 llvm::BasicBlock* assertbb = llvm::BasicBlock::Create(gIR->context(), "assert", p->topfunc(), oldend);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1796 llvm::BasicBlock* endbb = llvm::BasicBlock::Create(gIR->context(), "noassert", p->topfunc(), oldend);
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1797
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1798 // test condition
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
1799 LLValue* condval = DtoCast(loc, cond, Type::tbool)->getRVal();
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1800
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1801 // branch
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1802 llvm::BranchInst::Create(endbb, assertbb, condval, p->scopebb());
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1803
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1804 // call assert runtime functions
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1805 p->scope() = IRScope(assertbb,endbb);
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1136
diff changeset
1806 DtoAssert(p->func()->decl->getModule(), loc, msg ? msg->toElem(p) : NULL);
530
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1807
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1808 // rewrite the scope
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1809 p->scope() = IRScope(endbb,oldend);
d30c40f1128d Make class invariants work.
Christian Kamm <kamm incasoftware de>
parents: 525
diff changeset
1810 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1811
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1812 // no meaningful return value
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
1813 return NULL;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1814 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1815
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1816 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1817
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1818 DValue* NotExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1819 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1820 Logger::print("NotExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1821 LOG_SCOPE;
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* u = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1824
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
1825 LLValue* b = DtoCast(loc, u, Type::tbool)->getRVal();
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
1826
611
83ca663ecc20 Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents: 610
diff changeset
1827 LLConstant* zero = DtoConstBool(false);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1828 b = p->ir->CreateICmpEQ(b,zero);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1829
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1830 return new DImValue(type, b);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1831 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1832
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1833 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1834
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1835 DValue* AndAndExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1836 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1837 Logger::print("AndAndExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1838 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1839
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1840 DValue* u = e1->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1841
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1842 llvm::BasicBlock* oldend = p->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1843 llvm::BasicBlock* andand = llvm::BasicBlock::Create(gIR->context(), "andand", gIR->topfunc(), oldend);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1844 llvm::BasicBlock* andandend = llvm::BasicBlock::Create(gIR->context(), "andandend", gIR->topfunc(), oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1845
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
1846 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1847
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1848 llvm::BasicBlock* oldblock = p->scopebb();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1849 llvm::BranchInst::Create(andand,andandend,ubool,p->scopebb());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1850
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1851 p->scope() = IRScope(andand, andandend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1852 DValue* v = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1853
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1854 LLValue* vbool = 0;
859
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1855 if (!v->isFunc() && v->getType() != Type::tvoid)
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1856 {
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1857 vbool = DtoCast(loc, v, Type::tbool)->getRVal();
859
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1858 }
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1859
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1860 llvm::BasicBlock* newblock = p->scopebb();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1861 llvm::BranchInst::Create(andandend,p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1862 p->scope() = IRScope(andandend, oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1863
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1864 LLValue* resval = 0;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1865 if (ubool == vbool || !vbool) {
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1866 // No need to create a PHI node.
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1867 resval = ubool;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1868 } else {
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1869 llvm::PHINode* phi = p->ir->CreatePHI(LLType::getInt1Ty(gIR->context()), "andandval");
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1870 // If we jumped over evaluation of the right-hand side,
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1871 // the result is false. Otherwise it's the value of the right-hand side.
1559
06d5cc873350 getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents: 1556
diff changeset
1872 phi->addIncoming(LLConstantInt::getFalse(gIR->context()), oldblock);
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1873 phi->addIncoming(vbool, newblock);
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1874 resval = phi;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1875 }
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1876
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1877 return new DImValue(type, resval);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1878 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1879
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1880 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1881
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1882 DValue* OrOrExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1883 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1884 Logger::print("OrOrExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1885 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1886
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1887 DValue* u = e1->toElem(p);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1888
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1889 llvm::BasicBlock* oldend = p->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1890 llvm::BasicBlock* oror = llvm::BasicBlock::Create(gIR->context(), "oror", gIR->topfunc(), oldend);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1891 llvm::BasicBlock* ororend = llvm::BasicBlock::Create(gIR->context(), "ororend", gIR->topfunc(), oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1892
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
1893 LLValue* ubool = DtoCast(loc, u, Type::tbool)->getRVal();
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1894
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1895 llvm::BasicBlock* oldblock = p->scopebb();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1896 llvm::BranchInst::Create(ororend,oror,ubool,p->scopebb());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1897
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1898 p->scope() = IRScope(oror, ororend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1899 DValue* v = e2->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1900
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1901 LLValue* vbool = 0;
859
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1902 if (!v->isFunc() && v->getType() != Type::tvoid)
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1903 {
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1904 vbool = DtoCast(loc, v, Type::tbool)->getRVal();
859
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1905 }
a719f2ca3e92 Applied modification of wilsonk's patch for AndAnd and OrOrExp for void rhs funcs.
Christian Kamm <kamm incasoftware de>
parents: 858
diff changeset
1906
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1907 llvm::BasicBlock* newblock = p->scopebb();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
1908 llvm::BranchInst::Create(ororend,p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1909 p->scope() = IRScope(ororend, oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1910
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1911 LLValue* resval = 0;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1912 if (ubool == vbool || !vbool) {
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1913 // No need to create a PHI node.
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1914 resval = ubool;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1915 } else {
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1916 llvm::PHINode* phi = p->ir->CreatePHI(LLType::getInt1Ty(gIR->context()), "ororval");
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1917 // If we jumped over evaluation of the right-hand side,
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1918 // the result is true. Otherwise, it's the value of the right-hand side.
1559
06d5cc873350 getTrue/getFalse were moved back to ConstantInt
Benjamin Kramer <benny.kra@gmail.com>
parents: 1556
diff changeset
1919 phi->addIncoming(LLConstantInt::getTrue(gIR->context()), oldblock);
1225
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1920 phi->addIncoming(vbool, newblock);
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1921 resval = phi;
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1922 }
837f48560863 No need for temporary alloca's here, use a phi node instead.
Frits van Bommel <fvbommel wxs.nl>
parents: 1211
diff changeset
1923
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1924 return new DImValue(type, resval);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1925 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1926
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 #define BinBitExp(X,Y) \
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1930 DValue* X##Exp::toElem(IRState* p) \
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1931 { \
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1932 Logger::print("%sExp::toElem: %s @ %s\n", #X, toChars(), type->toChars()); \
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1933 LOG_SCOPE; \
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1934 DValue* u = e1->toElem(p); \
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1935 DValue* v = e2->toElem(p); \
1202
7c7072437a89 Introduce checks to fix #173.
Christian Kamm <kamm incasoftware de>
parents: 1166
diff changeset
1936 errorOnIllegalArrayOp(this, e1, e2); \
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
1937 LLValue* x = llvm::BinaryOperator::Create(llvm::Instruction::Y, u->getRVal(), v->getRVal(), "tmp", p->scopebb()); \
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1938 return new DImValue(type, x); \
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1939 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1940
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1941 BinBitExp(And,And);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1942 BinBitExp(Or,Or);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1943 BinBitExp(Xor,Xor);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1944 BinBitExp(Shl,Shl);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1945 BinBitExp(Ushr,LShr);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1946
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1947 DValue* ShrExp::toElem(IRState* p)
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1948 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1949 Logger::print("ShrExp::toElem: %s @ %s\n", toChars(), type->toChars());
268
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1950 LOG_SCOPE;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1951 DValue* u = e1->toElem(p);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1952 DValue* v = e2->toElem(p);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1953 LLValue* x;
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1954 if (e1->type->isunsigned())
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1955 x = p->ir->CreateLShr(u->getRVal(), v->getRVal(), "tmp");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1956 else
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1957 x = p->ir->CreateAShr(u->getRVal(), v->getRVal(), "tmp");
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1958 return new DImValue(type, x);
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1959 }
23d0d9855cad [svn r289] Fixed: right shift >> was broken for unsigned types.
lindquist
parents: 264
diff changeset
1960
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1961 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1962
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1963 DValue* HaltExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1964 {
262
88252a1af660 [svn r280] Fixed a bunch of issues with switch statements. Ended up a bit far reaching...
lindquist
parents: 259
diff changeset
1965 Logger::print("HaltExp::toElem: %s\n", toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1966 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1967
363
4d7495038ae8 [svn r384] Some minor code cleanups.
lindquist
parents: 361
diff changeset
1968 // FIXME: DMD inserts a trap here... we probably should as well !?!
4d7495038ae8 [svn r384] Some minor code cleanups.
lindquist
parents: 361
diff changeset
1969
281
f5f97ca47b33 [svn r302] Make HaltExps and assert(0) generate an assert message again instead of using llvm's trap intrinsic.
ChristianK
parents: 275
diff changeset
1970 #if 1
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1136
diff changeset
1971 DtoAssert(p->func()->decl->getModule(), loc, NULL);
258
8dbddae09152 [svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents: 245
diff changeset
1972 #else
217
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
1973 // call the new (?) trap intrinsic
0806379a5eca [svn r233] Added: -oq command line option for writing fully qualified object names.
lindquist
parents: 215
diff changeset
1974 p->ir->CreateCall(GET_INTRINSIC_DECL(trap),"");
291
068cb3c60afb [svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents: 286
diff changeset
1975 new llvm::UnreachableInst(p->scopebb());
258
8dbddae09152 [svn r276] Fixed debug info for 'this' arg seemed to be broken.
lindquist
parents: 245
diff changeset
1976 #endif
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
1977
282
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1978 // this terminated the basicblock, start a new one
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1979 // this is sensible, since someone might goto behind the assert
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1980 // and prevents compiler errors if a terminator follows the assert
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1981 llvm::BasicBlock* oldend = gIR->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1982 llvm::BasicBlock* bb = llvm::BasicBlock::Create(gIR->context(), "afterhalt", p->topfunc(), oldend);
282
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1983 p->scope() = IRScope(bb,oldend);
74348f162225 [svn r303] Start a new basicblock behind a HaltExp to prevent compiler errors.
ChristianK
parents: 281
diff changeset
1984
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1985 return 0;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1986 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1987
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1988 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1989
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
1990 DValue* DelegateExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1991 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
1992 Logger::print("DelegateExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1993 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1994
426
e763821ab244 Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1995 if(func->isStatic())
e763821ab244 Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1996 error("can't take delegate of static function %s, it does not require a context ptr", func->toChars());
e763821ab244 Disallow delegates to static functions.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1997
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
1998 const LLPointerType* int8ptrty = getPtrToType(LLType::getInt8Ty(gIR->context()));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1999
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2000 assert(type->toBasetype()->ty == Tdelegate);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2001 const LLType* dgty = DtoType(type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2002
143
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2003 DValue* u = e1->toElem(p);
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2004 LLValue* uval;
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 118
diff changeset
2005 if (DFuncValue* f = u->isFunc()) {
634
0084d2c76b74 Fixed problem with taking the delegate of a nested function of the current function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 629
diff changeset
2006 assert(f->func);
0084d2c76b74 Fixed problem with taking the delegate of a nested function of the current function.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 629
diff changeset
2007 LLValue* contextptr = DtoNestedContext(loc, f->func);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2008 uval = DtoBitCast(contextptr, getVoidPtrType());
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 118
diff changeset
2009 }
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 118
diff changeset
2010 else {
143
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2011 DValue* src = u;
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2012 if (ClassDeclaration* cd = u->getType()->isClassHandle())
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2013 {
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2014 Logger::println("context type is class handle");
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2015 if (cd->isInterfaceDeclaration())
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2016 {
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2017 Logger::println("context type is interface");
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2018 src = DtoCastInterfaceToObject(u, ClassDeclaration::object->type);
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2019 }
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2020 }
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2021 uval = src->getRVal();
119
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 118
diff changeset
2022 }
79c9ac745fbc [svn r123] Fixed some typeinfo module name mismatches.
lindquist
parents: 118
diff changeset
2023
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2024 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2025 Logger::cout() << "context = " << *uval << '\n';
143
336ec4f4bbb3 [svn r147] tango.io.Console is now working. True this time :) Yay!
lindquist
parents: 137
diff changeset
2026
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2027 LLValue* castcontext = DtoBitCast(uval, int8ptrty);
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2028
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2029 Logger::println("func: '%s'", func->toPrettyChars());
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2030
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2031 LLValue* castfptr;
837
331a176c1f4f Removed error on naked, not fully complete, but I'll be doing more work on it during this Christmas, and some things do work.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 836
diff changeset
2032 if (func->isVirtual() && !func->isFinal())
1434
5d0c043ff131 Remove code duplication for vtable loads and improve instruction naming to make
Frits van Bommel <fvbommel wxs.nl>
parents: 1419
diff changeset
2033 castfptr = DtoVirtualFunctionPointer(u, func, toChars());
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2034 else if (func->isAbstract())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2035 assert(0 && "TODO delegate to abstract method");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2036 else if (func->toParent()->isInterfaceDeclaration())
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2037 assert(0 && "TODO delegate to interface method");
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2038 else
150
2c336566ffed [svn r156] added a testcase for the most annoying bug ever
lindquist
parents: 144
diff changeset
2039 {
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
2040 func->codegen(Type::sir);
173
db9890b3fb64 [svn r189] moving IR data back into DMD frontend nodes
ChristianK
parents: 172
diff changeset
2041 castfptr = func->ir.irFunc->func;
150
2c336566ffed [svn r156] added a testcase for the most annoying bug ever
lindquist
parents: 144
diff changeset
2042 }
133
44a95ac7368a [svn r137] Many fixes towards tango.io.Console working, but not quite there yet...
lindquist
parents: 132
diff changeset
2043
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2044 castfptr = DtoBitCast(castfptr, dgty->getContainedType(1));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2045
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2046 return new DImValue(type, DtoAggrPair(castcontext, castfptr, ".dg"));
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2047 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2048
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2049 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2050
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2051 DValue* IdentityExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2052 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2053 Logger::print("IdentityExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2054 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2055
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2056 DValue* l = e1->toElem(p);
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2057 DValue* r = e2->toElem(p);
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2058 LLValue* lv = l->getRVal();
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2059 LLValue* rv = r->getRVal();
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2060
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
2061 Type* t1 = e1->type->toBasetype();
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
2062
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
2063 // handle dynarray specially
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
2064 if (t1->ty == Tarray)
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2065 return new DImValue(type, DtoDynArrayIs(op,l,r));
345
5320fe65a65d [svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents: 344
diff changeset
2066 // also structs
5320fe65a65d [svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents: 344
diff changeset
2067 else if (t1->ty == Tstruct)
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2068 return new DImValue(type, DtoStructEquals(op,l,r));
345
5320fe65a65d [svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents: 344
diff changeset
2069
5320fe65a65d [svn r366] Fixed identity exprs for structs was comparing addresses, not content!
lindquist
parents: 344
diff changeset
2070 // FIXME this stuff isn't pretty
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2071 LLValue* eval = 0;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2072
308
6b62e8cdf970 [svn r329] Cleaned up a bunch of array code for handling special slice cases no
lindquist
parents: 295
diff changeset
2073 if (t1->ty == Tdelegate) {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2074 if (r->isNull()) {
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2075 rv = NULL;
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 156
diff changeset
2076 }
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 156
diff changeset
2077 else {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2078 assert(lv->getType() == rv->getType());
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 156
diff changeset
2079 }
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2080 eval = DtoDelegateEquals(op,lv,rv);
162
1856c62af24b [svn r178] Fixed codegen values for function arguments, the old approach was completely broken, amazing it even worked...
lindquist
parents: 156
diff changeset
2081 }
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2082 else if (t1->isfloating()) // includes iscomplex
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 143
diff changeset
2083 {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2084 eval = DtoBinNumericEquals(loc, l, r, op);
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 143
diff changeset
2085 }
629
607b6b5819a7 Fixed issue with IsExpression and potential type mismatch for classes.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 628
diff changeset
2086 else if (t1->ty == Tpointer || t1->ty == Tclass)
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
2087 {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2088 if (lv->getType() != rv->getType()) {
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2089 if (r->isNull())
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2090 rv = llvm::ConstantPointerNull::get(isaPointer(lv->getType()));
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
2091 else
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2092 rv = DtoBitCast(rv, lv->getType());
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
2093 }
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
2094 eval = (op == TOKidentity)
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2095 ? p->ir->CreateICmpEQ(lv,rv,"tmp")
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2096 : p->ir->CreateICmpNE(lv,rv,"tmp");
167
adca7f32fb6d [svn r183] Fixed broken identity expressions with two pointers of different types.
lindquist
parents: 164
diff changeset
2097 }
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2098 else {
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2099 assert(lv->getType() == rv->getType());
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 364
diff changeset
2100 eval = (op == TOKidentity)
1503
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2101 ? p->ir->CreateICmpEQ(lv,rv,"tmp")
cc5fee7836dc Made is and !is use the same numeric comparison as == and !=, fixes #328
Christian Kamm <kamm incasoftware de>
parents: 1497
diff changeset
2102 : p->ir->CreateICmpNE(lv,rv,"tmp");
54
28e99b04a132 [svn r58] Fixed cond expression resulting in a non-basic type.
lindquist
parents: 53
diff changeset
2103 }
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2104 return new DImValue(type, eval);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2105 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2106
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2107 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2108
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2109 DValue* CommaExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2110 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2111 Logger::print("CommaExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2112 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2113
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2114 DValue* u = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2115 DValue* v = e2->toElem(p);
144
a27941d00351 [svn r149] fixed: a bunch of D-style variadics problems.
lindquist
parents: 143
diff changeset
2116 assert(e2->type == type);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2117 return v;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2118 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2119
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2120 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2121
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2122 DValue* CondExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2123 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2124 Logger::print("CondExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2125 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2126
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2127 Type* dtype = type->toBasetype();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2128
887
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2129 DValue* dvv;
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2130 // voids returns will need no storage
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2131 if (dtype->ty != Tvoid) {
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2132 // allocate a temporary for the final result. failed to come up with a better way :/
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1326
diff changeset
2133 LLValue* resval = DtoAlloca(dtype,"condtmp");
887
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2134 dvv = new DVarValue(type, resval);
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2135 } else {
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2136 dvv = new DConstValue(type, getNullValue(DtoTypeNotVoid(dtype)));
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2137 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2138
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2139 llvm::BasicBlock* oldend = p->scopeend();
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
2140 llvm::BasicBlock* condtrue = llvm::BasicBlock::Create(gIR->context(), "condtrue", gIR->topfunc(), oldend);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
2141 llvm::BasicBlock* condfalse = llvm::BasicBlock::Create(gIR->context(), "condfalse", gIR->topfunc(), oldend);
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1569
diff changeset
2142 llvm::BasicBlock* condend = llvm::BasicBlock::Create(gIR->context(), "condend", gIR->topfunc(), oldend);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2143
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2144 DValue* c = econd->toElem(p);
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
2145 LLValue* cond_val = DtoCast(loc, c, Type::tbool)->getRVal();
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
2146 llvm::BranchInst::Create(condtrue,condfalse,cond_val,p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2147
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2148 p->scope() = IRScope(condtrue, condfalse);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2149 DValue* u = e1->toElem(p);
887
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2150 if (dtype->ty != Tvoid)
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2151 DtoAssign(loc, dvv, u);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
2152 llvm::BranchInst::Create(condend,p->scopebb());
1
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 p->scope() = IRScope(condfalse, condend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2155 DValue* v = e2->toElem(p);
887
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2156 if (dtype->ty != Tvoid)
7f6eeb7b003e Fix #163.
Christian Kamm <kamm incasoftware de>
parents: 870
diff changeset
2157 DtoAssign(loc, dvv, v);
205
9d44ec83acd1 [svn r221] Update: Switched to the 2.3 LLVM svn branch, http://llvm.org/svn/llvm-project/llvm/branches/release_23 .
lindquist
parents: 203
diff changeset
2158 llvm::BranchInst::Create(condend,p->scopebb());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2159
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2160 p->scope() = IRScope(condend, oldend);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2161 return dvv;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2162 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2163
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2164 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2165
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2166 DValue* ComExp::toElem(IRState* p)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2167 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2168 Logger::print("ComExp::toElem: %s @ %s\n", toChars(), type->toChars());
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2169 LOG_SCOPE;
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2170
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2171 DValue* u = e1->toElem(p);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2172
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2173 LLValue* value = u->getRVal();
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
2174 LLValue* minusone = LLConstantInt::get(value->getType(), (uint64_t)-1, true);
704
43165a082535 Fixed issue with accessing a WithStatement context from inside a nested function. see mini/with2.d
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 703
diff changeset
2175 value = llvm::BinaryOperator::Create(llvm::Instruction::Xor, value, minusone, "tmp", p->scopebb());
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2176
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2177 return new DImValue(type, value);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2178 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2179
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2180 //////////////////////////////////////////////////////////////////////////////////////////
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2181
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2182 DValue* NegExp::toElem(IRState* p)
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2183 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2184 Logger::print("NegExp::toElem: %s @ %s\n", toChars(), type->toChars());
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2185 LOG_SCOPE;
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2186
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2187 DValue* l = e1->toElem(p);
164
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 163
diff changeset
2188
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 163
diff changeset
2189 if (type->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
2190 return DtoComplexNeg(loc, type, l);
164
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 163
diff changeset
2191 }
a64becf2a702 [svn r180] Fixed complex negation, and tango.math.Math now compiles.
lindquist
parents: 163
diff changeset
2192
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2193 LLValue* val = l->getRVal();
616
5ced42a55aa9 Fix NegExp not to use substraction.
Christian Kamm <kamm incasoftware de>
parents: 611
diff changeset
2194
5ced42a55aa9 Fix NegExp not to use substraction.
Christian Kamm <kamm incasoftware de>
parents: 611
diff changeset
2195 val = gIR->ir->CreateNeg(val,"negval");
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2196 return new DImValue(type, val);
23
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2197 }
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2198
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2199 //////////////////////////////////////////////////////////////////////////////////////////
77e3d1ddae3f [svn r27] * Fixed bug in aggregate field lookup.
lindquist
parents: 21
diff changeset
2200
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2201 DValue* CatExp::toElem(IRState* p)
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2202 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2203 Logger::print("CatExp::toElem: %s @ %s\n", toChars(), type->toChars());
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2204 LOG_SCOPE;
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2205
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2206 Type* t = type->toBasetype();
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2207
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2208 bool arrNarr = e1->type->toBasetype() == e2->type->toBasetype();
132
1700239cab2e [svn r136] MAJOR UNSTABLE UPDATE!!!
lindquist
parents: 131
diff changeset
2209
203
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2210 // array ~ array
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2211 if (arrNarr)
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2212 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2213 return DtoCatArrays(type, e1, e2);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2214 }
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2215 // array ~ element
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2216 // element ~ array
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2217 else
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2218 {
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2219 return DtoCatArrayElement(type, e1, e2);
e881c9b1c738 [svn r219] Fixed: the tango/lib/gc/basic garbage collector now compiles and links into an executable (change in tango/lib/llvmdc-posix.mak), closes #5 .
lindquist
parents: 201
diff changeset
2220 }
36
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2221 }
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2222
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2223 //////////////////////////////////////////////////////////////////////////////////////////
c0967c4b2a74 [svn r40] Cleaned up some of the array routines to use gep/load/store instead of memcpy/memset.
lindquist
parents: 34
diff changeset
2224
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2225 DValue* CatAssignExp::toElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2226 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2227 Logger::print("CatAssignExp::toElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2228 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2229
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2230 DValue* l = e1->toElem(p);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2231
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2232 Type* e1type = e1->type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
2233 Type* elemtype = e1type->nextOf()->toBasetype();
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2234 Type* e2type = e2->type->toBasetype();
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2235
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2236 if (e2type == elemtype) {
1633
5c0cebff9be8 Improve array append performance.
Christian Kamm <kamm incasoftware de>
parents: 1595
diff changeset
2237 DtoCatAssignElement(e1type, l, e2);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2238 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2239 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
2240 DSliceValue* slice = DtoCatAssignArray(l,e2);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
2241 DtoAssign(loc, l, slice);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2242 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2243 else
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2244 assert(0 && "only one element at a time right now");
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2245
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
2246 return l;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2247 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2248
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2249 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2250
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2251 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
2252 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2253 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
2254 LOG_SCOPE;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2255
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2256 assert(fd);
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2257
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2258 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
2259 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
2260
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
2261 fd->codegen(Type::sir);
521
99e95dae90d5 Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents: 520
diff changeset
2262 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
2263
520
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2264 if(fd->tok == TOKdelegate) {
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2265 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
2266
520
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2267 LLValue* cval;
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2268 IrFunction* irfn = p->func();
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2269 if (irfn->nestedVar)
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2270 cval = irfn->nestedVar;
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2271 else if (irfn->nestArg)
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2272 cval = irfn->nestArg;
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2273 else
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2274 cval = getNullPtr(getVoidPtrType());
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2275 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
2276
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2277 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
2278
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
2279 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
2280
520
73e41129b7f3 Fix function literals. They never carry a context.
Christian Kamm <kamm incasoftware de>
parents: 512
diff changeset
2281 } 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
2282 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
2283 }
521
99e95dae90d5 Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents: 520
diff changeset
2284
99e95dae90d5 Do not need to allocate temporary for function literal.
Christian Kamm <kamm incasoftware de>
parents: 520
diff changeset
2285 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
2286 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2287
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2288 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2289
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2290 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
2291 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2292 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
2293 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
2294
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2295 assert(fd);
1419
a6dfd3cb5b99 Error instead of assert on delegate literals as constant expressions.
Christian Kamm <kamm incasoftware de>
parents: 1401
diff changeset
2296 if (fd->tok != TOKfunction)
a6dfd3cb5b99 Error instead of assert on delegate literals as constant expressions.
Christian Kamm <kamm incasoftware de>
parents: 1401
diff changeset
2297 {
a6dfd3cb5b99 Error instead of assert on delegate literals as constant expressions.
Christian Kamm <kamm incasoftware de>
parents: 1401
diff changeset
2298 assert(fd->tok == TOKdelegate);
a6dfd3cb5b99 Error instead of assert on delegate literals as constant expressions.
Christian Kamm <kamm incasoftware de>
parents: 1401
diff changeset
2299 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
2300 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2301
1148
3d1b16dabd25 Eliminated the need for resolve, declare, const-init and define lists to drive code generation.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1147
diff changeset
2302 fd->codegen(Type::sir);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2303 assert(fd->ir.irFunc->func);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2304
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2305 return fd->ir.irFunc->func;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2306 }
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2307
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2308 //////////////////////////////////////////////////////////////////////////////////////////
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2309
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2310 DValue* ArrayLiteralExp::toElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2311 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2312 Logger::print("ArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2313 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2314
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2315 // D types
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2316 Type* arrayType = type->toBasetype();
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2317 Type* elemType = arrayType->nextOf()->toBasetype();
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2318
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2319 // is dynamic ?
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2320 bool dyn = (arrayType->ty == Tarray);
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2321 // length
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2322 size_t len = elements->dim;
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2323
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2324 // llvm target type
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2325 const LLType* llType = DtoType(arrayType);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2326 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2327 Logger::cout() << (dyn?"dynamic":"static") << " array literal with length " << len << " of D type: '" << arrayType->toChars() << "' has llvm type: '" << *llType << "'\n";
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2328
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2329 // llvm storage type
587
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2330 const LLType* llElemType = DtoTypeNotVoid(elemType);
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2331 const LLType* llStoType = LLArrayType::get(llElemType, len);
622
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2332 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 619
diff changeset
2333 Logger::cout() << "llvm storage type: '" << *llStoType << "'\n";
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2334
587
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2335 // don't allocate storage for zero length dynamic array literals
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2336 if (dyn && len == 0)
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2337 {
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2338 // dmd seems to just make them null...
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2339 return new DSliceValue(type, DtoConstSize_t(0), getNullPtr(getPtrToType(llElemType)));
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2340 }
23538d0f0d5b Fixed a few mini tests issues.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 585
diff changeset
2341
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2342 // dst pointer
592
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2343 LLValue* dstMem;
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2344 DSliceValue* dynSlice = NULL;
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2345 if(dyn)
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2346 {
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2347 dynSlice = DtoNewDynArray(loc, arrayType, new DConstValue(Type::tsize_t, DtoConstSize_t(len)), false);
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2348 dstMem = dynSlice->ptr;
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2349 }
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2350 else
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1326
diff changeset
2351 dstMem = DtoRawAlloca(llStoType, 0, "arrayliteral");
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2352
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2353 // store elements
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2354 for (size_t i=0; i<len; ++i)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2355 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2356 Expression* expr = (Expression*)elements->data[i];
592
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2357 LLValue* elemAddr;
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2358 if(dyn)
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2359 elemAddr = DtoGEPi1(dstMem, i, "tmp", p->scopebb());
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2360 else
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2361 elemAddr = DtoGEPi(dstMem,0,i,"tmp",p->scopebb());
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2362
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2363 // emulate assignment
585
fbb1a366cfbc Complex number should now follow the D ABI on x86. They're also treated as first class values now. Big change.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 575
diff changeset
2364 DVarValue* vv = new DVarValue(expr->type, elemAddr);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2365 DValue* e = expr->toElem(p);
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2366 DtoAssign(loc, vv, e);
40
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
175
c44e6a711885 [svn r191] Fixed: array literals did not support all type/storage combinations.
lindquist
parents: 173
diff changeset
2369 // return storage directly ?
486
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2370 if (!dyn)
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2371 return new DImValue(type, dstMem);
a34078905d01 Added pragma(llvmdc, "string") for misc per-module compiler configuration, currently "string" can only be "verbose" which forces -vv for module it appears in.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 485
diff changeset
2372
592
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2373 // return slice
5fb7ed0ac580 Allocate dynamic array literals on the heap.
Christian Kamm <kamm incasoftware de>
parents: 591
diff changeset
2374 return dynSlice;
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2375 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2376
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2377 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2378
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2379 LLConstant* ArrayLiteralExp::toConstElem(IRState* p)
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2380 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2381 Logger::print("ArrayLiteralExp::toConstElem: %s @ %s\n", toChars(), type->toChars());
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2382 LOG_SCOPE;
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2383
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2384 // extract D types
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2385 Type* bt = type->toBasetype();
758
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 720
diff changeset
2386 Type* elemt = bt->nextOf();
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2387
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2388 // build llvm array type
1496
b4fc62f047cd More DtoType -> DtoTypeNotVoid for getting the array element llvm type.
Christian Kamm <kamm incasoftware de>
parents: 1479
diff changeset
2389 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
2390
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2391 // dynamic arrays can occur here as well ...
603
10bc9eb9e262 Fix typo in ArrayLiteralExp::toConstElem.
Christian Kamm <kamm incasoftware de>
parents: 602
diff changeset
2392 bool dyn = (bt->ty == Tarray);
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2393
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2394 // build the initializer
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2395 std::vector<LLConstant*> vals(elements->dim, NULL);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2396 for (unsigned i=0; i<elements->dim; ++i)
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2397 {
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2398 Expression* expr = (Expression*)elements->data[i];
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2399 vals[i] = expr->toConstElem(p);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2400 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2401
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2402 // build the constant array initializer
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1548
diff changeset
2403 LLConstant* initval = LLConstantArray::get(arrtype, vals);
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2404
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2405 // if static array, we're done
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2406 if (!dyn)
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2407 return initval;
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2408
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2409 // for dynamic arrays we need to put the initializer in a global, and build a constant dynamic array reference with the .ptr field pointing into this global
1292
ad41053c336e Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents: 1272
diff changeset
2410 // Important: don't make the global constant, since this const initializer might
ad41053c336e Make static int[] a = [1, 2]; a[0] = 4; not segfault
Christian Kamm <kamm incasoftware de>
parents: 1272
diff changeset
2411 // be used as an initializer for a static T[] - where modifying contents is allowed.
1529
ad7f2f1862d6 Adjust LDC to work with the LLVMContext LLVM changes.
Christian Kamm <kamm incasoftware de>
parents: 1513
diff changeset
2412 LLConstant* globalstore = new LLGlobalVariable(*gIR->module, arrtype, false, LLGlobalValue::InternalLinkage, initval, ".dynarrayStorage");
602
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2413 LLConstant* idxs[2] = { DtoConstUint(0), DtoConstUint(0) };
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2414 LLConstant* globalstorePtr = llvm::ConstantExpr::getGetElementPtr(globalstore, idxs, 2);
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2415
48f079b4fe0f Fixed ArrayLiteralExp::toConstElem for dynamic arrays, tango-user library should now be possible to build. It seems to be related to DMD bug 2356, which must have been introduced recently, as we already handled this fine for ArrayInitializers, just not ArrayLiterals... Kinda annoying to have to do this work due to DMD bugs ...
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 600
diff changeset
2416 return DtoConstSlice(DtoConstSize_t(elements->dim), globalstorePtr);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2417 }
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2418
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2419 //////////////////////////////////////////////////////////////////////////////////////////
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2420
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2421 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
2422
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2423 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
2424 mem = DtoBitCast(mem, getVoidPtrType());
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2425 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
2426 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
2427 return mem;
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2428 }
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2429
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2430 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
2431 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2432 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
2433 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
2434
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2435 // 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
2436 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
2437
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2438 // alloca a stack slot
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2439 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
2440
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2441 // ready elements data
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2442 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
2443 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
2444 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
2445
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2446 LLValue* voidptr = mem;
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2447 unsigned offset = 0;
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2448
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2449 // go through fields
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2450 ArrayIter<VarDeclaration> it(sd->fields);
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2451 for (; !it.done(); it.next())
823
794c8af186ce Fixed non-static struct initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 820
diff changeset
2452 {
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2453 VarDeclaration* vd = it.get();
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2454
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2455 // don't re-initialize unions
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2456 if (vd->offset < offset)
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2457 {
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2458 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
2459 continue;
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2460 }
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2461 // 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
2462 if (vd->offset != offset)
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2463 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
2464 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
2465
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2466 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
2467
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2468 // get initializer
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2469 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
2470 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
2471 DValue* val;
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2472 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
2473 if (expr)
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2474 {
1372
229e02867307 Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents: 1367
diff changeset
2475 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
2476 val = expr->toElem(gIR);
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2477 }
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2478 else
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2479 {
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2480 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
2481 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
2482 val = &cv;
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2483 }
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2484
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2485 // 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
2486 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
2487
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2488 // store the initializer there
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2489 DtoAssign(loc, &field, val);
1255
9014d7f0433f Rewrote runtime struct literal codegen.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1248
diff changeset
2490 }
1479
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2491 // initialize trailing padding
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2492 if (sd->structsize != offset)
4f7d50c744ed Rewrite `StructLiteralExp::toElem` to store individual fields instead of
Frits van Bommel <fvbommel wxs.nl>
parents: 1465
diff changeset
2493 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
2494
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2495 // 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
2496 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
2497 }
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2498
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2499 //////////////////////////////////////////////////////////////////////////////////////////
e5c4bece7fa1 [svn r53] added basic support for delegate literals. if you access outer variables you get a broken module
lindquist
parents: 48
diff changeset
2500
213
7816aafeea3c [svn r229] Updated the object.d implementation to the latest Tango.
lindquist
parents: 212
diff changeset
2501 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
2502 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2503 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
2504 LOG_SCOPE;
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2505
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
2506 // 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
2507 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
2508
870
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2509 // get inits
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2510 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
2511
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2512 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
2513 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
2514
870
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 < nexprs; i++)
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2516 if (exprs[i])
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2517 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
2518
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2519 // 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
2520 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
2521
af7a6faf9406 Fix #153. Factor out common code in StructLiteralExp::to(Const)Elem.
Christian Kamm <kamm incasoftware de>
parents: 864
diff changeset
2522 // 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
2523 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
2524 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
2525 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
2526
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 778
diff changeset
2527 // return constant struct
1569
755abafbf25d Push the context through StructType::get.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1567
diff changeset
2528 return LLConstantStruct::get(gIR->context(), constvals, sd->ir.irStruct->packed);
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2529 }
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2530
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2531 //////////////////////////////////////////////////////////////////////////////////////////
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2532
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2533 DValue* InExp::toElem(IRState* p)
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2534 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2535 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
2536 LOG_SCOPE;
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2537
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2538 DValue* key = e1->toElem(p);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2539 DValue* aa = e2->toElem(p);
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2540
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
2541 return DtoAAIn(loc, type, aa, key);
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2542 }
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2543
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2544 DValue* RemoveExp::toElem(IRState* p)
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2545 {
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2546 Logger::print("RemoveExp::toElem: %s\n", toChars());
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2547 LOG_SCOPE;
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2548
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2549 DValue* aa = e1->toElem(p);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2550 DValue* key = e2->toElem(p);
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2551
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
2552 DtoAARemove(loc, aa, key);
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2553
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2554 return NULL; // does not produce anything useful
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2555 }
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2556
109
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2557 //////////////////////////////////////////////////////////////////////////////////////////
5ab8e92611f9 [svn r113] Added initial support for associative arrays (AAs).
lindquist
parents: 108
diff changeset
2558
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2559 DValue* AssocArrayLiteralExp::toElem(IRState* p)
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2560 {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1149
diff changeset
2561 Logger::print("AssocArrayLiteralExp::toElem: %s @ %s\n", toChars(), type->toChars());
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2562 LOG_SCOPE;
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2563
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2564 assert(keys);
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2565 assert(values);
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2566 assert(keys->dim == values->dim);
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2567
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
2568 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
2569 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
2570
9bb48fb57a7d [svn r304] Fix associative array literals by always reserving a zero inited temporary for them.
ChristianK
parents: 282
diff changeset
2571 // 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
2572 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
2573 DValue* aa = new DVarValue(type, tmp);
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1559
diff changeset
2574 DtoStore(LLConstant::getNullValue(DtoType(type)), tmp);
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2575
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2576 const size_t n = keys->dim;
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2577 for (size_t i=0; i<n; ++i)
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2578 {
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2579 Expression* ekey = (Expression*)keys->data[i];
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2580 Expression* eval = (Expression*)values->data[i];
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2581
1372
229e02867307 Fix format-string bugs by adding __attribute__((__format__)) in all applicable
Frits van Bommel <fvbommel wxs.nl>
parents: 1367
diff changeset
2582 Logger::println("(%zu) aa[%s] = %s", i, ekey->toChars(), eval->toChars());
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2583
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2584 // index
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2585 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
2586 DValue* mem = DtoAAIndex(loc, vtype, aa, key, true);
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2587
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2588 // store
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2589 DValue* val = eval->toElem(p);
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 397
diff changeset
2590 DtoAssign(loc, mem, val);
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2591 }
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2592
127
facc562f5674 [svn r131] Fixed #11
lindquist
parents: 125
diff changeset
2593 return aa;
125
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2594 }
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2595
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2596 //////////////////////////////////////////////////////////////////////////////////////////
c42d245468ea [svn r129] Started AA literals.
lindquist
parents: 124
diff changeset
2597
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
2598 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
2599 {
4435f57956e7 Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 594
diff changeset
2600 // 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
2601 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
2602 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
2603 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
2604 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
2605 }
4435f57956e7 Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 594
diff changeset
2606
4435f57956e7 Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 594
diff changeset
2607 //////////////////////////////////////////////////////////////////////////////////////////
4435f57956e7 Fixed .funcptr property of delegates, no longer uses the infamous DMD rewrites to pointer arithmetic, instead a GEPExp has been introduced.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 594
diff changeset
2608
666
0d934394ada1 Implement BoolExp.
Christian Kamm <kamm incasoftware de>
parents: 659
diff changeset
2609 DValue* BoolExp::toElem(IRState* p)
0d934394ada1 Implement BoolExp.
Christian Kamm <kamm incasoftware de>
parents: 659
diff changeset
2610 {
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 770
diff changeset
2611 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
2612 }
0d934394ada1 Implement BoolExp.
Christian Kamm <kamm incasoftware de>
parents: 659
diff changeset
2613
0d934394ada1 Implement BoolExp.
Christian Kamm <kamm incasoftware de>
parents: 659
diff changeset
2614 //////////////////////////////////////////////////////////////////////////////////////////
0d934394ada1 Implement BoolExp.
Christian Kamm <kamm incasoftware de>
parents: 659
diff changeset
2615
667
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2616 DValue* DotTypeExp::toElem(IRState* p)
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2617 {
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2618 Type* t = sym->getType();
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2619 assert(t);
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2620 return e1->toElem(p);
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2621 }
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2622
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2623 //////////////////////////////////////////////////////////////////////////////////////////
9c48213cfd96 Add DotTypeExp
Christian Kamm <kamm incasoftware de>
parents: 666
diff changeset
2624
973
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2625 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
2626 {
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2627 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
2628 //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
2629 // 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
2630 fatal();
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2631 return NULL;
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2632 }
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2633
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2634 //////////////////////////////////////////////////////////////////////////////////////////
d96471e8b5e5 Fix #216 by implementing TypeExp::toElem. It just provides the appropriate
Christian Kamm <kamm incasoftware de>
parents: 936
diff changeset
2635
86
fd32135dca3e [svn r90] Major updates to the gen directory. Redesigned the 'elem' struct. Much more... !!!
lindquist
parents: 85
diff changeset
2636 #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
2637 STUB(Expression);
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2638 STUB(ScopeExp);
92
70d6113eeb8c [svn r96] Updated to DMD 1.023.
lindquist
parents: 91
diff changeset
2639 STUB(TupleExp);
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2640
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
2641 #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
2642 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
2643 #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
2644
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
2645 #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
2646 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
2647 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
2648 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
2649 }
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2650 CONSTSTUB(Expression);
860
7edce7e58ab1 Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents: 859
diff changeset
2651 CONSTSTUB(GEPExp);
7edce7e58ab1 Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents: 859
diff changeset
2652 CONSTSTUB(SliceExp);
7edce7e58ab1 Add more toConstElem stubs to get better error messages.
Christian Kamm <kamm incasoftware de>
parents: 859
diff changeset
2653 CONSTSTUB(IndexExp);
40
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2654 CONSTSTUB(AssocArrayLiteralExp);
8b0e809563df [svn r44] Lots of bug fixes.
lindquist
parents: 37
diff changeset
2655
1146
1860414bf3b7 * Moved ir/irsymbol.cpp/h into ir/irdsymbol.cpp/h.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
2656 //////////////////////////////////////////////////////////////////////////////////////////
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2657
659
43d2ab9833bf Forgot a change from DMD update.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 656
diff changeset
2658 void obj_includelib(const char* lib)
340
351c0077d0b3 [svn r361] Removed some dead code.
lindquist
parents: 339
diff changeset
2659 {
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
2660 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
2661 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
2662 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
2663 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
2664 global.params.linkswitches->push(arg);
340
351c0077d0b3 [svn r361] Removed some dead code.
lindquist
parents: 339
diff changeset
2665 }
351c0077d0b3 [svn r361] Removed some dead code.
lindquist
parents: 339
diff changeset
2666
351c0077d0b3 [svn r361] Removed some dead code.
lindquist
parents: 339
diff changeset
2667 void backend_init()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2668 {
1161
f528e55fb32f Force initialize the runtime module in Module::genLLVMModule. It is required
Christian Kamm <kamm incasoftware de>
parents: 1152
diff changeset
2669 // 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
2670 // since it requires the semantic pass to be done
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2671 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2672
340
351c0077d0b3 [svn r361] Removed some dead code.
lindquist
parents: 339
diff changeset
2673 void backend_term()
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2674 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2675 LLVM_D_FreeRuntime();
987
73ff89728d85 Call llvm_shutdown when shutting down the backend.
Frits van Bommel <fvbommel wxs.nl>
parents: 973
diff changeset
2676 llvm::llvm_shutdown();
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2677 }