[LLVMdev] generating function declarations in c frontend

Chris Lattner sabre at nondot.org
Tue Oct 5 21:34:31 PDT 2004


On Tue, 5 Oct 2004, Michael McCracken wrote:
> I'm trying to generate the declarations for function intrinsics, and I
> must be misunderstanding how to create new functions - I saw that a
> function with no basic blocks is treated as a declaration, so I tried
> to just create one and add it to the globals list:
>
>   llvm_type *structTy, *ptrToStructTy;
>
>   structTy = llvm_type_create_struct(0, 0);
>   structTy = llvm_type_get_cannonical_struct(structTy);
>   ptrToStructTy = llvm_type_get_pointer(structTy);
>
>   llvm_function *dbg_stoppoint_fn = llvm_function_new(ptrToStructTy,
> "llvm.dbg.stoppoint");

This is the problem right here.  In particular, the type for the function
needs to be the type of the *function* itself, not the type of the return
value or the type of the argument.  For llvm.dbg.stoppoint, this should be
the "{}* ({}*, uint, uint, %lldb.compile_unit*)" type.  This is a function
type returning a "{}*", taking four arguments.

>   llvm_argument *arg = llvm_argument_new(structTy, "foo");
>   llvm_ilist_push_back(llvm_value, dbg_stoppoint_fn->Arguments, arg);

You don't need to do this.

>   llvm_ilist_push_back(llvm_global, TheProgram.Globals, dbg_stoppoint_fn);

Also, I suggest calling CreateIntrinsicFnWithType instead of
llvm_function_new, as it does the llvm_ilist_push_back for you.

-Chris

-- 
http://llvm.org/
http://nondot.org/sabre/




More information about the llvm-dev mailing list