KECC: KAIST 教育 C 编译器。 重要提示: 请勿分支!
Install rustup.
cargo build # debug build
cargo build --release # release buildcargo doc --document-private-items # built in target/doc
cargo doc --open --document-private-items # opens in default broswer. Firefox or Chrome recommended.…For more information, please refer to the KECC User's Manual.
…RUST_MIN_STACK=33554432 is necessary for deep call stack for irgen tests.
We encourage you to do homework using the test-driven development (TDD)approach. You will randomly generate a test input, and if it fails, reduce it as much as possible and manually inspect the reduced test input. For example:
# Randomly generates test inputs and tests them
python3 tests/fuzz.py
# Reduces the failing test input as much as possible
python3 tests/fuzz.py --reduce
# Fix your code for the reduced test input
cat tests/test_reduced.c`` can be --print or --irgen. It shall be the one used in Run.
For more information, please refer to the Fuzzer User's Manual.
# Ubuntu 20.04
sudo apt install -y build-essential clang make cmake python3 csmith libcsmith-dev creduce
pip3 install tqdmThe following script generates 10 random test cases and tests your C AST printer:
python3 tests/fuzz.py --help # print options
python3 tests/fuzz.py --print -n10 # test C AST printer for 10 timesWe use csmith to randomly generate C source codes.
csmith will be automatically downloaded and built by the test script.
For more information, we refer to the Csmith homepage.
When the fuzzer finds a buggy input program for your compiler,
the input program is likely too big to manually inspect.
We use creduce that reduces the buggy input program as much as possible.
Suppose tests/test_polished.c is the buggy input program.
Then the following script reduces the program to tests/test_reduced.c:
python3 tests/fuzz.py --reduce`` can be --print or --irgen. It shall be the one used in Run.
The script performs unguided test-case reduction using creduce: given a buggy program, it
randomly reduces the program;
check if the reduced program still fails on the test, and
if so, replaces the given program with the reduced one;
repeat until you get a small enough buggy program.
For more information, we refer to the Creduce homepage.
[NOTICE] The fuzzer only supports Ubuntu 20.04. It may work for other platforms, but if it doesn't, please run the fuzzer in Ubuntu 20.04.
# Ubuntu 20.04
sudo apt install gcc-riscv64-linux-gnu g++-riscv64-linux-gnu qemu-user-static gdb-multiarch# Compile C source code into RISC-V assembly
riscv64-linux-gnu-gcc hello.c -S -fsigned-char -o hello.S
# Link to an RISC-V executable
riscv64-linux-gnu-gcc -static hello.S -o hello
# Emulate the executable
qemu-riscv64-static ./hello
# Check the return value
echo $?You can use QEMU's debugging facilities to investigate whether the generated assembly works correctly.
Open two terminal windows.
In one, compile the assembly with -ggdb option and start up a gdb server with 8888 port.
(If 8888 is already in use, then try with a different port like 8889, 8890, ...)
# Link to an RISC-V executable with `-ggdb` option
riscv64-linux-gnu-gcc -ggdb -static hello.S -o hello
# Emulate the executable and wait for a debugging connection from GDB
qemu-riscv64-static -g 8888 helloIn the second terminal, run gdb-multiarch and set some configurations.
You should see something like this,
…Now you can debug the assembly using the GDB commands. For more information on GDB commands, see:
cd bench
make run./scripts/make-submissions.sh to generate irgen.zip to final.zip,
which you should submit for homework 2 to the final project.暂无开放 Issues,或尚未同步最近议题。