简体   繁体   中英

Converting llvm IR to NASM assembly

I am trying to convert a whole bunch of llvm IR code to assembly code that runs on NASM. I am not very familiar assembly or llvm IR. I wonder if there are any transpiler/assembler/tools which can help me do this or if any such tools are available.

LLVM-IR still needs to be compiled. Do that with clang -c -O3 -march=native -ffast-math for example, then disassemble with a NASM-syntax disassembler, for example Agner Fog's objconv which produces output that can be assembled. How to disassemble a binary executable in Linux to get the assembly code? .

Compile -> disassemble is not great for preserving label and symbol names, though.

If you mean hand-written LLVM-IR into maintainable NASM by hand, then I think the ease of porting would depend on whether the number of registers used by the code is less than 16; x86-64 only has 15 general-purpose integer registers not including the stack pointer.

If the LLVM-IR uses more, you'd need to decide which "variables" to spill/reload to/from the stack (and when, if you don't just leave some variables permanently on the stack vs. others permanently in registers).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM