Skip to content

Commit

Permalink
Merge pull request #332 from dalance/fix_modport_member
Browse files Browse the repository at this point in the history
Add modport member resolve
  • Loading branch information
dalance authored Aug 1, 2023
2 parents 721a9d9 + 0f82093 commit d32f303
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 2 deletions.
8 changes: 8 additions & 0 deletions crates/analyzer/src/handlers/create_symbol_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,13 +168,21 @@ impl<'a> VerylGrammarTrait for CreateSymbolTable<'a> {
if let HandlerPoint::Before = self.point {
let mut members = Vec::new();
let items: Vec<ModportItem> = arg.modport_list.as_ref().into();

self.namespace
.push(arg.identifier.identifier_token.token.text);

for item in items {
let member = ModportMember {
name: item.identifier.identifier_token.token.text,
direction: item.direction.as_ref().into(),
};
members.push(member);
self.insert_symbol(&item.identifier.identifier_token, SymbolKind::ModportMember);
}

self.namespace.pop();

let property = ModportProperty { members };
let kind = SymbolKind::Modport(property);
self.insert_symbol(&arg.identifier.identifier_token, kind);
Expand Down
5 changes: 4 additions & 1 deletion crates/analyzer/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ pub enum SymbolKind {
EnumMember(EnumMemberProperty),
Modport(ModportProperty),
Genvar,
ModportMember,
}

impl SymbolKind {
Expand All @@ -105,6 +106,7 @@ impl SymbolKind {
SymbolKind::EnumMember(_) => "enum member".to_string(),
SymbolKind::Modport(_) => "modport".to_string(),
SymbolKind::Genvar => "genvar".to_string(),
SymbolKind::ModportMember => "modport member".to_string(),
}
}
}
Expand Down Expand Up @@ -186,12 +188,13 @@ impl fmt::Display for SymbolKind {
format!("modport ({} ports)", x.members.len())
}
SymbolKind::Genvar => "genvar".to_string(),
SymbolKind::ModportMember => "modport member".to_string(),
};
text.fmt(f)
}
}

#[derive(Debug, Clone)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum Direction {
Input,
Output,
Expand Down
13 changes: 12 additions & 1 deletion crates/analyzer/src/symbol_table.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::evaluator::Evaluated;
use crate::namespace::Namespace;
use crate::namespace_table;
use crate::symbol::{Symbol, SymbolKind, TypeKind};
use crate::symbol::{Direction, Symbol, SymbolKind, TypeKind};
use std::cell::RefCell;
use std::collections::HashMap;
use std::fmt;
Expand Down Expand Up @@ -287,6 +287,17 @@ impl SymbolTable {
}
inner = true;
}
SymbolKind::Port(ref x) if x.direction == Direction::Modport => {
if let Some(ref x) = x.r#type {
if let TypeKind::UserDefined(ref x) = x.kind {
namespace = Namespace::default();
for x in x {
namespace.push(*x);
}
inner = true;
}
}
}
_ => (),
}
} else if let Some(last_found) = last_found {
Expand Down
1 change: 1 addition & 0 deletions crates/languageserver/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl Server {
veryl_analyzer::symbol::SymbolKind::EnumMember(_) => SymbolKind::ENUM_MEMBER,
veryl_analyzer::symbol::SymbolKind::Modport(_) => SymbolKind::INTERFACE,
veryl_analyzer::symbol::SymbolKind::Genvar => SymbolKind::VARIABLE,
veryl_analyzer::symbol::SymbolKind::ModportMember => SymbolKind::VARIABLE,
};
let location = to_location(&symbol.token);
#[allow(deprecated)]
Expand Down
18 changes: 18 additions & 0 deletions testcases/sv/39_modport.sv
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module veryl_testcase_Module38 (
veryl_testcase_Interface38.master mst,
veryl_testcase_Interface38.slave slv
);
assign mst.a = slv.a;
endmodule

interface veryl_testcase_Interface38;
logic a;

modport master (
output a
);

modport slave (
input a
);
endinterface
18 changes: 18 additions & 0 deletions testcases/vl/39_modport.vl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module Module38 (
mst: modport Interface38::master,
slv: modport Interface38::slave ,
) {
assign mst.a = slv.a;
}

interface Interface38 {
var a: logic;

modport master {
a: output,
}

modport slave {
a: input,
}
}

0 comments on commit d32f303

Please sign in to comment.