diff options
| author | nsfisis <nsfisis@gmail.com> | 2025-05-07 09:18:21 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2025-05-07 09:18:21 +0900 |
| commit | f427d5c99f0380d7f547101878e36ef5008e248b (patch) | |
| tree | c88435dabe710d9592a7b081cdb48922e5f96ffe | |
| parent | 68d9da9746d235e2d9a7d0ba61310c533b355847 (diff) | |
| download | ducc-f427d5c99f0380d7f547101878e36ef5008e248b.tar.gz ducc-f427d5c99f0380d7f547101878e36ef5008e248b.tar.zst ducc-f427d5c99f0380d7f547101878e36ef5008e248b.zip | |
start ducc project
| -rw-r--r-- | .gitignore | 2 | ||||
| -rw-r--r-- | README.md | 38 | ||||
| -rw-r--r-- | justfile | 26 | ||||
| -rw-r--r-- | tests/run.sh | 2 | ||||
| -rw-r--r-- | tests/test_diff.sh | 2 | ||||
| -rw-r--r-- | tests/test_exit_code.sh | 2 | ||||
| -rw-r--r-- | tests/test_output.sh | 2 |
7 files changed, 20 insertions, 54 deletions
@@ -1,3 +1,3 @@ /main*.s -/p4dcc* +/ducc* /tests/tmp @@ -1,10 +1,6 @@ -# P4Dcc +# Ducc -P4Dcc is a tiny, but self-hosted C compiler. It takes C source code and compiles it to assembly language. For assembling and linking, it deletegates to gcc as-is. - -This project was started to prove the hypothesis: "Could a self-hostable C compiler be built in four days, if the feature set is carefully limited?" - "P4D" stands for the ISO 8601 notation meaning "four days." However, I actually completed the project by the morning of the third day. - -The code is written following the instructions at https://www.sigbus.info/compilerbook, and several key design decisions were inspired by the book. +Ducc is a toy C compiler, based on [my another tiny C compiler](https://github.com/nsfisis/P4Dcc). ## Dependencies @@ -24,39 +20,9 @@ $ just build ``` $ just test -$ just test-all # test all things, including binary equiality between generations ``` -## Design - -To meet the four-day goal, many design decisions were made to reduce complexity (ideas directly taken from https://www.sigbus.info/compilerbook are not listed): - -* Simplified declaration syntax - * No support for `typedef` - * Structs always begin with `struct` keyword - * No support for array types - * No stack-allocated arrays - * All arrays are heap-allocated and accessed via pointers - * No support for function types - * Type information always precede the variable name -* Minimal syntax sugar - * ~~No increment/decrement operators~~ - * Partially implemented after self-hosting - * ~~No compound assignment operators~~ - * Implemented after self-hosting - * ~~No `while`~~ - * Implemented after self-hosting - * No `switch` -* Limited preprocessor - * Supports only simple `#define` that replaces identifiers with single integer or identifier -* No global variables - * Including `stdin`, `stdout`, and `stderr` - * Only function/struct definitions/declarations are allowed at the top level -* No variable shadowing - * All variables are function-scoped - - ## License See [LICENSE](./LICENSE). @@ -5,15 +5,15 @@ all: build build N="1": #!/usr/bin/env bash if [[ {{N}} = 1 ]]; then - gcc -g -O0 -o p4dcc main.c {{CFLAGS}} + gcc -g -O0 -o ducc main.c {{CFLAGS}} else if [[ {{N}} = 2 ]]; then prev="" else prev=$(({{N}} - 1)) fi - "./p4dcc${prev}" < main.c > main{{N}}.s - gcc -s -Wl,-z,noexecstack -o p4dcc{{N}} main{{N}}.s + "./ducc${prev}" < main.c > main{{N}}.s + gcc -s -Wl,-z,noexecstack -o ducc{{N}} main{{N}}.s fi build-upto-5-gen: @@ -24,11 +24,11 @@ build-upto-5-gen: just build 5 test-self-hosted: build-upto-5-gen - diff -u ./p4dcc2 ./p4dcc3 - diff -u ./p4dcc3 ./p4dcc4 - diff -u ./p4dcc4 ./p4dcc5 + diff -u ./ducc2 ./ducc3 + diff -u ./ducc3 ./ducc4 + diff -u ./ducc4 ./ducc5 -test TESTCASE="all" $BIN="p4dcc": build +test TESTCASE="all" $BIN="ducc": build #!/usr/bin/env bash if [[ {{TESTCASE}} = all ]]; then bash tests/all.sh @@ -38,13 +38,13 @@ test TESTCASE="all" $BIN="p4dcc": build test-all: just test-self-hosted - just test all p4dcc - just test all p4dcc2 - just test all p4dcc3 - just test all p4dcc4 - just test all p4dcc5 + just test all ducc + just test all ducc2 + just test all ducc3 + just test all ducc4 + just test all ducc5 clean: rm -f main*.s - rm -f p4dcc* + rm -f ducc* rm -rf tests/tmp diff --git a/tests/run.sh b/tests/run.sh index 2a5d9be..0e28a96 100644 --- a/tests/run.sh +++ b/tests/run.sh @@ -1,6 +1,6 @@ set -e -export p4dcc="../../../$BIN" +export ducc="../../../$BIN" export testcase=$1 export tmp_dir="tests/tmp/$testcase" diff --git a/tests/test_diff.sh b/tests/test_diff.sh index 44e00d0..ec0f1d0 100644 --- a/tests/test_diff.sh +++ b/tests/test_diff.sh @@ -1,6 +1,6 @@ cat > main.c -"$p4dcc" < main.c > main.s +"$ducc" < main.c > main.s if [[ $? -ne 0 ]]; then cat main.s >&2 exit 1 diff --git a/tests/test_exit_code.sh b/tests/test_exit_code.sh index f49d468..490de5b 100644 --- a/tests/test_exit_code.sh +++ b/tests/test_exit_code.sh @@ -1,6 +1,6 @@ cat > main.c -"$p4dcc" < main.c > main.s +"$ducc" < main.c > main.s if [[ $? -ne 0 ]]; then cat main.s >&2 exit 1 diff --git a/tests/test_output.sh b/tests/test_output.sh index 2c8fb29..2f8b984 100644 --- a/tests/test_output.sh +++ b/tests/test_output.sh @@ -1,6 +1,6 @@ cat > main.c -"$p4dcc" < main.c > main.s +"$ducc" < main.c > main.s if [[ $? -ne 0 ]]; then cat main.s >&2 exit 1 |
