From 1b7925d3f82c5a7514b55a6d5887a5f39a942bd1 Mon Sep 17 00:00:00 2001 From: Florian Zaruba Date: Sun, 15 Mar 2020 10:33:07 +0100 Subject: [PATCH] morty: Delay usage ident to second pass (fixes #6) --- src/main.rs | 27 +++++++++++++++------------ test/modules.sv | 2 ++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/main.rs b/src/main.rs index 62f5bf1..c3e3fa0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -305,28 +305,31 @@ fn main() -> Result<(), Error> { let id = unwrap_node!(x, SimpleIdentifier).unwrap(); pickle.register_declaration(&syntax_tree, id); } - // Instantiations, end-labels. - RefNode::ModuleIdentifier(x) => { + // Interface Declaration. + RefNode::InterfaceDeclaration(x) => { let id = unwrap_node!(x, SimpleIdentifier).unwrap(); - // an instantiation is potentially also a declaration (order doesn't matter) pickle.register_declaration(&syntax_tree, id); - let id = unwrap_node!(x, SimpleIdentifier).unwrap(); - pickle.register_usage(&syntax_tree, id); } - // Interface Declaration. - RefNode::InterfaceDeclaration(x) => { + // Package declarations. + RefNode::PackageDeclaration(x) => { let id = unwrap_node!(x, SimpleIdentifier).unwrap(); pickle.register_declaration(&syntax_tree, id); } - // Interface identifier. - RefNode::InterfaceIdentifier(x) => { + _ => (), + } + } + // Iterate again and check for usage + for node in &syntax_tree { + match node { + // Instantiations, end-labels. + RefNode::ModuleIdentifier(x) => { let id = unwrap_node!(x, SimpleIdentifier).unwrap(); pickle.register_usage(&syntax_tree, id); } - // Package declarations. - RefNode::PackageDeclaration(x) => { + // Interface identifier. + RefNode::InterfaceIdentifier(x) => { let id = unwrap_node!(x, SimpleIdentifier).unwrap(); - pickle.register_declaration(&syntax_tree, id); + pickle.register_usage(&syntax_tree, id); } // Package Qualifier (i.e., explicit package constants). RefNode::ClassScope(x) => { diff --git a/test/modules.sv b/test/modules.sv index d0ca5d7..1308af6 100644 --- a/test/modules.sv +++ b/test/modules.sv @@ -1,10 +1,12 @@ module module_1; module_2 i_module_2(); + module_external i_external_module(); endmodule module module_2 #(); endmodule +// Another one bites the dust. module /* test */ module_3 #()( input clk_i );