liu-zhy / wgtcc

a tiny C compiler in C++11

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

wgtcc Build Status

a small C11 compiler in C++11

ENVIRONMENT

  1. x86-64
  2. linux 4.4.0
  3. gcc 5.4.0 (or any version supports C++11)

INSTALL

$ make all
$ make install # root required
$ make test

then you can play with the examples:

$ wgtcc example/heart.c
$ wgtcc example/chinese.c

GOAL

wgtcc is aimed to implement the full C11 standard with some exceptions:

  1. some features are supported only in grammar level(like keyword register)
  2. features that disgusting me are removed(like default int type without type specifier)
  3. some non standard GNU extensions are supported, but you should not rely on wgtcc of a full supporting

FRONT END

A basic recursive descent parser

BACK END

wgtcc generates code from AST directly. The algorithm is TOSCA(top of stack caching). It is far from generating efficient code, but at least it works and generates code efficently.

MEMORY MANAGEMENT

Through wgtcc was wirtten in C++, i paid no effort for memory management except for a simple memory pool to accelerate allocations. only new is preferred because wgtcc runs fast and exits immediately after finishing parsing and generating code.

REFERENCE

  1. Compilers Principles, Techniques and Tools. second Edition.
  2. N1548, C11 standard draft
  3. 64-ia-32-architectures-software-developer-manual-325462
  4. 8cc
  5. macro expansion algorithm

TODO

  1. support GNU extensions(e.g. keyword __attribute__)
  2. support variable length array
  3. optimization(e.g. register allocation)
  4. support type qualification

About

a tiny C compiler in C++11

License:MIT License


Languages

Language:C++ 72.7%Language:C 27.0%Language:Makefile 0.3%