[LLVMdev] cannot understand global c++API code

Alexander Poddey alexander.poddey at gmx.net
Sat Mar 7 08:37:39 PST 2015


Hi all,

translating the following c code to llvm c++Api code, I can not understand 
the result.
Perhaps someone could explain it to me.

c code
---------------------------------

 struct stest {         
    int   age;
    float weight;
 } foo={44,67.2};       



int main() {

foo.weight=68.2;

...
----------------------------------------

API code

// this is clear
ConstantFP* const_float_102 = ConstantFP::get(mod->getContext(), 
APFloat(6.820000e+01f));


ConstantInt* const_int32_98 = ConstantInt::get(mod->getContext(), APInt(32, 
StringRef("0"), 10));
ConstantInt* const_int32_99 = ConstantInt::get(mod->getContext(), APInt(32, 
StringRef("1"), 10));


std::vector<Constant*> const_ptr_103_indices;
const_ptr_103_indices.push_back(const_int32_98);
const_ptr_103_indices.push_back(const_int32_99);
Constant* const_ptr_103 = ConstantExpr::getGetElementPtr(gvar_struct_foo, 
const_ptr_103_indices);

//the store inst is in principle clear
StoreInst* void_119 = new StoreInst(const_float_102, const_ptr_103, false, 
label_entry_113);
void_119->setAlignment(4);
---------------------------------------------

comment:
I don't get whats the meaning of the two const_int32 (98 & 99 above) and why 
the const_ptr_103 should relate the foo.weight field of the stest struct.


Any hint appreciated!

Alex







More information about the llvm-dev mailing list