Updates for issue #96

1)  Added process_029
  2)  Added tests
  3)  Updated code examples
  4)  Added documentation
This commit is contained in:
Jeremiah C Leary 2017-12-10 18:33:17 -06:00
parent 70a239b107
commit 14767e773d
14 changed files with 107 additions and 8 deletions

View File

@ -47,3 +47,24 @@ Parenthesis on multiple lines should be in the same column.
rd_full, wr_full
)
process_029
###########
This rule checks for **rising_edge** and **falling_edge** in processes.
**Violation**
.. code-block:: vhdl
if (rising_edge(CLK)) then
if (falling_edge(CLK)) then
**Fix**
.. code-block:: vhdl
if (CLK'event and CLK = '1') then
if (CLK'event and CLK = '0') then

View File

@ -27,3 +27,4 @@ from rule_025 import rule_025
from rule_026 import rule_026
from rule_027 import rule_027
from rule_028 import rule_028
from rule_029 import rule_029

View File

@ -0,0 +1,30 @@
from vsg import rule
from vsg import check
from vsg import fix
import re
class rule_029(rule.rule):
'''
Process rule 029 checks for "rising_edge" and "falling_edge" in processes.
'''
def __init__(self):
rule.rule.__init__(self)
self.name = 'process'
self.identifier = '029'
self.solution = 'Use \'event for clocks.'
self.phase = 1
def analyze(self, oFile):
for iLineNumber, oLine in enumerate(oFile.lines):
if oLine.insideProcess and ('ing_edge' in oLine.lineLower):
self.add_violation(iLineNumber)
def _fix_violations(self, oFile):
for iLineNumber in self.violations:
oLine = oFile.lines[iLineNumber]
oLine.update_line(re.sub(r'rising_edge\s*\(\s*(\w+)\s*\)', r'\1"event and \1 = "1"', oLine.line, re.IGNORECASE).replace('"', '\''))
oLine.update_line(re.sub(r'falling_edge\s*\(\s*(\w+)\s*\)', r'\1"event and \1 = "0"', oLine.line, re.IGNORECASE).replace('"', '\''))

View File

@ -80,7 +80,7 @@ begin
if (RST_I = '1') then
next_s <= reset_s;
elsif (rising_edge(CLK_I)) then
elsif (CLK_I'event and CLK_I = '1') then
flag <= INTA_I;
case next_s is

View File

@ -49,7 +49,7 @@ begin
process (CLK_I) is
begin
if (rising_edge(CLK_I)) then
if (CLK_I'event and CLK_I = '1') then
CE_16 <= '0'; -- make CE_16 stay on for (at most) one cycle
if (RST_I = '1') then

View File

@ -98,7 +98,7 @@ begin
process (Clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
if (State = IDLE) then
if (Reset = '1') then
State <= CLEAR;

View File

@ -33,7 +33,7 @@ begin
process (Clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
Counter <= nCounter;
ButtonHistory <= nButtonHistory;
end if;

View File

@ -45,7 +45,7 @@ begin
process (clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
if (BufferWrite = '1') then
mybuffer(conv_integer(addressWrite)) <= inColor;
end if;

View File

@ -22,7 +22,7 @@ begin
process (Clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
counter <= counter + 1;
end if;

View File

@ -40,7 +40,7 @@ begin
process (Clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
if (Move = '1') then
if (MoveLeft = '1' and MoveRight = '0') then
if (not (rX = "0000000000")) then

View File

@ -54,7 +54,7 @@ begin
process (Clk) is
begin
if (rising_edge(Clk)) then
if (Clk'event and Clk = '1') then
if (XState=TPW and X(7 downto 1)="1100000") then
X <= (others=>'0');
XState <= TBP;

View File

@ -0,0 +1,27 @@
architecture RTL of ENTITY1 is
begin
PROC_1 : process(CLK) is
begin
if (rising_edge(CLK)) then
wr_en <= '1';
end if;
if (falling_edge(CLK)) then
rd_en <= '1';
end if;
if (CLK'event and CLK = '1') then
overflow <= '1';
end if;
if (CLK'event and CLK = '0') then
underflow <= '1';
end if;
end process PROC_1;
end architecture RTL;

View File

@ -8,6 +8,7 @@ from vsg import vhdlFile
# Read in test file used for all tests
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'process_test_input.vhd'))
oFileEvent = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'process_event_test_input.vhd'))
class testFixRuleProcessMethods(unittest.TestCase):
@ -201,3 +202,12 @@ class testFixRuleProcessMethods(unittest.TestCase):
self.assertEqual(oFile.lines[35].line, ' ) is -- This is a comment')
self.assertEqual(oFile.lines[41].line, ' ) is')
self.assertEqual(oFile.lines[29].line, ' ) is')
def test_fix_rule_029(self):
oRule = process.rule_029()
dExpected = []
oRule.fix(oFileEvent)
oRule.analyze(oFileEvent)
self.assertEqual(oRule.violations, dExpected)
self.assertEqual(oFileEvent.lines[9].line, ' if (CLK\'event and CLK = \'1\') then')
self.assertEqual(oFileEvent.lines[13].line, ' if (CLK\'event and CLK = \'0\') then')

View File

@ -8,6 +8,7 @@ from vsg import vhdlFile
# Read in test file used for all tests
oFile = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'..','process','process_test_input.vhd'))
oFileEvent = vhdlFile.vhdlFile(os.path.join(os.path.dirname(__file__),'process_event_test_input.vhd'))
class testRuleProcessMethods(unittest.TestCase):
@ -262,3 +263,12 @@ class testRuleProcessMethods(unittest.TestCase):
dExpected = [27,33]
oRule.analyze(oFile)
self.assertEqual(oRule.violations, dExpected)
def test_rule_029(self):
oRule = process.rule_029()
self.assertTrue(oRule)
self.assertEqual(oRule.name, 'process')
self.assertEqual(oRule.identifier, '029')
dExpected = [9,13]
oRule.analyze(oFileEvent)
self.assertEqual(oRule.violations, dExpected)