annotate gen/llvmhelpers.cpp @ 1650:40bd4a0d4870

Update to work with LLVM 2.7. Removed use of dyn_cast, llvm no compiles without exceptions and rtti by default. We do need exceptions for the libconfig stuff, but rtti isn't necessary (anymore). Debug info needs to be rewritten, as in LLVM 2.7 the format has completely changed. To have something to look at while rewriting, the old code has been wrapped inside #ifndef DISABLE_DEBUG_INFO , this means that you have to define this to compile at the moment. Updated tango 0.99.9 patch to include updated EH runtime code, which is needed for LLVM 2.7 as well.
author Tomas Lindquist Olsen
date Wed, 19 May 2010 12:42:32 +0200
parents 8f121883bce8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1206
a5bfed1f6775 Reduce include-order dependencies
Frits van Bommel <fvbommel wxs.nl>
parents: 1189
diff changeset
1 #include "gen/llvmhelpers.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
2 #include "gen/llvm.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
3
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
4 #include "mars.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
5 #include "init.h"
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: 328
diff changeset
6 #include "id.h"
365
bfb9d28f045a [svn r386] Fixed broken DtoBoolean.
lindquist
parents: 363
diff changeset
7 #include "expression.h"
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
8 #include "template.h"
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 670
diff changeset
9 #include "module.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
10
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
11 #include "gen/tollvm.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
12 #include "gen/irstate.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
13 #include "gen/runtime.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
14 #include "gen/logger.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
15 #include "gen/arrays.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
16 #include "gen/dvalue.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
17 #include "gen/complex.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
18 #include "gen/classes.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
19 #include "gen/functions.h"
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
20 #include "gen/typeinf.h"
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
21 #include "gen/todebug.h"
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
22 #include "gen/cl_options.h"
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1206
diff changeset
23 #include "gen/nested.h"
683
b411c41a9716 Only allocate the module file name once. Fixes #90.
Christian Kamm <kamm incasoftware de>
parents: 670
diff changeset
24 #include "ir/irmodule.h"
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
25
482
aa8c050dfd19 Move zero init of padding to DtoInitializer in order to respect void initializers.
Christian Kamm <kamm incasoftware de>
parents: 481
diff changeset
26 #include <stack>
aa8c050dfd19 Move zero init of padding to DtoInitializer in order to respect void initializers.
Christian Kamm <kamm incasoftware de>
parents: 481
diff changeset
27
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
28 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
29 /*////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
30 // DYNAMIC MEMORY HELPERS
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
31 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
32
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
33 LLValue* DtoNew(Type* newtype)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
34 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
35 // get runtime function
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
36 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_allocmemoryT");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
37 // get type info
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
38 LLConstant* ti = DtoTypeInfoOf(newtype);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
39 assert(isaPointer(ti));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
40 // call runtime allocator
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1004
diff changeset
41 LLValue* mem = gIR->CreateCallOrInvoke(fn, ti, ".gc_mem").getInstruction();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
42 // cast
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
43 return DtoBitCast(mem, getPtrToType(DtoType(newtype)), ".gc_mem");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
44 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
45
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
46 void DtoDeleteMemory(LLValue* ptr)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
47 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
48 // get runtime function
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
49 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delmemory");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
50 // build args
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
51 LLSmallVector<LLValue*,1> arg;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
52 arg.push_back(DtoBitCast(ptr, getVoidPtrType(), ".tmp"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
53 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
54 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
55 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
56
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
57 void DtoDeleteClass(LLValue* inst)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
58 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
59 // get runtime function
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
60 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delclass");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
61 // build args
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
62 LLSmallVector<LLValue*,1> arg;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
63 arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
64 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
65 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
66 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
67
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
68 void DtoDeleteInterface(LLValue* inst)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
69 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
70 // get runtime function
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
71 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delinterface");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
72 // build args
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
73 LLSmallVector<LLValue*,1> arg;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
74 arg.push_back(DtoBitCast(inst, fn->getFunctionType()->getParamType(0), ".tmp"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
75 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
76 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
77 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
78
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
79 void DtoDeleteArray(DValue* arr)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
80 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
81 // get runtime function
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
82 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_delarray");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
83 // build args
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
84 LLSmallVector<LLValue*,2> arg;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
85 arg.push_back(DtoArrayLen(arr));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
86 arg.push_back(DtoBitCast(DtoArrayPtr(arr), getVoidPtrType(), ".tmp"));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
87 // call
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
88 gIR->CreateCallOrInvoke(fn, arg.begin(), arg.end());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
89 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
90
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
91 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
92 /*////////////////////////////////////////////////////////////////////////////////////////
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
93 // ALLOCA HELPERS
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
94 ////////////////////////////////////////////////////////////////////////////////////////*/
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
95
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
96
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
97 llvm::AllocaInst* DtoAlloca(Type* type, const char* name)
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
98 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
99 const llvm::Type* lltype = DtoType(type);
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
100 llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
101 ai->setAlignment(type->alignsize());
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
102 return ai;
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
103 }
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
104
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
105 llvm::AllocaInst* DtoArrayAlloca(Type* type, unsigned arraysize, const char* name)
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
106 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
107 const llvm::Type* lltype = DtoType(type);
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
108 llvm::AllocaInst* ai = new llvm::AllocaInst(
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
109 lltype, DtoConstUint(arraysize), name, gIR->topallocapoint());
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
110 ai->setAlignment(type->alignsize());
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
111 return ai;
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
112 }
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
113
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
114 llvm::AllocaInst* DtoRawAlloca(const llvm::Type* lltype, size_t alignment, const char* name)
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
115 {
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
116 llvm::AllocaInst* ai = new llvm::AllocaInst(lltype, name, gIR->topallocapoint());
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
117 if (alignment)
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
118 ai->setAlignment(alignment);
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
119 return ai;
479
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
120 }
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
121
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
122
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
123 /****************************************************************************************/
672eb4893b55 Move AllocaInst creation into DtoAlloca helper. Will enable special zero-init of fp80 reals' padding.
Christian Kamm <kamm incasoftware de>
parents: 468
diff changeset
124 /*////////////////////////////////////////////////////////////////////////////////////////
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
125 // ASSERT HELPER
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
126 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
127
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
128 void DtoAssert(Module* M, Loc loc, DValue* msg)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
129 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
130 std::vector<LLValue*> args;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
131
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
132 // func
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
133 const char* fname = msg ? "_d_assert_msg" : "_d_assert";
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
134 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
135
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
136 // msg param
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
137 if (msg)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
138 {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
139 args.push_back(msg->getRVal());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
140 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
141
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
142 // file param
936
2ebac4750adb Removed some dead code.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 934
diff changeset
143
2ebac4750adb Removed some dead code.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 934
diff changeset
144 // we might be generating for an imported template function
1278
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
145 const char* cur_file = M->srcfile->name->toChars();
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
146 if (loc.filename && strcmp(loc.filename, cur_file) != 0)
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
147 {
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
148 args.push_back(DtoConstString(loc.filename));
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
149 }
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
150 else
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
151 {
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
152 IrModule* irmod = getIrModule(M);
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
153 args.push_back(DtoLoad(irmod->fileName));
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
154 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
155
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
156 // line param
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
157 LLConstant* c = DtoConstUint(loc.linnum);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
158 args.push_back(c);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
159
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
160 // call
1013
8c73ff5f69e0 Use llvm::CallSite instead of custom CallOrInvoke class.
Frits van Bommel <fvbommel wxs.nl>
parents: 1004
diff changeset
161 gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
162
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
163 #ifndef DISABLE_DEBUG_INFO
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
164 // end debug info
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
165 if (global.params.symdebug)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
166 DtoDwarfFuncEnd(gIR->func()->decl);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
167 #endif
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: 290
diff changeset
168
068cb3c60afb [svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents: 290
diff changeset
169 // after assert is always unreachable
068cb3c60afb [svn r312] Changed assert codegen to insert an unreachable terminator after the call to the assert function, which currently calls abort().
lindquist
parents: 290
diff changeset
170 gIR->ir->CreateUnreachable();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
171 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
172
439
47b64d06eb9f Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents: 435
diff changeset
173
47b64d06eb9f Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents: 435
diff changeset
174 /****************************************************************************************/
47b64d06eb9f Enable array bounds check and emit them in IndexExp.
Christian Kamm <kamm incasoftware de>
parents: 435
diff changeset
175 /*////////////////////////////////////////////////////////////////////////////////////////
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
176 // LABEL HELPER
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
177 ////////////////////////////////////////////////////////////////////////////////////////*/
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
178 LabelStatement* DtoLabelStatement(Identifier* ident)
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
179 {
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
180 FuncDeclaration* fd = gIR->func()->decl;
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
181 FuncDeclaration::LabelMap::iterator iter = fd->labmap.find(ident->toChars());
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
182 if (iter == fd->labmap.end())
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
183 {
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
184 if (fd->returnLabel && fd->returnLabel->ident->equals(ident))
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
185 {
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
186 assert(fd->returnLabel->statement);
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
187 return fd->returnLabel->statement;
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
188 }
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
189 return NULL;
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
190 }
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
191 return iter->second;
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
192 }
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
193
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
194 /****************************************************************************************/
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
195 /*////////////////////////////////////////////////////////////////////////////////////////
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
196 // GOTO HELPER
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
197 ////////////////////////////////////////////////////////////////////////////////////////*/
1160
7d28dcbff23e Reenable error for gotos into or out of finally blocks.
Christian Kamm <kamm incasoftware de>
parents: 1151
diff changeset
198 void DtoGoto(Loc loc, Identifier* target, TryFinallyStatement* sourceFinally)
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
199 {
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
200 assert(!gIR->scopereturned());
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
201
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
202 LabelStatement* lblstmt = DtoLabelStatement(target);
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
203 if(!lblstmt) {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
204 error(loc, "the label %s does not exist", target->toChars());
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
205 fatal();
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
206 }
305
2b72433d5c8c [svn r326] Fixed a bunch of issues with printf's that MinGW32 did not support.
lindquist
parents: 304
diff changeset
207
304
3ebc136702dd [svn r325] Removed dead code.
ChristianK
parents: 302
diff changeset
208 // if the target label is inside inline asm, error
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
209 if(lblstmt->asmLabel) {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
210 error(loc, "cannot goto to label %s inside an inline asm block", target->toChars());
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
211 fatal();
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
212 }
304
3ebc136702dd [svn r325] Removed dead code.
ChristianK
parents: 302
diff changeset
213
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 339
diff changeset
214 // find target basic block
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
215 std::string labelname = gIR->func()->gen->getScopedLabelName(target->toChars());
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
216 llvm::BasicBlock*& targetBB = gIR->func()->gen->labelToBB[labelname];
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 339
diff changeset
217 if (targetBB == NULL)
1571
8d086d552909 IntegerType is now contextifed.
Benjamin Kramer <benny.kra@gmail.com>
parents: 1560
diff changeset
218 targetBB = llvm::BasicBlock::Create(gIR->context(), "label_" + labelname, gIR->topfunc());
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
219
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
220 // emit code for finallys between goto and label
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
221 DtoEnclosingHandlers(loc, lblstmt);
355
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
222
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
223 // goto into finally blocks is forbidden by the spec
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
224 // but should work fine
1160
7d28dcbff23e Reenable error for gotos into or out of finally blocks.
Christian Kamm <kamm incasoftware de>
parents: 1151
diff changeset
225 if(lblstmt->enclosingFinally != sourceFinally) {
7d28dcbff23e Reenable error for gotos into or out of finally blocks.
Christian Kamm <kamm incasoftware de>
parents: 1151
diff changeset
226 error(loc, "spec disallows goto into or out of finally block");
357
82af71383b8a [svn r378] Make some errors fatal to prevent segfaults. Error instead of assert on missing label.
ChristianK
parents: 356
diff changeset
227 fatal();
1160
7d28dcbff23e Reenable error for gotos into or out of finally blocks.
Christian Kamm <kamm incasoftware de>
parents: 1151
diff changeset
228 }
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
229
353
a7a26f538d6e [svn r374] Move label target basic block from AST to IRFunction. This is a first step to allowing labels to be emitted multiple times. (for instance within finally blocks)
ChristianK
parents: 339
diff changeset
230 llvm::BranchInst::Create(targetBB, gIR->scopebb());
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
231 }
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
232
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
233 /****************************************************************************************/
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
234 /*////////////////////////////////////////////////////////////////////////////////////////
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
235 // TRY-FINALLY, VOLATILE AND SYNCHRONIZED HELPER
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
236 ////////////////////////////////////////////////////////////////////////////////////////*/
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
237
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
238 void EnclosingSynchro::emitCode(IRState * p)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
239 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
240 if (s->exp)
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
241 DtoLeaveMonitor(s->exp->toElem(p)->getRVal());
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
242 else
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
243 DtoLeaveCritical(s->llsync);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
244 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
245
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
246 ////////////////////////////////////////////////////////////////////////////////////////
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
247
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
248 void EnclosingVolatile::emitCode(IRState * p)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
249 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
250 // store-load barrier
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
251 DtoMemoryBarrier(false, false, true, false);
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
252 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
253
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
254 ////////////////////////////////////////////////////////////////////////////////////////
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
255
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
256 void EnclosingTryFinally::emitCode(IRState * p)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
257 {
845
d128381e086e Only emit finalbody if there is one. Fixes #147.
Christian Kamm <kamm incasoftware de>
parents: 812
diff changeset
258 if (tf->finalbody)
1412
3f5ea912149d Fix #308 by giving finally code emitted by EnclosingTryFinally a different landing pad.
Christian Kamm <kamm incasoftware de>
parents: 1411
diff changeset
259 {
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
260 llvm::BasicBlock* oldpad = p->func()->gen->landingPad;
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
261 p->func()->gen->landingPad = landingPad;
845
d128381e086e Only emit finalbody if there is one. Fixes #147.
Christian Kamm <kamm incasoftware de>
parents: 812
diff changeset
262 tf->finalbody->toIR(p);
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
263 p->func()->gen->landingPad = oldpad;
1412
3f5ea912149d Fix #308 by giving finally code emitted by EnclosingTryFinally a different landing pad.
Christian Kamm <kamm incasoftware de>
parents: 1411
diff changeset
264 }
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
265 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
266
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
267 ////////////////////////////////////////////////////////////////////////////////////////
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
268
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
269 void DtoEnclosingHandlers(Loc loc, Statement* target)
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
270 {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
271 // labels are a special case: they are not required to enclose the current scope
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
272 // for them we use the enclosing scope handler as a reference point
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
273 LabelStatement* lblstmt = target ? target->isLabelStatement() : 0;
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
274 if (lblstmt)
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
275 target = lblstmt->enclosingScopeExit;
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
276
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
277 // figure out up until what handler we need to emit
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
278 FuncGen::TargetScopeVec::reverse_iterator targetit = gIR->func()->gen->targetScopes.rbegin();
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
279 FuncGen::TargetScopeVec::reverse_iterator it_end = gIR->func()->gen->targetScopes.rend();
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
280 while(targetit != it_end) {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
281 if (targetit->s == target) {
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
282 break;
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
283 }
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
284 ++targetit;
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
285 }
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
286
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
287 if (target && targetit == it_end) {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
288 if (lblstmt)
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
289 error(loc, "cannot goto into try, volatile or synchronized statement at %s", target->loc.toChars());
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
290 else
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
291 error(loc, "internal error, cannot find jump path to statement at %s", target->loc.toChars());
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
292 return;
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
293 }
355
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
294
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
295 //
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
296 // emit code for enclosing handlers
355
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
297 //
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
298
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
299 // since the labelstatements possibly inside are private
d8357f7004ca [svn r376] Fix bug with finally blocks and labels. The labels would get emitted multiple times and conflict.
ChristianK
parents: 353
diff changeset
300 // and might already exist push a label scope
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
301 gIR->func()->gen->pushUniqueLabelScope("enclosing");
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
302 FuncGen::TargetScopeVec::reverse_iterator it = gIR->func()->gen->targetScopes.rbegin();
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
303 while (it != targetit) {
1141
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
304 if (it->enclosinghandler)
f99a3b393c03 Reorganize EnclosingHandlers to require less changes to the frontend and allow us to
Christian Kamm <kamm incasoftware de>
parents: 1088
diff changeset
305 it->enclosinghandler->emitCode(gIR);
1145
40caa8207b3e Moved IRTargetScopeS from IRState into IrFunction, fixes #240 .
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1141
diff changeset
306 ++it;
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
307 }
1508
e1e93343fc11 Move function codegen data from IrFunction to new FuncGen.
Christian Kamm <kamm incasoftware de>
parents: 1500
diff changeset
308 gIR->func()->gen->popLabelScope();
302
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
309 }
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
310
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
311 /****************************************************************************************/
bef811104734 [svn r323] Branching out of inline asm works.
ChristianK
parents: 295
diff changeset
312 /*////////////////////////////////////////////////////////////////////////////////////////
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
313 // SYNCHRONIZED SECTION HELPERS
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
314 ////////////////////////////////////////////////////////////////////////////////////////*/
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
315
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
316 void DtoEnterCritical(LLValue* g)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
317 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
318 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_criticalenter");
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
319 gIR->CreateCallOrInvoke(fn, g);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
320 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
321
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
322 void DtoLeaveCritical(LLValue* g)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
323 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
324 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_criticalexit");
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
325 gIR->CreateCallOrInvoke(fn, g);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
326 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
327
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
328 void DtoEnterMonitor(LLValue* v)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
329 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
330 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_monitorenter");
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
331 v = DtoBitCast(v, fn->getFunctionType()->getParamType(0));
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
332 gIR->CreateCallOrInvoke(fn, v);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
333 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
334
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
335 void DtoLeaveMonitor(LLValue* v)
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
336 {
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
337 LLFunction* fn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_monitorexit");
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
338 v = DtoBitCast(v, fn->getFunctionType()->getParamType(0));
315
a9697749e898 [svn r336] Made sure calls within a landing pad area are invokes.
ChristianK
parents: 309
diff changeset
339 gIR->CreateCallOrInvoke(fn, v);
309
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
340 }
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
341
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
342 /****************************************************************************************/
d59c363fccad [svn r330] Implemented synchronized statements.
lindquist
parents: 305
diff changeset
343 /*////////////////////////////////////////////////////////////////////////////////////////
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
344 // ASSIGNMENT HELPER (store this in that)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
345 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
346
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
347 // is this a good approach at all ?
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
348
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
349 void DtoAssign(Loc& loc, DValue* lhs, DValue* rhs)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
350 {
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: 611
diff changeset
351 Logger::println("DtoAssign(...);\n");
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
352 LOG_SCOPE;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
353
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: 483
diff changeset
354 Type* t = lhs->getType()->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: 483
diff changeset
355 Type* t2 = rhs->getType()->toBasetype();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
356
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
357 if (t->ty == Tstruct) {
295
895e1b50cf2a [svn r316] Fixed array slice assignments like: int[] arr = ...; arr[] = 42;
lindquist
parents: 294
diff changeset
358 if (!t->equals(t2)) {
1018
e8c6dbcd33d1 - Fixed x86-32 C ABI for complex number return values.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1013
diff changeset
359 // FIXME: use 'rhs' for something !?!
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
360 DtoAggrZeroInit(lhs->getLVal());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
361 }
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: 483
diff changeset
362 else {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
363 DtoAggrCopy(lhs->getLVal(), rhs->getRVal());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
364 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
365 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
366 else if (t->ty == Tarray) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
367 // lhs is slice
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
368 if (DSliceValue* s = lhs->isSlice()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
369 if (DSliceValue* s2 = rhs->isSlice()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
370 DtoArrayCopySlices(s, s2);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
371 }
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: 757
diff changeset
372 else if (t->nextOf()->toBasetype()->equals(t2)) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
373 DtoArrayInit(loc, s, rhs);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
374 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
375 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
376 DtoArrayCopyToSlice(s, rhs);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
377 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
378 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
379 // rhs is slice
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
380 else if (DSliceValue* s = rhs->isSlice()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
381 assert(s->getType()->toBasetype() == lhs->getType()->toBasetype());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
382 DtoSetArray(lhs->getLVal(),DtoArrayLen(s),DtoArrayPtr(s));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
383 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
384 // null
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
385 else if (rhs->isNull()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
386 DtoSetArrayToNull(lhs->getLVal());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
387 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
388 // reference assignment
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
389 else if (t2->ty == Tarray) {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
390 DtoStore(rhs->getRVal(), lhs->getLVal());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
391 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
392 // some implicitly converting ref assignment
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
393 else {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
394 DtoSetArray(lhs->getLVal(), DtoArrayLen(rhs), DtoArrayPtr(rhs));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
395 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
396 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
397 else if (t->ty == Tsarray) {
709
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
398 // T[n] = T[n]
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
399 if (DtoType(lhs->getType()) == DtoType(rhs->getType())) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
400 DtoStaticArrayCopy(lhs->getLVal(), rhs->getRVal());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
401 }
709
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
402 // T[n] = T
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: 757
diff changeset
403 else if (t->nextOf()->toBasetype()->equals(t2)) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
404 DtoArrayInit(loc, lhs, rhs);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
405 }
709
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
406 // T[n] = T[] - generally only generated by frontend in rare cases
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: 757
diff changeset
407 else if (t2->ty == Tarray && t->nextOf()->toBasetype()->equals(t2->nextOf()->toBasetype())) {
709
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
408 DtoMemCpy(lhs->getLVal(), DtoArrayPtr(rhs), DtoArrayLen(rhs));
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
409 } else {
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
410 assert(0 && "Unimplemented static array assign!");
b972fb129d37 Add missing case to DtoAssign for T[n] = T[]. Fixes downs' initializer bug.
Christian Kamm <kamm incasoftware de>
parents: 704
diff changeset
411 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
412 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
413 else if (t->ty == Tdelegate) {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
414 LLValue* l = lhs->getLVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
415 LLValue* r = rhs->getRVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
416 if (Logger::enabled())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
417 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
418 DtoStore(r, l);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
419 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
420 else if (t->ty == Tclass) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
421 assert(t2->ty == Tclass);
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: 453
diff changeset
422 LLValue* l = lhs->getLVal();
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: 453
diff changeset
423 LLValue* r = rhs->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: 611
diff changeset
424 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: 611
diff changeset
425 {
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: 611
diff changeset
426 Logger::cout() << "l : " << *l << '\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: 611
diff changeset
427 Logger::cout() << "r : " << *r << '\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: 611
diff changeset
428 }
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: 453
diff changeset
429 r = DtoBitCast(r, l->getType()->getContainedType(0));
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: 453
diff changeset
430 DtoStore(r, l);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
431 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
432 else if (t->iscomplex()) {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
433 LLValue* dst = lhs->getLVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
434 LLValue* src = DtoCast(loc, rhs, lhs->getType())->getRVal();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
435 DtoStore(src, dst);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
436 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
437 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
438 LLValue* l = lhs->getLVal();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
439 LLValue* r = rhs->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: 611
diff changeset
440 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: 611
diff changeset
441 Logger::cout() << "assign\nlhs: " << *l << "rhs: " << *r << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
442 const LLType* lit = l->getType()->getContainedType(0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
443 if (r->getType() != lit) {
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
444 r = DtoCast(loc, rhs, lhs->getType())->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: 611
diff changeset
445 if (Logger::enabled())
26fce59fe80a Wrapped all the most potentially expensive logging calls in a conditional to only do work when actually requested.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 611
diff changeset
446 Logger::cout() << "really assign\nlhs: " << *l << "rhs: " << *r << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
447 assert(r->getType() == l->getType()->getContainedType(0));
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
448 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
449 gIR->ir->CreateStore(r, l);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
450 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
451 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
452
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
453 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
454 /*////////////////////////////////////////////////////////////////////////////////////////
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
455 // NULL VALUE HELPER
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
456 ////////////////////////////////////////////////////////////////////////////////////////*/
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
457
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
458 DValue* DtoNullValue(Type* type)
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
459 {
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
460 Type* basetype = type->toBasetype();
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
461 TY basety = basetype->ty;
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
462 const LLType* lltype = DtoType(basetype);
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
463
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
464 // complex, needs to be first since complex are also floating
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
465 if (basetype->iscomplex())
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
466 {
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
467 const LLType* basefp = DtoComplexBaseType(basetype);
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
468 LLValue* res = DtoAggrPair(DtoType(type), LLConstant::getNullValue(basefp), LLConstant::getNullValue(basefp));
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: 583
diff changeset
469 return new DImValue(type, res);
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
470 }
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
471 // integer, floating, pointer and class have no special representation
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
472 else if (basetype->isintegral() || basetype->isfloating() || basety == Tpointer || basety == Tclass)
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
473 {
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
474 return new DConstValue(type, LLConstant::getNullValue(lltype));
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
475 }
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
476 // dynamic array
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
477 else if (basety == Tarray)
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
478 {
373
d1574e142e93 [svn r394] Fixed the new DtoNullValue function
lindquist
parents: 372
diff changeset
479 LLValue* len = DtoConstSize_t(0);
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: 757
diff changeset
480 LLValue* ptr = getNullPtr(getPtrToType(DtoType(basetype->nextOf())));
373
d1574e142e93 [svn r394] Fixed the new DtoNullValue function
lindquist
parents: 372
diff changeset
481 return new DSliceValue(type, len, ptr);
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
482 }
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
483 // delegate
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
484 else if (basety == Tdelegate)
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
485 {
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
486 return new DNullValue(type, LLConstant::getNullValue(lltype));
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
487 }
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
488
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
489 // unknown
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
490 error("unsupported: null value for %s", type->toChars());
372
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
491 assert(0);
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
492 return 0;
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
493
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
494 }
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
495
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
496
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
497 /****************************************************************************************/
83ade4f4025a [svn r393] Started implementation for DtoNullValue.
ChristianK
parents: 370
diff changeset
498 /*////////////////////////////////////////////////////////////////////////////////////////
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
499 // CASTING HELPERS
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
500 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
501
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
502 DValue* DtoCastInt(Loc& loc, DValue* val, Type* _to)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
503 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
504 const LLType* tolltype = DtoType(_to);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
505
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: 483
diff changeset
506 Type* to = _to->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: 483
diff changeset
507 Type* from = val->getType()->toBasetype();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
508 assert(from->isintegral());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
509
611
83ca663ecc20 Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents: 610
diff changeset
510 size_t fromsz = from->size();
83ca663ecc20 Backed out changeset 1b62222581fb
Christian Kamm <kamm incasoftware de>
parents: 610
diff changeset
511 size_t tosz = to->size();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
512
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
513 LLValue* rval = val->getRVal();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
514 if (rval->getType() == tolltype) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
515 return new DImValue(_to, rval);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
516 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
517
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
518 if (to->ty == Tbool) {
1554
d6e8d5db259f LLVMContext changes up to r77366
Benjamin Kramer <benny.kra@gmail.com>
parents: 1552
diff changeset
519 LLValue* zero = LLConstantInt::get(rval->getType(), 0, false);
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
520 rval = gIR->ir->CreateICmpNE(rval, zero, "tmp");
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
521 }
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
522 else if (to->isintegral()) {
757
2c730d530c98 Special case DtoCastInt for bool.
Christian Kamm <kamm incasoftware de>
parents: 747
diff changeset
523 if (fromsz < tosz || from->ty == Tbool) {
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: 611
diff changeset
524 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: 611
diff changeset
525 Logger::cout() << "cast to: " << *tolltype << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
526 if (from->isunsigned() || from->ty == Tbool) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
527 rval = new llvm::ZExtInst(rval, tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
528 } else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
529 rval = new llvm::SExtInst(rval, tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
530 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
531 }
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
532 else if (fromsz > tosz) {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
533 rval = new llvm::TruncInst(rval, tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
534 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
535 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
536 rval = DtoBitCast(rval, tolltype);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
537 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
538 }
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 358
diff changeset
539 else if (to->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
540 return DtoComplex(loc, to, val);
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 358
diff changeset
541 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
542 else if (to->isfloating()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
543 if (from->isunsigned()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
544 rval = new llvm::UIToFPInst(rval, tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
545 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
546 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
547 rval = new llvm::SIToFPInst(rval, tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
548 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
549 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
550 else if (to->ty == Tpointer) {
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: 611
diff changeset
551 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: 611
diff changeset
552 Logger::cout() << "cast pointer: " << *tolltype << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
553 rval = gIR->ir->CreateIntToPtr(rval, tolltype, "tmp");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
554 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
555 else {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
556 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), _to->toChars());
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
557 fatal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
558 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
559
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
560 return new DImValue(_to, rval);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
561 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
562
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
563 DValue* DtoCastPtr(Loc& loc, DValue* val, Type* to)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
564 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
565 const LLType* tolltype = DtoType(to);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
566
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: 483
diff changeset
567 Type* totype = to->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: 483
diff changeset
568 Type* fromtype = val->getType()->toBasetype();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
569 assert(fromtype->ty == Tpointer || fromtype->ty == Tfunction);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
570
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
571 LLValue* rval;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
572
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
573 if (totype->ty == Tpointer || totype->ty == Tclass) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
574 LLValue* src = val->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: 611
diff changeset
575 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: 611
diff changeset
576 Logger::cout() << "src: " << *src << "to type: " << *tolltype << '\n';
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
577 rval = DtoBitCast(src, tolltype);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
578 }
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
579 else if (totype->ty == Tbool) {
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
580 LLValue* src = val->getRVal();
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
581 LLValue* zero = LLConstant::getNullValue(src->getType());
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
582 rval = gIR->ir->CreateICmpNE(src, zero, "tmp");
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
583 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
584 else if (totype->isintegral()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
585 rval = new llvm::PtrToIntInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
586 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
587 else {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
588 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
589 fatal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
590 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
591
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
592 return new DImValue(to, rval);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
593 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
594
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
595 DValue* DtoCastFloat(Loc& loc, DValue* val, Type* to)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
596 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
597 if (val->getType() == to)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
598 return val;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
599
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
600 const LLType* tolltype = DtoType(to);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
601
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: 483
diff changeset
602 Type* totype = to->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: 483
diff changeset
603 Type* fromtype = val->getType()->toBasetype();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
604 assert(fromtype->isfloating());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
605
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
606 size_t fromsz = fromtype->size();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
607 size_t tosz = totype->size();
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
608
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
609 LLValue* rval;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
610
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
611 if (totype->ty == Tbool) {
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
612 rval = val->getRVal();
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
613 LLValue* zero = LLConstant::getNullValue(rval->getType());
784
a45179dfaa43 Fix float->bool, #130. Thanks fvbommel.
Christian Kamm <kamm incasoftware de>
parents: 778
diff changeset
614 rval = gIR->ir->CreateFCmpUNE(rval, zero, "tmp");
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
615 }
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
616 else if (totype->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
617 return DtoComplex(loc, to, val);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
618 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
619 else if (totype->isfloating()) {
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 442
diff changeset
620 if (fromsz == tosz) {
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
621 rval = val->getRVal();
445
cc40db549aea Changed the handling of variadic intrinsics a bit.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 442
diff changeset
622 assert(rval->getType() == tolltype);
359
926f65e39246 [svn r380] Improve complex number support.
ChristianK
parents: 358
diff changeset
623 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
624 else if (fromsz < tosz) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
625 rval = new llvm::FPExtInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
626 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
627 else if (fromsz > tosz) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
628 rval = new llvm::FPTruncInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
629 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
630 else {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
631 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
632 fatal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
633 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
634 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
635 else if (totype->isintegral()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
636 if (totype->isunsigned()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
637 rval = new llvm::FPToUIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
638 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
639 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
640 rval = new llvm::FPToSIInst(val->getRVal(), tolltype, "tmp", gIR->scopebb());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
641 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
642 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
643 else {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
644 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
645 fatal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
646 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
647
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
648 return new DImValue(to, rval);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
649 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
650
419
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
651 DValue* DtoCastDelegate(Loc& loc, DValue* val, Type* to)
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
652 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
653 if (to->toBasetype()->ty == Tdelegate)
419
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
654 {
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
655 return DtoPaintType(loc, val, to);
419
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
656 }
778
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
657 else if (to->toBasetype()->ty == Tbool)
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
658 {
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
659 return new DImValue(to, DtoDelegateEquals(TOKnotequal, val->getRVal(), NULL));
4adf0f742896 Get rid of DtoBoolean - use DtoCast(... Type::tbool) instead.
Christian Kamm <kamm incasoftware de>
parents: 773
diff changeset
660 }
419
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
661 else
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
662 {
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
663 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
664 fatal();
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
665 }
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
666 }
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
667
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
668 DValue* DtoCast(Loc& loc, DValue* val, Type* to)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
669 {
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: 483
diff changeset
670 Type* fromtype = val->getType()->toBasetype();
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
671 Type* totype = to->toBasetype();
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
672 if (fromtype->equals(totype))
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
673 return val;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
674
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
675 Logger::println("Casting from '%s' to '%s'", fromtype->toChars(), to->toChars());
1151
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
676 LOG_SCOPE;
3cf0066e6faf - Versioned Expresssion::toElem with #if IN_DMD/IN_LLVM.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1148
diff changeset
677
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
678 if (fromtype->isintegral()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
679 return DtoCastInt(loc, val, to);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
680 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
681 else if (fromtype->iscomplex()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
682 return DtoCastComplex(loc, val, to);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
683 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
684 else if (fromtype->isfloating()) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
685 return DtoCastFloat(loc, val, to);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
686 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
687 else if (fromtype->ty == Tclass) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
688 return DtoCastClass(val, to);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
689 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
690 else if (fromtype->ty == Tarray || fromtype->ty == Tsarray) {
424
c8d98ccad0cc Error if static array is cast to an array such that oldarraysize % newelemsize != 0.
Christian Kamm <kamm incasoftware de>
parents: 419
diff changeset
691 return DtoCastArray(loc, val, to);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
692 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
693 else if (fromtype->ty == Tpointer || fromtype->ty == Tfunction) {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
694 return DtoCastPtr(loc, val, to);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
695 }
419
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
696 else if (fromtype->ty == Tdelegate) {
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
697 return DtoCastDelegate(loc, val, to);
023fa78c1203 Fixed delegate casts.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 399
diff changeset
698 }
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
699 else {
399
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
700 error(loc, "invalid cast from '%s' to '%s'", val->getType()->toChars(), to->toChars());
0e6b4d65d3f8 Give error messages for invalid casts.
Christian Kamm <kamm incasoftware de>
parents: 373
diff changeset
701 fatal();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
702 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
703 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
704
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
705 //////////////////////////////////////////////////////////////////////////////////////////
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
706
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
707 DValue* DtoPaintType(Loc& loc, DValue* val, Type* to)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
708 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
709 Type* from = val->getType()->toBasetype();
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
710 Logger::println("repainting from '%s' to '%s'", from->toChars(), to->toChars());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
711
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
712 if (from->ty == Tarray)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
713 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
714 Type* at = to->toBasetype();
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
715 assert(at->ty == Tarray);
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: 757
diff changeset
716 Type* elem = at->nextOf()->pointerTo();
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
717 if (DSliceValue* slice = val->isSlice())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
718 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
719 return new DSliceValue(to, slice->len, DtoBitCast(slice->ptr, DtoType(elem)));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
720 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
721 else if (val->isLVal())
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
722 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
723 LLValue* ptr = val->getLVal();
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
724 ptr = DtoBitCast(ptr, DtoType(at->pointerTo()));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
725 return new DVarValue(to, ptr);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
726 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
727 else
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
728 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
729 LLValue *len, *ptr;
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
730 len = DtoArrayLen(val);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
731 ptr = DtoArrayPtr(val);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
732 ptr = DtoBitCast(ptr, DtoType(elem));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
733 return new DImValue(to, DtoAggrPair(len, ptr, "tmp"));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
734 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
735 }
719
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
736 else if (from->ty == Tdelegate)
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
737 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
738 Type* dgty = to->toBasetype();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
739 assert(dgty->ty == Tdelegate);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
740 if (val->isLVal())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
741 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
742 LLValue* ptr = val->getLVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
743 assert(isaPointer(ptr));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
744 ptr = DtoBitCast(ptr, getPtrToType(DtoType(dgty)));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
745 if (Logger::enabled())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
746 Logger::cout() << "dg ptr: " << *ptr << '\n';
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
747 return new DVarValue(to, ptr);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
748 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
749 else
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
750 {
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
751 LLValue* dg = val->getRVal();
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
752 LLValue* context = gIR->ir->CreateExtractValue(dg, 0, ".context");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
753 LLValue* funcptr = gIR->ir->CreateExtractValue(dg, 1, ".funcptr");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
754 funcptr = DtoBitCast(funcptr, DtoType(dgty)->getContainedType(1));
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
755 LLValue* aggr = DtoAggrPair(context, funcptr, "tmp");
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
756 if (Logger::enabled())
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
757 Logger::cout() << "dg: " << *aggr << '\n';
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
758 return new DImValue(to, aggr);
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
759 }
7261ff0f95ff Implemented first class delegates. closes #101
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 715
diff changeset
760 }
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
761 else if (from->ty == Tpointer || from->ty == Tclass || from->ty == Taarray)
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
762 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
763 Type* b = to->toBasetype();
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
764 assert(b->ty == Tpointer || b->ty == Tclass || b->ty == Taarray);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
765 LLValue* ptr = DtoBitCast(val->getRVal(), DtoType(b));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
766 return new DImValue(to, ptr);
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
767 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
768 else
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
769 {
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
770 assert(!val->isLVal());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
771 assert(DtoType(to) == DtoType(to));
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
772 return new DImValue(to, val->getRVal());
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
773 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
774 }
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
775
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
776 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
777 /*////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
778 // TEMPLATE HELPERS
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
779 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
780
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
781 TemplateInstance* DtoIsTemplateInstance(Dsymbol* s)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
782 {
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
783 if (!s) return NULL;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
784 if (s->isTemplateInstance() && !s->isTemplateMixin())
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
785 return s->isTemplateInstance();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
786 else if (s->parent)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
787 return DtoIsTemplateInstance(s->parent);
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
788 return NULL;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
789 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
790
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
791 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
792 /*////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
793 // PROCESSING QUEUE HELPERS
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
794 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
795
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
796 void DtoResolveDsymbol(Dsymbol* dsym)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
797 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
798 if (StructDeclaration* sd = dsym->isStructDeclaration()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
799 DtoResolveStruct(sd);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
800 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
801 else if (ClassDeclaration* cd = dsym->isClassDeclaration()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
802 DtoResolveClass(cd);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
803 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
804 else if (FuncDeclaration* fd = dsym->isFuncDeclaration()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
805 DtoResolveFunction(fd);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
806 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
807 else if (TypeInfoDeclaration* fd = dsym->isTypeInfoDeclaration()) {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
808 DtoResolveTypeInfo(fd);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
809 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
810 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
811 error(dsym->loc, "unsupported dsymbol: %s", dsym->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
812 assert(0 && "unsupported dsymbol for DtoResolveDsymbol");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
813 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
814 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
815
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
816 //////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
817
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
818 void DtoConstInitGlobal(VarDeclaration* vd)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
819 {
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
820 vd->codegen(Type::sir);
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
821
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
822 if (vd->ir.initialized) return;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
823 vd->ir.initialized = gIR->dmodule;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
824
1278
8fb39f7f1a7c Fixed file name in imported mixins containing assertions.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1271
diff changeset
825 Logger::println("DtoConstInitGlobal(%s) @ %s", vd->toChars(), vd->loc.toChars());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
826 LOG_SCOPE;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
827
798
92ea3015ace6 Use toParent instead of toParent2 to determine whether inside a function body.
Christian Kamm <kamm incasoftware de>
parents: 797
diff changeset
828 Dsymbol* par = vd->toParent();
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
829
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
830 // build the initializer
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
831 LLConstant* initVal = DtoConstInitializer(vd->loc, vd->type, vd->init);
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: 611
diff changeset
832
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
833 // set the initializer if appropriate
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
834 IrGlobal* glob = vd->ir.irGlobal;
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
835 llvm::GlobalVariable* gvar = llvm::cast<llvm::GlobalVariable>(glob->value);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
836
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
837 // refine the global's opaque type to the type of the initializer
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
838 llvm::cast<LLOpaqueType>(glob->type.get())->refineAbstractTypeTo(initVal->getType());
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
839
812
6c2ff06c4201 Fixed a nasty bug with how interface vtables for class initializers were output, causing some class fields to be skipped.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 803
diff changeset
840 assert(!glob->constInit);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
841 glob->constInit = initVal;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
842
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
843 // assign the initializer
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
844 llvm::GlobalVariable* globalvar = llvm::cast<llvm::GlobalVariable>(glob->value);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
845
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
846 if (!(vd->storage_class & STCextern) && mustDefineSymbol(vd))
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
847 {
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: 611
diff changeset
848 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: 611
diff changeset
849 {
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: 611
diff changeset
850 Logger::println("setting initializer");
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: 611
diff changeset
851 Logger::cout() << "global: " << *gvar << '\n';
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1457
diff changeset
852 #if 0
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
853 Logger::cout() << "init: " << *initVal << '\n';
1463
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1457
diff changeset
854 #endif
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: 611
diff changeset
855 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
856
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
857 gvar->setInitializer(initVal);
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
858
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
859 #ifndef DISABLE_DEBUG_INFO
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
860 // do debug info
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
861 if (global.params.symdebug)
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
862 {
946
1714836f2c0b Mostly rewrite debug info generation in terms of llvm/Analysis/DebugInfo.h.
Christian Kamm <kamm incasoftware de>
parents: 945
diff changeset
863 LLGlobalVariable* gv = DtoDwarfGlobalVariable(gvar, vd).getGV();
250
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
864 // keep a reference so GDCE doesn't delete it !
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
865 gIR->usedArray.push_back(llvm::ConstantExpr::getBitCast(gv, getVoidPtrType()));
fc9c1a0eabbd [svn r267] Fixed debug info for global variables.
lindquist
parents: 244
diff changeset
866 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
867 #endif
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
868 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
869 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
870
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
871 /****************************************************************************************/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
872 /*////////////////////////////////////////////////////////////////////////////////////////
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
873 // DECLARATION EXP HELPER
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
874 ////////////////////////////////////////////////////////////////////////////////////////*/
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
875 DValue* DtoDeclarationExp(Dsymbol* declaration)
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
876 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
877 Logger::print("DtoDeclarationExp: %s\n", declaration->toChars());
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
878 LOG_SCOPE;
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
879
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
880 // variable declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
881 if (VarDeclaration* vd = declaration->isVarDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
882 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
883 Logger::println("VarDeclaration");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
884
648
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
885 // if aliassym is set, this VarDecl is redone as an alias to another symbol
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
886 // this seems to be done to rewrite Tuple!(...) v;
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
887 // as a TupleDecl that contains a bunch of individual VarDecls
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
888 if (vd->aliassym)
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
889 return DtoDeclarationExp(vd->aliassym);
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
890
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
891 // static
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
892 if (vd->isDataseg())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
893 {
1147
dbe4af57b240 Changed use of toObjFile to a new codegen method.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1145
diff changeset
894 vd->codegen(Type::sir);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
895 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
896 else
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
897 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
898 if (global.params.llvmAnnotate)
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
899 DtoAnnotation(declaration->toChars());
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
900
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
901 Logger::println("vdtype = %s", vd->type->toChars());
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
902
1593
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
903 // ref vardecls are generated when DMD lowers foreach to a for statement,
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
904 // and this is a hack to support them for this case only
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
905 if(vd->isRef())
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
906 {
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
907 if (!vd->ir.irLocal)
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
908 vd->ir.irLocal = new IrLocal(vd);
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
909
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
910 ExpInitializer* ex = vd->init->isExpInitializer();
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
911 assert(ex && "ref vars must have expression initializer");
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
912 assert(ex->exp);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
913 AssignExp* as = ex->exp->isAssignExp();
1593
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
914 assert(as && "ref vars must be initialized by an assign exp");
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
915 vd->ir.irLocal->value = as->e2->toElem(gIR)->getLVal();
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
916 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
917
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
918 // referenced by nested delegate?
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: 757
diff changeset
919 #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: 757
diff changeset
920 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: 757
diff changeset
921 #else
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
922 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: 757
diff changeset
923 #endif
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
924 Logger::println("has nestedref set");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
925 assert(vd->ir.irLocal);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
926
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1206
diff changeset
927 DtoNestedInit(vd);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
928 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
929 // normal stack variable, allocate storage on the stack if it has not already been done
1592
91af6d05338c Fix codegen for foreach with ref value being lowered to for.
Christian Kamm <kamm incasoftware de>
parents: 1571
diff changeset
930 else if(!vd->ir.irLocal && !vd->isRef()) {
91af6d05338c Fix codegen for foreach with ref value being lowered to for.
Christian Kamm <kamm incasoftware de>
parents: 1571
diff changeset
931 vd->ir.irLocal = new IrLocal(vd);
91af6d05338c Fix codegen for foreach with ref value being lowered to for.
Christian Kamm <kamm incasoftware de>
parents: 1571
diff changeset
932
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
933 const LLType* lltype = DtoType(vd->type);
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
934
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
935 llvm::Value* allocainst;
1592
91af6d05338c Fix codegen for foreach with ref value being lowered to for.
Christian Kamm <kamm incasoftware de>
parents: 1571
diff changeset
936 if(gTargetData->getTypeSizeInBits(lltype) == 0)
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
937 allocainst = llvm::ConstantPointerNull::get(getPtrToType(lltype));
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
938 else
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
939 allocainst = DtoAlloca(vd->type, vd->toChars());
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
940
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
941 //allocainst->setAlignment(vd->type->alignsize()); // TODO
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
942 vd->ir.irLocal->value = allocainst;
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
943
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
944 #ifndef DISABLE_DEBUG_INFO
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
945 if (global.params.symdebug)
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
946 DtoDwarfLocalVariable(allocainst, vd);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
947 #endif
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
948 }
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: 483
diff changeset
949 else
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: 483
diff changeset
950 {
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: 483
diff changeset
951 assert(vd->ir.irLocal->value);
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: 483
diff changeset
952 }
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
953
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: 611
diff changeset
954 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: 611
diff changeset
955 Logger::cout() << "llvm value for decl: " << *vd->ir.irLocal->value << '\n';
1593
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
956 if (!vd->isRef())
b0dfdd5f6006 Make ref vars work with nesting.
Christian Kamm <kamm incasoftware de>
parents: 1592
diff changeset
957 DValue* ie = DtoInitializer(vd->ir.irLocal->value, vd->init);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
958 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
959
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: 583
diff changeset
960 return new DVarValue(vd->type, vd, vd->ir.getIrValue());
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
961 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
962 // struct declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
963 else if (StructDeclaration* s = declaration->isStructDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
964 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
965 Logger::println("StructDeclaration");
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
966 s->codegen(Type::sir);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
967 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
968 // function declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
969 else if (FuncDeclaration* f = declaration->isFuncDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
970 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
971 Logger::println("FuncDeclaration");
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
972 f->codegen(Type::sir);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
973 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
974 // alias declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
975 else if (AliasDeclaration* a = declaration->isAliasDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
976 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
977 Logger::println("AliasDeclaration - no work");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
978 // do nothing
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
979 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
980 // enum
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
981 else if (EnumDeclaration* e = declaration->isEnumDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
982 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
983 Logger::println("EnumDeclaration - no work");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
984 // do nothing
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
985 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
986 // class
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
987 else if (ClassDeclaration* e = declaration->isClassDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
988 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
989 Logger::println("ClassDeclaration");
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
990 e->codegen(Type::sir);
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
991 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
992 // typedef
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
993 else if (TypedefDeclaration* tdef = declaration->isTypedefDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
994 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
995 Logger::println("TypedefDeclaration");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
996 DtoTypeInfoOf(tdef->type, false);
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
997 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
998 // attribute declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
999 else if (AttribDeclaration* a = declaration->isAttribDeclaration())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1000 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1001 Logger::println("AttribDeclaration");
1516
0f08b145b878 Treat ConditionalDeclarations correctly in DtoDeclarationExp.
Christian Kamm <kamm incasoftware de>
parents: 1509
diff changeset
1002 // choose the right set in case this is a conditional declaration
0f08b145b878 Treat ConditionalDeclarations correctly in DtoDeclarationExp.
Christian Kamm <kamm incasoftware de>
parents: 1509
diff changeset
1003 Array *d = a->include(NULL, NULL);
0f08b145b878 Treat ConditionalDeclarations correctly in DtoDeclarationExp.
Christian Kamm <kamm incasoftware de>
parents: 1509
diff changeset
1004 if (d)
0f08b145b878 Treat ConditionalDeclarations correctly in DtoDeclarationExp.
Christian Kamm <kamm incasoftware de>
parents: 1509
diff changeset
1005 for (int i=0; i < d->dim; ++i)
1500
c3c46399bcf1 fix problem reported in ticket 327 - thanks d0k
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1482
diff changeset
1006 {
1516
0f08b145b878 Treat ConditionalDeclarations correctly in DtoDeclarationExp.
Christian Kamm <kamm incasoftware de>
parents: 1509
diff changeset
1007 DtoDeclarationExp((Dsymbol*)d->data[i]);
1500
c3c46399bcf1 fix problem reported in ticket 327 - thanks d0k
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1482
diff changeset
1008 }
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1009 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1010 // mixin declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1011 else if (TemplateMixin* m = declaration->isTemplateMixin())
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1012 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1013 Logger::println("TemplateMixin");
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1014 for (int i=0; i < m->members->dim; ++i)
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1015 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1016 Dsymbol* mdsym = (Dsymbol*)m->members->data[i];
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1017 DtoDeclarationExp(mdsym);
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1018 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1019 }
648
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1020 // tuple declaration
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1021 else if (TupleDeclaration* tupled = declaration->isTupleDeclaration())
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1022 {
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1023 Logger::println("TupleDeclaration");
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1024 if(!tupled->isexp) {
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1025 error(declaration->loc, "don't know how to handle non-expression tuple decls yet");
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1026 assert(0);
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1027 }
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1028
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1029 assert(tupled->objects);
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1030 for (int i=0; i < tupled->objects->dim; ++i)
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1031 {
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1032 DsymbolExp* exp = (DsymbolExp*)tupled->objects->data[i];
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1033 DtoDeclarationExp(exp->s);
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1034 }
8d850fa25713 Fix VarDecls for tuples. Closes #99.
Christian Kamm <kamm incasoftware de>
parents: 639
diff changeset
1035 }
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1036 // unsupported declaration
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1037 else
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1038 {
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1039 error(declaration->loc, "Unimplemented Declaration type for DeclarationExp. kind: %s", declaration->kind());
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1040 assert(0);
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1041 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1042 return NULL;
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1043 }
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1044
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1045 // does pretty much the same as DtoDeclarationExp, except it doesn't initialize, and only handles var declarations
1185
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1046 LLValue* DtoRawVarDeclaration(VarDeclaration* var, LLValue* addr)
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1047 {
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1048 // we don't handle globals with this one
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1049 assert(!var->isDataseg());
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1050
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1051 // we don't handle aliases either
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1052 assert(!var->aliassym);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1053
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1054 // alloca if necessary
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1055 LLValue* allocaval = NULL;
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1056 if (!addr && (!var->ir.irLocal || !var->ir.irLocal->value))
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1057 {
1350
15e9762bb620 Adds explicit alignment information for alloca instructions in general, there's a few cases that still needs to be looked at but this should catch the majority. Fixes ticket #293 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1279
diff changeset
1058 addr = DtoAlloca(var->type, var->toChars());
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1059
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1060 #ifndef DISABLE_DEBUG_INFO
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1061 // add debug info
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1062 if (global.params.symdebug)
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1063 DtoDwarfLocalVariable(addr, var);
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1064 #endif
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1065 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1066
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1067 // referenced by nested function?
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: 757
diff changeset
1068 #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: 757
diff changeset
1069 if (var->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: 757
diff changeset
1070 #else
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1071 if (var->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: 757
diff changeset
1072 #endif
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1073 {
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1074 assert(var->ir.irLocal);
1185
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1075 if(!var->ir.irLocal->value)
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1076 {
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1077 assert(addr);
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1078 var->ir.irLocal->value = addr;
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1079 }
1185
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1080 else
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1081 assert(!addr || addr == var->ir.irLocal->value);
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1082
1207
83d3b25c2213 Isolate all knowledge of what a function's nested context looks like in a
Frits van Bommel <fvbommel wxs.nl>
parents: 1206
diff changeset
1083 DtoNestedInit(var);
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1084 }
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1085 // normal local variable
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1086 else
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1087 {
1185
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1088 // if this already has storage, it must've been handled already
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1089 if (var->ir.irLocal && var->ir.irLocal->value) {
1411
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1090 if (addr && addr != var->ir.irLocal->value) {
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1091 // This can happen, for example, in scope(exit) blocks which
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1092 // are translated to IR multiple times.
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1093 // That *should* only happen after the first one is completely done
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1094 // though, so just set the address.
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1095 IF_LOG {
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1096 Logger::println("Replacing LLVM address of %s", var->toChars());
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1097 LOG_SCOPE;
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1098 Logger::cout() << "Old val: " << *var->ir.irLocal->value << '\n';
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1099 Logger::cout() << "New val: " << *addr << '\n';
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1100 }
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1101 var->ir.irLocal->value = addr;
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1102 }
e57859ca8f1e Fix `scope(exit) foreach (ref v; arr) foo(v);`
Frits van Bommel <fvbommel wxs.nl>
parents: 1408
diff changeset
1103 return addr;
1185
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1104 }
8baf611f0009 Fix nested references to 'ref' foreach variables.
Frits van Bommel <fvbommel wxs.nl>
parents: 1167
diff changeset
1105
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1106 assert(!var->ir.isSet());
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1107 assert(addr);
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1108 var->ir.irLocal = new IrLocal(var);
1189
c0091f3b72f1 Make sure debug info is only declared once per alloca.
Christian Kamm <kamm incasoftware de>
parents: 1185
diff changeset
1109 var->ir.irLocal->value = addr;
747
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1110 }
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1111
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1112 // return the alloca
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1113 return var->ir.irLocal->value;
46d0755451a4 Added DtoRawVarDeclaration routine to handle special variables in some statements.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 719
diff changeset
1114 }
433
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1115
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1116 /****************************************************************************************/
b5f55f471e0b Move DeclarationExp code into a helper function so it can call itself for template mixin members.
Christian Kamm <kamm incasoftware de>
parents: 424
diff changeset
1117 /*////////////////////////////////////////////////////////////////////////////////////////
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1118 // INITIALIZER HELPERS
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1119 ////////////////////////////////////////////////////////////////////////////////////////*/
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1120
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1121 LLConstant* DtoConstInitializer(Loc loc, Type* type, Initializer* init)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1122 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1123 LLConstant* _init = 0; // may return zero
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1124 if (!init)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1125 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1126 Logger::println("const default initializer for %s", type->toChars());
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1127 _init = DtoConstExpInit(loc, type, type->defaultInit());
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1128 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1129 else if (ExpInitializer* ex = init->isExpInitializer())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1130 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1131 Logger::println("const expression initializer");
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1132 _init = DtoConstExpInit(loc, type, ex->exp);;
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1133 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1134 else if (StructInitializer* si = init->isStructInitializer())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1135 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1136 Logger::println("const struct initializer");
1228
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1207
diff changeset
1137 si->ad->codegen(Type::sir);
79758fd2f48a Added Doxygen file.
Tomas Lindquist Olsen <tomas.l.olsen gmail.com>
parents: 1207
diff changeset
1138 return si->ad->ir.irStruct->createStructInitializer(si);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1139 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1140 else if (ArrayInitializer* ai = init->isArrayInitializer())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1141 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1142 Logger::println("const array initializer");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1143 _init = DtoConstArrayInitializer(ai);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1144 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1145 else if (init->isVoidInitializer())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1146 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1147 Logger::println("const void initializer");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1148 const LLType* ty = DtoType(type);
1560
1d5c3354b3c2 getNullValue is in Constant again
Benjamin Kramer <benny.kra@gmail.com>
parents: 1554
diff changeset
1149 _init = LLConstant::getNullValue(ty);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1150 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1151 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1152 Logger::println("unsupported const initializer: %s", init->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1153 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1154 return _init;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1155 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1156
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1157 //////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1158
482
aa8c050dfd19 Move zero init of padding to DtoInitializer in order to respect void initializers.
Christian Kamm <kamm incasoftware de>
parents: 481
diff changeset
1159 DValue* DtoInitializer(LLValue* target, Initializer* init)
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1160 {
328
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
1161 if (!init)
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
1162 return 0;
7086a84ab3d6 [svn r349] Fixed problems with static arrays of void as well as a static arrays with zero length.
lindquist
parents: 315
diff changeset
1163 else if (ExpInitializer* ex = init->isExpInitializer())
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1164 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1165 Logger::println("expression initializer");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1166 assert(ex->exp);
1004
45ed9e125a00 Remove initialization of padding of reals, ireals and creals.
Frits van Bommel <fvbommel wxs.nl>
parents: 994
diff changeset
1167 return ex->exp->toElem(gIR);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1168 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1169 else if (init->isVoidInitializer())
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1170 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1171 // do nothing
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1172 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1173 else {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1174 Logger::println("unsupported initializer: %s", init->toChars());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1175 assert(0);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1176 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1177 return 0;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1178 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1179
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1180 //////////////////////////////////////////////////////////////////////////////////////////
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1181
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1182 static LLConstant* expand_to_sarray(Type *base, Expression* exp)
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1183 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1184 Logger::println("building type %s from expression (%s) of type %s", base->toChars(), exp->toChars(), exp->type->toChars());
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1185 const LLType* dstTy = DtoType(base);
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: 611
diff changeset
1186 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: 611
diff changeset
1187 Logger::cout() << "final llvm type requested: " << *dstTy << '\n';
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1188
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1189 LLConstant* val = exp->toConstElem(gIR);
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1190
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1191 Type* expbase = exp->type->toBasetype();
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1192 Logger::println("expbase: %s", expbase->toChars());
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1193 Type* t = base->toBasetype();
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1194
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1195 LLSmallVector<size_t, 4> dims;
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1196
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1197 while(1)
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1198 {
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1199 Logger::println("t: %s", t->toChars());
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1200 if (t->equals(expbase))
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1201 break;
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1202 assert(t->ty == Tsarray);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1203 TypeSArray* tsa = (TypeSArray*)t;
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1204 dims.push_back(tsa->dim->toInteger());
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: 757
diff changeset
1205 assert(t->nextOf());
f04dde6e882c Added initial D2 support, D2 frontend and changes to codegen to make things compile.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 757
diff changeset
1206 t = t->nextOf()->toBasetype();
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1207 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1208
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1209 size_t i = dims.size();
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1210 assert(i);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1211
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1212 std::vector<LLConstant*> inits;
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1213 while (i--)
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1214 {
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1215 const LLArrayType* arrty = LLArrayType::get(val->getType(), dims[i]);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1216 inits.clear();
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1217 inits.insert(inits.end(), dims[i], val);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1218 val = LLConstantArray::get(arrty, inits);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1219 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1220
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1221 return val;
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1222 }
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1223
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1224 LLConstant* DtoConstExpInit(Loc loc, Type* type, Expression* exp)
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1225 {
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1226 Type* expbase = exp->type->toBasetype();
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1227 Type* base = type->toBasetype();
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1228
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1229 // if not the same basetypes, we won't get the same llvm types either
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1230 if (!expbase->equals(base))
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1231 {
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1232 if (base->ty == Tsarray)
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1233 {
796
6e7a4c3b64d2 Error instead of assert when trying to build a default initializer for void[n].
Christian Kamm <kamm incasoftware de>
parents: 794
diff changeset
1234 if (base->nextOf()->toBasetype()->ty == Tvoid) {
6e7a4c3b64d2 Error instead of assert when trying to build a default initializer for void[n].
Christian Kamm <kamm incasoftware de>
parents: 794
diff changeset
1235 error(loc, "static arrays of voids have no default initializer");
6e7a4c3b64d2 Error instead of assert when trying to build a default initializer for void[n].
Christian Kamm <kamm incasoftware de>
parents: 794
diff changeset
1236 fatal();
6e7a4c3b64d2 Error instead of assert when trying to build a default initializer for void[n].
Christian Kamm <kamm incasoftware de>
parents: 794
diff changeset
1237 }
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
1238 Logger::println("type is a static array, building constant array initializer to single value");
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1239 return expand_to_sarray(base, exp);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1240 }
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1241 else
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1242 {
715
30b42a283c8e Removed TypeOpaque from DMD.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 709
diff changeset
1243 error("cannot yet convert default initializer %s to type %s to %s", exp->toChars(), exp->type->toChars(), type->toChars());
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1244 fatal();
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1245 }
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1246 assert(0);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1247 }
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1248
502
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1249 return exp->toConstElem(gIR);
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1250 }
837af2a63564 Fixed problems constant multidimensional static array initializers.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 486
diff changeset
1251
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1252 //////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1253
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1254 void DtoAnnotation(const char* str)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1255 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1256 std::string s("CODE: ");
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1257 s.append(str);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1258 char* p = &s[0];
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1259 while (*p)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1260 {
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1261 if (*p == '"')
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1262 *p = '\'';
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1263 ++p;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1264 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1265 // create a noop with the code as the result name!
797
340acf1535d0 Removed KDevelop3 project files, CMake can generate them just fine!
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 796
diff changeset
1266 // FIXME: this is const folded and eliminated immediately ... :/
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1267 gIR->ir->CreateAnd(DtoConstSize_t(0),DtoConstSize_t(0),s.c_str());
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1268 }
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1269
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1270 //////////////////////////////////////////////////////////////////////////////////////////
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1271
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1272 LLConstant* DtoTypeInfoOf(Type* type, bool base)
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1273 {
1466
8bf5fa175555 Make sure typeinfo output are mutable types, this is a temporary workaround to get druntime genobj.d to compile until we figure out what typeinfos are actually needed here and there ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1463
diff changeset
1274 #if DMDV2
8bf5fa175555 Make sure typeinfo output are mutable types, this is a temporary workaround to get druntime genobj.d to compile until we figure out what typeinfos are actually needed here and there ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1463
diff changeset
1275 // FIXME: this is probably wrong, but it makes druntime's genobj.d compile!
8bf5fa175555 Make sure typeinfo output are mutable types, this is a temporary workaround to get druntime genobj.d to compile until we figure out what typeinfos are actually needed here and there ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1463
diff changeset
1276 type = type->mutableOf()->merge(); // needed.. getTypeInfo does the same
8bf5fa175555 Make sure typeinfo output are mutable types, this is a temporary workaround to get druntime genobj.d to compile until we figure out what typeinfos are actually needed here and there ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1463
diff changeset
1277 #else
290
ebaf65fc4726 [svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents: 289
diff changeset
1278 type = type->merge(); // needed.. getTypeInfo does the same
1466
8bf5fa175555 Make sure typeinfo output are mutable types, this is a temporary workaround to get druntime genobj.d to compile until we figure out what typeinfos are actually needed here and there ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1463
diff changeset
1279 #endif
290
ebaf65fc4726 [svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents: 289
diff changeset
1280 type->getTypeInfo(NULL);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1281 TypeInfoDeclaration* tidecl = type->vtinfo;
290
ebaf65fc4726 [svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents: 289
diff changeset
1282 assert(tidecl);
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
1283 tidecl->codegen(Type::sir);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1284 assert(tidecl->ir.irGlobal != NULL);
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
1285 assert(tidecl->ir.irGlobal->value != NULL);
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1286 LLConstant* c = isaConstant(tidecl->ir.irGlobal->value);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1287 assert(c != NULL);
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1288 if (base)
290
ebaf65fc4726 [svn r311] Fixed: structs no longer output two static typeinfos.
lindquist
parents: 289
diff changeset
1289 return llvm::ConstantExpr::getBitCast(c, DtoType(Type::typeinfo->type));
244
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1290 return c;
a95056b3c996 [svn r261] Fixed debug info for integer and floating local variables, can now be inspected in GDB.
lindquist
parents:
diff changeset
1291 }
284
70c370e97944 [svn r305] Started support for custom class allocators/deallocators. Allocators with more than one argument still need to be fixed.
lindquist
parents: 250
diff changeset
1292
289
17d3b3236334 [svn r310] Fixed a problem with incomplete types and templates in typeinfo code.
lindquist
parents: 284
diff changeset
1293 //////////////////////////////////////////////////////////////////////////////////////////
17d3b3236334 [svn r310] Fixed a problem with incomplete types and templates in typeinfo code.
lindquist
parents: 284
diff changeset
1294
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1295 void DtoOverloadedIntrinsicName(TemplateInstance* ti, TemplateDeclaration* td, std::string& name)
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1296 {
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1297 Logger::println("DtoOverloadedIntrinsicName");
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1298 LOG_SCOPE;
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1299
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1300 Logger::println("template instance: %s", ti->toChars());
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1301 Logger::println("template declaration: %s", td->toChars());
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1302 Logger::println("intrinsic name: %s", td->intrinsicName.c_str());
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1303
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1304 // for now use the size in bits of the first template param in the instance
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1305 assert(ti->tdtypes.dim == 1);
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1306 Type* T = (Type*)ti->tdtypes.data[0];
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1307
1079
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1308 char prefix = T->isreal() ? 'f' : T->isintegral() ? 'i' : 0;
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1309 if (!prefix) {
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1310 ti->error("has invalid template parameter for intrinsic: %s", T->toChars());
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1311 fatal(); // or LLVM asserts
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1312 }
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1313
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1314 char tmp[21]; // probably excessive, but covers a uint64_t
1167
ed4b050ada45 Another big-endian fix. (Don't lie to [s]printf...)
Frits van Bommel <fvbommel wxs.nl>
parents: 1160
diff changeset
1315 sprintf(tmp, "%lu", (unsigned long) gTargetData->getTypeSizeInBits(DtoType(T)));
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1316
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1317 // replace # in name with bitsize
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1318 name = td->intrinsicName;
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1319
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1320 std::string needle("#");
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1321 size_t pos;
1079
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1322 while(std::string::npos != (pos = name.find(needle))) {
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1323 if (pos > 0 && name[pos-1] == prefix) {
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1324 // Properly prefixed, insert bitwidth.
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1325 name.replace(pos, 1, tmp);
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1326 } else {
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1327 if (pos && (name[pos-1] == 'i' || name[pos-1] == 'f')) {
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1328 // Wrong type character.
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1329 ti->error("has invalid parameter type for intrinsic %s: %s is not a%s type",
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1330 name.c_str(), T->toChars(),
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1331 (name[pos-1] == 'i' ? "n integral" : " floating-point"));
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1332 } else {
1088
a08983bf972e Move "invalid intrinsic name" error to declaration, not instantiation.
Frits van Bommel <fvbommel wxs.nl>
parents: 1079
diff changeset
1333 // Just plain wrong. (Error in declaration, not instantiation)
a08983bf972e Move "invalid intrinsic name" error to declaration, not instantiation.
Frits van Bommel <fvbommel wxs.nl>
parents: 1079
diff changeset
1334 td->error("has an invalid intrinsic name: %s", name.c_str());
1079
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1335 }
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1336 fatal(); // or LLVM asserts
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1337 }
4e388d9d0e25 Intrinsics overhaul:
Frits van Bommel <fvbommel wxs.nl>
parents: 1067
diff changeset
1338 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1339
527
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1340 Logger::println("final intrinsic name: %s", name.c_str());
cecfee2d01a8 Added support for overloaded intrinsics.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 505
diff changeset
1341 }
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1342
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1343 //////////////////////////////////////////////////////////////////////////////////////////
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1344
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1345 bool mustDefineSymbol(Dsymbol* s)
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1346 {
1279
04c36605feb9 Fixed array operation codegen when used from imported templates. All array operations are now emitted with template linkage. Fixed #270 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1278
diff changeset
1347 if (FuncDeclaration* fd = s->isFuncDeclaration())
04c36605feb9 Fixed array operation codegen when used from imported templates. All array operations are now emitted with template linkage. Fixed #270 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1278
diff changeset
1348 {
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1349 // we can't (and probably shouldn't?) define functions
1403
e5c5d354c649 Tentative fix for semantic3 on imported modules and unnecessary template
Christian Kamm <kamm incasoftware de>
parents: 1356
diff changeset
1350 // that weren't semantic3'ed
e5c5d354c649 Tentative fix for semantic3 on imported modules and unnecessary template
Christian Kamm <kamm incasoftware de>
parents: 1356
diff changeset
1351 if (fd->semanticRun < 4)
e5c5d354c649 Tentative fix for semantic3 on imported modules and unnecessary template
Christian Kamm <kamm incasoftware de>
parents: 1356
diff changeset
1352 return false;
1408
afecdb8ee962 Fix bug #307 by doing what DMD does: add the arrayop to
Christian Kamm <kamm incasoftware de>
parents: 1403
diff changeset
1353
afecdb8ee962 Fix bug #307 by doing what DMD does: add the arrayop to
Christian Kamm <kamm incasoftware de>
parents: 1403
diff changeset
1354 if (fd->isArrayOp)
afecdb8ee962 Fix bug #307 by doing what DMD does: add the arrayop to
Christian Kamm <kamm incasoftware de>
parents: 1403
diff changeset
1355 return true;
1482
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1356
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1357 if (global.params.useAvailableExternally && fd->availableExternally) {
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1358 // Emit extra functions if we're inlining.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1359 // These will get available_externally linkage,
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1360 // so they shouldn't end up in object code.
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1361
1482
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1362 assert(fd->type->ty == Tfunction);
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1363 TypeFunction* tf = (TypeFunction*) fd->type;
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1364 // * If we define extra static constructors, static destructors
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1365 // and unittests they'll get registered to run, and we won't
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1366 // be calling them directly anyway.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1367 // * If it's a large function, don't emit it unnecessarily.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1368 // Use DMD's canInline() to determine whether it's large.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1369 // inlineCost() members have been changed to pay less attention
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1370 // to DMDs limitations, but still have some issues. The most glaring
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1371 // offenders are any kind of control flow statements other than
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1372 // 'if' and 'return'.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1373 if ( !fd->isStaticCtorDeclaration()
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1374 && !fd->isStaticDtorDeclaration()
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1375 && !fd->isUnitTestDeclaration()
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1376 && fd->canInline(true))
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1377 {
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1378 return true;
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1379 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1380
1482
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1381 // This was only semantic'ed for inlining checks.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1382 // We won't be inlining this, so we only need to emit a declaration.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1383 return false;
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1384 }
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1385 }
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1386
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1387 // Inlining checks may create some variable and class declarations
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1388 // we don't need to emit.
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1389 if (global.params.useAvailableExternally)
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1390 {
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1391 if (VarDeclaration* vd = s->isVarDeclaration())
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1392 if (vd->availableExternally)
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1393 return false;
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1394
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1395 if (ClassDeclaration* cd = s->isClassDeclaration())
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1396 if (cd->availableExternally)
d9c5f5a43403 Run `semantic3` on imported modules, and emit new symbols with
Frits van Bommel <fvbommel wxs.nl>
parents: 1479
diff changeset
1397 return false;
1279
04c36605feb9 Fixed array operation codegen when used from imported templates. All array operations are now emitted with template linkage. Fixed #270 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1278
diff changeset
1398 }
04c36605feb9 Fixed array operation codegen when used from imported templates. All array operations are now emitted with template linkage. Fixed #270 .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1278
diff changeset
1399
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1400 TemplateInstance* tinst = DtoIsTemplateInstance(s);
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1401 if (tinst)
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1402 {
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1403 if (!opts::singleObj)
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1404 return true;
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1405
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1406 if (!tinst->emittedInModule)
1478
4dca8ed9d8b7 Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents: 1466
diff changeset
1407 {
4dca8ed9d8b7 Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents: 1466
diff changeset
1408 gIR->seenTemplateInstances.insert(tinst);
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1409 tinst->emittedInModule = gIR->dmodule;
1478
4dca8ed9d8b7 Fix #318 by making a list of all seen template instances in a module for
Christian Kamm <kamm incasoftware de>
parents: 1466
diff changeset
1410 }
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1411 return tinst->emittedInModule == gIR->dmodule;
947
9a10fa839dc5 Switch some getModule to getCompilationModule to make sure templates are
Christian Kamm <kamm incasoftware de>
parents: 946
diff changeset
1412 }
1650
40bd4a0d4870 Update to work with LLVM 2.7.
Tomas Lindquist Olsen
parents: 1643
diff changeset
1413
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1414 return s->getModule() == gIR->dmodule;
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1415 }
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1416
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1417 //////////////////////////////////////////////////////////////////////////////////////////
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1418
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1419 bool needsTemplateLinkage(Dsymbol* s)
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1420 {
1067
7ce8355fbcc6 Improved template emission control for singleobj building.
Christian Kamm <kamm incasoftware de>
parents: 1044
diff changeset
1421 return DtoIsTemplateInstance(s) && mustDefineSymbol(s);
940
39519a1ff603 Changed the way LDC determines if a template instantiation needs to get a definition, seems to speed up compile times quite a bit in some cases.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 936
diff changeset
1422 }
1029
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1423
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1424 //////////////////////////////////////////////////////////////////////////////////////////
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1425
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1426 bool hasUnalignedFields(Type* t)
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1427 {
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1428 t = t->toBasetype();
1044
39f12f5aa515 Fix hasUnalignedFields(): take static arrays into account too.
Frits van Bommel <fvbommel wxs.nl>
parents: 1029
diff changeset
1429 if (t->ty == Tsarray) {
1452
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1412
diff changeset
1430 assert(t->nextOf()->size() % t->nextOf()->alignsize() == 0);
638d16625da2 LDC 2 compiles again.
Robert Clipsham <robert@octarineparrot.com>
parents: 1412
diff changeset
1431 return hasUnalignedFields(t->nextOf());
1044
39f12f5aa515 Fix hasUnalignedFields(): take static arrays into account too.
Frits van Bommel <fvbommel wxs.nl>
parents: 1029
diff changeset
1432 } else if (t->ty != Tstruct)
1029
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1433 return false;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1434
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1435 TypeStruct* ts = (TypeStruct*)t;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1436 if (ts->unaligned)
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1437 return (ts->unaligned == 2);
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1438
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1439 StructDeclaration* sym = ts->sym;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1440
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1441 // go through all the fields and try to find something unaligned
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1442 ts->unaligned = 2;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1443 for (int i = 0; i < sym->fields.dim; i++)
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1444 {
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1445 VarDeclaration* f = (VarDeclaration*)sym->fields.data[i];
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1446 unsigned a = f->type->alignsize() - 1;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1447 if (((f->offset + a) & ~a) != f->offset)
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1448 return true;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1449 else if (f->type->toBasetype()->ty == Tstruct && hasUnalignedFields(f->type))
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1450 return true;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1451 }
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1452
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1453 ts->unaligned = 1;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1454 return false;
4d366a75d95f Added hasUnalignedFields helper to check if a type has unaligned fields - as per request from fvbommel. Result is cached in TypeStruct.
Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
parents: 1019
diff changeset
1455 }
1271
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1456
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1457 //////////////////////////////////////////////////////////////////////////////////////////
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1458
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1459 IrModule * getIrModule(Module * M)
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1460 {
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1461 if (M == NULL)
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1462 M = gIR->func()->decl->getModule();
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1463 assert(M && "null module");
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1464 if (!M->ir.irModule)
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1465 M->ir.irModule = new IrModule(M, M->srcfile->toChars());
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1466 return M->ir.irModule;
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1467 }
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1468
0686701178d3 Moved special casing of 'assert(this, "null this");' generated statements from !ThisExp into !AssertExp.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1255
diff changeset
1469 //////////////////////////////////////////////////////////////////////////////////////////
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1470
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1471 size_t realignOffset(size_t offset, Type* type)
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1472 {
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1473 size_t alignsize = type->alignsize();
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1474 size_t alignedoffset = (offset + alignsize - 1) & ~(alignsize - 1);
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1475
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1476 // if the aligned offset already matches the input offset
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1477 // don't waste time checking things are ok!
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1478 if (alignedoffset == offset)
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1479 return alignedoffset;
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1480
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1481 // we cannot get the llvm alignment if the type is still opaque, this can happen in some
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1482 // forward reference situations, so when this happens we fall back to manual padding.
1550
c704fea92f80 Fixed potential crash with complex recursive struct types.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1545
diff changeset
1483 // also handle arbitrary "by-value" opaques nested inside aggregates.
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1484 const llvm::Type* T = DtoType(type);
1550
c704fea92f80 Fixed potential crash with complex recursive struct types.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1545
diff changeset
1485 if (!T->isSized())
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1486 {
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1487 return offset;
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1488 }
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1489
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1490 // then we check against the llvm alignment
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1491 size_t alignsize2 = gTargetData->getABITypeAlignment(T);
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1492
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1493 // if it differs we need to insert manual padding as well
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1494 if (alignsize != alignsize2)
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1495 {
1355
c5410f294c89 Erm... Revert the rev [1352] change, the original code was correct ...
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1352
diff changeset
1496 assert(alignsize > alignsize2 && "this is not good, the D and LLVM "
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1497 "type alignments differ, but LLVM's is bigger! This will break "
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1498 "aggregate type mapping");
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1499 // don't try and align the offset, and let the mappers pad 100% manually
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1500 return offset;
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1501 }
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1502
1356
59c2aa9def23 Enabled fix for ticket #294 . It will try it's best to let LLVM handle the alignment, and fall back to manual padding when that's not possible. If this causes problems again, we'll have to consistently pad manually using packed structs.
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1355
diff changeset
1503 // ok, we're good, llvm will align properly!
1351
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1504 return alignedoffset;
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1505 }
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1506
8d501abecd24 Initial (but disabled) fix for ticket #294 , the actual part that fixes the bug is in a #if 0 block as I'm afraid it will cause regressions. I'm most likely not going to be around tonight, and maybe not tomorrow as well, so I'm pushing it in case someone wants to run some serious testing/investigate the problem noted in llvmhelpers.cpp : realignOffset .
Tomas Lindquist Olsen <tomas.l.olsen gmail com>
parents: 1350
diff changeset
1507 //////////////////////////////////////////////////////////////////////////////////////////
1504
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1508
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1509 Type * stripModifiers( Type * type )
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1510 {
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1511 #if DMDV2
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1512 Type *t = type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1513 while (t->mod)
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1514 {
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1515 switch (t->mod)
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1516 {
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1517 case MODconst:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1518 t = type->cto;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1519 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1520 case MODshared:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1521 t = type->sto;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1522 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1523 case MODinvariant:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1524 t = type->ito;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1525 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1526 case MODshared | MODconst:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1527 t = type->scto;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1528 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1529 default:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1530 assert(0 && "Unhandled type modifier");
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1531 }
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1532
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1533 if (!t)
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1534 {
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1535 unsigned sz = type->sizeTy[type->ty];
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1536 t = (Type *)malloc(sz);
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1537 memcpy(t, type, sz);
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1538 t->mod = 0;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1539 t->deco = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1540 t->arrayof = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1541 t->pto = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1542 t->rto = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1543 t->cto = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1544 t->ito = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1545 t->sto = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1546 t->scto = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1547 t->vtinfo = NULL;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1548 t = t->merge();
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1549
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1550 t->fixTo(type);
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1551 switch (type->mod)
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1552 {
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1553 case MODconst:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1554 t->cto = type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1555 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1556
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1557 case MODinvariant:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1558 t->ito = type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1559 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1560
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1561 case MODshared:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1562 t->sto = type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1563 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1564
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1565 case MODshared | MODconst:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1566 t->scto = type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1567 break;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1568
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1569 default:
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1570 assert(0);
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1571 }
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1572 }
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1573 }
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1574 return t;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1575 #else
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1576 return type;
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1577 #endif
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1578 }
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1579
855f188aab7a Added a stripModifiers() function to remove shared|const|immutable storage classes in D2 (should eventually be moved to a dhelpers file rather than llvm helpers).
Robert Clipsham <robert@octarineparrot.com>
parents: 1500
diff changeset
1580 //////////////////////////////////////////////////////////////////////////////////////////
1643
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1581
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1582 LLValue* makeLValue(Loc& loc, DValue* value)
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1583 {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1584 Type* valueType = value->getType();
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1585 bool needsMemory;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1586 LLValue* valuePointer;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1587 if (value->isIm()) {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1588 valuePointer = value->getRVal();
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1589 needsMemory = !DtoIsPassedByRef(valueType);
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1590 }
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1591 else if (DVarValue* var = value->isVar()) {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1592 valuePointer = value->getLVal();
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1593 needsMemory = false;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1594 }
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1595 else if (value->isConst()) {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1596 valuePointer = value->getRVal();
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1597 needsMemory = true;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1598 }
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1599 else {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1600 valuePointer = DtoAlloca(valueType, ".makelvaluetmp");
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1601 DVarValue var(valueType, valuePointer);
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1602 DtoAssign(loc, &var, value);
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1603 needsMemory = false;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1604 }
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1605
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1606 if (needsMemory) {
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1607 LLValue* tmp = DtoAlloca(valueType, ".makelvaluetmp");
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1608 DtoStore(valuePointer, tmp);
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1609 valuePointer = tmp;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1610 }
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1611
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1612 return valuePointer;
8f121883bce8 Apply patch from klickverbot. This is his 'proper fix' patch for bug #395.
Kelly Wilson <wilsonk cpsc.ucalgary.ca>
parents: 1593
diff changeset
1613 }