annotate gen/toir.cpp @ 1183:df386fd4030e

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