<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Mar 7, 2015 at 8:37 AM, Alexander Poddey <span dir="ltr"><<a href="mailto:alexander.poddey@gmx.net" target="_blank">alexander.poddey@gmx.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi all,<br>
<br>
translating the following c code to llvm c++Api code, I can not understand<br>
the result.<br>
Perhaps someone could explain it to me.<br>
<br>
c code<br>
---------------------------------<br>
<br>
 struct stest {<br>
    int   age;<br>
    float weight;<br>
 } foo={44,67.2};<br>
<br>
<br>
<br>
int main() {<br>
<br>
foo.weight=68.2;<br>
<br>
...<br>
----------------------------------------<br>
<br>
API code<br>
<br>
// this is clear<br>
ConstantFP* const_float_102 = ConstantFP::get(mod->getContext(),<br>
APFloat(6.820000e+01f));<br>
<br>
<br>
ConstantInt* const_int32_98 = ConstantInt::get(mod->getContext(), APInt(32,<br>
StringRef("0"), 10));<br>
ConstantInt* const_int32_99 = ConstantInt::get(mod->getContext(), APInt(32,<br>
StringRef("1"), 10));<br>
<br>
<br>
std::vector<Constant*> const_ptr_103_indices;<br>
const_ptr_103_indices.push_back(const_int32_98);<br>
const_ptr_103_indices.push_back(const_int32_99);<br>
Constant* const_ptr_103 = ConstantExpr::getGetElementPtr(gvar_struct_foo,<br>
const_ptr_103_indices);<br>
<br>
//the store inst is in principle clear<br>
StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, false,<br>
label_entry_113);<br>
void_119->setAlignment(4);<br>
---------------------------------------------<br>
<br>
comment:<br>
I don't get whats the meaning of the two const_int32 (98 & 99 above) and why<br>
the const_ptr_103 should relate the foo.weight field of the stest struct.<br></blockquote><div><br><a href="http://llvm.org/docs/GetElementPtr.html">http://llvm.org/docs/GetElementPtr.html</a><br><br>They're indexes into the structure (well, imagine that the pointer to the struct is a pointer to an array of structs of length 1 - so the first index is 0, to access the first (and only) element of that array, and the second index is 1 to access the second element of the structure)<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<br>
<br>
Any hint appreciated!<br>
<br>
Alex<br>
<br>
<br>
<br>
<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div></div>