This document contains important information for developers working on the Verilua project.
Parts of the Verilua codebase are auto-generated. DO NOT edit these files directly as any modifications will be overwritten when the generation scripts are run.
The scheduler files are auto-generated.
Verilua requires multiple scheduler variants to support different simulation modes and performance optimizations:
- NORMAL mode: Standard simulation with time-based scheduling
- STEP mode: Fixed-period step simulation
- EDGE_STEP mode: Edge-triggered simulation with separate posedge/negedge handling
Each mode has two variants - with and without performance profiling (P suffix). This specialization eliminates runtime conditionals and optimizes memory usage by including only mode-specific code.
To modify scheduler files:
- Edit the generator:
src/gen/gen_scheduler.lua - Run the generation script:
cd src/gen && ./gen_scheduler.sh
The following files are generated (in src/lua/verilua/scheduler/):
LuaNormalSchedulerV2.luaLuaNormalSchedulerV2P.luaLuaStepSchedulerV2.luaLuaStepSchedulerV2P.luaLuaEdgeStepSchedulerV2.luaLuaEdgeStepSchedulerV2P.lua
The CHDL access files are auto-generated.
They are split into three variants (Single, Double, Multi) to match the different widths of hardware signals that Verilua needs to drive from Lua:
Single– 1–32-bit signalsDouble– 33–64-bit signalsMulti– wider than 64-bit signals
This separation keeps the generated Lua glue code minimal and fast: each variant inlines the exact bit-width it needs, avoiding runtime width checks and letting the JIT specialize on the concrete type.
If you need to change how Lua talks to CHDL (e.g., add a new bit-width, change the FFI signatures, or tweak the callback policy) you edit the single generator instead of touching any of the three hand-tuned files.
To modify CHDL access files:
- Edit the generator:
src/gen/gen_chdl_access.lua - Run the generation script:
cd src/gen && ./gen_chdl_access.sh
The following files are generated (in src/lua/verilua/handles/):
ChdlAccessSingle.luaChdlAccessDouble.luaChdlAccessMulti.lua
Some Rust files are auto-generated.
To modify generated Rust files:
- Edit the generator:
libverilua/src/gen/gen.lua - Run the generation script:
cd libverilua/src/gen && luajit gen.lua
The following files are generated (in libverilua/src/gen/):
gen_callback_policy.rsgen_register_callback_func.rsgen_verilua_env_struct.rsgen_verilua_env_init.rsgen_sim_event_chunk_init.rs
Important: When adding or implementing any new feature, please include relevant tests to ensure correctness and avoid future breakage.
Running comprehensive test suite:
xmake run test- Run complete test suite including all example projects(This may take a few minutes to complete!)- This command automatically detects available simulators and runs tests on all found simulators
Running Lua unit tests:
cd tests
xmake run -P . test_all- Run single test file:
cd tests
luajit test_lua_utils.lua --stop-on-fail --no-quiet
# or simply
luajit test_lua_utils.luaRunning integration tests:
To run tests in a specific test directory:
cd tests/test_basic_signal
xmake build -P .
xmake run -P .Or from the project root directory:
xmake build -P tests/test_basic_signal
xmake run -P tests/test_basic_signalEnvironment variables:
SIMenvironment variable specifies the supported simulator (verilator/iverilog/vcs)- Example:
SIM=iverilog xmake run -P tests/test_basic_signal