[llvm-dev] Generating C headers from LLVM

Adrien Guinet via llvm-dev llvm-dev at lists.llvm.org
Tue Apr 16 07:09:20 PDT 2019


On 4/12/19 12:53 PM, Peter Lammich via llvm-dev wrote:
> Hi List,
> 
> is there any way to generate proper C header files for functions that
> are defined in LLVM-IR. My current attempts fail when clang does some
> fancy transformations (to adhere to some ABIs ??), e.g., for returning
> a struct.
> 
> For example the declaration
> 
> typedef struct {int64_t a; int64_t b;int64_t c;} test;
> test create_test(void);yields the LLVM code
> 
> %struct.test = type { i64, i64, i64 }
> declare void @create_test(%struct.test* sret) #1
> 
> However, the function is defined in LLVM-IR as
> {i64,i64,i64} @create_test()
> 
> Questions:
> 1) Is there any way to convince clang to generate the "correct" output,
> that fits the given definition in LLVM-IR?
> 
> 2) What other surprises to expect? Is there a "safe fragment" where the
>  obvious C code actually matches the obvious LLVM-IR?
> 
> 3) If 1 does not exist, is there a way to generate "wrapper-functions"
> in LLVM-IR, that map the given functions to what clang expects?
> 
> 
> Thanks in advance for any help,
>   Peter

Hello,

In DragonFFI [1], I use the debug information emitted by clang to "reconstruct" the C
function types. This could be used to potentially emit proper C headers that define these
functions.

Regards,

[1] https://github.com/aguinet/dragonffi


More information about the llvm-dev mailing list