Package: shivyc
ShivyCA hobby C compiler created in Python.ShivyC is a hobby C compiler written in Python 3 that supports a subset of the C11 standard and generates reasonably efficient binaries, including some optimizations. ShivyC also generates helpful compile-time error messages.Thisimplementation of a trieis an example of what ShivyC can compile today. For a more comprehensive list of features, see thefeature test directory.Quickstartx86-64 LinuxShivyC requires only Python 3.6 or later to compile C code. Assembling and linking are done using the GNU binutils and glibc, which you almost certainly already have installed.To install ShivyC:pip3 install shivycTo create, compile, and run an example program:$vimhello.c$cathello.c#include<stdio.h>intmain(){printf("hello, world!\n");}$shivychello.c$./outhello,world!To run the tests:git clone https://github.com/ShivamSarodia/ShivyC.git
cd ShivyC
python3 -m unittest discoverOther ArchitecturesFor the convenience of those not running Linux, thedocker/directory provides a Dockerfile that sets up an x86-64 Linux Ubuntu environment with everything necessary for ShivyC. To use this, run:git clone https://github.com/ShivamSarodia/ShivyC.git
cd ShivyC
docker build -t shivyc docker/
docker/shellThis will open up a shell in an environment with ShivyC installed and ready to use withshivyc any_c_file.c           # to compile a file
python3 -m unittest discover  # to run testsThe Docker ShivyC executable will update live with any changes made in your local ShivyC directory.Implementation OverviewPreprocessorShivyC today has a very limited preprocessor that parses out comments and expands#includedirectives. These features are implemented betweenlexer.pyandpreproc.py.LexerThe ShivyC lexer is implemented primarily inlexer.py. Additionally,tokens.pycontains definitions of the token classes used in the lexer andtoken_kinds.pycontains instances of recognized keyword and symbol tokens.ParserThe ShivyC parser uses recursive descent techniques for all parsing. It is implented inparser/*.pyand creates a parse tree of nodes defined intree/nodes.pyandtree/expr_nodes.py.IL generationShivyC traverses the parse tree to generate a flat custom IL (intermediate language). The commands for this IL are inil_cmds/*.py. Objects used for IL generation are inil_gen.py, but most of the IL generating code is in themake_codefunction of each tree node intree/*.py.ASM generationShivyC sequentially reads the IL commands, converting each into Intel-format x86-64 assembly code. ShivyC performs register allocation using George and Appel’s iterated register coalescing algorithm (see References below). The general ASM generation functionality is inasm_gen.py, but much of the ASM generating code is in themake_asmfunction of each IL command inil_cmds/*.py.ContributingPull requests to ShivyC are very welcome. A good place to start is theIssues page. Allissues labeled "feature"are TODO tasks.Issues labeled "bug"are individual miscompilations in ShivyC. If you have any questions, please feel free to ask in the comments of the relevant issue or create a new issue labeled "question". Of course, please add test(s) for all new functionality.Many thanks to our current and past contributers:ShivamSarodiacclaussTBladenchristian-stephenjubnzvReferencesShivC- ShivyC is a rewrite from scratch of my old C compiler, ShivC, with much more emphasis on feature completeness and code quality. See the ShivC README for more details.C11 Specification -http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdfx86_64 ABI -https://github.com/hjl-tools/x86-psABI/wiki/x86-64-psABI-1.0.pdfIterated Register Coalescing (George and Appel) -https://www.cs.purdue.edu/homes/hosking/502/george.pdf