forked from dalance/svlint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from ronitnallagatla/unpacked_array
New Rule: Forbid unpacked array declarations
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This rule forbids unpacked array declarations. | ||
|
||
Unpacked arrays are not guaranteed to be represented as contiguous memory, and can cause issues with synthesis tools, especially with how multidimensional arrays are synthesized. For example, a synthesis tool might synthesize out unused memory locations of an unpacked array which is not the intended behavior. | ||
|
||
Additionally, packed arrays allow the user to intuitively index and slice the array and apply bitwise operations. | ||
|
||
The most relevant clauses of IEEE1800-2017 are: | ||
- 7.4 Packed and unpacked arrays |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::config::ConfigOption; | ||
use crate::linter::{SyntaxRule, SyntaxRuleResult}; | ||
use sv_parser::{NodeEvent, RefNode, SyntaxTree}; | ||
|
||
#[derive(Default)] | ||
pub struct UnpackedArray; | ||
|
||
impl SyntaxRule for UnpackedArray { | ||
fn check( | ||
&mut self, | ||
_syntax_tree: &SyntaxTree, | ||
event: &NodeEvent, | ||
_option: &ConfigOption, | ||
) -> SyntaxRuleResult { | ||
let node = match event { | ||
NodeEvent::Enter(x) => x, | ||
NodeEvent::Leave(_) => { | ||
return SyntaxRuleResult::Pass; | ||
} | ||
}; | ||
|
||
match node { | ||
RefNode::UnpackedDimension(_) => SyntaxRuleResult::Fail, | ||
_ => SyntaxRuleResult::Pass, | ||
} | ||
} | ||
fn name(&self) -> String { | ||
String::from("unpacked_array") | ||
} | ||
|
||
fn hint(&self, _option: &ConfigOption) -> String { | ||
String::from("Avoid using unpacked arrays in variable declarations.") | ||
} | ||
|
||
fn reason(&self) -> String { | ||
String::from("Unpacked arrays can lead to issues during synthesis.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module M; | ||
|
||
logic a [7:0]; | ||
|
||
endmodule; | ||
//////////////////////////////////////////////////////////////////////////////// | ||
module M; | ||
|
||
logic [31:0] b [0:7]; | ||
|
||
endmodule; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module M; | ||
|
||
logic [31:0] a; | ||
|
||
endmodule | ||
//////////////////////////////////////////////////////////////////////////////// | ||
module M; | ||
|
||
logic [7:0][3:0] b; | ||
|
||
endmodule |