# Code Style Guidelines **Author: Johannes Hofmann, Niklas Sirch 2025** ## Naming Conventions ```{list-table} Naming Conventions :header-rows: 1 * - Category - Convention - Example(s) - Notes * - Classes - `snake_case` - `c_peripheral_interface` - Use `c` for pure software classes. Use `c_soft_` prefix for SW version of HW modules. * - Variables - `snake_case` - `memory_size`, `base_address` - Start with lowercase, use snake_case. * - Methods/Functions - `snake_case` - `load_elf`, `write_peripheral` - Start with lowercase, use snake_case. * - Constants (Macros) - `UPPER_SNAKE_CASE` - `PN_MEMORY_SIZE_128K`, `CORE_TRACE_FILE` - All caps with underscores. * - SystemC Modules - `snake_case` with `m_` prefix - `m_alu`, `m_wb_uart` - Prefix `m` for hardware modules. * - SystemC Processes - `snake_case` with `proc_` prefix - `proc_clk`, `proc_cmb_iport` - Use `proc_` + `clk`/`cmb` + optional suffix. * - Enumerations (enum) - Type: `snake_case`
Values: `UPPER_SNAKE_CASE` - `e_memu_state`, `MEMU_IDLE` - Enum values must have a prefix to avoid name collisions. * - Config Options - `UPPER_SNAKE_CASE` with `CFG_` prefix - `CFG_REGFILE_SIZE`, `WB_UART_ADDR` - Used in `config.mk` / `piconut-config.h`. `CFG_` indicates processor config. ``` ## Formatting The project uses `clang-format` to format the code. The configuration is in `.clang-format`. It is highly recommended to follow these guidelines to ensure a consistent code style. You can use the VS-Code Extension `xaver.clang-format` or format with these commands. ```console $ # For single files use $ clang-format -i file.cpp $ # For all project files use $ git ls-files '*.[ch]' '*.[ch]pp' | xargs clang-format -i ```