Generated: 2026-03-10 Commit: ccb5391 Branch: main
C++ compiler (C++20) targeting a C-like language → RISC-V assembly. Contains a separate Rust-based deductive prover (cierra/) for formal verification of annotated programs.
SimpleCompiler/
├── src/ # C++ compiler source (pipeline: scan→lex→parse→typecheck→IR→codegen)
│ ├── include/ # 20 headers; common.h is the hub that includes everything
│ ├── codegen/ # RISC-V assembly generation
│ ├── ir/ # IR generation, parsing, low-level IR
│ ├── lexical/ # Lexer + token definitions
│ ├── parser/ # Recursive descent parser → AST
│ ├── scanner/ # File I/O scanner
│ ├── typechecker/ # Semantic analysis + type checking
│ ├── error/ # Error reporting
│ └── test/ # Test input files (.c)
├── cierra/ # Rust workspace: deductive prover (independent from C++ compiler)
├── cmake/ # CMake modules: deps (CPM), compile config, coverage functions
├── test/ # GTest unit/system tests (mostly commented out)
├── doc/ # Doxygen documentation
└── tools/ # cppcheck suppression config
| Task | Location | Notes |
|---|---|---|
| Add language construct | src/parser/, src/include/ast.h, src/typechecker/ |
Parser→AST→TypeCheck chain |
| Modify code generation | src/codegen/codegen.cpp |
Outputs RISC-V assembly |
| Change IR representation | src/ir/, src/include/ir.h, src/include/irast.h |
Two-level IR: high IR → low IR |
| Token/keyword changes | src/include/token.h, src/lexical/ |
tag_t enum + keywords_t class |
| Add type support | src/include/type.h, src/typechecker/ |
Currently int-only (see TODOs) |
| Build configuration | cmake/compile_config.cmake, CMakePresets.json |
C17/C++20 enforced |
| Third-party deps | cmake/3rd.cmake |
CPM-based: googletest, spdlog, PackageProject |
| Formal verification | cierra/ |
Entirely separate Rust project |
| CI pipeline | .github/workflows/test.yml |
Rust-only — no C++ CI jobs |
- Code style: LLVM via
.clang-format; extensive.clang-tidychecks enabled - Out-of-source builds only: CMake enforces
build/directory; in-source builds are fatal - Comments in Chinese: Inline comments and CMake comments are predominantly in Chinese (中文)
- Doxygen headers: Every source file has a standard doxygen comment block (file, brief, author, date, copyright)
- Header guard style:
SIMPLECOMPILER_<FILENAME>_H(not#pragma once) - Global state:
Error *errorandstd::vector<std::string> src_filesare globals inmain.cpp - Smart pointers for AST:
using ASTPtr = std::unique_ptr<MetaAST>throughout - Logging: All pipeline stages log via
SPDLOG_LOGGER_INFO(SCLOG, ...)— spdlog required
- Type system is int-only: Multiple
// TODO: 只支持 intin parser.cpp — do not assume multi-type support - Test subdirectories commented out:
test/CMakeLists.txthasadd_subdirectorycalls commented out - References SimpleRenderer:
test/CMakeLists.txtuses${SimpleRenderer_SOURCE_DIR}— likely a copy-paste bug - No C++ CI: GitHub Actions workflow only builds/tests Rust (
cierra/), not the C++ compiler
# Build C++ compiler
mkdir build && cd build
cmake --preset build ..
cmake --build .
# Run compiler
./build/bin/SimpleCompiler <input.c> -o 1 # -o 1 = lexical output
./build/bin/SimpleCompiler -h # help
# Code quality
make clang-format # format all source
make clang-tidy # lint all source
make cppcheck # static analysis
make coverage # test coverage report (lcov + genhtml)
# Cierra (Rust prover) — run from cierra/
cargo build
cargo test
cargo run -- <file> <function_symbol>- Compilation pipeline in
main.cppis linear per-file: Scanner→Lexer→Parser→TypeCheck→IRGenerator→IRParser→LowIRGenerator→CodeGen - IR is stringified between stages (IRGenerator outputs string, IRParser re-parses it) — not a direct AST pass
common.his a "god header" that includes all 19 other headers — any header change triggers full recompile- The
cierra/Rust project and C++ compiler share no code; they are co-located but independent