News for hackers. Stuff that matters.
Re:C as an intermediate language (2012) by pjmlp on Wednesday July 17, 2013 @07:29AM (#6057073)
For anyone wanting to read about C as intermediate language,

Compiler Design in C (1990)

http://www.amazon.com/Compiler-Design-C-Prentice-Hall-softwa...

EDIT: Adding some extra remarks I think might also be interesting to share.

Another approach, that I really like, is to output bytecodes that are mapped directly to macros in typical macro assemblers like NASM/MASM/TASM. Those macro assemblers provide very powerful macro systems.

Then map those macros to the corresponding assembly code.

Sure it gives a bit more work, but I find it more fun.

Re:C as an intermediate language (2012) by argv_empty on Wednesday July 17, 2013 @07:59AM (#6057152)
From a look over the Amazon page, the book seems to be about writing a compiler in C, not about writing a compiler targeting C. Does it actually describe potential issues with compiling to C?
Re:C as an intermediate language (2012) by pjmlp on Wednesday July 17, 2013 @08:26AM (#6057236)
It is an old book about implementing an C compiler in C.

The intermediate code is similar to the article, a mix of macros and basic C expressions as high level assembler.

I cannot remember all the details, the last time I used the book was around 1996.

You can still get the source code, http://www.holub.com/software/compiler.design.in.c.html

Re:C as an intermediate language (2012) by octo_t on Wednesday July 17, 2013 @08:00AM (#6057156)
here's my one line C compiler (compiles to C):

  touch *.c *.h
Re:C as an intermediate language (2012) by CJefferson on Wednesday July 17, 2013 @07:48AM (#6057118)
One advantage of going through C (which admittedly might not pay off) is that you get the advantage of compiler optimisations.

When compiling dynamic languages of course, that often doesn't work as the optimiser doesn't have anything to go on if you do everything through void* pointers, or a similar dynamic construct.

Re:C as an intermediate language (2012) by pjmlp on Wednesday July 17, 2013 @08:33AM (#6057260)
Agree.

You might find some anti-C bias from my post history, but I am also very pragmatic and would certainly use C if required to do so.

I used the compilation to bytecode disguised as Assembler macros as part of a few toy compilers back in late 90's.

If it was today I would probably use LLVM or C(++) as being discussed in the article.

Re:C as an intermediate language (2012) by Roboprog on Wednesday July 17, 2013 @10:26AM (#6057793)
C: AKA "portable assembler" :-)
Re:C as an intermediate language (2012) by pjmlp on Wednesday July 17, 2013 @12:57PM (#6058739)
TI has a DSP processor where the assembly looks quite much like the early days of C:

    mov reg1, reg2    ==>  reg1 = reg2
    mov reg1, [reg2]  ==>  reg1 = *reg2
    add reg1, reg2    ==>  reg1 += reg2
And so on.
Re:C as an intermediate language (2012) by Roboprog on Thursday July 18, 2013 @10:31AM (#6063846)
looks sort of like PDP 11 assembler, particularly the [] brackets for indirect access through a register.