本文介绍了如何使用LLVM库编写汇编器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为x86/arm写一个简单的汇编器.由于执行所有指令很麻烦,因此我想我可以使用LLVM项目,而无需使用LLVM IR .

I want to write a simple assembler for x86/arm. Since implementing all instructions would be cumbersome, I figuered I could use the LLVM project without using LLVM IR.

llvm-mc 似乎完全具有该功能:

llvm-mc seems to have exactly that feature:

$ echo "addl %eax, %ebx" | llvm-mc -show-encoding -show-inst

但是,我找不到任何资源来解释如何在C ++代码中使用MC.我本来希望与以下内容类似:

However I can't find any resources that explain how to use the MC in C++ code.I woulde have expected something similar to:

MCBuilder builder = X86::MCBuilder::create(rwx_memory_loc);
builder.AddInst("add", EAX, ECX);
builder.AddInst("mov", RAX, RDX);
...

我可以选择使用模块化内联汇编.

推荐答案

汇编器是后端的一部分.因此,您可能想看一下lib/Target/ARM子目录.这是LLVM的相当复杂的部分,但是可以在此处找到一些指导.

Assembler is a part of the backend. So, you'll probably want to take a look at lib/Target/ARM subdirectory. It is pretty complex piece of LLVM, but some guidance can be found here.

我怀疑,您是否有兴趣修改/添加一些asm指令?看看*InstrInfo.td文件.

I suspect, you are interested in modifying/adding some asm instructions? Take a look at *InstrInfo.td file.

这篇关于如何使用LLVM库编写汇编器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 15:13