Cyclone is a safe dialect of C. It is designed to prevent buffer overflows, format string attacks, and memory management errors that are common in C programs, while retaining C's syntax and low-level control.
This repository contains the source code for the Cyclone compiler, a self-hosting, source-to-source compiler that translates Cyclone code into C.
The project uses Bazel for its build system.
To build the entire project:
bazel build //cyclone/...To run the test suite:
bazel test //testsuite/...library/: Contains the core compiler source code and standard libraries.library/compiler/: The Cyclone compiler implementation (written in Cyclone).library/banshee/: Constraint solver used for flow analysis.library/std/: The Cyclone standard library.
testsuite/: Comprehensive test suite for the compiler.tools/: various utilities.build_defs.bzl: Custom Bazel definitions for the Cyclone build process.
The Cyclone compiler follows a classic multi-pass architecture but utilizes a mutable AST design where passes often modify the Abstract Syntax Tree in place.
- Parsing: Uses
bison(parse.cyy) and a custom lexer (lex.cyl) to produce an AST. - Semantic Analysis: A modular type-checking system (
tc*.cyc) traverses the AST, enforcing Cyclone's advanced type rules (regions, pointers, effects). It relies on the Banshee constraint solver. - Transformation/Lowering: Several passes transform the AST to simplify it (e.g.,
remove_aggregates.cyc,lower.cyc). - Code Generation: The
toc.cycpass translates the Cyclone AST into a C AST, which is then emitted as C code.
See the library/compiler directory for more details on the compiler internals.