1

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.

washerman
  • 23
  • 1
  • 4

1 Answers1

2

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).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847