print machine code using llvm c++ api

Hi,

I know using llc i can print machine code (-print-machineinstrs).

How can i print machine code using llvm c++ api.. i looked into llc code but not able to find it..

Thanks & Regards,
Pachauri

Hi,

Look for the function addPassesToEmitFile, in LLVMTargetMachine. This is
called directly from llc.cpp if I recall correctly, and will emit a
string representation of the assembler code.

If you want pure ELF, look for addPassesToEmitMachineCode (old version)
or addPassesToEmitMC (new version).

Cheers,

James