How to use the LLVM library to write an assembler

耗尽温柔 提交于 2019-12-13 09:13:35

问题


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 seems to have exactly that feature:

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

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

As an alternative I propably would use Module inline assembly.


回答1:


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.

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



来源:https://stackoverflow.com/questions/57885801/how-to-use-the-llvm-library-to-write-an-assembler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!