LLVM Discussion Forums

Add flag to generate LLVM IR for forward declaration entities

As the LLVM gets more popular, more people wants to use it’s JIT engine to implement their own interpreter. One of the most useful feature of a new interpreter is link capability to C/C++ codes.

regardless of how this link bridge is implemented, some basic functions of an interpreter must be implemented in C. So having prototypes of functions (at least) is very useful.

Clang generates LLVM IR for any C/C++ source, but it omits Forward-Declared entities (Mostly live in header files). It will be very useful to add a flag to Clang, to generate LLVM IR of Forward Declarations to add them in a llvm::Module.

here is the scenario:

  • Build C/C++ library
  • Use Clang to generate Function/Struct/Class prototype and signature form header files
  • Load this generated LLVM in the JIT Session
  • Let the Module Linker to find and link this function in the loadable binary of library

In addition, for a function it may seems not so necessary but for classes and structures, it will extend the interpreter capability. having the definition of a class lets interpreter to construct objects of that class, that its functions are implemented in C++ and placed in a loadable object file.