(original) (raw)
Hello,
I'm trying to get the pointer to the first element of a string (so that I can pass it to a function).
The string itself is a constant kept in a global variable.
My end goal is to generate the IR for something like "puts("Hello World")";
I'm stuck on the parameter part of the call instruction.
So far I have something like this:
const std::string& str = strExpr->value();
llvm::ArrayType\* type = llvm::ArrayType::get(llvm:: IntegerType::get(m\_context, 8), str.size()+1);
llvm::GlobalVariable\* var = new llvm::GlobalVariable(m\_module, type, true, llvm::GlobalValue:: PrivateLinkage, nullptr, ".str");
var->setAlignment(1);;
llvm::Constant\* c = llvm::ConstantDataArray:: getString(m\_context, str);
var->setInitializer(c);
The part below is the one I have problems with:
llvm::ConstantInt\* const\_int32\_12 = llvm::ConstantInt::get(m\_ context, llvm::APInt(32, llvm::StringRef("0"), 10));
std::vector const\_ptr\_14\_indices;
const\_ptr\_14\_indices.push\_ back(const\_int32\_12);
const\_ptr\_14\_indices.push\_ back(const\_int32\_12);
return llvm::ConstantExpr:: getGetElementPtr(nullptr,c, const\_ptr\_14\_indices);
I realize that the GlobalVariable should not be declared every time I get in that function but that's something I'll fix after I get this working.
Any help here would be appreciated.
Regards,
Lorin