Could I get one single bc file from multiple files?(which may have a real big amount of files including .c/.h/.hpp)

Hello everyone, i am a new one here.
Just like the question, I know it’s not a question about LLVM itself. But I need do some analysis job on code divided in different files.
It more like to be a question about preprocessing, that put the code not including the header files into a single file and then use clang command make them to one single file in bc format.
I hope to get some useful tools to finish it, since it’s not the main thing i working on.
I appreciate any word from you. Thanks again.

I can think of two ways to do this. One is often called a “unity” build, where you have one file (maybe unity.cpp) that just includes all the .cpp files from your project. So if you had main.cpp, dep1,cpp, and dep1.cpp, you would create a file with:

#include "main.cpp"
#include "dep1.cpp"
#include "dep2.cpp"

so that clang -c -emit-llvm unity.cpp will process all your sources and emit a single .bc file.

The other way is to use the llvm-link tool; I have not done this myself so I’m not completely sure how it works, but this is a bitcode linker (not an object-file linker).

2 Likes

Thanks for your suggestion! : )
I will try them all to find if them work.
The first way seem like could be finished by a simple script. And i will do some research on the llvm-link.
If I find a good way to solve this question finally, i will post it here hoping to help someonelse.
Again, I would like to expreour thanks to you and your time.