Updates for issue #196
Adding test for after statement in clock process: 1) Enhanced testing 2) Added after_001 rule 3) Updated documentation 4) Fixed bug in detecting the end of a sequential statement 5) Updated classification logic
This commit is contained in:
parent
68c6a3860c
commit
e6ff07855c
|
|
@ -0,0 +1,39 @@
|
|||
After Rules
|
||||
-----------
|
||||
|
||||
after_001
|
||||
#########
|
||||
|
||||
This rule checks for **after x** in signal assignments in clock processes.
|
||||
|
||||
**Violation**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
CLK_PROC : process(clock, reset) is
|
||||
begin
|
||||
if (reset = '1') then
|
||||
a <= '0';
|
||||
b <= '1';
|
||||
elsif (clock'event and clock = '1') then
|
||||
a <= d;
|
||||
b <= c;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
**Fix**
|
||||
|
||||
.. code-block:: vhdl
|
||||
|
||||
CLK_PROC : process(clock, reset) is
|
||||
begin
|
||||
if (reset = '1') then
|
||||
a <= '0';
|
||||
b <= '1';
|
||||
elsif (clock'event and clock = '1') then
|
||||
a <= d after 1 ns;
|
||||
b <= c after 1 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
.. NOTE:: This is disabled by default.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
|
||||
from .rule_001 import rule_001
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
|
||||
import re
|
||||
|
||||
from vsg import rule
|
||||
from vsg import utils
|
||||
|
||||
|
||||
class rule_001(rule.rule):
|
||||
'''
|
||||
After rule 001 checks for the "after" keyword in signal assignments in clock processes.
|
||||
'''
|
||||
|
||||
def __init__(self):
|
||||
rule.rule.__init__(self, 'after', '001')
|
||||
self.fixable = False
|
||||
self.phase = 1
|
||||
|
||||
def _pre_analyze(self):
|
||||
self.sequentialStatement = ""
|
||||
|
||||
def _analyze(self, oFile, oLine, iLineNumber):
|
||||
if oLine.insideClockProcess:
|
||||
if oLine.isSequentialEnd:
|
||||
self.sequentialStatement += oLine.lineNoComment.replace('--', ' ')
|
||||
print(self.sequentialStatement)
|
||||
if not re.match('^\s*.*\safter\s', self.sequentialStatement):
|
||||
self.add_violation(iLineNumber)
|
||||
self.sequentialStatement = ""
|
||||
elif oLine.insideSequential:
|
||||
self.sequentialStatement += oLine.lineNoComment.replace('--', ' ')
|
||||
elif oLine.isSequential:
|
||||
self.sequentialStatement = oLine.lineNoComment.replace('--', ' ')
|
||||
|
|
@ -36,6 +36,33 @@ begin
|
|||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This process checks for different alignments of the after statement
|
||||
CLK_PROC : process (reset, clk) is
|
||||
begin
|
||||
|
||||
if (reset = '1') then
|
||||
a <= '0';
|
||||
b <= '1';
|
||||
c <= '0';
|
||||
d <= '1';
|
||||
elsif (clk'event and clk = '1') then
|
||||
a <= b -- after 1 ns;
|
||||
after 1 ns;
|
||||
b <= c
|
||||
after
|
||||
1
|
||||
ns;
|
||||
c <= d
|
||||
after
|
||||
-- some comment
|
||||
1 -- more comments
|
||||
ns -- another comment
|
||||
; -- yet more comments
|
||||
d <= e after 1 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This process checks for incorrect times
|
||||
-- This process checks for incorrect times
|
||||
CLK_PROC : process (reset, clk) is
|
||||
begin
|
||||
|
|
|
|||
|
|
@ -15,10 +15,10 @@ oFile = vhdlFile.vhdlFile(lFile)
|
|||
class testRuleAfterMethods(unittest.TestCase):
|
||||
|
||||
def test_rule_001(self):
|
||||
oRule = signal.rule_001()
|
||||
oRule = after.rule_001()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'after')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
lExpected = [32, 33]
|
||||
lExpected = [33, 34]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, lExpected)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ begin
|
|||
PROC_2 : process (a) is
|
||||
begin
|
||||
|
||||
a <= b or
|
||||
a <= b or -- c = '2';
|
||||
c or
|
||||
d = '1';
|
||||
c1 <= d;
|
||||
|
|
|
|||
|
|
@ -13,9 +13,13 @@ class testVhdlFileAfterMethods(unittest.TestCase):
|
|||
lExpected = []
|
||||
lExpected.extend(range(15, 19))
|
||||
lExpected.extend([32,35])
|
||||
lExpected.extend(range(49, 53))
|
||||
lExpected.extend(range(66, 70))
|
||||
lExpected.append(74)
|
||||
lExpected.append(50)
|
||||
lExpected.append(52)
|
||||
lExpected.append(56)
|
||||
lExpected.append(61)
|
||||
lExpected.extend(range(76, 80))
|
||||
lExpected.extend(range(93, 97))
|
||||
lExpected.append(101)
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
|
|
@ -28,8 +32,9 @@ class testVhdlFileAfterMethods(unittest.TestCase):
|
|||
lExpected = []
|
||||
lExpected.extend(range(14, 21))
|
||||
lExpected.extend(range(31, 38))
|
||||
lExpected.extend(range(48, 55))
|
||||
lExpected.extend(range(65, 72))
|
||||
lExpected.extend(range(48, 64))
|
||||
lExpected.extend(range(75, 82))
|
||||
lExpected.extend(range(92, 99))
|
||||
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
|
|
|
|||
|
|
@ -3,6 +3,9 @@ import re
|
|||
|
||||
def after(dVars, oLine):
|
||||
|
||||
if oLine.isEndConcurrent or oLine.isSequentialEnd:
|
||||
if re.match('^.*\safter\s', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
if oLine.isEndConcurrent or oLine.isSequentialEnd or oLine.insideSequential:
|
||||
if re.match('^.*\s+after\s', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.hasAfterKeyword = True
|
||||
if re.match('^.*after$', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.hasAfterKeyword = True
|
||||
|
||||
|
|
|
|||
|
|
@ -11,5 +11,5 @@ def sequential(dVars, oLine):
|
|||
oLine.indentLevel = dVars['iCurrentIndentLevel']
|
||||
oLine.sequentialAlignmentColumn = oLine.line.find('<=')
|
||||
if oLine.insideSequential:
|
||||
if ';' in oLine.line:
|
||||
if ';' in oLine.lineNoComment:
|
||||
oLine.isSequentialEnd = True
|
||||
|
|
|
|||
Loading…
Reference in New Issue