Importing existing function declarations into LLVM C++ API

Hi,

This is a tricky problem to search for on the llvmdev list as all the ways I can think of describing this seem to use pretty common keywords, so this may have been asked before.

I'm looking for a way of importing or including existing function declarations or global variables into LLVM IR that I'm building manually using the API. These declarations are written in C++, so I guess there are two possible ways of doing this, either parsing and importing them using the Clang API (though I'm not particularly familiar with this) or compiling them to IR externally without running any optimisation passes and importing them from .ll files? Or maybe produce two separate modules and merge them?

Is there anything in the codebase or the documentation that someone could point me to? Or any suggestions on how better to tackle this would be appreciated?

Thanks,
Dan

Hi Dan,

The name of C++ declarations is changed by name mangling. If you want to import
C++ declarations into LLVM IR directly, Clang's APIs related to mangling will help you.
You can find basic mangling APIs of Clang in following files.
"include/clang/AST/Mangle.h"
"lib/AST/Mangle.cpp"
etc.. (name mangling is affected by compiler vendors such as Microsoft.)

Good luck,
Jin-Gu Kang

Hi Dan,

This is a tricky problem to search for on the llvmdev list as all the
ways I can think of describing this seem to use pretty common keywords,
so this may have been asked before.

I'm looking for a way of importing or including existing function
declarations or global variables into LLVM IR that I'm building manually
using the API. These declarations are written in C++, so I guess there
are two possible ways of doing this, either parsing and importing them
using the Clang API (though I'm not particularly familiar with this) or
compiling them to IR externally without running any optimisation passes
and importing them from .ll files? Or maybe produce two separate modules
and merge them?

Is there anything in the codebase or the documentation that someone
could point me to? Or any suggestions on how better to tackle this would
be appreciated?

you should probably compile the C++ containing your definitions etc into
an IR module, which you then link with other modules as needed using the
linker API.

Ciao, Duncan.