Moved constant array creation helper to llvmhelpers.h.

This commit is contained in:
David Nadlinger
2013-05-12 01:24:04 +02:00
parent ad03a435ad
commit e1501c712f
2 changed files with 13 additions and 15 deletions

View File

@@ -220,4 +220,17 @@ void printLabelName(std::ostream& target, const char* func_mangle, const char* l
void AppendFunctionToLLVMGlobalCtorsDtors(llvm::Function* func, const uint32_t priority, const bool isCtor);
template <typename T>
LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true)
{
std::vector<LLConstant*> vals;
vals.reserve(len+1);
for (size_t i = 0; i < len; ++i) {
vals.push_back(LLConstantInt::get(ct, str[i], false));
}
if (nullterm)
vals.push_back(LLConstantInt::get(ct, 0, false));
return LLConstantArray::get(at, vals);
}
#endif

View File

@@ -423,21 +423,6 @@ LLConstant* ComplexExp::toConstElem(IRState* p)
//////////////////////////////////////////////////////////////////////////////////////////
template <typename T>
static inline LLConstant* toConstantArray(LLType* ct, LLArrayType* at, T* str, size_t len, bool nullterm = true)
{
std::vector<LLConstant*> vals;
vals.reserve(len+1);
for (size_t i = 0; i < len; ++i) {
vals.push_back(LLConstantInt::get(ct, str[i], false));
}
if (nullterm)
vals.push_back(LLConstantInt::get(ct, 0, false));
return LLConstantArray::get(at, vals);
}
//////////////////////////////////////////////////////////////////////////////////////////
DValue* StringExp::toElem(IRState* p)
{
Logger::print("StringExp::toElem: %s @ %s\n", toChars(), type->toChars());