comparison gen/llvmhelpers.cpp @ 683:b411c41a9716

Only allocate the module file name once. Fixes #90.
author Christian Kamm <kamm incasoftware de>
date Sun, 12 Oct 2008 10:35:16 +0200
parents 4f004553de33
children 43165a082535
comparison
equal deleted inserted replaced
682:518b8cc84369 683:b411c41a9716
4 #include "mars.h" 4 #include "mars.h"
5 #include "init.h" 5 #include "init.h"
6 #include "id.h" 6 #include "id.h"
7 #include "expression.h" 7 #include "expression.h"
8 #include "template.h" 8 #include "template.h"
9 #include "module.h"
9 10
10 #include "gen/tollvm.h" 11 #include "gen/tollvm.h"
11 #include "gen/llvmhelpers.h" 12 #include "gen/llvmhelpers.h"
12 #include "gen/irstate.h" 13 #include "gen/irstate.h"
13 #include "gen/runtime.h" 14 #include "gen/runtime.h"
17 #include "gen/complex.h" 18 #include "gen/complex.h"
18 #include "gen/classes.h" 19 #include "gen/classes.h"
19 #include "gen/functions.h" 20 #include "gen/functions.h"
20 #include "gen/typeinf.h" 21 #include "gen/typeinf.h"
21 #include "gen/todebug.h" 22 #include "gen/todebug.h"
23 #include "ir/irmodule.h"
22 24
23 #include <stack> 25 #include <stack>
24 26
25 /****************************************************************************************/ 27 /****************************************************************************************/
26 /*//////////////////////////////////////////////////////////////////////////////////////// 28 /*////////////////////////////////////////////////////////////////////////////////////////
108 ////////////////////////////////////////////////////////////////////////////////////////*/ 110 ////////////////////////////////////////////////////////////////////////////////////////*/
109 111
110 void DtoAssert(Loc* loc, DValue* msg) 112 void DtoAssert(Loc* loc, DValue* msg)
111 { 113 {
112 std::vector<LLValue*> args; 114 std::vector<LLValue*> args;
113 LLConstant* c;
114 115
115 // func 116 // func
116 const char* fname = msg ? "_d_assert_msg" : "_d_assert"; 117 const char* fname = msg ? "_d_assert_msg" : "_d_assert";
117 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname); 118 llvm::Function* fn = LLVM_D_GetRuntimeFunction(gIR->module, fname);
118 119
119 // param attrs 120 // param attrs
120 llvm::AttrListPtr palist; 121 llvm::AttrListPtr palist;
121 int idx = 1; 122 int idx = 1;
122 123
123 // FIXME: every assert creates a global for the filename !!!
124 c = DtoConstString(loc->filename);
125
126 // msg param 124 // msg param
127 if (msg) 125 if (msg)
128 { 126 {
129 if (DSliceValue* s = msg->isSlice()) 127 if (DSliceValue* s = msg->isSlice())
130 { 128 {
131 llvm::AllocaInst* alloc = gIR->func()->msgArg; 129 llvm::AllocaInst* alloc = gIR->func()->msgArg;
132 if (!alloc) 130 if (!alloc)
133 { 131 {
134 alloc = DtoAlloca(c->getType(), ".assertmsg"); 132 alloc = DtoAlloca(DtoArrayType(LLType::Int8Ty), ".assertmsg");
135 DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s)); 133 DtoSetArray(alloc, DtoArrayLen(s), DtoArrayPtr(s));
136 gIR->func()->msgArg = alloc; 134 gIR->func()->msgArg = alloc;
137 } 135 }
138 args.push_back(alloc); 136 args.push_back(alloc);
139 } 137 }
143 } 141 }
144 palist = palist.addAttr(idx++, llvm::Attribute::ByVal); 142 palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
145 } 143 }
146 144
147 // file param 145 // file param
148 llvm::AllocaInst* alloc = gIR->func()->srcfileArg; 146 args.push_back(gIR->dmodule->ir.irModule->fileName);
149 if (!alloc)
150 {
151 alloc = DtoAlloca(c->getType(), ".srcfile");
152 gIR->func()->srcfileArg = alloc;
153 }
154 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
155 DtoStore(c->getOperand(0), ptr);
156 ptr = DtoGEPi(alloc, 0,1, "tmp");
157 DtoStore(c->getOperand(1), ptr);
158
159 args.push_back(alloc);
160 palist = palist.addAttr(idx++, llvm::Attribute::ByVal); 147 palist = palist.addAttr(idx++, llvm::Attribute::ByVal);
161 148
162 149
163 // line param 150 // line param
164 c = DtoConstUint(loc->linnum); 151 LLConstant* c = DtoConstUint(loc->linnum);
165 args.push_back(c); 152 args.push_back(c);
166 153
167 // call 154 // call
168 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end()); 155 CallOrInvoke* call = gIR->CreateCallOrInvoke(fn, args.begin(), args.end());
169 call->setAttributes(palist); 156 call->setAttributes(palist);