Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,15 @@ jobs:
cargo test --locked -p celox-test-suite --features "$VERIFY_TOOL"
--test oracles -- --ignored

# The VPI host's time-step regions against Icarus, through the same
# cocotb test module, with the locked cocotb and Icarus versions.
- name: Cross-check cocotb time-step regions against Icarus
if: matrix.suite == 'sv' && matrix.tool == 'icarus'
run: >-
nix develop "$VERIFY_SHELL" --no-update-lock-file --command
cargo test --locked -p celox-vpi --features systemverilog
--test cocotb_e2e icarus_and_celox_agree_on_dut_processes -- --ignored --exact

- name: Catalogue every shared case
if: ${{ !cancelled() }}
run: |
Expand Down
67 changes: 48 additions & 19 deletions crates/celox-vpi/src/bin/celox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ use std::{
};

use celox::{
NativeProgramImage, NativeProgramInstance, StateDifference, StateFile, StateObject, StateRole,
format_state_value,
NativeProgramImage, StateDifference, StateFile, StateObject, StateRole, format_state_value,
};
use clap::{Args, CommandFactory, FromArgMatches, Parser, Subcommand};

Expand Down Expand Up @@ -395,27 +394,60 @@ fn build(arguments: BuildArgs) -> Result<(), String> {
Ok(())
}

/// The SystemVerilog compilation options of `design`.
#[cfg(feature = "systemverilog")]
fn configure_sv<'a, T>(
design: &'a Design,
builder: celox::SimulatorBuilder<'a, T>,
) -> celox::SimulatorBuilder<'a, T> {
let builder = builder
.four_state(design.four_state.unwrap_or(false))
.diagnostic_policy(design.diagnostics.clone())
.sv_timescale(design.timescale)
.signal_access(design.signal_access.clone())
.opt_level(design.opt_level.unwrap_or(celox::OptLevel::O1));
design.apply_parameters(builder)
}

fn compile_native_design(design: &Design) -> Result<NativeProgramImage, String> {
if design.is_sv() {
#[cfg(feature = "systemverilog")]
{
let sources = design.sv_sources()?;
let refs = sources
let refs: Vec<_> = sources
.iter()
.map(|(text, path)| (text.as_str(), path.as_path()))
.collect();
let builder = celox::Simulator::from_sv_sources(refs, &design.top)
.four_state(design.four_state.unwrap_or(false))
.diagnostic_policy(design.diagnostics.clone())
.sv_timescale(design.timescale)
.signal_access(design.signal_access.clone())
.opt_level(design.opt_level.unwrap_or(celox::OptLevel::O1));
let simulator = design
.apply_parameters(builder)
.compile_native()
.map_err(|error| format!("compilation failed:\n{error}"))?;
report_warnings(simulator.warnings())?;
return Ok(simulator.into_program_image());
let untimed = configure_sv(
design,
celox::Simulator::from_sv_sources(refs.clone(), &design.top),
)
.compile_native();
let image = match untimed {
Ok(simulator) => {
report_warnings(simulator.warnings())?;
simulator.into_program_image()
}
// A design with processes runs as a timed simulation, in step
// with the VPI time callbacks.
Err(error)
if matches!(
error.kind(),
celox::SimulatorErrorKind::ProcessRequiresSimulation(_)
) =>
{
let simulation = configure_sv(
design,
celox::Simulation::from_sv_sources(refs, &design.top),
)
.compile_native()
.map_err(|error| format!("compilation failed:\n{error}"))?;
report_warnings(simulation.warnings())?;
simulation.into_program_image()
}
Err(error) => return Err(format!("compilation failed:\n{error}")),
};
return Ok(image);
}
#[cfg(not(feature = "systemverilog"))]
return Err(
Expand Down Expand Up @@ -690,10 +722,7 @@ fn run_simulation(image: NativeProgramImage, arguments: SimulationArgs) -> Resul
}
set_environment("COCOTB_RESULTS_FILE", &results_file);

// Safety: the image is compiler-produced data attached to this executable.
let instance = unsafe { NativeProgramInstance::from_image(image) }
.map_err(|error| format!("failed to load attached design: {error}"))?;
celox_vpi::driver::run_cocotb(instance, &vpi)?;
celox_vpi::driver::run_cocotb_image(image, &vpi)?;
check_results(&python, &results_file)
}

Expand Down
Loading
Loading