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
32 changes: 16 additions & 16 deletions conformance/sv-tests/expected.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -1177,18 +1177,18 @@ chapter-6/6.19.4--enum_numerical_expr_cast.sv 2state pass
chapter-6/6.19.4--enum_numerical_expr_cast.sv 4state pass
chapter-6/6.19.4--enum_numerical_expr_no_cast.sv 2state fail
chapter-6/6.19.4--enum_numerical_expr_no_cast.sv 4state fail
chapter-6/6.19.5.1--enum_first.sv 2state fail
chapter-6/6.19.5.1--enum_first.sv 4state fail
chapter-6/6.19.5.2--enum_last.sv 2state fail
chapter-6/6.19.5.2--enum_last.sv 4state fail
chapter-6/6.19.5.3--enum_next.sv 2state fail
chapter-6/6.19.5.3--enum_next.sv 4state fail
chapter-6/6.19.5.4--enum_prev.sv 2state fail
chapter-6/6.19.5.4--enum_prev.sv 4state fail
chapter-6/6.19.5.5--enum_num.sv 2state fail
chapter-6/6.19.5.5--enum_num.sv 4state fail
chapter-6/6.19.5.6--enum_name.sv 2state fail
chapter-6/6.19.5.6--enum_name.sv 4state fail
chapter-6/6.19.5.1--enum_first.sv 2state pass
chapter-6/6.19.5.1--enum_first.sv 4state pass
chapter-6/6.19.5.2--enum_last.sv 2state pass
chapter-6/6.19.5.2--enum_last.sv 4state pass
chapter-6/6.19.5.3--enum_next.sv 2state pass
chapter-6/6.19.5.3--enum_next.sv 4state pass
chapter-6/6.19.5.4--enum_prev.sv 2state pass
chapter-6/6.19.5.4--enum_prev.sv 4state pass
chapter-6/6.19.5.5--enum_num.sv 2state pass
chapter-6/6.19.5.5--enum_num.sv 4state pass
chapter-6/6.19.5.6--enum_name.sv 2state pass
chapter-6/6.19.5.6--enum_name.sv 4state pass
chapter-6/6.20.2--parameter.sv 2state pass
chapter-6/6.20.2--parameter.sv 4state pass
chapter-6/6.20.2--parameter_aggregate.sv 2state pass
Expand Down Expand Up @@ -1557,10 +1557,10 @@ chapter-8/8.5--properties_enum.sv 2state fail
chapter-8/8.5--properties_enum.sv 4state fail
chapter-8/8.6--methods.sv 2state pass
chapter-8/8.6--methods.sv 4state pass
chapter-8/8.7--constructor.sv 2state fail
chapter-8/8.7--constructor.sv 4state fail
chapter-8/8.7--constructor_param.sv 2state fail
chapter-8/8.7--constructor_param.sv 4state fail
chapter-8/8.7--constructor.sv 2state pass
chapter-8/8.7--constructor.sv 4state pass
chapter-8/8.7--constructor_param.sv 2state pass
chapter-8/8.7--constructor_param.sv 4state pass
chapter-8/8.7--constructor_super.sv 2state pass
chapter-8/8.7--constructor_super.sv 4state pass
chapter-8/8.8--typed_constructor.sv 2state pass
Expand Down
119 changes: 116 additions & 3 deletions crates/celox-frontend-sv/src/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,7 +1468,8 @@ fn kernel_written_names(
}
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
| sv::ir::Callee::Checked { .. } => continue,
| sv::ir::Callee::Checked { .. }
| sv::ir::Callee::Lookup { .. } => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = subroutines
Expand Down Expand Up @@ -1672,7 +1673,8 @@ impl DriverScan<'_> {
}
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
| sv::ir::Callee::Checked { .. } => continue,
| sv::ir::Callee::Checked { .. }
| sv::ir::Callee::Lookup { .. } => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = self
Expand Down Expand Up @@ -4945,6 +4947,56 @@ pub(crate) fn attach_instance_glue(
Ok(())
}

/// A [`sv::ir::Callee::Lookup`] call as nested multiplexers of case
/// equalities. The selector is lowered once and its node shared by every
/// comparison, so nested lookups lower in linear time. `lower` lowers an
/// operand with a context width and signedness.
fn lower_lookup<A: std::hash::Hash + Eq + Clone>(
args: &[Option<sv::ir::Expr>],
width: usize,
signed: bool,
arena: &mut SLTNodeArena<A>,
lower: &mut dyn FnMut(
&sv::ir::Expr,
&mut SLTNodeArena<A>,
Option<usize>,
Option<bool>,
) -> Option<NodeId>,
) -> Option<NodeId> {
let (selector, rest) = args.split_first()?;
let (default, pairs) = rest.split_last()?;
let (pairs, []) = pairs.as_chunks::<2>() else {
return None;
};
let selector = lower(selector.as_ref()?, arena, None, None)?;
let resized = |expr: &Option<sv::ir::Expr>| {
Some(sv::ir::Expr::Resize {
expr: Box::new(expr.clone()?),
width,
signed,
})
};
let mut result = lower(&resized(default)?, arena, Some(width), Some(signed))?;
for [key, value] in pairs.iter().rev() {
let key = lower(key.as_ref()?, arena, None, None)?;
let compared = celox_slt::get_width(selector, arena).max(celox_slt::get_width(key, arena));
let left = coerce_node_width(arena, selector, Some(compared), false).ok()?;
let right = coerce_node_width(arena, key, Some(compared), false).ok()?;
let cond = arena
.alloc(SLTNode::Binary(left, BinaryOp::EqCase, right))
.ok()?;
let then_expr = lower(&resized(value)?, arena, Some(width), Some(signed))?;
result = arena
.alloc(SLTNode::Mux {
cond,
then_expr,
else_expr: result,
})
.ok()?;
}
Some(result)
}

/// `expr inside { items }` as the comparisons the language defines: a value
/// matches by wildcard equality, a range by an inclusive bounds check.
fn inside_as_comparisons(expr: &sv::ir::Expr, items: &[sv::ir::InsideItem]) -> sv::ir::Expr {
Expand Down Expand Up @@ -7232,6 +7284,38 @@ fn lower_glue_parent_expr(
source_ids,
))
}
sv::ir::Expr::Call {
callee: sv::ir::Callee::Lookup { width, signed },
args,
..
} => {
let mut sources = HashSet::default();
let mut source_ids = Vec::new();
let node = lower_lookup(
args,
*width,
*signed,
arena,
&mut |expr, arena, context_width, context_signed| {
let (node, expr_sources, expr_source_ids) = lower_glue_parent_expr(
expr,
variables,
name_to_id,
constants,
parameter_types,
arena,
context_width,
context_signed,
)?;
sources.extend(expr_sources);
source_ids.extend(expr_source_ids);
Some(node)
},
)?;
source_ids.sort();
source_ids.dedup();
Some((node, sources, source_ids))
}
sv::ir::Expr::Inside { expr, items } => lower_glue_parent_expr(
&inside_as_comparisons(expr, items),
variables,
Expand Down Expand Up @@ -8635,6 +8719,34 @@ fn lower_expr_with_context(
sources,
))
}
sv::ir::Expr::Call {
callee: sv::ir::Callee::Lookup { width, signed },
args,
..
} => {
let mut sources = HashSet::default();
let node = lower_lookup(
args,
*width,
*signed,
arena,
&mut |expr, arena, context_width, context_signed| {
let (node, expr_sources) = lower_expr_with_context(
expr,
variables,
name_to_id,
constants,
parameter_types,
arena,
context_width,
context_signed,
)?;
sources.extend(expr_sources);
Some(node)
},
)?;
Some((node, sources))
}
sv::ir::Expr::Inside { expr, items } => lower_expr_with_context(
&inside_as_comparisons(expr, items),
variables,
Expand Down Expand Up @@ -10857,7 +10969,8 @@ mod tests {
}
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
| sv::ir::Callee::Checked { .. } => continue,
| sv::ir::Callee::Checked { .. }
| sv::ir::Callee::Lookup { .. } => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = self
Expand Down
7 changes: 4 additions & 3 deletions crates/celox-frontend-sv/src/lowering/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ impl<'p, 'a> Ff<'p, 'a> {
}
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
| sv::ir::Callee::Checked { .. } => continue,
| sv::ir::Callee::Checked { .. }
| sv::ir::Callee::Lookup { .. } => continue,
sv::ir::Callee::Subroutine(name) => name,
};
let Some(subroutine) = self.m.subroutine(&name).cloned() else {
Expand Down Expand Up @@ -7744,8 +7745,8 @@ fn impure_call(pm: &ProcModule<'_>, expr: &sv::ir::Expr) -> Option<String> {
}
continue;
}
// A string operation is a value of its operands.
sv::ir::Callee::String(_) => continue,
// A string operation or lookup is a value of its operands.
sv::ir::Callee::String(_) | sv::ir::Callee::Lookup { .. } => continue,
// Container contents are immutable: reading an element is a
// value of the container handle and index, unlike a class
// property that can change without its handle changing.
Expand Down
3 changes: 3 additions & 0 deletions crates/celox-frontend-sv/src/lowering/procedural.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ impl<'a> ProcModule<'a> {
}
continue;
}
// A lookup is a value of its operands.
sv::ir::Callee::Lookup { .. } => continue,
// String operations use the simulator's heap.
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
Expand Down Expand Up @@ -1147,6 +1149,7 @@ impl<'a> ProcModule<'a> {
pub fn is_callee(&self, callee: &sv::ir::Callee) -> bool {
match callee {
sv::ir::Callee::System(function) => function.reads_simulation_state(),
sv::ir::Callee::Lookup { .. } => false,
sv::ir::Callee::String(_)
| sv::ir::Callee::Object(_)
| sv::ir::Callee::Checked { .. } => true,
Expand Down
Loading
Loading