Zifre
Zifre

Reputation: 27008

Is it possible to read an LLVM bitcode file into an llvm::Module?

I'm writing a compiler with LLVM. Each source file is compiled into an LLVM bitcode file. Eventually the linker links and optimizes all the bitcode files into one final binary.

I need a way to read the bitcode files in the compiler in order to access the type information. The LLVM documentation shows a class called BitcodeReader, but that appears to be internal to LLVM.

Is there any publicly accessible way to read a bitcode file into an llvm::Module?

Upvotes: 12

Views: 3154

Answers (1)

Zifre
Zifre

Reputation: 27008

I looked through the source to the llvm-dis tool and found the function I was looking for:

Module *ParseBitcodeFile(MemoryBuffer *Buffer, LLVMContext& Context,
                         std::string *ErrMsg = 0);

from llvm/Bitcode/ReaderWriter.h.

Upvotes: 16

Related Questions