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
31 changes: 27 additions & 4 deletions crates/celox-design/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,6 @@ impl<A: Copy> HostRequestValue<A> {
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct HostRequestSite<A> {
pub process: usize,
/// This request belongs to an edge procedure lowered to a scheduled kernel.
pub requires_timed_simulation: bool,
pub kind: HostRequestKind,
pub operation: u32,
pub args: Vec<HostRequestValue<A>>,
Expand All @@ -403,7 +401,6 @@ impl<A: Copy> HostRequestSite<A> {
pub fn map<B>(&self, mut map: impl FnMut(A) -> B) -> HostRequestSite<B> {
HostRequestSite {
process: self.process,
requires_timed_simulation: self.requires_timed_simulation,
kind: self.kind,
operation: self.operation,
args: self.args.iter().map(|value| value.map(&mut map)).collect(),
Expand All @@ -421,6 +418,30 @@ impl<A: Copy> HostRequestSite<A> {
}
}

/// The source procedure a process kernel was lowered from, for diagnostics.
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct ProcessOrigin {
/// The construct, such as `initial` or `always`.
pub construct: String,
/// `path:line:column` of the construct, when known.
pub location: Option<String>,
/// Fully elaborated module-instance scope that owns the process.
pub scope: Option<String>,
}

impl std::fmt::Display for ProcessOrigin {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "`{}`", self.construct)?;
if let Some(location) = &self.location {
write!(f, " at {location}")?;
}
if let Some(scope) = &self.scope {
write!(f, " in `{scope}`")?;
}
Ok(())
}
}

/// State through which one process kernel exchanges control with the runtime.
///
/// A process kernel is a resumable function. On entry it reads `resume` to
Expand Down Expand Up @@ -795,6 +816,8 @@ pub struct RuntimeSchema<A> {
pub live_signals: HashSet<A>,
/// Control slots of the process kernels, in kernel order.
pub processes: Vec<ProcessSlots<A>>,
/// Source procedures of the process kernels, in kernel order.
pub process_origins: Vec<ProcessOrigin>,
/// Counted signals and their occurrence counters.
pub watches: Vec<EventWatch<A>>,
/// Wait sites of the process kernels. A process's sites appear in the
Expand Down Expand Up @@ -833,6 +856,7 @@ impl<A> Default for RuntimeSchema<A> {
dead_store_policy: DeadStorePolicy::Off,
live_signals: HashSet::default(),
processes: Vec::new(),
process_origins: Vec::new(),
watches: Vec::new(),
wait_sites: Vec::new(),
nba_sites: Vec::new(),
Expand Down Expand Up @@ -1516,7 +1540,6 @@ mod tests {
let site = HostRequestSite {
process: 2,
kind: HostRequestKind::Plusargs,
requires_timed_simulation: false,
operation: 1,
args: vec![value(3u32)],
results: vec![value(5)],
Expand Down
10 changes: 9 additions & 1 deletion crates/celox-frontend-core/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1732,7 +1732,15 @@ fn lower_processes(
candidates.extend(crate::watch::multi_store_candidates(&kernel, |address| {
stable_signal(address, artifact.signals().len())
}));
processes.push(SymbolicProcess { kernel, slots });
processes.push(SymbolicProcess {
kernel,
slots,
origin: celox_design::ProcessOrigin {
construct: "process".to_string(),
location: None,
scope: None,
},
});
}
Ok(LoweredProcesses {
processes,
Expand Down
1 change: 1 addition & 0 deletions crates/celox-frontend-core/src/symbolic/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl<A> FfPart<A> {
pub struct SymbolicProcess {
pub kernel: ExecutionUnit<SymbolicRegionedAddr>,
pub slots: ProcessSlots<SourceVarId>,
pub origin: celox_design::ProcessOrigin,
}

/// The commit of a trigger group's results, split by region.
Expand Down
18 changes: 14 additions & 4 deletions crates/celox-frontend-core/src/symbolic/assembly.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1691,10 +1691,14 @@ pub fn schedule_symbolic_rtl_reporting_loops(
);
select_nba_paths(&mut timing, &staged, &mut processes);
}
let (process_kernels, process_slots): (Vec<_>, Vec<_>) = processes
.into_iter()
.map(|process| (process.kernel, process.slots))
.unzip();
let mut process_kernels = Vec::with_capacity(processes.len());
let mut process_slots = Vec::with_capacity(processes.len());
let mut process_origins = Vec::with_capacity(processes.len());
for process in processes {
process_kernels.push(process.kernel);
process_slots.push(process.slots);
process_origins.push(process.origin);
}
let TimingMetadata {
wait_sites,
nba_sites,
Expand Down Expand Up @@ -2034,6 +2038,7 @@ pub fn schedule_symbolic_rtl_reporting_loops(
dead_store_policy: Default::default(),
live_signals: Default::default(),
processes: process_slots,
process_origins,
watches,
wait_sites,
nba_sites,
Expand Down Expand Up @@ -3087,6 +3092,10 @@ fn relocate_units(
&extern_function_map,
),
slots: process.slots.map(|var_id| bindings.locate(*id, var_id)),
origin: celox_design::ProcessOrigin {
scope: Some(scope.clone()),
..process.origin.clone()
},
key: (*id, index),
},
));
Expand Down Expand Up @@ -3214,6 +3223,7 @@ fn relocate_units(
struct RelocatedProcess {
kernel: ExecutionUnit<RegionedAbsoluteAddr>,
slots: ProcessSlots<AbsoluteAddr>,
origin: celox_design::ProcessOrigin,
/// The instance and the module-local index of the process.
key: (InstanceId, usize),
}
Expand Down
20 changes: 16 additions & 4 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3918,6 +3918,21 @@ fn process_random_seeds(module: &sv::ir::Module) -> HashMap<(u8, usize), u32> {
.collect()
}

/// The source procedure of a process kernel, for diagnostics.
fn process_origin(process: &sv::ir::InitialProcess) -> celox_design::ProcessOrigin {
let construct = match process.site() {
Some(site) => site.construct,
None if process.is_initializer() => "declaration initializer",
None if process.repeats() => "always",
None => "initial",
};
celox_design::ProcessOrigin {
construct: construct.to_string(),
location: process.site().map(ToString::to_string),
scope: None,
}
}

/// The `initial` blocks and declaration initializers (IEEE 1800-2023 9.2.1,
/// 10.5): the initial state they define, and the processes that run the
/// others from time zero.
Expand Down Expand Up @@ -4108,15 +4123,12 @@ fn lower_initial_processes(
nba_switches.extend(kernel.nba_switches);
host_request_sites.extend(kernel.host_request_sites.into_iter().map(|mut site| {
site.process = index;
// Repeating ordinary always processes also execute only in
// the timed scheduler. Keep this site requirement separate
// from the converted-FF startup marker on ProcessSlots.
site.requires_timed_simulation = process.repeats();
site
}));
Ok(SymbolicProcess {
kernel: kernel.unit,
slots,
origin: process_origin(process),
})
})
.collect::<Result<Vec<_>, sv::AnalyzerError>>();
Expand Down
3 changes: 0 additions & 3 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,6 @@ impl<'p, 'a> Ff<'p, 'a> {
self.host_request_sites.push(HostRequestSite {
process: self.process,
kind: HostRequestKind::Vcd,
requires_timed_simulation: false,
operation: operation as u32,
args: values,
results: Vec::new(),
Expand Down Expand Up @@ -1905,7 +1904,6 @@ impl<'p, 'a> Ff<'p, 'a> {
self.host_request_sites.push(HostRequestSite {
process: 0,
kind: HostRequestKind::Distribution,
requires_timed_simulation: false,
operation,
args: operands,
results: vec![value(ret_id), value(seed_id)],
Expand Down Expand Up @@ -1983,7 +1981,6 @@ impl<'p, 'a> Ff<'p, 'a> {
self.host_request_sites.push(HostRequestSite {
process: 0,
kind: HostRequestKind::Plusargs,
requires_timed_simulation: false,
operation: u32::from(value_query),
args: vec![HostRequestValue {
float_precision: None,
Expand Down
1 change: 0 additions & 1 deletion crates/celox-frontend-sv/src/lowering/ff/file_io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl Ff<'_, '_> {
.count() as u32;
self.host_request_sites.push(HostRequestSite {
process: 0,
requires_timed_simulation: false,
kind: HostRequestKind::FileIo,
operation,
args,
Expand Down
1 change: 0 additions & 1 deletion crates/celox-frontend-sv/src/lowering/ff/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ impl Ff<'_, '_> {
self.host_request_sites.push(HostRequestSite {
process: 0,
kind: HostRequestKind::Scan,
requires_timed_simulation: false,
operation: u32::from(function == sv::ir::SystemFunction::Fscanf),
args: inputs,
results,
Expand Down
12 changes: 12 additions & 0 deletions crates/celox-sv-analyzer/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ impl Module {
first_block,
InitialProcess {
creation_order: 0,
site: None,
condition: None,
body: static_initializers,
initializer: true,
Expand Down Expand Up @@ -2260,6 +2261,7 @@ pub struct FfProcess {
always_ff: bool,
suspendable: bool,
creation_order: usize,
site: Option<crate::procedural::ProcessSite>,
events: Vec<FfEvent>,
body: Vec<Stmt>,
}
Expand All @@ -2274,11 +2276,16 @@ impl FfProcess {
self.creation_order
}

pub fn site(&self) -> Option<&crate::procedural::ProcessSite> {
self.site.as_ref()
}

fn new(events: Vec<FfEvent>, body: Vec<Stmt>) -> Self {
Self {
always_ff: false,
suspendable: false,
creation_order: 0,
site: None,
events,
body,
}
Expand All @@ -2297,6 +2304,7 @@ impl FfProcess {
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct InitialProcess {
creation_order: usize,
site: Option<crate::procedural::ProcessSite>,
condition: Option<ConstExpr>,
body: Vec<Stmt>,
initializer: bool,
Expand All @@ -2311,6 +2319,10 @@ impl InitialProcess {
self.creation_order
}

pub fn site(&self) -> Option<&crate::procedural::ProcessSite> {
self.site.as_ref()
}

pub fn condition(&self) -> Option<&ConstExpr> {
self.condition.as_ref()
}
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/array_parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ impl ArrayParameter {
};
Ok(InitialProcess {
creation_order: 0,
site: None,
condition: None,
body: vec![Stmt::Assign {
lhs: LValue::Ident(name),
Expand Down
9 changes: 9 additions & 0 deletions crates/celox-sv-analyzer/src/ast/ff_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ pub(super) fn ff_processes_from_scope(
}
for process in &mut processes[start..] {
process.creation_order = creation_order;
process.site = procedural::process_site(
if process.always_ff {
"always_ff"
} else {
"always"
},
syntax_tree.declarations().body_item(item.id).tokens,
syntax_tree,
);
for event in &mut process.events {
event.signal = item.name(&event.signal);
}
Expand Down
37 changes: 37 additions & 0 deletions crates/celox-sv-analyzer/src/ast/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,11 @@ pub(super) fn initial_processes_from_scope(
if !body.is_empty() {
initializers.push(InitialProcess {
creation_order,
site: process_site(
"declaration initializer",
tree.declarations().body_item(item.id).tokens,
tree,
),
condition: None,
body,
initializer: true,
Expand All @@ -1734,6 +1739,10 @@ pub(super) fn initial_processes_from_scope(
let Some(procedure) = item.procedure(tree.declarations())? else {
continue;
};
let construct = match procedure.kind {
celox_sv_syntax::ProcedureKind::Initial => "initial",
_ => "always",
};
let repeats = match procedure.kind {
celox_sv_syntax::ProcedureKind::Initial => false,
celox_sv_syntax::ProcedureKind::Always
Expand Down Expand Up @@ -1772,6 +1781,11 @@ pub(super) fn initial_processes_from_scope(
}
processes.push(InitialProcess {
creation_order,
site: process_site(
construct,
tree.declarations().body_item(item.id).tokens,
tree,
),
condition: None,
body,
initializer: false,
Expand Down Expand Up @@ -1800,6 +1814,29 @@ pub(super) fn written_names<'s>(stmts: impl IntoIterator<Item = &'s Stmt>) -> Ha
names
}

/// Where the first token of a native token range was invoked.
pub(super) fn process_site(
construct: &'static str,
tokens: celox_sv_syntax::TokenRange,
tree: &SyntaxTree,
) -> Option<crate::procedural::ProcessSite> {
let native = tree.declarations();
let token = native
.tokens
.get(tokens.start..tokens.end)?
.iter()
.find(|token| !token.is_trivia())?;
let span = native.sources.invocation(token.origin);
let file = native.sources.file(span.file);
let (line, column) = file.line_column(span.start);
Some(crate::procedural::ProcessSite {
construct,
path: file.path.clone(),
line,
column,
})
}

/// Original invocation span of a native token range, when it belongs to one file.
pub(super) fn source_span(
tokens: celox_sv_syntax::TokenRange,
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/procedural/timed_tasks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ pub(in crate::ast) fn classify<'a>(
body.extend(process.body);
processes.push(InitialProcess {
creation_order: process.creation_order,
site: process.site.clone(),
condition: None,
body: vec![Stmt::Loop {
kind: LoopKind::Forever,
Expand Down
2 changes: 2 additions & 0 deletions crates/celox-sv-analyzer/src/ast/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ impl ScopeSymbols {
.filter(|process| initializes(process, target))
.map(|process| InitialProcess {
creation_order: process.creation_order,
site: process.site.clone(),
condition: process.condition.clone(),
body: process
.body
Expand Down Expand Up @@ -562,6 +563,7 @@ impl ScopeSymbols {
.iter()
.map(|process| InitialProcess {
creation_order: process.creation_order,
site: process.site.clone(),
condition: process
.condition
.clone()
Expand Down
Loading
Loading