diff --git a/src/core/fast_hdlparam.rs b/src/core/fast_hdlparam.rs index 8bf3926..36f0cd7 100644 --- a/src/core/fast_hdlparam.rs +++ b/src/core/fast_hdlparam.rs @@ -1,18 +1,18 @@ use serde::Serialize; -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, PartialEq)] pub struct Position { pub line: u32, pub character: u32 } -#[derive(Debug, Clone, Serialize)] +#[derive(Debug, Clone, Serialize, PartialEq)] pub struct Range { pub start: Position, pub end: Position } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, PartialEq)] pub struct Port { pub name: String, pub dir_type: String, @@ -22,7 +22,7 @@ pub struct Port { pub range: Range } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, PartialEq)] pub struct Parameter { pub name: String, pub net_type: String, @@ -123,6 +123,7 @@ impl FastHdlparam { } }; last_module.ports.push(port); + last_module.ports.dedup(); } pub fn add_instance(&mut self, name: &str, inst_type: &str, line: u32, character: u32, end_character: u32, diff --git a/src/core/sv_parser.rs b/src/core/sv_parser.rs index af609a0..e7feba9 100644 --- a/src/core/sv_parser.rs +++ b/src/core/sv_parser.rs @@ -24,7 +24,6 @@ pub fn make_fast_from_syntaxtree(syntax_tree: SyntaxTree) -> FastHdlparam { let mut hdlparam = FastHdlparam { fast: Vec::new() }; - let mut nonansi_port_locate = HashMap::new(); let mut ansi_port_last_dir = ""; let content = syntax_tree.text.text().split('\n') @@ -79,13 +78,6 @@ pub fn make_fast_from_syntaxtree(syntax_tree: SyntaxTree) -> FastHdlparam { _ => () } } - RefNode::Port(x) => { - let id = unwrap_node!(x, SimpleIdentifier).unwrap(); - let locate = get_identifier(id).unwrap(); - let name = syntax_tree.get_str(&locate.clone()).unwrap(); - // println!("get port {} {:?}", name, locate); - nonansi_port_locate.insert(name, locate); - } RefNode::PortDeclaration(x) => { let id = unwrap_node!(x, InputDeclaration, OutputDeclaration, InoutDeclaration).unwrap(); let id = get_identifier(id).unwrap(); @@ -108,18 +100,20 @@ pub fn make_fast_from_syntaxtree(syntax_tree: SyntaxTree) -> FastHdlparam { _ => "1".to_string() }; - let id = unwrap_node!(x, PortIdentifier).unwrap(); - let id = get_identifier(id).unwrap(); - let name = syntax_tree.get_str(&id).unwrap(); - let (start_line, start_character, end_line, end_character) = if nonansi_port_locate.contains_key(name) { - let start_character = get_column_by_offset(&content, nonansi_port_locate[name].offset); - (nonansi_port_locate[name].line, start_character as u32, - nonansi_port_locate[name].line, (start_character + nonansi_port_locate[name].len) as u32) - } else { - (dir_line, dir_character, id.line, (get_column_by_offset(&content, id.offset) + id.len) as u32) - }; + if let Some(RefNode::ListOfPortIdentifiers(x)) = unwrap_node!(x, ListOfPortIdentifiers) { + for node in x { + if let RefNode::PortIdentifier(x) = node { + let id = unwrap_node!(x, Identifier).unwrap(); + let id = get_identifier(id).unwrap(); + let name = syntax_tree.get_str(&id).unwrap(); + let (start_line, start_character, end_line, end_character) = + (dir_line, dir_character, id.line, (get_column_by_offset(&content, id.offset) + id.len) as u32); - hdlparam.add_port(name, dir_type, net_type, width.as_str(), start_line, start_character, end_line, end_character); + hdlparam.add_port(name, dir_type, net_type, width.as_str(), start_line, start_character, + end_line, end_character); + } + } + } } RefNode::AnsiPortDeclaration(x) => { let id = unwrap_node!(x, PortIdentifier).unwrap(); diff --git a/sv-parser b/sv-parser index af11f5f..4960ea3 160000 --- a/sv-parser +++ b/sv-parser @@ -1 +1 @@ -Subproject commit af11f5ff1ef091562d2b17cdf4de3614aedf2286 +Subproject commit 4960ea3fb7c848462ce6e78dbae454ffc775803f