c++ - How to create LLVM Array type using AllocaInst? -


i want create llvm arraytype on stack wanted use allocainst (type *ty, value *arraysize=nullptr, const twine &name="", instruction *insertbefore=nullptr). problem don't understand interface. guessed ty arraytype::get(i.gettype(), 4), should give arraysize. furthermore, requires value*, confused me lot.

either misunderstood llvm alloc or need provide llvm constant value array size. if have give constant, isn't little bit redundant since arraytype contains numelement information.

as example line of code, way trying to:

allocainst* arr_alloc = new allocainst(arraytype::get(i.gettype(), num)                                        /*, parameter for?*/,                                        "",                                        funcentry.getfirstinsertionpt()); 

i type of array elements such as:

type* = integertype::getint32ty(module->getcontext()); 

then can create arraytype of num elements:

arraytype* arraytype = arraytype::get(i, num); 

this type can used in allocinstr following:

allocainst* arr_alloc = new allocainst(     arraytype, "myarray" , funcentry //             ~~~~~~~~~ // -> custom variable name in llvm ir can omitted, //    llvm create random name such %2. ); 

this example yield following llvm ir instruction:

%myarray = alloca [10 x i32] 

edit seems allowed pass variable array size allocinstr following:

type* = integertype::getint32ty(module->getcontext()); auto num = 10; auto funcentry = label_entry;  arraytype* arraytype = arraytype::get(i, num);  allocainst* variable = new allocainst(   i, "array_size", funcentry );  new storeinst(constantint::get(i, apint(32, 10)), variable, funcentry);  auto load = new loadinst(variable, "loader", funcentry);  allocainst* arr_alloc = new allocainst(   i, load, "my_array", funcentry ); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -