[LLVMdev] Dynamic Creation of a simple program

Chris Lattner sabre at nondot.org
Tue Mar 15 07:44:15 PST 2005


On Tue, 15 Mar 2005, xavier wrote:
> Thanks for the information
> I am trying to use one of your examples for recursive data structures:
>
> =========================
> PATypeHolder StructTy = OpaqueType::get();
> std::vector<const Type*> Elts;
> Elts.push_back(PointerType::get(StructTy));
> Elts.push_back(PointerType::get(Type::SByteTy));
> StructType *NewSTy = StructType::get(Elts);
>
> // At this point, NewSTy = "{ opaque*, sbyte* }", tell VMCore that
> // the struct and the opaque type are actually the same.
> cast<OpaqueType>(StructTy.get())->refineAbstractTypeTo(NewSTy);
>
> // NewSTy is potentially invalidated, but StructTy (a PATypeHolder) is
> // kept up-to-date.
> NewSTy = StructTy.get();
> =========================
>
> It gives this error in the last line:
>
>         invalid conversion from `llvm::Type*' to `llvm::StructType*'
> How can I create such a recursive DS?

Replace the last line with:

   NewSTy = cast<StructType>(StructTy.get());

-Chris

> --- Chris Lattner <sabre at nondot.org> wrote:
>> On Mon, 14 Mar 2005, xavier wrote:
>>
>>> Could please somebody give some guidelines? Maybe I can compile a
>>> program with the LLVM and then load the bytecode in memory and finally
>>> dump some kind of text/XML representation which I will use to understand
>>> the set of classes needed to dynamically create the sample program
>>
>> Check out these directories:
>>
>> examples/ModuleMaker/ : Builds a module from scratch
>>
>> examples/Fibonacci/
>> examples/HowToUseJIT/ : Examples building a module and JIT'ing them.
>>
>> -Chris
>>
>> --
>> http://nondot.org/sabre/
>> http://llvm.cs.uiuc.edu/
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
>> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://mail.cs.uiuc.edu/mailman/listinfo/llvmdev
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/




More information about the llvm-dev mailing list