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
2 changes: 1 addition & 1 deletion crates/celox-vpi/src/bin/celox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ fn run_sv(arguments: RunConfig) -> Result<(), String> {
simulate_sv(simulation, max_steps, &mut std::io::stdout().lock())
}};
}
match arguments.execution.backend {
match arguments.execution.backend() {
runner::Backend::Native => execute!(build),
runner::Backend::Cranelift => execute!(build_cranelift),
runner::Backend::Interpreter => execute!(build_interpreter),
Expand Down
33 changes: 28 additions & 5 deletions crates/celox-vpi/src/bin/celox/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ macro_rules! report {

#[derive(Args, Default)]
pub(super) struct ExecutionArgs {
#[arg(long, value_enum, default_value = "native")]
pub backend: Backend,
/// Defaults to `tiered`, or to `native` when an option needs native code
/// (compile-only, native images, the build cache or IR dumps) and in
/// cross-codegen builds.
#[arg(long, value_enum)]
backend: Option<Backend>,
#[arg(long)]
compile_only: bool,
/// Write a pointer-free native image during compile-only mode.
Expand Down Expand Up @@ -74,6 +77,26 @@ pub(super) struct ExecutionArgs {
}

impl ExecutionArgs {
pub(super) fn backend(&self) -> Backend {
self.backend.unwrap_or(
// A cross-codegen build only exports foreign native images.
if cfg!(any(
all(target_arch = "x86_64", feature = "arm64-codegen"),
all(target_arch = "aarch64", feature = "x86_64-codegen")
)) || self.compile_only
|| self.native_image_output.is_some()
|| self.native_image_input.is_some()
|| self.build_cache_dir.is_some()
|| self.dump_ir_dir.is_some()
|| self.dump_ir_and_run
{
Backend::Native
} else {
Backend::Tiered
},
)
}

#[cfg(feature = "systemverilog")]
pub(super) fn validate_sv(&self) -> Result<(), String> {
if self.compile_only
Expand Down Expand Up @@ -149,9 +172,8 @@ pub(super) enum RunError {
TestFailed { message: String },
}

#[derive(Clone, Copy, Default, PartialEq, ValueEnum)]
#[derive(Clone, Copy, PartialEq, ValueEnum)]
pub(super) enum Backend {
#[default]
Native,
Cranelift,
Interpreter,
Expand Down Expand Up @@ -182,6 +204,7 @@ pub(super) fn run(
design: super::project::Design,
max_steps: u64,
) -> Result<(), RunError> {
let backend = cli.backend();
let mut opts = Options {
report: cli.report,
require_compiled: cli.require_compiled,
Expand All @@ -194,7 +217,7 @@ pub(super) fn run(
}),
test: design.top.clone(),
opt_level: design.opt_level.unwrap_or(OptLevel::O2),
backend: cli.backend,
backend,
four_state: design.four_state.unwrap_or(false),
compile_only: cli.compile_only,
native_image_output: cli.native_image_output,
Expand Down
19 changes: 19 additions & 0 deletions crates/celox-vpi/tests/run_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,25 @@ fn veryl_backends_share_cli_execution_and_opt_in_reports() {
assert!(output.stdout.is_empty(), "{output:?}");
}

#[cfg(not(any(
all(target_arch = "x86_64", feature = "arm64-codegen"),
all(target_arch = "aarch64", feature = "x86_64-codegen")
)))]
#[test]
fn backend_defaults_to_tiered_unless_native_code_is_requested() {
let source =
"#[test(Top)] module Top { inst clk: $tb::clock_gen; initial { clk.next(4); $finish(); } }";
let output = run(&[("top.veryl", source)], &["--report"]);
assert!(output.status.success(), "{output:?}");
let report = String::from_utf8(output.stdout).unwrap();
assert!(report.contains("backend=tiered "), "{report}");

let output = run(&[("top.veryl", source)], &["--report", "--compile-only"]);
assert!(output.status.success(), "{output:?}");
let report = String::from_utf8(output.stdout).unwrap();
assert!(report.contains("backend=native "), "{report}");
}

#[cfg(feature = "systemverilog")]
#[test]
fn sv_defaults_to_two_state_and_four_state_is_explicit() {
Expand Down
3 changes: 2 additions & 1 deletion docs/guide/cocotb.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ clock limit is needed. `--unlimited` removes the step/tick limit. Source languag

`celox run` accepts `--threads N` (1–64, default 1) and `--four-state` for both
languages. Both languages support `--backend native|tiered|interpreter|cranelift|wasm`
(default: native). Tiered starts interpreted and adopts compiled code at a scheduler
(default: tiered; native when `--compile-only`, a native image, `--build-cache-dir` or an
IR dump is requested). Tiered starts interpreted and adopts compiled code at a scheduler
safe point while preserving pending events. For example:

```sh
Expand Down
Loading