Skip to content
Closed
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
20 changes: 20 additions & 0 deletions crates/celox-frontend-sv/src/lowering/comb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3425,6 +3425,7 @@ impl<'p, 'a> Comb<'p, 'a> {
// Copy the inputs in, left to right, in the caller's scope.
let mut outputs = Vec::new();
let mut copied = Vec::new();
let mut references = Vec::new();
let positions: Vec<_> = if arg_order.is_empty() {
(0..subroutine.params.len()).collect()
} else {
Expand All @@ -3445,6 +3446,19 @@ impl<'p, 'a> Comb<'p, 'a> {
.cloned()
.flatten()
.or_else(|| param.default.clone());
if param.direction.is_reference() {
// A reference formal names the actual variable itself
// (IEEE 1800-2023 13.5.2); other actuals fall back to Ff.
let target = match &actual {
Some(sv::ir::Expr::Ident(actual)) => self.m.id(actual),
_ => None,
}
.ok_or_else(|| {
unsupported(format!("ref argument `{}` of `{name}`", param.source_name))
})?;
references.push((param.name.clone(), id, target));
continue;
}
if param.direction.is_written() {
let actual = actual.as_ref().and_then(lvalue_from_expr).ok_or_else(|| {
unsupported(format!(
Expand Down Expand Up @@ -3510,6 +3524,9 @@ impl<'p, 'a> Comb<'p, 'a> {
let width = self.m.var(id).width;
self.write(store, id, full(width), value)?;
}
for (formal, _, target) in &references {
self.m.name_to_id.insert(formal.clone(), *target);
}
let return_var = match &subroutine.return_var {
Some(name) => {
let id = self
Expand All @@ -3533,6 +3550,9 @@ impl<'p, 'a> Comb<'p, 'a> {
self.active_calls.push(name.to_string());
let result = self.exec_block(store.fork(), &call_frames, &subroutine.body);
self.active_calls.pop();
for (formal, original, _) in references {
self.m.name_to_id.insert(formal, original);
}
*store = result?;
// Copy the outputs back.
for (id, lvalues) in outputs {
Expand Down
Loading
Loading