|
| 1 | +# AGENTS.md — Guide for AI Coding Agents |
| 2 | + |
| 3 | +This file helps AI coding agents (Claude Code, Kiro, Copilot, etc.) work |
| 4 | +effectively with this codebase. |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Project Overview |
| 9 | + |
| 10 | +**EBMC** (Enhanced Bounded Model Checker) is a formal verification tool for |
| 11 | +hardware designs. It verifies LTL (Linear Temporal Logic) properties and |
| 12 | +SystemVerilog Assertions (SVA) against hardware circuits described in: |
| 13 | + |
| 14 | +- Verilog 2005 / SystemVerilog 2017 |
| 15 | +- NuSMV (`.smv` files) |
| 16 | +- ISCAS89 netlist format |
| 17 | + |
| 18 | +The companion tool **hw-cbmc** generates C software interfaces for hardware |
| 19 | +designs, enabling software model checking of hardware/software systems. |
| 20 | + |
| 21 | +This codebase is a C++17 project. It depends on **CBMC** (as a git submodule |
| 22 | +at `lib/cbmc/`) and extends CBMC with hardware-specific functionality. |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## Repository Layout |
| 27 | + |
| 28 | +``` |
| 29 | +hw-cbmc/ |
| 30 | +├── src/ # All source code |
| 31 | +│ ├── ebmc/ # Main EBMC tool (entry point: main.cpp) |
| 32 | +│ ├── hw-cbmc/ # hw-cbmc tool (interface generation) |
| 33 | +│ ├── verilog/ # Verilog/SystemVerilog parser & type checker |
| 34 | +│ ├── vhdl/ # VHDL language support |
| 35 | +│ ├── smvlang/ # NuSMV model language support |
| 36 | +│ ├── temporal-logic/ # LTL and SVA handling |
| 37 | +│ ├── trans-word-level/ # Word-level transition system transformations |
| 38 | +│ ├── trans-netlist/ # Netlist transformations |
| 39 | +│ ├── aiger/ # AIGER format support |
| 40 | +│ ├── ic3/ # IC3 unbounded model checker |
| 41 | +│ ├── vlindex/ # Verilog indexer tool |
| 42 | +│ ├── util/ # Shared utility functions |
| 43 | +│ └── Makefile # Top-level build file for all tools |
| 44 | +├── regression/ # Regression test suites |
| 45 | +│ ├── ebmc/ # Tests for the EBMC engine |
| 46 | +│ ├── verilog/ # Tests for Verilog/SystemVerilog input |
| 47 | +│ ├── smv/ # Tests for SMV input |
| 48 | +│ └── vlindex/ # Tests for the Verilog indexer |
| 49 | +├── unit/ # Unit tests (built with `make -C unit`) |
| 50 | +├── lib/ |
| 51 | +│ └── cbmc/ # CBMC dependency (git submodule) |
| 52 | +└── .github/workflows/ # CI configuration |
| 53 | +``` |
| 54 | + |
| 55 | +--- |
| 56 | + |
| 57 | +## Building |
| 58 | + |
| 59 | +### Prerequisites |
| 60 | + |
| 61 | +- g++ 7.0+ or Clang 19+ |
| 62 | +- GNU Make 3.81+ |
| 63 | +- Flex and Bison |
| 64 | +- Z3 (optional, for SMT-based solving) |
| 65 | + |
| 66 | +### First-time setup |
| 67 | + |
| 68 | +```bash |
| 69 | +git submodule update --init |
| 70 | +make -C lib/cbmc/src minisat2-download |
| 71 | +make -C lib/cbmc/src cadical-download |
| 72 | +``` |
| 73 | + |
| 74 | +### Build all tools |
| 75 | + |
| 76 | +```bash |
| 77 | +make -C src |
| 78 | +# or parallel: |
| 79 | +make -C src -j4 |
| 80 | +``` |
| 81 | + |
| 82 | +Compiled binaries: |
| 83 | +- `src/ebmc/ebmc` |
| 84 | +- `src/hw-cbmc/hw-cbmc` |
| 85 | +- `src/vlindex/vlindex` |
| 86 | + |
| 87 | +### Incremental builds |
| 88 | + |
| 89 | +Each subdirectory has its own Makefile. You can rebuild a single component: |
| 90 | + |
| 91 | +```bash |
| 92 | +make -C src/verilog |
| 93 | +``` |
| 94 | + |
| 95 | +--- |
| 96 | + |
| 97 | +## Testing |
| 98 | + |
| 99 | +### Unit tests |
| 100 | + |
| 101 | +```bash |
| 102 | +make -C unit |
| 103 | +``` |
| 104 | + |
| 105 | +### Regression tests |
| 106 | + |
| 107 | +```bash |
| 108 | +make -C regression/ebmc test # SAT-based |
| 109 | +make -C regression/ebmc test-z3 # Z3-based |
| 110 | + |
| 111 | +make -C regression/verilog test |
| 112 | +make -C regression/verilog test-z3 |
| 113 | + |
| 114 | +make -C regression/smv test |
| 115 | +make -C regression/smv test-z3 |
| 116 | +make -C regression/vlindex test |
| 117 | +``` |
| 118 | + |
| 119 | +Run all regression tests (matches CI): |
| 120 | + |
| 121 | +```bash |
| 122 | +make -C regression/ebmc test test-z3 |
| 123 | +make -C regression/verilog test test-z3 |
| 124 | +make -C regression/smv test test-z3 |
| 125 | +make -C regression/vlindex test |
| 126 | +``` |
| 127 | + |
| 128 | +### Test descriptor format |
| 129 | + |
| 130 | +Regression tests use `.desc` files. Example: |
| 131 | + |
| 132 | +``` |
| 133 | +CORE buechi |
| 134 | +case1.sv |
| 135 | +--buechi --bound 20 --numbered-trace |
| 136 | +^\[main\.p0\] always \(.*\): REFUTED$ |
| 137 | +^Counterexample with 11 states:$ |
| 138 | +^EXIT=10$ |
| 139 | +^SIGNAL=0$ |
| 140 | +``` |
| 141 | + |
| 142 | +Fields: |
| 143 | +1. Test category (`CORE`, `KNOWNBUG`, `FUTURE`) |
| 144 | +2. Input file |
| 145 | +3. Command-line arguments |
| 146 | +4. Expected output lines (regex, anchored with `^`) |
| 147 | +5. `EXIT=N` — expected exit code |
| 148 | +6. `SIGNAL=0` — expected signal |
| 149 | + |
| 150 | +`KNOWNBUG` tests are known failures and are skipped. `FUTURE` tests are |
| 151 | +planned but not yet implemented. |
| 152 | + |
| 153 | +--- |
| 154 | + |
| 155 | +## Coding Conventions |
| 156 | + |
| 157 | +### Language standard |
| 158 | + |
| 159 | +C++17. |
| 160 | + |
| 161 | +### Formatting |
| 162 | + |
| 163 | +Configured via `.clang-format` (symlinked from CBMC). Always run |
| 164 | +`clang-format` on modified files. The CI enforces this via |
| 165 | +`.github/workflows/syntax-checks.yaml`. |
| 166 | + |
| 167 | +### Style rules |
| 168 | + |
| 169 | +- **Indentation:** 2 spaces, no tabs |
| 170 | +- **Line length:** 80 columns |
| 171 | +- **Pointer/reference alignment:** right-aligned (`int *p`, `int &r`) |
| 172 | +- **Brace style:** Allman (opening brace on its own line) |
| 173 | +- **Naming:** |
| 174 | + - Class names end with `t`: `verilog_typecheckt`, `ebmc_parse_optionst` |
| 175 | + - Include guards: `CPROVER_<DIRECTORY>_<FILE>_H` (all caps) |
| 176 | + - Free functions and methods: lowercase with underscores |
| 177 | + - Use `PRECONDITION(...)` and `POSTCONDITION(...)` from `<util/invariant.h>` |
| 178 | + |
| 179 | +### File header template |
| 180 | + |
| 181 | +```cpp |
| 182 | +/*******************************************************************\ |
| 183 | +
|
| 184 | +Module: <Module Name> |
| 185 | +
|
| 186 | +Author: <Name>, <email> |
| 187 | +
|
| 188 | +\*******************************************************************/ |
| 189 | +``` |
| 190 | + |
| 191 | +### Include guards |
| 192 | + |
| 193 | +```cpp |
| 194 | +#ifndef CPROVER_VERILOG_VERILOG_TYPECHECK_H |
| 195 | +#define CPROVER_VERILOG_VERILOG_TYPECHECK_H |
| 196 | +// ... |
| 197 | +#endif // CPROVER_VERILOG_VERILOG_TYPECHECK_H |
| 198 | +``` |
| 199 | + |
| 200 | +### IREP / expression conventions |
| 201 | + |
| 202 | +This codebase uses CBMC's `irept`/`exprt`/`typet` IR. Key points: |
| 203 | +- Custom IREP IDs are declared in `src/hw_cbmc_irep_ids.h` |
| 204 | +- Use `.get(ID_...)`, `.set(ID_...)` for IREP attribute access |
| 205 | +- Prefer typed accessors (`to_symbol_expr(...)`, etc.) over raw casts |
| 206 | + |
| 207 | +--- |
| 208 | + |
| 209 | +## Key Architectural Concepts |
| 210 | + |
| 211 | +- **Transition system:** A hardware design is represented as a transition |
| 212 | + system with initial states, a state-space type, and a transition relation. |
| 213 | + See `src/trans-word-level/` and `src/trans-netlist/`. |
| 214 | +- **Netlist:** A Boolean gate-level representation. The `aig_` prefix |
| 215 | + indicates And-Inverter Graph nodes. |
| 216 | +- **BMC:** Bounded model checking unrolls the transition relation for |
| 217 | + `--bound N` steps and hands the formula to a SAT/SMT solver. |
| 218 | +- **Buechi:** LTL is converted to a Buechi automaton and combined with the |
| 219 | + design for liveness property checking. |
| 220 | +- **IC3/PDR:** Unbounded model checking via `src/ic3/`. |
| 221 | +- **SVA:** SystemVerilog Assertions are parsed by the Verilog front-end and |
| 222 | + lowered to temporal logic. See `src/temporal-logic/`. |
| 223 | + |
| 224 | +--- |
| 225 | + |
| 226 | +## Dependencies on CBMC |
| 227 | + |
| 228 | +`lib/cbmc/` is a git submodule. Never edit files inside `lib/cbmc/` — changes |
| 229 | +must go to the upstream CBMC repository. When CBMC is updated, run: |
| 230 | + |
| 231 | +```bash |
| 232 | +git submodule update |
| 233 | +make -C src |
| 234 | +``` |
| 235 | + |
| 236 | +The build system automatically links against CBMC libraries including |
| 237 | +`util`, `solvers`, `big-int`, and language modules. |
| 238 | + |
| 239 | +--- |
| 240 | + |
| 241 | +## Git Conventions |
| 242 | + |
| 243 | +Commit message style from recent history: |
| 244 | + |
| 245 | +``` |
| 246 | +Component: Brief imperative description |
| 247 | +
|
| 248 | +Longer explanation if needed. Reference IEEE 1800-2017 sections when |
| 249 | +relevant (e.g., "Per 1800-2017 section A.9.3, ..."). |
| 250 | +``` |
| 251 | + |
| 252 | +Examples: |
| 253 | +- `Verilog: package-scoped function calls` |
| 254 | +- `SMV: support for range types in module parameters` |
| 255 | +- `KNOWNBUG test for function and task in a package` |
| 256 | + |
| 257 | +Branch names follow `username/short-description` and are submitted as |
| 258 | +GitHub pull requests against `main`. |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | +## CI |
| 263 | + |
| 264 | +GitHub Actions workflows (`.github/workflows/`): |
| 265 | + |
| 266 | +| Workflow | Trigger | What it does | |
| 267 | +|---|---|---| |
| 268 | +| `pull-request-checks.yaml` | PRs | Build + unit + regression tests (GCC & Clang) | |
| 269 | +| `syntax-checks.yaml` | PRs | `clang-format` check | |
| 270 | +| `ebmc-release.yaml` | Tags/manual | Release builds | |
| 271 | + |
| 272 | +The CI uses `ccache` for faster incremental builds. |
| 273 | + |
| 274 | +--- |
| 275 | + |
| 276 | +## Common Tasks |
| 277 | + |
| 278 | +### Add a new Verilog language feature |
| 279 | + |
| 280 | +1. Extend the grammar in `src/verilog/verilog_parser.y` |
| 281 | +2. Regenerate with `make -C src/verilog` (runs Bison/Flex automatically) |
| 282 | +3. Add type-checking logic in `src/verilog/verilog_typecheck*.cpp` |
| 283 | +4. Add lowering/elaboration in `src/verilog/verilog_lowering.cpp` |
| 284 | +5. Add a regression test in `regression/verilog/` |
| 285 | + |
| 286 | +### Add a new temporal logic operator |
| 287 | + |
| 288 | +1. Extend the AST in `src/temporal-logic/` |
| 289 | +2. Update the conversion to automaton in `ltl_to_automaton.cpp` or SVA |
| 290 | + lowering in `sva_to_ltl.cpp` |
| 291 | +3. Add tests in `regression/verilog/SVA/` |
| 292 | + |
| 293 | +### Add a new EBMC command-line option |
| 294 | + |
| 295 | +1. Declare the option in `src/ebmc/ebmc_parse_options.h` |
| 296 | +2. Parse and dispatch in `src/ebmc/ebmc_parse_options.cpp` |
| 297 | +3. Implement in an appropriate engine file under `src/ebmc/` |
0 commit comments