[LLVMdev] static constant structs

Duncan Sands baldrick at free.fr
Mon Jul 23 23:36:52 PDT 2012


Hi,

> Um...  That's exactly what the example above demonstrates.  But maybe I
> did not explain my problem well enough.  If I have a type like, for
> example:
>
> { i32, [ 4 x i8 ] }
>
> How can I create a constant of this type like this:
>
> { i32 0x1ffff, [ i8 0, i8 4, i8 10, i8 8 ] }
>
> from the C++ API without going through nasty pointer cast tricks?

for each number, you create a corresponding ConstantInt using ConstantInt::get
   static Constant *get(Type *Ty, uint64_t V, bool isSigned = false);
(there are a bunch of other methods too).  Once you have them, you create the
array using ConstantArray::get
   static Constant *get(ArrayType *T, ArrayRef<Constant*> V);
Then you create the struct using ConstantStruct::get
   static Constant *get(StructType *T, ArrayRef<Constant*> V);

Ciao, Duncan.



More information about the llvm-dev mailing list