<div dir="ltr"><span style="font-size:12.8px">Hello,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I'm trying to get the pointer to the first element of a string (so that I can pass it to a function).</div><div style="font-size:12.8px">The string itself is a constant kept in a global variable.</div><div style="font-size:12.8px">My end goal is to generate the IR for something like "puts("Hello World")";</div><div style="font-size:12.8px">I'm stuck on the parameter part of the call instruction.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">So far I have something like this:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div>const std::string& str = strExpr->value();</div><div>llvm::ArrayType* type = llvm::ArrayType::get(llvm::<wbr>IntegerType::get(m_context, 8), str.size()+1);</div><div>llvm::GlobalVariable* var = new llvm::GlobalVariable(m_module, type, true, llvm::GlobalValue::<wbr>PrivateLinkage, nullptr, ".str");</div><div>var->setAlignment(1);;</div><div><br></div><div>llvm::Constant* c = llvm::ConstantDataArray::<wbr>getString(m_context, str);</div><div>var->setInitializer(c);</div><div><br></div><div>The part below is the one I have problems with:</div><div><br></div><div>llvm::ConstantInt* const_int32_12 = llvm::ConstantInt::get(m_<wbr>context, llvm::APInt(32, llvm::StringRef("0"), 10));</div><div>std::vector<llvm::Constant*> const_ptr_14_indices;</div><div>const_ptr_14_indices.push_<wbr>back(const_int32_12);</div><div>const_ptr_14_indices.push_<wbr>back(const_int32_12);</div><div>return llvm::ConstantExpr::<wbr>getGetElementPtr(nullptr,c, const_ptr_14_indices);</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">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.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Any help here would be appreciated.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Regards,</div><div style="font-size:12.8px">Lorin</div></div>