A C compiler for the risc-v instruction set, with features being refined.
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)
cd thrvcc
# if cross compile
export RISCV=~/riscv
# if local riscv
export RISCV=
# binary
make thrvcc
# test
make test
./thrvcc -o out in.c
./thrvcc -S in.c
./thrvcc in.c
./thrvcc --help
arithmetic operator
- + - * / % ++ --
relational operator
- == != > < >= <=
logical operator
- && || !
bitwise operator
- & | ^ ~ << >>
assignment operator
- = += -= *= /= %= <<= >>= &= ^= |=
pointer operator
- & *
other
- sizeof ?:
- 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
- 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:
TenHian
Related Projects:
chibicc
MIT license