Hacker News new | past | comments | ask | show | jobs | submit login

Wouldn'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?



Advantage of writing it in C: You can prototype an example client of your runtime in C before your code generator is working.


Again, why couldn't you do that with LLVM IR?


LLVM 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.


Sure, but you can write your runtime test code in C - or any other language with an LLVM compiler.


In 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.


Yes 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.


LLVM 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.


You 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.


LLVM 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.)




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: