Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
342 views
in Technique[技术] by (71.8m points)

llvm - Best Compiler Destination

I've got a few languages I've been building as interpreters. When I'm ready to take "that next step", what options are best for non-native compiled formats... what are the pros and cons of each?

I've been looking at compiling to CLR or LLVM, and contemplated C-midcompile a few times, but I'm not completely certain.

A few features I'm hoping to be able to port are as follows:

  1. REPL - One of the languages I'm building supports block-level evaluation during runtime.
  2. Robust Macros - One of the languages I'm building requires the ability to filter through code seperately before tokenizing, and in the midstep between tokenizing and parsing.

Ok, not really "a few", just two. I like to think I can port any other features my languages support to "anything".

What are my best options, and their pros/cons?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Code generation is my business :-)

Comments on a few options:

  • CLR:

    • Pro: industrial support
    • Con: you have to buy into their type system pretty much completely; depending on what you want to do with types, this may not matter
    • Con: Only Windows platform is really prime-time quality
  • LLVM:

    • Pro: enthusiastic user community with charismatic leader
    • Pro: serious backing from Apple
    • Pro: many interesting performance improvements
    • Con: somewhat complex interface
    • Con: history of holes in the engineering; as LLVM matures expect the holes in the engineering to be plugged by adding to the complexity of the interface
  • C--

    • Pro: target is an actual written language, not an API; you can easily inspect, debug, and edit your C-- code
    • Pro: design is reasonably mature and reasonably clean
    • Pro: supports accurate garbage collection
    • Pro: most users report it is very easy to use
    • Con: very small development team
    • Con: as of early 2009, supports only three hardware platforms (x86, PPC, ARM)
    • Con: does not ship with a garbage collector
    • Con: project has no future
  • C as target language

    • Pro: looks easy
    • Con: nearly impossible to get decent performance
    • Con: will drive you nuts in the long run; ask the long line of people who have tried to compile Haskell, ML, Modula-3, Scheme and more using this technique. At some point every one of these people gave up and built their own native code generator.

Summary: anything except C is a reasonable choice. For the best combination of flexibility, quality, and expected longevity, I'd probably recommend LLVM.

Full disclosure: I am affiliated with the C-- project.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...