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
13 changes: 8 additions & 5 deletions crates/celox-frontend-veryl/src/artifact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,22 @@ pub fn external_signatures(
ExternalModule {
sim_module,
port_order,
// Veryl children link through the IR; only SV children are
// left for the SV frontend to resolve by name.
unresolved_instances: module
.declarations
.iter()
.filter_map(|declaration| {
let veryl_analyzer::ir::Declaration::Inst(instance) = declaration else {
return None;
};
let name = match instance.component.as_ref() {
Component::Module(module) => module.name,
Component::SystemVerilog(module) => module.name,
Component::Interface(_) => return None,
let Component::SystemVerilog(module) = instance.component.as_ref() else {
return None;
};
Some(veryl_parser::resource_table::get_str_value(name).unwrap_or_default())
Some(
veryl_parser::resource_table::get_str_value(module.name)
.unwrap_or_default(),
)
})
.collect(),
},
Expand Down
21 changes: 15 additions & 6 deletions crates/celox-frontend-veryl/src/hierarchy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,15 @@ pub fn parse_ir_with_external_hierarchy<'a>(
}

/// Link the explicitly identified Veryl exports without matching SV namesakes.
/// `native_modules` maps each external module name that stands for a Veryl
/// body to the name of that body in `ir`.
pub fn parse_ir_with_external_hierarchy_and_native_modules<'a>(
ir: &'a veryl_analyzer::ir::Ir,
loop_provenance: &LoopProvenance,
external: &'a ExternalHierarchy,
config: &BuildConfig,
top: &StrId,
native_modules: &HashSet<String>,
native_modules: &HashMap<String, StrId>,
) -> Result<VerylSymbolicRtl<'a>, ParserError> {
parse_external_hierarchy(
ir,
Expand All @@ -72,7 +74,7 @@ fn parse_external_hierarchy<'a>(
external: &'a ExternalHierarchy,
config: &BuildConfig,
top: &StrId,
native_modules: Option<&HashSet<String>>,
native_modules: Option<&HashMap<String, StrId>>,
) -> Result<VerylSymbolicRtl<'a>, ParserError> {
// Token-to-scope resolution uses process-global analyzer state and is not
// safe while independent compilations run on other test threads. Snapshot
Expand Down Expand Up @@ -116,7 +118,7 @@ fn parse_external_hierarchy<'a>(
let top_name = resource_table::get_str_value(*top).unwrap_or_default();
let root_ir = name_to_ir.get(top).copied();
let external_root = external.roots.get(&top_name).copied().filter(|_| {
root_ir.is_none() || native_modules.is_none_or(|names| names.contains(&top_name))
root_ir.is_none() || native_modules.is_none_or(|names| names.contains_key(&top_name))
});
if root_ir.is_none() && external_root.is_none() {
return Err(ParserError::TopNotFound { name: top_name });
Expand Down Expand Up @@ -172,11 +174,18 @@ fn parse_external_hierarchy<'a>(
binding.package = external_ids[&binding.package];
}
module_names.insert(global_id, external_module.sim_module.name.clone());
let native_name = resource_table::insert_str(&external_module.sim_module.name);
if let Some(&native_module) = name_to_ir.get(&native_name)
&& native_modules.is_none_or(|names| names.contains(&external_module.sim_module.name))
let native_name = match native_modules {
Some(names) => names.get(&external_module.sim_module.name).copied(),
None => Some(resource_table::insert_str(&external_module.sim_module.name)),
};
if let Some(native_name) = native_name
&& let Some(&native_module) = name_to_ir.get(&native_name)
&& !module_ir.contains_key(&global_id)
{
module_names.insert(
global_id,
resource_table::get_str_value(native_name).unwrap_or_default(),
);
module_ir.insert(global_id, native_module);
signature_to_id.insert(native_module.signature.clone(), global_id);
worklist.push((global_id, native_module));
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/comb_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub(super) fn comb_processes_from_module_node(
if !relevant {
continue;
}
let _constant_functions = item.enter();
let start = processes.len();
let (dimensions, literals) = views.get(item);
comb_processes_from_module_or_generate_item(
Expand Down
4 changes: 4 additions & 0 deletions crates/celox-sv-analyzer/src/ast/const_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ impl ConstantFunctions {
.retain(|name, _| keep(name));
}

pub(super) fn contains(&self, name: &str) -> bool {
self.functions.contains_key(name) || self.errors.by_name.contains_key(name)
}

/// Make the function `target` callable as `name` too.
pub(super) fn alias(&mut self, name: &str, target: &str) {
if let Some(function) = self.functions.get(target).cloned() {
Expand Down
3 changes: 2 additions & 1 deletion crates/celox-sv-analyzer/src/ast/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,12 @@ pub(super) fn signals_from_module_node(
}
ScopeItem::Package(_) => continue,
};
let _constant_functions = item.enter();
let start = signals.len();
signals_from_module_or_generate_item(
node,
syntax_tree,
type_aliases,
&item.type_aliases(type_aliases),
&item.env,
None,
&mut signals,
Expand Down
1 change: 1 addition & 0 deletions crates/celox-sv-analyzer/src/ast/ff_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(super) fn ff_processes_from_module_node(
) {
continue;
}
let _constant_functions = item.enter();
let start = processes.len();
let (dimensions, literals) = views.get(item);
ff_processes_from_module_or_generate_item(
Expand Down
6 changes: 4 additions & 2 deletions crates/celox-sv-analyzer/src/ast/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ pub(super) fn functions_from_module_node(
packed_dimensions: &PackedDimensions,
) -> Result<HashMap<String, Function>, AnalyzerError> {
let mut functions = HashMap::default();
let type_aliases =
let module_type_aliases =
type_aliases_from_module_node_with_env(node.clone(), syntax_tree, const_env)?;
let active = generate::items(node.clone(), syntax_tree, const_env, &type_aliases)?;
let active = generate::items(node.clone(), syntax_tree, const_env, &module_type_aliases)?;
let mut views = generate::ScopeViews::new(packed_dimensions);
for (item, child) in active
.iter()
.flat_map(|item| item.node.node().into_iter().map(move |child| (item, child)))
{
let _constant_functions = item.enter();
let type_aliases = item.type_aliases(&module_type_aliases);
if let RefNode::TaskDeclaration(declaration) = child {
let task_dimensions = views.dimensions(item);
let const_env = &item.env;
Expand Down
Loading
Loading