Skip to content

Commit

Permalink
morty: Delay usage ident to second pass (fixes #6)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarubaf committed Mar 15, 2020
1 parent 2478d76 commit 1b7925d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
27 changes: 15 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
2 changes: 2 additions & 0 deletions test/modules.sv
Original file line number Diff line number Diff line change
@@ -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
);
Expand Down

0 comments on commit 1b7925d

Please sign in to comment.