Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A bug when parsing nesting ifStatement #102

Open
Yang-Qirui opened this issue Apr 10, 2022 · 0 comments
Open

A bug when parsing nesting ifStatement #102

Yang-Qirui opened this issue Apr 10, 2022 · 0 comments

Comments

@Yang-Qirui
Copy link

Hello,I found there's probably a mistake when i try to parse a certain type of verilog to do a resource sharing algorithm research, just as the following one, it has a nesting ifStatement structure.

module top(
    input CLK,
    input [31:0] a,
    input [31:0] b,
    input [31:0] c,
    input [31:0] d,
    input [31:0] e,
    input [31:0] f,
    input [1:0] state,
    output [31:0] out
);
reg [31:0] o;
assign out = o;
always @(posedge CLK) begin
    if (state == 0) begin
        o = a + b + c + e;
    end
    else if (state == 1) begin
        o = a + b + d + f;
    end
    else if (state > 1) begin
        if (state == 4) begin
            o = b + c + e + f;
        end
        else begin
            o = c + e + f + a;
        end
    end
end
endmodule

the parsed ast output is:

              ...
              IfStatement:  (at 21)
                GreaterThan:  (at 21)
                  Identifier: state (at 21)
                  IntConst: 1 (at 21)
                Block: None (at 21)
                  IfStatement:  (at 22)
                    Eq:  (at 22)
                      Identifier: state (at 22)
                      IntConst: 4 (at 22)
                    Block: None (at 22)
                      BlockingSubstitution:  (at 23)
                        Lvalue:  (at 23)
                          Identifier: o (at 23)
                        Rvalue:  (at 23)
                          Plus:  (at 23)
                            Plus:  (at 23)
                              Plus:  (at 23)
                                Identifier: b (at 23)
                                Identifier: c (at 23)
                              Identifier: e (at 23)
                            Identifier: f (at 23)
                    Block: None (at 25)
                      BlockingSubstitution:  (at 26)
                        Lvalue:  (at 26)
                          Identifier: o (at 26)
                        Rvalue:  (at 26)
                          Plus:  (at 26)
                            Plus:  (at 26)
                              Plus:  (at 26)
                                Identifier: c (at 26)
                                Identifier: e (at 26)
                              Identifier: f (at 26)
                            Identifier: a (at 26)

as you can see,the last Block object should at least be the child of the first IfStatement (at line 21) instead of the child of the second one (at line 22). Besides, i believe it's necessary to add an IfStatement parent to the last Block, to make it clear that it requires a condition to do the operation ( such as: GreaterThan 1 and NotEq 4) in this block.
Looking forward to your reply.

@Yang-Qirui Yang-Qirui changed the title A mistake when parsing nesting ifStatement A bug when parsing nesting ifStatement Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant