commit abc269ec4be88de2485c8ef07ca7e78a50fb3448
parent a40c44015b4f5a32571357cff412dde8766ac468
Author: Achuthan TM <achuthantm05@gmail.com>
Date: Thu, 2 Apr 2026 17:18:15 +0530
Week 3: Generate first batch of NFA Verilog modules (Part 1: Initial definitions)
Diffstat:
1 file changed, 44 insertions(+), 0 deletions(-)
diff --git a/output-eg/nfa_0.v b/output-eg/nfa_0.v
@@ -0,0 +1,44 @@
+`timescale 1ns / 1ps
+
+// NFA for regex index 0
+module nfa_0 (
+ input wire clk,
+ input wire en,
+ input wire rst,
+ input wire start,
+ input wire end_of_str,
+ input wire [7:0] char_in,
+ output reg match
+);
+
+ // One-hot state register
+ reg [2:0] state_reg;
+ wire [2:0] next_state;
+
+ assign next_state[0] = 1'b0;
+ assign next_state[1] = (state_reg[0] && (char_in == 8'd97));
+ assign next_state[2] = (state_reg[0] && (char_in == 8'd98));
+
+ always @(posedge clk) begin
+ if (rst || start) begin
+ // Reset to start state (one-hot)
+ state_reg <= 1 << 0;
+ end else if (en) begin
+ state_reg <= next_state;
+ end
+ end
+
+ // Match logic: asserted on cycle following end_of_str
+ always @(posedge clk) begin
+ if (rst || start) begin
+ match <= 1'b0;
+ end else if (en) begin
+ if (end_of_str) begin
+ match <= (|{state_reg[1], state_reg[2]});
+ end else begin
+ match <= 1'b0;
+ end
+ end
+ end
+
+endmodule