4 ms·
Related: https://blog.pankajgarg.com/ceed/ https://blog.pankajgarg.com/ceed/ >"It supports 32-bit Linux and Windows and can generate output file in either ELF
by peter_d_sherman 3y ago
Related:
https://blog.pankajgarg.com/ceed/ https://blog.pankajgarg.com/ceed/
>"It supports 32-bit Linux and Windows and can generate output file in either ELF or PE format. Complete code for Ceed is around 1400 lines of Flex/Bison/C code excluding comments."
PDS -- Note that the 1400 LOC figure also includes the code to produce 32-bit ELF and PE executables... in other words, the lines of solely compilation code are significantly less...
Many ultra-small open source teaching compilers only emit intermediary code that subsequently needs to be compiled with another utility or utilites, e.g., an assembler and possibly a linker.
Not this one.
Which makes it worthy of study for any would-be compiler writers, regardless of the language that is to be compiled...
- anta40 3y agoFor example: https://github.com/ipankajg/ceed/blob/master/src/ceedpe.c https://github.com/ipankajg/ceed/blob/master/src/ceedpe.c While other small compilers still rely on gcc/llvm/etc to build the actual executable. Looks interesting.
- foldr 3y agoIt is indeed quite fun and educational to figure out how to construct an executable from scratch. I managed to do it for MachO and ELF executables a while back, and got some 'Hello World' style programs working. Ten or twenty years ago it would have been a bit easier, but modern executables are quite complex – especially if you are dynamically linking libc. As a strategy for implementing a compiler it does introduce a heavy maintenance burden. MacOS, for example, is constantly adding new requirements on valid executables and will often refuse to execute perfectly valid executables from only a few versions back.