问题
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