[LLVMdev] common type at compile time?

John Criswell criswell at illinois.edu
Thu Oct 20 09:48:30 PDT 2011


On 10/20/11 11:34 AM, ret val wrote:
> I'm a bit confused. For the Type did you mean something like:
>          ArrayType *type = ArrayType::get(Type::getInt8PtrTy(M.getContext()), 4);

I assume that creates an ArrayType of 4 elements whose elements are 
pointers to 8-bit values.  If so, then this is what I meant.

> This does not work, it gives me ""Wrong type in array element
> initializer" at runtime.
>
> Also it doesn't look like ConstantExpr inherits ConstantArray, so I'm
> not sure how I could use this instead.

What I meant here is that each element (Function *, GlobalVariable *) 
that you want to put into the ConstantArray will need to be casted to an 
i8 * type.  To do the casting, you will need to use a bitcast 
ConstantExpr instead of a BitCastInst since you can't use instructions.

-- John T.

>
> Thanks
>
> On Thu, Oct 20, 2011 at 12:04 PM, John Criswell<criswell at illinois.edu>  wrote:
>> On 10/20/11 10:43 AM, ret val wrote:
>>> I'm trying to create a ConstantArray(whose contents will be of types
>>> Function*, GlobalVariable *) so I can immediately create a new
>>> GlobalVariable(that will be in its own section). I'm doing this so I
>>> have these address stored. In order to create this ConstantArray I
>>> need a valid ArrayType, but I'm not sure what to use for the element
>>> type.
>>>
>>> I want this to be done at compile time, so I cant use a BitCastInst to
>>> make them all generic pointers. What else can I do?
>> You can use a ConstantExpr (constant expression) for Function  and
>> GlobalVariable objects.  The ArrayType can be an array of pointers to 8-byte
>> characters (basically a void pointer type).
>>
>> -- John T.
>>
>>> In other words
>>> * I built up a vector id like to eventually store as a GlobalVariable
>>> array: vector<Constant *>    v_elements;
>>> * Turned it into something for the ConstantArray::get can use:
>>> ArrayRef<Constant *>    a_elements(v_elements);
>>> * And now I need to come up with the ArrayType arg for the
>>> ConstantArray::get() method where I only know: ArrayType::get(???, 4);
>>>
>>> Thanks
>>> _______________________________________________
>>> LLVM Developers mailing list
>>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>




More information about the llvm-dev mailing list