简体   繁体   English

将 llvm IR 转换为 NASM 程序集

[英]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.我正在尝试将一大堆 llvm IR 代码转换为在 NASM 上运行的汇编代码。 I am not very familiar assembly or llvm IR.我不是很熟悉汇编或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. LLVM-IR 仍然需要编译。 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.例如,使用clang -c -O3 -march=native -ffast-math执行此操作,然后使用 NASM 语法反汇编程序进行反汇编,例如Agner Fog 的objconv生成可以组装的 output。 How to disassemble a binary executable in Linux to get the assembly code? 如何在 Linux 中反汇编二进制可执行文件以获取汇编代码? . .

Compile -> disassemble is not great for preserving label and symbol names, though.不过,编译 -> 反汇编对于保留 label 和符号名称并不是很好。

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;如果您的意思是手动将 LLVM-IR 手写到可维护的 NASM 中,那么我认为移植的难易程度取决于代码使用的寄存器数量是否小于 16; x86-64 only has 15 general-purpose integer registers not including the stack pointer. x86-64 只有 15 个通用 integer 寄存器,不包括堆栈指针。

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).如果 LLVM-IR 使用更多,您需要决定哪些“变量”从堆栈溢出/重新加载(以及何时,如果您不只是将一些变量永久留在堆栈上,而将其他变量永久留在寄存器中)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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