-
-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathcheck_port.rs
More file actions
129 lines (117 loc) · 4.62 KB
/
Copy pathcheck_port.rs
File metadata and controls
129 lines (117 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
use crate::analyzer_error::AnalyzerError;
use veryl_parser::ParolError;
use veryl_parser::veryl_grammar_trait::*;
use veryl_parser::veryl_walker::{Handler, HandlerPoint};
#[derive(Default)]
pub struct CheckPort {
pub errors: Vec<AnalyzerError>,
point: HandlerPoint,
in_function: bool,
in_module: bool,
in_modport: bool,
}
impl CheckPort {
pub fn new() -> Self {
Self::default()
}
}
impl Handler for CheckPort {
fn set_point(&mut self, p: HandlerPoint) {
self.point = p;
}
}
impl VerylGrammarTrait for CheckPort {
fn port_declaration_item(&mut self, arg: &PortDeclarationItem) -> Result<(), ParolError> {
println!("PER: x {:?}", arg.identifier.identifier_token.token.to_string());
if let HandlerPoint::Before = self.point {
if let PortDeclarationItemGroup::PortTypeConcrete(x) =
arg.port_declaration_item_group.as_ref()
{
let x = x.port_type_concrete.as_ref();
// println!("PER: x {:?}", x.port_type_concrete_opt);
// println!("PER: x {:?}", x.port_type_concrete_opt0);
let direction = x.direction.as_ref();
if let Direction::Inout(_) = direction {
let r#type = &x.array_type;
let is_tri = r#type
.scalar_type
.scalar_type_list
.iter()
.any(|x| matches!(x.type_modifier.as_ref(), TypeModifier::Tri(_)));
if !is_tri {
self.errors
.push(AnalyzerError::missing_tri(&r#type.as_ref().into()));
}
}
if let Some(x) = &x.port_type_concrete_opt0 {
let is_valid_port_default_value = match direction {
Direction::Input(_) => {
// For now, port default value is allowed for module only.
// https://github.com/veryl-lang/veryl/issues/1178#issuecomment-2568996379
!self.in_function
}
Direction::Output(_) => {
// For SystemVerilog, output ports of a function cannot be released.
!self.in_function
&& x.port_default_value.expression.is_anonymous_expression()
}
_ => false,
};
if !is_valid_port_default_value {
self.errors.push(AnalyzerError::invalid_port_default_value(
&arg.identifier.identifier_token.to_string(),
&direction.to_string(),
&x.port_default_value.expression.as_ref().into(),
));
}
}
}
}
Ok(())
}
fn direction(&mut self, arg: &Direction) -> Result<(), ParolError> {
if let HandlerPoint::Before = self.point {
match arg {
Direction::Modport(x) => {
if !self.in_module || self.in_function {
self.errors.push(AnalyzerError::invalid_direction(
"modport",
&x.modport.modport_token.token.into(),
));
}
}
Direction::Import(x) => {
if !self.in_modport {
self.errors.push(AnalyzerError::invalid_direction(
"import",
&x.import.import_token.token.into(),
));
}
}
_ => (),
}
}
Ok(())
}
fn function_declaration(&mut self, _arg: &FunctionDeclaration) -> Result<(), ParolError> {
match self.point {
HandlerPoint::Before => self.in_function = true,
HandlerPoint::After => self.in_function = false,
}
Ok(())
}
fn module_declaration(&mut self, _arg: &ModuleDeclaration) -> Result<(), ParolError> {
match self.point {
HandlerPoint::Before => self.in_module = true,
HandlerPoint::After => self.in_module = false,
}
Ok(())
}
fn modport_declaration(&mut self, _arg: &ModportDeclaration) -> Result<(), ParolError> {
match self.point {
HandlerPoint::Before => self.in_modport = true,
HandlerPoint::After => self.in_modport = false,
}
Ok(())
}
}