开发者

Emitting native code (for a specific platform)

How do you get started generating native code for a target platform? I've got (some) experience and (some) skill in C++, and am interested in going and writing my own compiler (for C++). But I've got little idea how I'm going to turn the end result into native code to execute on my target platform, which at the moment is just Windows, x86.

I've had a look at LLVM, but couldn't understand their documentation for shiz.

Edit: In addition, LLVM won't build on VS2010. I went through and cleaned up all the places where they apparently added .in on the end of the filename for fun, and fixed up the typedefs, and now they have some str开发者_如何学Pythonange .def files that appear to be utterly needless that won't compile, and I have no idea where in the trillion headers they're called from.

More edit: I'm already building/built my own AST/parser/lexer. I just need to know how to turn the results into native.


Look at some of the other questions on writing compilers, such as learning-to-write-a-compiler, and having worked through something like the dragon book or Programming Language Pragmatics, you'll understand enough of LLVM or gnu lightning to use them as your back end.

Don't try to write a C++ compiler unless you have several years to devote to the exercise; on the other hand creating something based on an existing back-end and expression templates might only take a couple of months.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜