8cc icon indicating copy to clipboard operation
8cc copied to clipboard

Can't see any assembly code for a self-hosting compiler

Open 0decimal0 opened this issue 6 years ago • 4 comments

A self-hosting compiler involves writing a rudimentary compiler for a language X(Here C) in another language (Suppose assembly), I can't find any assembly or any other language used for compiling a code . I have been googling my wits out to find at least a simple guide to write a compiler in assembly for C language . Your blog is the closest one I found but still I don't see any .

0decimal0 avatar Sep 11 '17 10:09 0decimal0

it needs to be bootstrapped with an existing compiler, once that is done you can use 8cc to compile 8cc and can forget about the existing compiler. that is what is meant by self hosted.

andrewchambers avatar Sep 11 '17 11:09 andrewchambers

Here's an idea. Write a compiler for a very simple, minimal language in asm. Then use that language to write a compiler for a slightly more complex language with more abstractions. Then write your C compiler in that. The way 8cc can be bootstrapped, is by using gcc or clang, since those already exist. You could also ask this guy.

moon-chilled avatar Oct 14 '17 00:10 moon-chilled

Thanks Elronnd. I knew this way , was just looking for assembly code(using which a c compiler has been implemented) to read . There are a lot of self hosted compiler code but I could not find in an assembly lang.

0decimal0 avatar Oct 22 '17 19:10 0decimal0

@0decimal0 Your definition of self-hosting is not the one I have seen for years [https://en.wikipedia.org/wiki/Self-hosting_(compilers)](Wikipedia definition and history of the term). Bootstrapping is the name of the process for getting a compiler to run on and for a target machine. Sometimes people bootstrap starting with assembly, others start by cross-compiling.

cardiffman avatar Sep 06 '19 17:09 cardiffman