5 ms·
There's a lot of extra stuff you get with targeting C: being able to write the run time in C very easily. For example its a lot easier to write your entire OO s
by octo_t 13y ago
There's a lot of extra stuff you get with targeting C: being able to write the run time in C very easily. For example its a lot easier to write your entire OO system in C in a few hundred lines, and keeping that easily debuggable is a massive time saver.
- lmm 13y agoWouldn't that be even easier if you used LLVM IR, as you'd then be able to write your runtime in any language that LLVM supports?
- limmeau 13y agoAdvantage of writing it in C: You can prototype an example client of your runtime in C before your code generator is working.
- lmm 13y agoAgain, why couldn't you do that with LLVM IR?
- luikore 13y agoLLVM IR is designed for machine, not human, it's too verbose, and requires SSA form. A normal person can't easily reason the logic in such verbose language. Plus people are more familiar with C.
- lmm 13y agoSure, but you can write your runtime test code in C - or any other language with an LLVM compiler.
- __alexs 13y agoIn C you can write you run-time in any language that C can link to. Which is rather a lot of languages, and isn't tied to any particular compiler.
- lmm 13y agoYes and no. You can, but if you wrote your runtime in e.g. Haskell or Python you'd lose most of the advantages the article describes - debugging and tracing would be much more complicated for anything that called into the runtime, and profiling would become very difficult. As a linkage format C is both too high-level (it provides a lot of facilities that are irrelevant to this use case - so while C may be ubiquitous now, I suspect it's much easier to implement an interpreter from scratch for something like LLVM bytecode) and too low-level (it exposes the host machine's memory model, making it inherently unportable). Use the right tool for the job - programming languages for writing programs in, intermediate representations for code for representing intermediate code.
- rayiner 13y agoYou lose a lot of things the C compiler does for you by targeting LLVM directly. A big one is debug info. The C compiler will emit debug information for you, and with some line directives, as shown in the article, or maybe scripts, you can get minimally usable source-level debugging without having to generate your own debug info.
- pcwalton 13y agoLLVM has high-level support for debug info. (You have to actually generate it, which isn't free, but neither is generating #line directives, so it's arguably a wash.)
- _yosefk 13y agoLLVM IR is less portable than C; and even where an LLVM back-end is available (say, x86 Windows machines), it's really nice to be able to compile everything with another compiler (say, VS) and get debug info and browse info in the generated files.