Printing x86 ASM for Function

Hello,

I would like to know how to go about printing the x86 assembly output for a
compiled function (I'm using the JIT). I saw there is a X86IntelAsmPrinter
on doxygen. However, it takes several arguments I don't know how to fill in.
Is there a helper function to create such a pass? Once I have the pass
created, do I just add it to a FunctionPassManager?

Thank you for your time,

- Maxime

Dear Maxime,

Nyx wrote:

Hello,

I would like to know how to go about printing the x86 assembly output for a
compiled function (I'm using the JIT). I saw there is a X86IntelAsmPrinter
on doxygen. However, it takes several arguments I don't know how to fill in.
Is there a helper function to create such a pass? Once I have the pass
created, do I just add it to a FunctionPassManager?

X86IntelAsmPrinter is used when compiling to an assembly file. If you want to see the output of your jitted code, you need udis (./configure --with-udis=...) and that the macro NDEBUG is not defined (see lib/ExecutionEngine/JIT/JITEmitter.cpp line 1156).

Nicolas

Dear Maxime,

Dear Maxime,

Nyx wrote:

Hello,

I would like to know how to go about printing the x86 assembly output for a
compiled function (I'm using the JIT). I saw there is a X86IntelAsmPrinter
on doxygen. However, it takes several arguments I don't know how to fill in.
Is there a helper function to create such a pass? Once I have the pass
created, do I just add it to a FunctionPassManager?

If what you want is to get a string with the asm code, that is what I
asked long time ago in this list. As I didn't get any answer, I looked
at how llc is doing it. This is how I'm doing it now, but I don't know
if is the best way:

   std::string Err;
   const llvm::TargetMachineRegistry::entry* _arch =
llvm::TargetMachineRegistry::getClosestTargetForJIT(Err);

   std::string FeaturesStr;
   std::auto_ptr<llvm::TargetMachine> target(_arch->CtorFn(*_module,
FeaturesStr));

   std::ostringstream os;
   llvm::raw_ostream *Out = new llvm::raw_os_ostream(os);
   target->addPassesToEmitFile(*_passManager, *Out,
llvm::TargetMachine::AssemblyFile, true);
   target->addPassesToEmitFileFinish(*_passManager, 0, true);

Hope it helps you,

bests.