Skip to content

HyperCPU-Project/hcc

Repository files navigation

Hyper C Compiler

Hyper C Compiler

GitHub opened issues Status License Stars

Hyper C Compiler (hcc) is a C compiler developed for HyperCPU and qproc. It's very extensible and allows easily create backends for it.

Hyper C Compiler uses bison, flex and fmt libraries. Although it may be not very optimized in code generation, it's a good choice to develop software for above referenced processors.

Warning

The compiler is intended for use with HyperCPU and qproc only. It can't compile for architectures like x86_32, x86_64, ARM64, etc.

Here's how hcc generated assembly can look like:

  • Input (C)
int main(){
    return (69 / 3) * 3;
}
  • Output (hASM; HyperCPU backend with constant folding, DCE and fp omission)
main:
mov x0, 0u69;
ret;

Installation

Warning

The project supports GNU/Linux systems only. It is known to be successfully built on x86_32, x86_64, ARMv7 and ARMv8 architectures.

Windows and BSD* support is not tested, but it could possibly be built under these systems

Binaries

Pre-compiled binaries are currently not available. Sorry.

Building from sources

Building Hyper C Compiler requires these dependencies to be installed:

  • GCC >=12 or Clang >=14;
  • GNU make, CMake >=3.25;
  • bison, flex and fmt libraries.

After installing dependencies build the project by executing these commands:

git clone --recursive https://github.com/HyperCPU-Project/hcc # Clone the repository.
cd hcc
cmake -S . -B build # Generate build files.
cd build
make

Besides hcc executable file, tests also will be built. If you are not interested in tests, specify HCC_NO_TESTS=1 CMake build option.

Usage

hcc executable file is kinda large (2 MB / 1.9MiB) because of C++, but whatever.

$ ./hcc [-h | --help] [-o FILENAME] [--backend BACKEND] [--ast] [-fOPTIMIZATION] [-fno-OPTIMIZATION] source
  • source — source code file to be compiled.
  • -h, --help — display help message and exit.
  • -o FILENAME — specify output binary file name.
  • --backend BACKEND — specify compilation backend (target). Available values are: qproc, hypercpu.
  • --ast — print an abstract syntax tree when the parsing is done.
  • -fOPTIMIZATION — enable optimization.
  • -fno-OPTIMIZATION — disables optimization.

Authors

Hyper C Compiler is brought to you by these wonderful people:

  • aceinetx — project founder and lead developer.
  • Ivan Movchan — project artist and just a contributor.

License

Hyper C Compiler is free software released under the terms of the GNU General Public License v3.0.

About

Multi-backend K&R style C compiler

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •