[LLVMdev] Printing x86 ASM for Function

Álvaro Castro Castilla alvaro.castro.castilla at gmail.com
Wed Mar 18 10:17:40 PDT 2009


Dear Maxime,



2009/3/17 Nicolas Geoffray <nicolas.geoffray at lip6.fr>:
> 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.



>
> 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
>
>> Thank you for your time,
>>
>> - Maxime
>>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>



-- 
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> http://www.alvarocastro.es




More information about the llvm-dev mailing list