Hi to all,
I need the class in object, but the file ConstantsContext,h isn’t installed.
What can I do? Copy that header under include? It’s an installation bug?
Thanks!
Hi to all,
I need the class in object, but the file ConstantsContext,h isn’t installed.
What can I do? Copy that header under include? It’s an installation bug?
Thanks!
Alessio Giovanni Baroni <alessiogiovanni.baroni@gmail.com> writes:
I need the class in object, but the file ConstantsContext,h isn't installed.
What can I do? Copy that header under include? It's an installation bug?
That's an internal header, not part of the public API.
Why do you need the classes declared on that header?
Because I need to convert an [4 x i8] type to i8* in the instantiation of a GlobalVariable.
I have the follow declaration: %xxx = type { i8* } and I must emit the following variable:
@yyy = linkonce_odr constant %xxx { [4 x i8] c"hello\00" }, but it’s wrong.
How do I do?
Alessio Giovanni Baroni <alessiogiovanni.baroni@gmail.com> writes:
Because I need to convert an [4 x i8] type to i8* in the instantiation of a
GlobalVariable.
I have the follow declaration: %xxx = type { i8* } and I must emit the
following variable:
@yyy = linkonce_odr constant %xxx { [4 x i8] c"hello\00" }, but it's wrong.How do I do?
You can use the ConstantExpr::getBitCast static member function:
http://llvm.org/doxygen/classllvm_1_1ConstantExpr.html#aba93ec4079f8d709a1d5b4745310782e
This is a common idiom on LLVM: a base class has static methods for
creating instances of derived classes.
Ok, now it’s arising another problem. IR code that I obtain is the following:
i8* bitcast ([5 x i8] c"hello\00" to i8*)
generated from instructions:
ConstantExpr::getBitCast (ConstantDataArray::getString (getGlobalContext (), “hello”), PointerType::get (Type::getInt8Ty (getGlobalContext ()), 0))
but the LLC tool says: invalid cast opcode for cast from ‘[5 x i8]’ to ‘i8*’.
Any help?
Ok, now it's arising another problem. IR code that I obtain is the following:
i8* bitcast ([5 x i8] c"hello\00" to i8*)
You need to put your "hello" in a (constant) global variable. You can then
bitcast the address of the global to i8*. I suggest you compile some C code
that makes use of the address of a string using "clang -emit-llvm" to see how
this can be done.
Ciao, Duncan.
PS: Unlike in C, in LLVM IR an array is not the same thing as a pointer to the
first element.
Thanks to all! It’s all ok now.
Alessio.