How to create a empty LLVM module

Hello All,

How to (programmatically) create a program that creates an empty llvm module via c++ api and how to dump it.

Thanks

Hi!

Creating an empty module for file FileName using TargetMachine TM, and dumping the module (for debug purpose):

llvm::LLVMContext Ctx;
llvm::Module *M = new llvm::Module(FileName, Ctx);
M->setTargetTriple(TM->getTargetTriple().getTriple());
M->setDataLayout(TM->createDataLayout());
M->dump();

Creating the TargetMachine is a bit more involved. You can look at the createTargetMachine() function from here as an example. If you want to emit assembly/IR instead of just a debug dump then have a look at function emit() in the same file.

Regards,
Kai