All Projects → ShivamSarodia → Shivyc

ShivamSarodia / Shivyc

Licence: mit
C compiler created in Python.

Programming Languages

python
139335 projects - #7 most used programming language
c
50402 projects - #5 most used programming language

Labels

Projects that are alternatives of or similar to Shivyc

Numba
NumPy aware dynamic Python compiler using LLVM
Stars: ✭ 7,090 (+739.05%)
Mutual labels:  compiler
Modiscript
Acche din aa gaye
Stars: ✭ 888 (+5.09%)
Mutual labels:  compiler
Orcc
Open RVC-CAL Compiler
Stars: ✭ 26 (-96.92%)
Mutual labels:  compiler
Tinycc
Unofficial mirror of mob development branch
Stars: ✭ 784 (-7.22%)
Mutual labels:  compiler
Pyterminfo
A terminfo-to-python cross compiler
Stars: ✭ 5 (-99.41%)
Mutual labels:  compiler
Venom
venom - shellcode generator/compiler/handler (metasploit)
Stars: ✭ 904 (+6.98%)
Mutual labels:  compiler
J2cl
Java to Closure JavaScript transpiler
Stars: ✭ 773 (-8.52%)
Mutual labels:  compiler
Hamler
Haskell-style functional programming language running on Erlang VM.
Stars: ✭ 840 (-0.59%)
Mutual labels:  compiler
Grin
GRIN is a compiler back-end for lazy and strict functional languages with whole program optimization support.
Stars: ✭ 834 (-1.3%)
Mutual labels:  compiler
Diez
The Design Token Framework — Adopt a unified design language across platforms, codebases, and teams
Stars: ✭ 928 (+9.82%)
Mutual labels:  compiler
Typescripttolua
Typescript to lua transpiler. https://typescripttolua.github.io/
Stars: ✭ 783 (-7.34%)
Mutual labels:  compiler
Tvm
Open deep learning compiler stack for cpu, gpu and specialized accelerators
Stars: ✭ 7,494 (+786.86%)
Mutual labels:  compiler
Radon
A scripting language.
Stars: ✭ 22 (-97.4%)
Mutual labels:  compiler
Compiler
Compiler for Elm, a functional language for reliable webapps.
Stars: ✭ 6,672 (+689.59%)
Mutual labels:  compiler
Ldc
The LLVM-based D Compiler.
Stars: ✭ 937 (+10.89%)
Mutual labels:  compiler
Elm Platform
Bundle of all core development tools for Elm
Stars: ✭ 775 (-8.28%)
Mutual labels:  compiler
Gccrs
GCC Front-End for Rust
Stars: ✭ 875 (+3.55%)
Mutual labels:  compiler
Cfl
a Compileable statically typed Functional programming Language
Stars: ✭ 7 (-99.17%)
Mutual labels:  compiler
Fly Coffee
☕️ Fly plugin for CoffeeScript
Stars: ✭ 7 (-99.17%)
Mutual labels:  compiler
Viper
[WIP] A Pythonesque language with a design that focuses on efficiency and expressiveness. Compiles to WebAssembly
Stars: ✭ 23 (-97.28%)
Mutual labels:  compiler

ShivyC Build Status Code Coverage

A hobby C compiler created in Python.

ShivyC demo GIF.


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.

This implementation of a trie is an example of what ShivyC can compile today. For a more comprehensive list of features, see the feature test directory.

Quickstart

x86-64 Linux

ShivyC 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 shivyc

To create, compile, and run an example program:

$ vim hello.c
$ cat hello.c

#include <stdio.h>
int main() {
  printf("hello, world!\n");
}

$ shivyc hello.c
$ ./out
hello, world!

To run the tests:

git clone https://github.com/ShivamSarodia/ShivyC.git
cd ShivyC
python3 -m unittest discover

Other Architectures

For the convenience of those not running Linux, the docker/ 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/shell

This will open up a shell in an environment with ShivyC installed and ready to use with

shivyc any_c_file.c           # to compile a file
python3 -m unittest discover  # to run tests

The Docker ShivyC executable will update live with any changes made in your local ShivyC directory.

Implementation Overview

Preprocessor

ShivyC today has a very limited preprocessor that parses out comments and expands #include directives. These features are implemented between lexer.py and preproc.py.

Lexer

The ShivyC lexer is implemented primarily in lexer.py. Additionally, tokens.py contains definitions of the token classes used in the lexer and token_kinds.py contains instances of recognized keyword and symbol tokens.

Parser

The ShivyC parser uses recursive descent techniques for all parsing. It is implented in parser/*.py and creates a parse tree of nodes defined in tree/nodes.py and tree/expr_nodes.py.

IL generation

ShivyC traverses the parse tree to generate a flat custom IL (intermediate language). The commands for this IL are in il_cmds/*.py . Objects used for IL generation are in il_gen.py , but most of the IL generating code is in the make_code function of each tree node in tree/*.py.

ASM generation

ShivyC 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 in asm_gen.py , but much of the ASM generating code is in the make_asm function of each IL command in il_cmds/*.py.

Contributing

Pull requests to ShivyC are very welcome. A good place to start is the Issues page. All issues 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:

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].