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
83 changes: 79 additions & 4 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,86 @@ pub struct TriggerSet<A> {
pub resets: Vec<A>,
}

#[derive(Clone, Copy, Debug, Serialize, Deserialize)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub enum RuntimeEventKind {
Display,
Write,
AssertContinue,
AssertFatal,
/// A message of a severity task, or of a Veryl assertion
/// (IEEE 1800-2023 20.10). [`Severity::Fatal`] ends the simulation with
/// an error.
Report(Severity),
/// `$finish` executed by the design (IEEE 1800-2023 20.2).
Finish,
/// `$stop` executed by the design (IEEE 1800-2023 20.2).
Stop,
Comment thread
tignear marked this conversation as resolved.
Resolved
}

impl RuntimeEventKind {
/// A report that ends the simulation with an error.
pub fn is_fatal(self) -> bool {
self == Self::Report(Severity::Fatal)
}
}

/// The severity of a report (IEEE 1800-2023 20.10).
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
pub enum Severity {
/// `$info`: a message of no specific severity.
Info,
/// `$warning`.
Warning,
/// `$error`, and the default action of a failed `assert` or `assume`.
Error,
/// `$fatal`.
Fatal,
}

/// Where a report is written: the file and line of `__FILE__` and
/// `__LINE__` at the task call (IEEE 1800-2023 20.10).
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ReportLocation {
pub file: String,
pub line: usize,
}

/// The assertion whose action block issues a report.
#[derive(Clone, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct AssertionSite {
/// The statement label, which names the assertion within its scope
/// (IEEE 1800-2023 16.3).
pub label: Option<String>,
pub directive: AssertionDirective,
pub deferral: AssertionDeferral,
pub outcome: AssertionOutcome,
}

#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AssertionDirective {
Assert,
Assume,
Cover,
}

/// When an assertion reports (IEEE 1800-2023 16.4).
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AssertionDeferral {
/// A simple immediate assertion: at once.
None,
/// `#0`: in the Reactive region.
Observed,
/// `final`: in the Postponed region.
Final,
}

/// Which action block of an assertion issues a report.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum AssertionOutcome {
/// The pass action, or the statement of a `cover`.
Pass,
/// The fail action.
Fail,
}

/// How a runtime event site sizes its formatted arguments.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
pub enum DisplaySizing {
Expand All @@ -118,6 +186,11 @@ pub struct RuntimeEventSite {
pub sizing: DisplaySizing,
/// Fully elaborated module-instance scope that emitted this event.
pub scope: Option<String>,
#[serde(default)]
pub location: Option<ReportLocation>,
/// The assertion whose action issues this report.
#[serde(default)]
pub assertion: Option<AssertionSite>,
pub arg_widths: Vec<usize>,
pub arg_signed: Vec<bool>,
pub arg_is_string: Vec<bool>,
Expand Down Expand Up @@ -1883,10 +1956,12 @@ mod tests {
let mut runtime = RuntimeSchema::default();
runtime.runtime_errors.insert(1, error.clone());
runtime.runtime_event_sites.push(RuntimeEventSite {
kind: RuntimeEventKind::AssertFatal,
kind: RuntimeEventKind::Report(Severity::Fatal),
template: Some("failed".to_string()),
sizing: DisplaySizing::Veryl,
scope: None,
location: None,
assertion: None,
arg_widths: Vec::new(),
arg_signed: Vec::new(),
arg_is_string: Vec::new(),
Expand Down
20 changes: 9 additions & 11 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
&unpacked_element_widths,
)?;
for (site_id, site) in runtime_event_sites.iter().enumerate() {
if !matches!(site.kind, RuntimeEventKind::AssertFatal) {
if !site.kind.is_fatal() {
continue;
}
runtime_errors
Expand Down Expand Up @@ -4224,11 +4224,10 @@ fn build_comb_observer_capture_paths(
| RuntimeEventKind::Finish
| RuntimeEventKind::Stop
);
let fatal_error_code = matches!(
sites[observer.site_id as usize].kind,
RuntimeEventKind::AssertFatal
)
.then_some(observer.site_id as i64);
let fatal_error_code = sites[observer.site_id as usize]
.kind
.is_fatal()
.then_some(observer.site_id as i64);
let pre_lower_nodes = observer_pre_lower_nodes(observer, arena);
for idx in &order_after {
comb_blocks[idx.0]
Expand Down Expand Up @@ -4281,11 +4280,10 @@ fn build_comb_observer_capture_paths(
| RuntimeEventKind::Finish
| RuntimeEventKind::Stop
);
let member_fatal_error_code = matches!(
sites[member.site_id as usize].kind,
RuntimeEventKind::AssertFatal
)
.then_some(member.site_id as i64);
let member_fatal_error_code = sites[member.site_id as usize]
.kind
.is_fatal()
.then_some(member.site_id as i64);
let member_expr = match member
.loop_runner
.or(member.guard)
Expand Down
6 changes: 3 additions & 3 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use std::path::Path;
use celox_design::{
BinaryOp, BitAccess, DisplaySizing, DomainKind, ExternFunction, ExternSignature, ExternType,
InitialStateData, InitialStateValue, ModuleId, NbaSite, PROCESS_DELAY_WIDTH,
PROCESS_STATUS_WIDTH, PortTypeKind, ProcessSlots, RegionedVarAddrBase, RuntimeErrorInfo,
RuntimeEventKind, RuntimeEventSite, STABLE_REGION, TIME_SLOT_WIDTH, TriggerSet, UnaryOp,
VarAtomBase, WORKING_REGION, WaitSite,
PROCESS_STATUS_WIDTH, PortTypeKind, ProcessSlots, RegionedVarAddrBase, ReportLocation,
RuntimeErrorInfo, RuntimeEventKind, RuntimeEventSite, STABLE_REGION, Severity, TIME_SLOT_WIDTH,
TriggerSet, UnaryOp, VarAtomBase, WORKING_REGION, WaitSite,
};
use celox_frontend_core::process::PROCESS_RESUME_WIDTH;
use celox_frontend_core::symbolic::artifact::{
Expand Down
33 changes: 22 additions & 11 deletions crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2183,6 +2183,7 @@ impl<'p, 'a> Comb<'p, 'a> {
task: sv::ir::SystemTask::Readmem(format),
args,
site,
..
} => {
self.readmem(&mut store, frames, *format, args, site.as_ref())?;
Ok(store)
Expand All @@ -2203,8 +2204,20 @@ impl<'p, 'a> Comb<'p, 'a> {
sv::ir::Stmt::SystemTask { task, .. } if self.initial => Err(unsupported(format!(
"system task `{task}` inside an initial block"
))),
sv::ir::Stmt::SystemTask { task, args, .. } => {
self.system_task(&mut store, frames, *task, args)?;
sv::ir::Stmt::SystemTask {
task,
args,
site,
assertion,
} => {
self.system_task(
&mut store,
frames,
*task,
args,
site.as_ref(),
assertion.as_ref(),
)?;
Ok(store)
}
}
Expand Down Expand Up @@ -3456,6 +3469,8 @@ impl<'p, 'a> Comb<'p, 'a> {
frames: &[Frame],
task: sv::ir::SystemTask,
args: &[sv::ir::SystemTaskArg<sv::ir::Expr>],
site: Option<&sv::ir::SourceSpan>,
assertion_site: Option<&celox_design::AssertionSite>,
) -> Result<(), sv::AnalyzerError> {
let kind =
system_task_kind(task).ok_or_else(|| unsupported(format!("system task `{task}`")))?;
Expand Down Expand Up @@ -3529,13 +3544,7 @@ impl<'p, 'a> Comb<'p, 'a> {
arg_widths.push(self.width(node));
captured.push(self.capture(node)?);
}
let event_kind = match &kind {
SystemTaskKind::Print(kind, _) => *kind,
SystemTaskKind::Control(kind) => *kind,
SystemTaskKind::Message => RuntimeEventKind::AssertContinue,
SystemTaskKind::Fatal => RuntimeEventKind::AssertFatal,
SystemTaskKind::Assertion(kind) => *kind,
};
let event_kind = kind.event_kind();
let condition = self.path_condition()?;
let guard = if let Some(passed) = assertion {
// An assertion fires only on failure and only on the active path.
Expand All @@ -3554,10 +3563,10 @@ impl<'p, 'a> Comb<'p, 'a> {
Some(node)
}
// Assertion sites fire when their guard is false.
(SystemTaskKind::Message | SystemTaskKind::Fatal, None) => {
(SystemTaskKind::Message(_) | SystemTaskKind::Fatal, None) => {
Some(self.constant(0, 1)?)
}
(SystemTaskKind::Message | SystemTaskKind::Fatal, Some((node, sources))) => {
(SystemTaskKind::Message(_) | SystemTaskKind::Fatal, Some((node, sources))) => {
observed.extend(sources);
Some(slt_not(self.arena, &mut self.consts, node)?)
}
Expand Down Expand Up @@ -3594,6 +3603,8 @@ impl<'p, 'a> Comb<'p, 'a> {
template,
sizing: DisplaySizing::Ieee,
scope: None,
location: report_location(site),
assertion: assertion_site.cloned(),
arg_widths,
arg_signed,
arg_is_string,
Expand Down
22 changes: 12 additions & 10 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,7 @@ impl<'p, 'a> Ff<'p, 'a> {
),
],
None,
None,
)?;
let (_, name) = self.m.temp("tagged_member", *width, *signed, true);
self.assign(&sv::ir::LValue::Ident(name.clone()), value)?;
Expand Down Expand Up @@ -2023,6 +2024,7 @@ impl<'p, 'a> Ff<'p, 'a> {
),
],
None,
None,
)?;
}
Ok(())
Expand Down Expand Up @@ -2990,9 +2992,12 @@ impl<'p, 'a> Ff<'p, 'a> {
self.eval(expr, None)?;
Ok(true)
}
sv::ir::Stmt::SystemTask { task, args, site } => {
self.system_task(*task, args, site.as_ref())
}
sv::ir::Stmt::SystemTask {
task,
args,
site,
assertion,
} => self.system_task(*task, args, site.as_ref(), assertion.as_ref()),
}
}

Expand All @@ -3003,6 +3008,7 @@ impl<'p, 'a> Ff<'p, 'a> {
task: sv::ir::SystemTask,
args: &[sv::ir::SystemTaskArg<sv::ir::Expr>],
site: Option<&sv::ir::SourceSpan>,
assertion_site: Option<&celox_design::AssertionSite>,
) -> Result<bool, sv::AnalyzerError> {
if let sv::ir::SystemTask::Vcd(operation) = task {
self.vcd_task(operation, args)?;
Expand Down Expand Up @@ -3161,18 +3167,14 @@ impl<'p, 'a> Ff<'p, 'a> {
}
_ => None,
};
let event_kind = match &kind {
SystemTaskKind::Print(kind, _) => *kind,
SystemTaskKind::Control(kind) => *kind,
SystemTaskKind::Message => RuntimeEventKind::AssertContinue,
SystemTaskKind::Fatal => RuntimeEventKind::AssertFatal,
SystemTaskKind::Assertion(kind) => *kind,
};
let event_kind = kind.event_kind();
let site_id = self.m.event_site(RuntimeEventSite {
kind: event_kind,
template: template.clone(),
sizing: DisplaySizing::Ieee,
scope: None,
location: report_location(site),
assertion: assertion_site.cloned(),
arg_widths,
arg_signed,
arg_is_string,
Expand Down
35 changes: 27 additions & 8 deletions crates/celox-frontend-sv/src/lowering/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,7 +1232,7 @@ pub(super) enum SystemTaskKind {
/// `$finish` and `$stop`, with their event kind.
Control(RuntimeEventKind),
/// `$error`, `$warning`, `$info`: a message, then execution continues.
Message,
Message(Severity),
/// `$fatal`: a message, then the simulation ends with an error.
Fatal,
/// Veryl's assertion calls: eagerly evaluate every argument, then report
Expand All @@ -1242,13 +1242,26 @@ pub(super) enum SystemTaskKind {

impl SystemTaskKind {
pub(super) fn is_fatal(&self) -> bool {
matches!(
self,
Self::Fatal | Self::Assertion(RuntimeEventKind::AssertFatal)
)
self.event_kind().is_fatal()
}

pub(super) fn event_kind(&self) -> RuntimeEventKind {
match *self {
Self::Print(kind, _) | Self::Control(kind) | Self::Assertion(kind) => kind,
Self::Message(severity) => RuntimeEventKind::Report(severity),
Self::Fatal => RuntimeEventKind::Report(Severity::Fatal),
}
}
}

/// Where a report is written, from the span of its task call.
pub(super) fn report_location(site: Option<&sv::ir::SourceSpan>) -> Option<ReportLocation> {
site.map(|site| ReportLocation {
file: site.logical_path.display().to_string(),
line: site.line,
})
}

/// How a task reports, for the tasks that report: `$readmemh`/`$readmemb`
/// load memory instead, the analyzer rewrites `$printtimescale` into a
/// `$display`, and `$exit` outside a program block does nothing.
Expand All @@ -1261,10 +1274,16 @@ pub(super) fn system_task_kind(task: sv::ir::SystemTask) -> Option<SystemTaskKin
SystemTask::Write(radix) => SystemTaskKind::Print(RuntimeEventKind::Write, radix.letter()),
SystemTask::Finish => SystemTaskKind::Control(RuntimeEventKind::Finish),
SystemTask::Stop => SystemTaskKind::Control(RuntimeEventKind::Stop),
SystemTask::Severity(_) => SystemTaskKind::Message,
SystemTask::Severity(severity) => SystemTaskKind::Message(match severity {
sv::ir::Severity::Error => Severity::Error,
sv::ir::Severity::Warning => Severity::Warning,
sv::ir::Severity::Info => Severity::Info,
}),
SystemTask::Fatal => SystemTaskKind::Fatal,
SystemTask::Assert => SystemTaskKind::Assertion(RuntimeEventKind::AssertFatal),
SystemTask::AssertContinue => SystemTaskKind::Assertion(RuntimeEventKind::AssertContinue),
SystemTask::Assert => SystemTaskKind::Assertion(RuntimeEventKind::Report(Severity::Fatal)),
SystemTask::AssertContinue => {
SystemTaskKind::Assertion(RuntimeEventKind::Report(Severity::Error))
}
SystemTask::Readmem(_)
| SystemTask::Writemem(_)
| SystemTask::Fclose
Expand Down
9 changes: 6 additions & 3 deletions crates/celox-frontend-veryl/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ use crate::{
use bit_set::BitSet;
use celox_design::{
BinaryOp, BitAccess, DisplaySizing, RuntimeErrorInfo, RuntimeEventKind, RuntimeEventSite,
SPARSE_WORKING_REGION, STABLE_REGION, TriggerSet, UnaryOp, VarAtomBase, WORKING_REGION,
SPARSE_WORKING_REGION, STABLE_REGION, Severity, TriggerSet, UnaryOp, VarAtomBase,
WORKING_REGION,
};
use celox_sir::{
BlockId, RegisterId, RegisterType, SIRBuilder, SIRInstruction, SIROffset, SIRTerminator,
Expand Down Expand Up @@ -552,6 +553,8 @@ impl<'a> FfParser<'a> {
template,
sizing: DisplaySizing::Veryl,
scope: None,
location: None,
assertion: None,
arg_widths: value_args
.iter()
.map(|arg| self.get_expression_width(&arg.0))
Expand Down Expand Up @@ -769,8 +772,8 @@ impl<'a> FfParser<'a> {
let pass_bb = ir_builder.new_block();
let fail_bb = ir_builder.new_block();
let event_kind = match kind {
AssertKind::Fatal => RuntimeEventKind::AssertFatal,
AssertKind::Continue => RuntimeEventKind::AssertContinue,
AssertKind::Fatal => RuntimeEventKind::Report(Severity::Fatal),
AssertKind::Continue => RuntimeEventKind::Report(Severity::Error),
};
let site_id = self.register_runtime_event_site(event_kind, args);
// Assertion message arguments are observationally eager: any
Expand Down
Loading
Loading