Skip to content

TenHian/thrvcc

Repository files navigation

thrvcc

Description

A C compiler for the risc-v instruction set, with features being refined.

Build

Install Dependencies

base dev tools:

sudo pacman -S base-devel

riscv cross compilation tool chain:

# for tool chain dependencies, see https://github.com/riscv-collab/riscv-gnu-toolchain#prerequisites
curl https://mirror.iscas.ac.cn/riscv-toolchains/git/riscv-collab/riscv-gnu-toolchain.sh | bash
cd riscv-gnu-toolchain
mkdir build
cd build
../configure --prefix=$HOME/riscv
make build-sim linux -j$(nproc)

Build with Makefile

cd thrvcc
# if cross compile
export RISCV=~/riscv
# if local riscv
export RISCV=
# binary
make thrvcc
# test
make test

Usage

./thrvcc -o out in.c
./thrvcc -S in.c
./thrvcc in.c
./thrvcc --help

TODO

operator

arithmetic operator

  • + - * / % ++ --

relational operator

  • == != > < >= <=

logical operator

  • && || !

bitwise operator

  • & | ^ ~ << >>

assignment operator

  • = += -= *= /= %= <<= >>= &= ^= |=

pointer operator

  • & *

other

  • sizeof ?:

keywords

  • auto
  • break continue goto return
  • if else switch case default
  • do for while
  • char✔ double✔ float✔ int✔ long✔ register✔ short✔ void✔
  • enum struct typedef union
  • const✔ extern✔ signed✔ unsigned✔ static✔ volatile✔

c99

  • _Bool
  • _Complex
  • _Imaginary
  • inline
  • restrict

c11

  • _Alignas
  • _Alignof
  • _Atomic
  • _Generic
  • _Noreturn
  • _Static_assert
  • _Thread_local

features

  • local variable
  • branch statement
  • cyclic statement
  • pointer
  • function
  • one-dimensional and multi-dimensional arrays
  • global variable
  • string
  • escape character
  • comment
  • scope
  • struct
  • union
  • short long long long
  • void
  • typedef
  • sizeof
  • type cast
  • enum
  • uncomplete array
  • const expr
  • initializer
  • extern
  • static
  • do while
  • signed unsigned
  • function pointer
  • separate out cc1
    ......

Authors and acknowledgment

Authors:
  TenHian
Related Projects:
  chibicc

License

MIT license

Releases

No releases published

Packages

No packages published