Writing a new jit

笑着哭i 提交于 2019-12-10 10:25:41

问题


I'm interested in starting my own JIT project in C++. I'm not that unfamiliar with assembly, or compiler design etc etc. But, I am very unfamiliar with the resulting machine code format - like, what does a mov instruction actually look like when all is said and done and it's time to call that function pointer. So, what are the best resources for creating such a thing?

Edit: Right now, I'm only interested in x86 on Windows, stretching a tiny bit to 64bit Windows in the future.


回答1:


You want to have a look at the processor manuals for the architecture you are interested in. Those manuals describe the opcode encoding. For x86 processors, the manuals can be downloaded from this page.




回答2:


Starting your project on top of LLVM might shield you from the platform details.

http://llvm.org/

LLVM is used by several dynamic language JIT compilers.




回答3:


GNU lightning is a multi-architecture (x86, SPARC, PPC) library for generating code within another program. You'll need to understand general assembly language concepts, but not at a very deep level. You won't have to write anything architecture-specific at all. The down side to lightning (at least last time I used it) is that the interface presented is the intersection of the features available on the supported targets: The small register set of x86, a RISC instruction set like SPARC, and so on. The single-pass code generation is easy to use but has its own quirks, like you can't relocate your output buffer (because of address references) so if you run out of space you generally have to start over. The good thing is that you will probably get a working example going very quickly.




回答4:


Older versions of NASM come with a fairly concise opcode reference that has x86 instruction encodings. (Looks like there's no 64-bit info, though.) I found this one using google:

http://alien.dowling.edu/~rohit/nasmdocb.html

The official manuals say basically the same thing (and a lot more besides), but not quite so conveniently.



来源:https://stackoverflow.com/questions/4097301/writing-a-new-jit

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