comparison gen/arrays.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 93433f4b6963
children 30b42a283c8e
comparison
equal deleted inserted replaced
682:518b8cc84369 683:b411c41a9716
1 #include "gen/llvm.h" 1 #include "gen/llvm.h"
2 2
3 #include "mtype.h" 3 #include "mtype.h"
4 #include "module.h"
4 #include "dsymbol.h" 5 #include "dsymbol.h"
5 #include "aggregate.h" 6 #include "aggregate.h"
6 #include "declaration.h" 7 #include "declaration.h"
7 #include "init.h" 8 #include "init.h"
8 9
11 #include "gen/llvmhelpers.h" 12 #include "gen/llvmhelpers.h"
12 #include "gen/arrays.h" 13 #include "gen/arrays.h"
13 #include "gen/runtime.h" 14 #include "gen/runtime.h"
14 #include "gen/logger.h" 15 #include "gen/logger.h"
15 #include "gen/dvalue.h" 16 #include "gen/dvalue.h"
17 #include "ir/irmodule.h"
16 18
17 ////////////////////////////////////////////////////////////////////////////////////////// 19 //////////////////////////////////////////////////////////////////////////////////////////
18 20
19 const LLStructType* DtoArrayType(Type* arrayTy) 21 const LLStructType* DtoArrayType(Type* arrayTy)
20 { 22 {
1070 1072
1071 std::vector<LLValue*> args; 1073 std::vector<LLValue*> args;
1072 llvm::AttrListPtr palist; 1074 llvm::AttrListPtr palist;
1073 1075
1074 // file param 1076 // file param
1075 // FIXME: every array bounds check creates a global for the filename !!! 1077 args.push_back(gIR->dmodule->ir.irModule->fileName);
1076 LLConstant* c = DtoConstString(loc.filename);
1077
1078 llvm::AllocaInst* alloc = gIR->func()->srcfileArg;
1079 if (!alloc)
1080 {
1081 alloc = DtoAlloca(c->getType(), ".srcfile");
1082 gIR->func()->srcfileArg = alloc;
1083 }
1084 LLValue* ptr = DtoGEPi(alloc, 0,0, "tmp");
1085 DtoStore(c->getOperand(0), ptr);
1086 ptr = DtoGEPi(alloc, 0,1, "tmp");
1087 DtoStore(c->getOperand(1), ptr);
1088
1089 args.push_back(alloc);
1090 palist = palist.addAttr(1, llvm::Attribute::ByVal); 1078 palist = palist.addAttr(1, llvm::Attribute::ByVal);
1091 1079
1092 // line param 1080 // line param
1093 c = DtoConstUint(loc.linnum); 1081 LLConstant* c = DtoConstUint(loc.linnum);
1094 args.push_back(c); 1082 args.push_back(c);
1095 1083
1096 // call 1084 // call
1097 llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds"); 1085 llvm::Function* errorfn = LLVM_D_GetRuntimeFunction(gIR->module, "_d_array_bounds");
1098 CallOrInvoke* call = gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end()); 1086 CallOrInvoke* call = gIR->CreateCallOrInvoke(errorfn, args.begin(), args.end());