Giter VIP home page Giter VIP logo

c-compiler's Introduction

C Compiler

This is a C17 compiler written from scratch in C. It can compile itself and most portable C programs.

You can read the tests or the source code to get a sense of what this compiler supports.

Only a linker is required to build programs. Both the preprocessor and assembler are included in the compiler.

I have successfully built TinyCC, Git, and a few other medium to large code-bases using this compiler. Some small patching is often needed, but seldom anything major.

Build instructions

To compile, use the command:

make

Configuration is done through config.h. This file will be generated from config.def.h at the first run of make.

Alternatively a CMakeLists.txt, and a simple compile.sh script is provided. When not using make, the config.h file needs to be created manually.

Compilation instructions

bin/cc input.c -o output.s -S -Iinclude/directory -DDEFINITION -DNAME=VALUE
bin/cc input.c -o output.o -c -Iinclude/directory -DDEFINITION -DNAME=VALUE

output.s is a x86-64 assembly file with AT&T syntax, and output.o is a 64-bit relocatable elf file. The command line format is similar to that of the c99 POSIX utility.

Without any -S or -c flag, the compiler will try to link the input into an executable elf file. The linker is still under development, and will most likely not work for any non-trivial program.

Self compilation

For self compilation, use the command:

make self-compile

The resulting binaries are bin/cc2, and bin/cc3 for the second and third generations. The binaries are expected to be exactly identical.

Testing

To run tests, use the command:

make check

This compiles and runs all tests/*.c files and ensures that there are no errors during compilation or run time. It also self compiles and checks that the second and third generations are identical.

c-compiler's People

Contributors

lasarus avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.