-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfsm.vhd.bak
100 lines (93 loc) · 3.21 KB
/
fsm.vhd.bak
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
library ieee;
use IEEE.std_logic_1164.all;
use ieee.numeric_std.all;
-- Do not modify the port map of this structure
entity comments_fsm is
port (clk : in std_logic;
reset : in std_logic;
input : in std_logic_vector(7 downto 0);
output : out std_logic
);
end comments_fsm;
architecture behavioral of comments_fsm is
-- type for states, current implementation uses 4 states, could be reduced to 3
type STATE_TYPE is (no_comment, first_slash, incomment, incomment_star, block_exit);
signal state: STATE_TYPE := no_comment;
-- The ASCII value for the '/', '*' and end-of-line characters
constant SLASH_CHARACTER : std_logic_vector(7 downto 0) := "00101111";
constant STAR_CHARACTER : std_logic_vector(7 downto 0) := "00101010";
constant NEW_LINE_CHARACTER : std_logic_vector(7 downto 0) := "00001010";
begin
-- process for FSM for comment checking in C
process (clk, reset)
begin
-- check to see if FSM is reset
if reset = '1' then
state <= no_comment;
output <= '0';
-- if not in reset mode run FSM
elsif rising_edge(clk) then
case state is
-- when we are in no_comment check to see if slash is next char
when no_comment =>
-- if slash is next char enter "first_slash" state
if input = SLASH_CHARACTER then
state <= first_slash;
output <= '0';
-- if slash is not next char, stay in no_comment state
else
state <= no_comment;
output <= '0';
end if;
-- if we are in first_slash state check to see if next char starts a comment
when first_slash =>
-- if next char is a slash enter incomment_slash state
if input = SLASH_CHARACTER then
output <= '0';
state <= incomment_slash;
-- if next char is a star enter incomment_star state
elsif input = STAR_CHARACTER then
output <= '0';
state <= incomment_star;
-- else return to no_comment state
else
output <= '0';
state <= no_comment;
end if;
-- if we are in incomment_slash state wait to detect new_line char
when incomment_slash =>
-- if next char is new_line char then exit comment section
if input = NEW_LINE_CHARACTER then
output <= '1';
state <= no_comment;
--else wait for new line to exit comment
else
output <= '1';
state <= incomment_slash;
end if;
-- if we are in incomment_star wait to detect * char
when incomment_star =>
-- if next char is a * char then move to block_exit state
if input = STAR_CHARACTER then
output <= '1';
state <= block_exit;
--else wait for * char
else
output <= '1';
state <= incomment_star;
end if;
-- if we are in block_exit state check next char to see if comment block is over
when block_exit =>
-- if next char is a slash then exit comment and return to "no_comment"
if input = SLASH_CHARACTER then
output <= '1';
state <= no_comment;
--else return to incomment_star state (i.e. we are still in a block comment)
else
output <= '1';
state <= incomment_star;
end if;
end case;
end if;
end process;
end behavioral;