[llvm-dev] Generating C headers from LLVM

Peter Lammich via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 12 03:53:34 PDT 2019


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




More information about the llvm-dev mailing list