All Projects → falgon → htcc

falgon / htcc

Licence: BSD-3-Clause license
🐤 A tiny C language compiler (x86-64) (WIP)

Programming Languages

haskell
3896 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to htcc

Perfectwindows
PerfectWindows 软件家族 - Windows 从未如此完美!
Stars: ✭ 1,326 (+4177.42%)
Mutual labels:  tiny
Busker
An extremely simple web framework.
Stars: ✭ 161 (+419.35%)
Mutual labels:  tiny
Tinycreditcard
A clear and animated credit card input workflow implement
Stars: ✭ 236 (+661.29%)
Mutual labels:  tiny
Ipfs Mini
A super tiny module for querying IPFS that works in the browser and node.
Stars: ✭ 115 (+270.97%)
Mutual labels:  tiny
Scoped Style
A tiny css in js library 🚀
Stars: ✭ 129 (+316.13%)
Mutual labels:  tiny
Bahunya
10KB classless CSS framework with responsive typography, navbar, syntax highlighting, etc.
Stars: ✭ 170 (+448.39%)
Mutual labels:  tiny
Pyclue
Python toolkit for Chinese Language Understanding(CLUE) Evaluation benchmark
Stars: ✭ 91 (+193.55%)
Mutual labels:  tiny
Just
A library of dependency-free JavaScript functions that do just do one thing.
Stars: ✭ 3,837 (+12277.42%)
Mutual labels:  tiny
Vue Final Modal
🍕Vue Final Modal is a tiny, renderless, mobile-friendly, feature-rich modal component for Vue.js.
Stars: ✭ 128 (+312.9%)
Mutual labels:  tiny
Webpack Nano
A teensy, squeaky 🐤 clean Webpack CLI
Stars: ✭ 199 (+541.94%)
Mutual labels:  tiny
React Plain Router
🛣 A 2kb React router that works exactly as expected with native Javascript
Stars: ✭ 119 (+283.87%)
Mutual labels:  tiny
Fsharp.domain.validation
Designing with types requires a lot of code - this library fixes that
Stars: ✭ 119 (+283.87%)
Mutual labels:  tiny
Graceful Server
Tiny (~5k), KISS, dependency-free Node.JS library to make your API more graceful
Stars: ✭ 173 (+458.06%)
Mutual labels:  tiny
Charm
A really tiny crypto library.
Stars: ✭ 116 (+274.19%)
Mutual labels:  tiny
Huejumper2k
2 Kilobyte 3D racing game in JavaScript
Stars: ✭ 236 (+661.29%)
Mutual labels:  tiny
Unissist
⛑ A ~300b unistore helper to persist your data using equally tiny storage adapters
Stars: ✭ 94 (+203.23%)
Mutual labels:  tiny
Tinn
A tiny neural network library
Stars: ✭ 1,944 (+6170.97%)
Mutual labels:  tiny
Tic 80
TIC-80 is a fantasy computer for making, playing and sharing tiny games.
Stars: ✭ 3,176 (+10145.16%)
Mutual labels:  tiny
Cwebsocket
cWebsocket is lightweight websocket server library
Stars: ✭ 241 (+677.42%)
Mutual labels:  tiny
Pristine
Vanilla javascript form validation micro-library
Stars: ✭ 197 (+535.48%)
Mutual labels:  tiny

htcc

🐤 A tiny C language compiler (x86-64) (WIP)

Build

$ stack build
$ stack build --fast # no optimized

Usage

$ stack exec htcc -- -h
Usage: htcc [--visualize-ast] [--img-resolution RESOLUTION] file [-o|--out file]
            [-w|--supress-warns]

Available options:
  -h,--help                Show this help text
  --visualize-ast          Visualize an AST built from source code
  --img-resolution RESOLUTION
                           Specify the resolution of the AST graph to be
                           generated (default: 640x480)
  file                     Specify the input file name
  -o,--out file            Specify the output destination file name, supported
                           only svg (default: ./out.svg)
  -w,--supress-warns       Disable all warning messages

Simple compilation:

$ echo 'int printf(); int main() { printf("hello world!\n"); }' > t.c
$ stack exec htcc -- t.c > t.s
$ gcc -no-pie t.s -o out

For one liner:

$ echo 'int printf(); int main() { printf("hello world!\n"); }' | stack exec htcc -- /dev/stdin | gcc -xassembler -no-pie -o out -  

AST diagram generation

htcc has the ability to visualize ASTs built from loaded C code. This option allows to specify the resolution and output file. Examples are shown in the following table.

Command Output
$ echo 'int main() { return 1 * 2 + 4; }' |\
    stack exec htcc -- /dev/stdin --visualize-ast
AST graph of the some calculation
$ echo 'int printf();
    void fizzbuzz(int n) { 
        for (int i = 1; i < n; ++i) { 
            if (!(i % 15)) printf("fizzbuzz\n"); 
            else if (!(i % 3)) printf("fizz\n"); 
            else if (!(i % 5)) printf("buzz\n"); 
            else printf("%d\n", i); 
        } 
    } 
    int main() { fizzbuzz(50); }' |\
    stack exec htcc -- /dev/stdin\
        --visualize-ast\
        --img-resolution 1280x720\
        --out fizzbuzz.svg
AST graph of FizzBuzz

Appearance of operations

an gif animation image of operations

Tests and run examples

If you want to run outside the Linux environment, if docker and docker-compose are installed, you can run tests inside the docker container by specifying docker as an argument.

$ stack test --test-arguments --help
htcc> test (suite: htcc-test, args: --help)
Usage: htcc-test [--clean] COMMAND
  The htcc unit tester

Available options:
  -h,--help                Show this help text
  --clean                  clean the docker container

Available commands:
  subp                     run tests with subprocess
  docker                   run tests in docker container
  self                     run the test using htcc's processing power

htcc> Test suite htcc-test passed
$ stack test --test-arguments self
$ stack test --test-arguments subp
$ stack test --test-arguments docker # For running outside the linux environment. It requires docker and docker-compose.

If you want to delete the created test container and its image, execute as follows:

$ stack test --test-arguments docker --test-arguments --clean

Source files that can be compiled by htcc are placed under the example/.

$ cd example
$ make

For the same reason, when running in docker (lifegame is not supported because it need to clear standard output):

$ cd example
$ make docker
$ make clean_docker # Stop and delete docker container, and delete image

Benchmark

$ stack bench

Documents

The implementation description is available in here.

Specification and Requirements

htcc outputs x86_64 assembly according to System V ABI [2] and GCC 7.4.0 is used for assemble. Perhaps a newer version of GCC will work, but not checked currently.

About emoji of commit messages

The emoji included in the commit message is used according to gitmoji.

FAQ

Your compiler is inefficient :)

I know 😕

This is a compiler made for research, not for practical purposes and the author also developed the compiler for the first time. If you can suggest improvements, please submit issues or send PRs. Thanks in advance for all the improvements.

When I try to play with ghci, I get a warning "WARNING:. is owned by someone else, IGNORING!"

Check your permissions. The answer on stack overflow may be useful.

License

FOSSA Status

References

  1. JTC1/SC22/WG14. (2011). N1570 Commitee Draft [online]. Available from: PDF, HTML.
  2. H.J. Lu, Michael Matz, Milind Girkar, Jan Hubicka, Andreas Jaeger and Mark Mitchell. (2018). System V Application Binary Interface AMD64 Architecture Processor Supplement (With LP64 and ILP32 Programming Models) Version 1.0 [online]. Available from: PDF.
  3. Rui Ueyama. (2019). 低レイヤを知りたい人のためのCコンパイラ作成入門 [online]. Available from: https://www.sigbus.info/compilerbook.
  4. 前橋和弥. (2009). プログラミング言語を作る. 技術評論社.
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].