Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ This project's goal is to rewrite refs/tinycc in MoonBit. Please keep implementa

- If fix bug, add tests to avoid regression in future
- Keep refs/quickjs compile + smoke tests in the test pipeline (scripts/run_mbtcc_ctest.sh) to avoid regressions
- Run quickjs JS tests (QUICKJS_TESTS=1 with QUICKJS_TEST_LIST) in the pipeline to validate tinycc.mbt-built quickjs behavior
- Run quickjs JS tests (QUICKJS_TESTS=1 with QUICKJS_TEST_LIST) in the pipeline to validate fastcc.mbt-built quickjs behavior

## Quick Reference

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# tinycc.mbt
# fastcc.mbt

## Benchmarks

### refs/vc/v.c (bench_tinycc_compile.sh DATASET=vc)

File: `refs/vc/v.c` (138152 LOC)

Environment: macOS arm64, tinycc from this repo built in release mode.
Environment: macOS arm64, fastcc from this repo built in release mode.

Command:

Expand All @@ -16,7 +16,7 @@ DATASET=vc APPLY_VC_PATCH=1 DETAIL=1 REPEAT=3 WARMUP=1 scripts/bench_tinycc_comp

Results (3 runs):

- tinycc.mbt total: 0.425s
- fastcc.mbt total: 0.425s
- refs/tinycc total: 0.113s
- clang total: 1.592s
- ratio (mbt/ref): 3.77x
Expand Down
4 changes: 2 additions & 2 deletions docs/architecture.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Architecture Overview

This document summarizes the current architecture of tinycc.mbt, how data flows
This document summarizes the current architecture of fastcc.mbt, how data flows
through the compiler, and where each major responsibility lives today. The code
is intentionally close to refs/tinycc and is now split into focused MoonBit
packages under `src/`.
Expand All @@ -21,7 +21,7 @@ CLI args

Key entrypoints:
- `main` lives in `src/cmd/tinycc/main.mbt`; root `src/main.mbt` delegates to
`@cmd_tinycc.run_main` for compatibility with existing scripts.
`@cmd_fastcc.run_main` for compatibility with existing scripts.
- Compilation pipeline uses `compile_to_object_path` in `src/driver/driver.mbt`.
- Preprocessor entry: `@preproc.new_preprocessor` + `@parser.parse_translation_unit`.
- Semantic analysis entry: `@sem.check_translation_unit` in `src/sem/sem.mbt`.
Expand Down
2 changes: 1 addition & 1 deletion docs/tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ The bigger test files are intentionally “edge-case heavy”:
## Parallelization note

Tests were originally introduced under a single `src/blackbox` package, which made it hard for `moon test` to parallelize work.
They are now distributed into their owning packages, and shared filesystem helpers were extracted into `hackwaly/tinycc/testutil`.
They are now distributed into their owning packages, and shared filesystem helpers were extracted into `hackwaly/fastcc/testutil`.
4 changes: 2 additions & 2 deletions moon.mod.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "hackwaly/tinycc",
"name": "hackwaly/fastcc",
"deps": {
"moonbitlang/x": "0.4.38"
},
"source": "src",
"preferred-target": "native"
}
}
16 changes: 8 additions & 8 deletions scripts/bench_tinycc_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ TINYCC_DIR="${ROOT_DIR}/refs/tinycc"
TINYCC_MBT_C_DIR="${ROOT_DIR}/tests/tinycc_mbt_c"
OUT_DIR="${ROOT_DIR}/target/bench"

TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/tinycc.exe}"
TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/fastcc.exe}"
TINYCC_REF_BIN="${TINYCC_REF_BIN:-${TINYCC_DIR}/tcc}"
CLANG_BIN="${CLANG_BIN:-clang}"
CLANG_FLAGS="${CLANG_FLAGS:-}"
Expand Down Expand Up @@ -37,8 +37,8 @@ Env vars:
TINYCC_SOURCES="..." Space-separated refs/tinycc sources (default: tcc.c)
REPEAT=N Repeat the full compile set N times (default: 1)
WARMUP=0|1 Run a warmup compile pass (default: 0)
BUILD_MBT=0|1 Build tinycc.mbt before benchmarking (default: 1)
DETAIL=0|1 Collect per-phase timings from tinycc.mbt -bench (default: 0)
BUILD_MBT=0|1 Build fastcc.mbt before benchmarking (default: 1)
DETAIL=0|1 Collect per-phase timings from fastcc.mbt -bench (default: 0)
BASELINE_FILE=path Baseline README to compare (default: README.md)
REGRESSION_PCT=N Flag regression if slower by N percent (default: 0)
TINYCC_MBT_BIN=path
Expand All @@ -54,12 +54,12 @@ if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
fi

if [[ "${BUILD_MBT}" == "1" ]]; then
echo "Building tinycc.mbt (${TINYCC_MBT_BIN})"
echo "Building fastcc.mbt (${TINYCC_MBT_BIN})"
moon build --release --target native src
fi

if [[ ! -x "${TINYCC_MBT_BIN}" ]]; then
echo "error: tinycc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
echo "error: fastcc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
exit 1
fi
if [[ ! -x "${TINYCC_REF_BIN}" ]]; then
Expand Down Expand Up @@ -254,7 +254,7 @@ clang_time, _ = run_compile("clang", clang_bin, clang_flags, False)
ratio_mbt_ref = mbt_time / ref_time if ref_time > 0 else float("inf")
ratio_mbt_clang = mbt_time / clang_time if clang_time > 0 else float("inf")
ratio_ref_clang = ref_time / clang_time if clang_time > 0 else float("inf")
print(f"tinycc.mbt total: {mbt_time:.3f}s")
print(f"fastcc.mbt total: {mbt_time:.3f}s")
print(f"refs/tinycc total: {ref_time:.3f}s")
print(f"clang total: {clang_time:.3f}s")
print(f"ratio (mbt/ref): {ratio_mbt_ref:.2f}x")
Expand All @@ -265,7 +265,7 @@ if detail:
avg_sem = mbt_phases["sem_us"] / (1000.0 * repeat)
avg_codegen = mbt_phases["codegen_us"] / (1000.0 * repeat)
avg_total = mbt_phases["total_us"] / (1000.0 * repeat)
print(f"tinycc.mbt phases (avg ms): parse={avg_parse:.3f} sem={avg_sem:.3f} codegen={avg_codegen:.3f} total={avg_total:.3f}")
print(f"fastcc.mbt phases (avg ms): parse={avg_parse:.3f} sem={avg_sem:.3f} codegen={avg_codegen:.3f} total={avg_total:.3f}")

def load_baseline(path, dataset_name):
if not path or not os.path.isfile(path):
Expand Down Expand Up @@ -336,7 +336,7 @@ if baseline:
print(f"Baseline ({baseline_file})")
regressions = []
if baseline.get("mbt_total_s") is not None:
regressions.append(report_delta("tinycc.mbt total", mbt_time, baseline["mbt_total_s"], "s"))
regressions.append(report_delta("fastcc.mbt total", mbt_time, baseline["mbt_total_s"], "s"))
if baseline.get("ratio_mbt_ref") is not None:
regressions.append(report_delta("ratio (mbt/ref)", ratio_mbt_ref, baseline["ratio_mbt_ref"], "x"))
if detail and baseline.get("phase_total_ms") is not None:
Expand Down
14 changes: 7 additions & 7 deletions scripts/profile_tinycc_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ VC_PATCH="${ROOT_DIR}/refs/vc_patches/arm64_closure_bytes.patch"
TINYCC_DIR="${ROOT_DIR}/refs/tinycc"
TINYCC_MBT_C_DIR="${ROOT_DIR}/tests/tinycc_mbt_c"

TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/tinycc.exe}"
TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/fastcc.exe}"
DATASET="${DATASET:-vc}" # vc | tinycc | tinycc_mbt_c
APPLY_VC_PATCH="${APPLY_VC_PATCH:-1}"
TINYCC_SOURCES="${TINYCC_SOURCES:-}"
Expand All @@ -32,7 +32,7 @@ Env vars:
TINYCC_SOURCES="..." Space-separated refs/tinycc sources (default: tcc.c)
PROFILE_SOURCE=path Override source file to compile (relative to repo ok)
PROFILE_INCLUDES="..." Override include dirs (space-separated), used with PROFILE_SOURCE
BUILD_MBT=0|1 Build tinycc.mbt before profiling (default: 1)
BUILD_MBT=0|1 Build fastcc.mbt before profiling (default: 1)
TRACE_DIR=path Output directory for .trace and summary (default: target/trace)
TRACE_NAME=name.trace Trace file name (default: tinycc_${DATASET}_timeprof_YYYYmmdd_HHMMSS.trace)
XCTRACE_TEMPLATE=name xctrace template (default: Time Profiler)
Expand All @@ -55,12 +55,12 @@ if ! xcrun --find xctrace >/dev/null 2>&1; then
fi

if [[ "${BUILD_MBT}" == "1" ]]; then
echo "Building tinycc.mbt (${TINYCC_MBT_BIN})"
echo "Building fastcc.mbt (${TINYCC_MBT_BIN})"
moon build --release --target native src
fi

if [[ ! -x "${TINYCC_MBT_BIN}" ]]; then
echo "error: tinycc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
echo "error: fastcc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
exit 1
fi

Expand Down Expand Up @@ -228,7 +228,7 @@ def collect_counts(leaf_only):
if f is None:
continue
fid = f.get("id") or f.get("ref")
if frame_binary_name.get(fid) != "tinycc.exe":
if frame_binary_name.get(fid) != "fastcc.exe":
continue
name = f.get("name") or "<unknown>"
counts[name] += 1
Expand All @@ -238,11 +238,11 @@ inclusive = collect_counts(leaf_only=False)
leaf = collect_counts(leaf_only=True)

lines = []
lines.append("Top inclusive frames (tinycc.exe):")
lines.append("Top inclusive frames (fastcc.exe):")
for name, count in inclusive.most_common(20):
lines.append(f"{count:4d} {name}")
lines.append("")
lines.append("Top leaf frames (tinycc.exe):")
lines.append("Top leaf frames (fastcc.exe):")
for name, count in leaf.most_common(20):
lines.append(f"{count:4d} {name}")

Expand Down
16 changes: 8 additions & 8 deletions scripts/run_mbtcc_ctest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CTEST_DIR="${ROOT_DIR}/refs/mbtcc/ctest"
LOCAL_CTEST_DIR="${ROOT_DIR}/tests/mbtcc/ctest"
TMP_DIR="${ROOT_DIR}/target/mbtcc-ctest"
SUPPORT_C="${ROOT_DIR}/tests/mbtcc/ctest_support.c"
BOOTSTRAP_TINYCC_BIN="${TINYCC_BIN:-${ROOT_DIR}/_build/native/release/build/tinycc.exe}"
BOOTSTRAP_TINYCC_BIN="${TINYCC_BIN:-${ROOT_DIR}/_build/native/release/build/fastcc.exe}"
TINYCC_BUILD_TARGET="${TINYCC_BUILD_TARGET:-${ROOT_DIR}/src}"
SELFHOST="${SELFHOST:-0}"
SELFHOST_BIN="${SELFHOST_BIN:-${ROOT_DIR}/target/selfhost/tcc_selfhost}"
Expand All @@ -33,18 +33,18 @@ Usage:
Env vars:
FILTER=regex Run only tests whose filename matches regex (grep -E).
MODE=strict|allow-fail
SELFHOST=1 Build refs/tinycc with tinycc.mbt and run tests via tcc_selfhost.
SELFHOST=1 Build refs/tinycc with fastcc.mbt and run tests via tcc_selfhost.
TINYCC_BIN=path Bootstrap compiler path (used to build tcc_selfhost in SELFHOST mode).
SELFHOST_BIN=path Override tcc_selfhost path.
QUICKJS=0|1 Compile refs/quickjs/quickjs.c with tinycc.mbt (default: 1).
QUICKJS_TESTS=0|1 Run quickjs JS smoke tests using a qjs built by tinycc.mbt (default: 1).
QUICKJS=0|1 Compile refs/quickjs/quickjs.c with fastcc.mbt (default: 1).
QUICKJS_TESTS=0|1 Run quickjs JS smoke tests using a qjs built by fastcc.mbt (default: 1).
QUICKJS_TEST_LIST=... Space-separated test list (paths relative to refs/quickjs).
QUICKJS_TINYCC_BIN=path Compiler used for quickjs build (default: bootstrap tinycc.mbt).
QUICKJS_TINYCC_BIN=path Compiler used for quickjs build (default: bootstrap fastcc.mbt).

This runs mbtcc's C file tests (refs/mbtcc/ctest/*.c) against tinycc.mbt:
This runs mbtcc's C file tests (refs/mbtcc/ctest/*.c) against fastcc.mbt:
- also includes local tests in tests/mbtcc/ctest (if present)
- expected output: gcc
- actual output: tinycc.mbt (-c -> .o) + clang link -> run
- actual output: fastcc.mbt (-c -> .o) + clang link -> run
EOF
}

Expand Down Expand Up @@ -441,7 +441,7 @@ EOF
continue
fi
if ! "${TMP_DIR}/${base}.tinycc.out" >"${actual_file}"; then
echo "FAILED: tinycc.mbt run failed"
echo "FAILED: fastcc.mbt run failed"
fail=$((fail + 1))
continue
fi
Expand Down
10 changes: 5 additions & 5 deletions scripts/run_mbtcc_ctest2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ CTEST_DIR="${ROOT_DIR}/refs/mbtcc/ctest2"
TMP_DIR="${ROOT_DIR}/target/mbtcc-ctest2"
EXTRA_HDR="${ROOT_DIR}/tests/mbtcc/extra.h"
PATCH_DIR="${ROOT_DIR}/tests/mbtcc/ctest2_patches"
BOOTSTRAP_TINYCC_BIN="${TINYCC_BIN:-${ROOT_DIR}/_build/native/release/build/tinycc.exe}"
BOOTSTRAP_TINYCC_BIN="${TINYCC_BIN:-${ROOT_DIR}/_build/native/release/build/fastcc.exe}"
TINYCC_BUILD_TARGET="${TINYCC_BUILD_TARGET:-${ROOT_DIR}/src}"
SELFHOST="${SELFHOST:-0}"
SELFHOST_BIN="${SELFHOST_BIN:-${ROOT_DIR}/target/selfhost/tcc_selfhost}"
Expand All @@ -25,13 +25,13 @@ Usage:
Env vars:
FILTER=regex Run only tests whose filename matches regex (grep -E).
MODE=strict|allow-fail
SELFHOST=1 Build refs/tinycc with tinycc.mbt and run tests via tcc_selfhost.
SELFHOST=1 Build refs/tinycc with fastcc.mbt and run tests via tcc_selfhost.
TINYCC_BIN=path Bootstrap compiler path (used to build tcc_selfhost in SELFHOST mode).
SELFHOST_BIN=path Override tcc_selfhost path.

This runs mbtcc's second C test suite (refs/mbtcc/ctest2/*.c) against tinycc.mbt:
This runs mbtcc's second C test suite (refs/mbtcc/ctest2/*.c) against fastcc.mbt:
- expected output: gcc
- actual output: tinycc.mbt (-c -> .o) + clang link -> run
- actual output: fastcc.mbt (-c -> .o) + clang link -> run
EOF
}

Expand Down Expand Up @@ -189,7 +189,7 @@ EOF
continue
fi
if ! "${TMP_DIR}/${base}.tinycc.out" >"${actual_file}"; then
echo "FAILED: tinycc.mbt run failed"
echo "FAILED: fastcc.mbt run failed"
fail=$((fail + 1))
continue
fi
Expand Down
12 changes: 6 additions & 6 deletions scripts/run_sqlite_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ set -euo pipefail
ROOT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." && pwd)"
SQLITE_SRC="${ROOT_DIR}/refs/sqlite"
SQLITE_BUILD_DIR="${SQLITE_BUILD_DIR:-${ROOT_DIR}/target/sqlite_build}"
TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/tinycc.exe}"
TINYCC_MBT_BIN="${TINYCC_MBT_BIN:-${ROOT_DIR}/_build/native/release/build/fastcc.exe}"
BUILD_MBT="${BUILD_MBT:-1}"
SQLITE_TESTS="${SQLITE_TESTS:-1}"
SQLITE_TEST_LIST="${SQLITE_TEST_LIST:-test/veryquick.test}"
Expand Down Expand Up @@ -45,8 +45,8 @@ Env vars:
TCL_CONFIG_SH=path Path to tclConfig.sh (auto-detected if unset)
SQLITE_PATCH=path Optional patch to apply to refs/sqlite before tests
MAKE_ASSUME_OLD="..." Space-separated make targets to treat as up-to-date when building testfixture
BUILD_MBT=0|1 Build tinycc.mbt before compiling sqlite3.c (default: 1)
TINYCC_MBT_BIN=path Path to tinycc.mbt executable
BUILD_MBT=0|1 Build fastcc.mbt before compiling sqlite3.c (default: 1)
TINYCC_MBT_BIN=path Path to fastcc.mbt executable
EOF
}

Expand Down Expand Up @@ -124,12 +124,12 @@ if [[ -z "${TCL_CONFIG_SH}" || ! -f "${TCL_CONFIG_SH}" ]]; then
fi

if [[ "${BUILD_MBT}" == "1" ]]; then
echo "Building tinycc.mbt (${TINYCC_MBT_BIN})"
echo "Building fastcc.mbt (${TINYCC_MBT_BIN})"
moon build --release --target native src
fi

if [[ ! -x "${TINYCC_MBT_BIN}" ]]; then
echo "error: tinycc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
echo "error: fastcc.mbt executable missing at ${TINYCC_MBT_BIN}" >&2
exit 1
fi

Expand Down Expand Up @@ -203,7 +203,7 @@ SQLITE_INCLUDES=(
-I "${SQLITE_SRC}/ext/misc"
)

echo "Compiling sqlite3.c with tinycc.mbt"
echo "Compiling sqlite3.c with fastcc.mbt"
"${TINYCC_MBT_BIN}" \
"${SQLITE_CFLAGS[@]}" \
"${SQLITE_INCLUDES[@]}" \
Expand Down
3 changes: 3 additions & 0 deletions src/backend/arm64/moon.pkg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import {
"hackwaly/fastcc/backend/object",
}
5 changes: 0 additions & 5 deletions src/backend/arm64/moon.pkg.json

This file was deleted.

4 changes: 2 additions & 2 deletions src/backend/arm64/pkg.generated.mbti
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Generated using `moon info`, DON'T EDIT IT
package "hackwaly/tinycc/backend/arm64"
package "hackwaly/fastcc/backend/arm64"

import {
"hackwaly/tinycc/backend/object",
"hackwaly/fastcc/backend/object",
}

// Values
Expand Down
Loading