News for hackers. Stuff that matters.
Re:C as an intermediate language (2012) by lmm on Wednesday July 17, 2013 @08:45AM (#6057304)
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?
Re:C as an intermediate language (2012) by limmeau on Wednesday July 17, 2013 @09:14AM (#6057448)
Advantage of writing it in C: You can prototype an example client of your runtime in C before your code generator is working.
Re:C as an intermediate language (2012) by lmm on Wednesday July 17, 2013 @09:25AM (#6057501)
Again, why couldn't you do that with LLVM IR?
Re:C as an intermediate language (2012) by luikore on Wednesday July 17, 2013 @10:00AM (#6057676)
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.
Re:C as an intermediate language (2012) by lmm on Wednesday July 17, 2013 @11:02AM (#6058033)
Sure, but you can write your runtime test code in C - or any other language with an LLVM compiler.
Re:C as an intermediate language (2012) by __alexs on Wednesday July 17, 2013 @09:56AM (#6057660)
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.
Re:C as an intermediate language (2012) by lmm on Wednesday July 17, 2013 @06:29PM (#6060478)
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.

Re:C as an intermediate language (2012) by _yosefk on Wednesday July 17, 2013 @12:45PM (#6058673)
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.
Re:C as an intermediate language (2012) by rayiner on Wednesday July 17, 2013 @11:03AM (#6058036)
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.
Re:C as an intermediate language (2012) by pcwalton on Wednesday July 17, 2013 @12:00PM (#6058419)
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.)