Updates for issue #195:
1) Added classification of clock processes 2) Added classification for after keyword 3) Added tests to validate classifications
This commit is contained in:
parent
8c8d89b3e6
commit
43e708cf16
|
|
@ -76,6 +76,7 @@ class line():
|
|||
self.insideSensitivityList = False
|
||||
self.isSensitivityListBegin = False
|
||||
self.isSensitivityListEnd = False
|
||||
self.insideClockProcess = False
|
||||
# Concurrent attributes
|
||||
self.insideConcurrent = False
|
||||
self.isConcurrentBegin = False
|
||||
|
|
@ -219,6 +220,8 @@ class line():
|
|||
# Code tags
|
||||
self.hasCodeTag = False
|
||||
self.codeTags = {}
|
||||
# After attributes
|
||||
self.hasAfterKeyword = False
|
||||
|
||||
def update_line(self, sLine):
|
||||
'''
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
|
||||
architecture ARCH of ENTITY is
|
||||
|
||||
begin
|
||||
|
||||
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;
|
||||
b <= c after 1 ns;
|
||||
c <= d after 1 ns;
|
||||
d <= e after 1 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This process checks for missing after statements
|
||||
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;
|
||||
b <= c;
|
||||
c <= d;
|
||||
d <= e after 1 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This process checks for incorrect times
|
||||
CLK_PROC : process (reset, clk) is
|
||||
begin
|
||||
|
||||
if (reset = '1') then
|
||||
a <= '0';
|
||||
b <= '1';
|
||||
c <= '0';
|
||||
d <= '1';
|
||||
elsif (rising_edge(clk)) then
|
||||
a <= b after 1 s;
|
||||
b <= c after 1 ms;
|
||||
c <= d after 200 ns;
|
||||
d <= e after 10 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This process checks for unalined after statements
|
||||
CLK_PROC : process (reset, clk) is
|
||||
begin
|
||||
|
||||
if (reset = '1') then
|
||||
a <= '0';
|
||||
b <= '1';
|
||||
c <= '0';
|
||||
d <= '1';
|
||||
elsif (falling_edge(clk)) then
|
||||
a <= b after 1 ns;
|
||||
b <= c after 1 ns;
|
||||
c <= d after 1 ns;
|
||||
d <= e after 1 ns;
|
||||
end if;
|
||||
end process CLK_PROC;
|
||||
|
||||
-- This checks detection of after outside clock processes
|
||||
a <= b after 10 ns;
|
||||
|
||||
end architecture ARCH;
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
import sys
|
||||
sys.path.append('vsg')
|
||||
|
||||
from vsg.rules import after
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
# Read in test file used for all tests
|
||||
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'after_test_input.vhd'))
|
||||
oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
class testRuleAfterMethods(unittest.TestCase):
|
||||
|
||||
def test_rule_001(self):
|
||||
oRule = signal.rule_001()
|
||||
self.assertTrue(oRule)
|
||||
self.assertEqual(oRule.name, 'after')
|
||||
self.assertEqual(oRule.identifier, '001')
|
||||
lExpected = [32, 33]
|
||||
oRule.analyze(oFile)
|
||||
self.assertEqual(oRule.violations, lExpected)
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import os
|
||||
|
||||
import unittest
|
||||
from vsg import vhdlFile
|
||||
from vsg.tests import utils
|
||||
|
||||
lFile = utils.read_vhdlfile(os.path.join(os.path.dirname(__file__),'..','after','after_test_input.vhd'))
|
||||
oFile = vhdlFile.vhdlFile(lFile)
|
||||
|
||||
class testVhdlFileAfterMethods(unittest.TestCase):
|
||||
|
||||
def test_after_detection(self):
|
||||
lExpected = []
|
||||
lExpected.extend(range(15, 19))
|
||||
lExpected.extend([32,35])
|
||||
lExpected.extend(range(49, 53))
|
||||
lExpected.extend(range(66, 70))
|
||||
lExpected.append(74)
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.hasAfterKeyword:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
||||
def test_inside_clock_process(self):
|
||||
lExpected = []
|
||||
lExpected.extend(range(14, 21))
|
||||
lExpected.extend(range(31, 38))
|
||||
lExpected.extend(range(48, 55))
|
||||
lExpected.extend(range(65, 72))
|
||||
|
||||
# Generic actual list
|
||||
lActual = []
|
||||
for iIndex, oLine in enumerate(oFile.lines):
|
||||
if oLine.insideClockProcess:
|
||||
lActual.append(iIndex)
|
||||
# Compare
|
||||
self.assertEqual(lActual, lExpected)
|
||||
|
|
@ -1,3 +1,4 @@
|
|||
from .after import after
|
||||
from .architecture import architecture
|
||||
from .assert_statement import assert_statement
|
||||
from .attribute import attribute
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
import re
|
||||
|
||||
|
||||
def after(dVars, oLine):
|
||||
|
||||
if oLine.isEndConcurrent or oLine.isSequentialEnd:
|
||||
if re.match('^.*\safter\s', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.hasAfterKeyword = True
|
||||
|
|
@ -7,6 +7,7 @@ def process(dVars, oLine):
|
|||
classify_process_sensitivity_list(dVars, oLine)
|
||||
classify_process_begin_keyword(dVars, oLine)
|
||||
classify_process_end_keyword(dVars, oLine)
|
||||
classify_clock_process(dVars, oLine)
|
||||
|
||||
|
||||
def classify_process_keyword(dVars, oLine):
|
||||
|
|
@ -64,3 +65,11 @@ def classify_process_end_keyword(dVars, oLine):
|
|||
dVars['fFoundProcessBegin'] = False
|
||||
dVars['iCurrentIndentLevel'] = dVars['iCurrentIndentLevel'] - 1
|
||||
dVars['SensitivityListFound'] = False
|
||||
|
||||
def classify_clock_process(dVars, oLine):
|
||||
if re.match('^\s*elsif\s*.*\'event\s+and\s+\w+\s*=\s*\'[0-1]\'', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.insideClockProcess = True
|
||||
if re.match('^\s*elsif\s*.*rising_edge', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.insideClockProcess = True
|
||||
if re.match('^\s*elsif\s*.*falling_edge', oLine.lineNoComment, flags=re.IGNORECASE):
|
||||
oLine.insideClockProcess = True
|
||||
|
|
|
|||
|
|
@ -33,6 +33,8 @@ def update_process_attributes(oPreviousLine, oCurrentLine):
|
|||
|
||||
if oPreviousLine.insideProcess and not oPreviousLine.isEndProcess:
|
||||
oCurrentLine.insideProcess = True
|
||||
if oPreviousLine.insideClockProcess and not oPreviousLine.isEndProcess:
|
||||
oCurrentLine.insideClockProcess = True
|
||||
|
||||
|
||||
def update_concurrent_attributes(oPreviousLine, oCurrentLine):
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ class vhdlFile():
|
|||
classify.sequential(dVars, oLine)
|
||||
classify.variable_assignment(dVars, oLine)
|
||||
classify.wait(dVars, oLine)
|
||||
classify.after(dVars, oLine)
|
||||
|
||||
# Check instantiation statements
|
||||
if oLine.insideArchitecture and not oLine.insideProcess and \
|
||||
|
|
|
|||
Loading…
Reference in New Issue