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

can't parse when resetall is present and module has multiple parameters #89

Open
charletes opened this issue Aug 11, 2023 · 5 comments
Open

Comments

@charletes
Copy link

Hi, I'm trying to parse the following code and it fails when reaching the #:

`resetall
`timescale 1ns/1ps

module test #(
    parameter VAL1 = 3,
    parameter VAL = 4
) (data_out);

output data_out;

endmodule

However, this works:

// `resetall <------------
`timescale 1ns/1ps

module test #(
    parameter VAL1 = 3,
    parameter VAL = 4
) (data_out);

output data_out;

endmodule

This one also works:

`resetall
`timescale 1ns/1ps

module test #(
//    parameter VAL1 = 3, <------------
    parameter VAL = 4
) (data_out);

output data_out;

endmodule

Any idea about how to proceed?

@charletes
Copy link
Author

charletes commented Aug 11, 2023

This is how I'm processing it btw:

        let mut defines = HashMap::new();
        let includes = Vec<PathBuf>::new();
        let res = preprocess(&path, &defines, &includes, false, false);

        match res {
            Ok((text, new_defines)) => {
                println!("Yay!");

                let orig = String::from(text.text());
                let res = parse_sv_pp(text, new_defines, false);

                match res {
                    Ok((syntax, new_defines)) => {
                        println!("yay again!");
                    }
                    Err(x) => { // <- this is the error I get
                        println!("booo (2)");
                        debug_println!("{:?}", x);
                        print!("{}", orig);
                    }
                }
            }
            Err(err) => {
                println!("Boo!");
            }
        }

The output is:

Yay!
booo (2)
Parse(Some(("test_module.sv", 45)))

(... original verilog goes here ...)

@DaveMcEwan
Copy link

I can reproduce this with svlint v0.9.0.

`ifdef DIRECTIVE_RESETALL
`resetall
`endif// DIRECTIVE_RESETALL
module M
#(
P
`ifdef SECOND_PARAM
,
`ifdef KEYWORD_PARAMETER
parameter
`endif// KEYWORD_PARAMETER
Q
`endif// SECOND_PARAM
) () ; endmodule

Omitting any of the preprocessor defines avoids the parse error. I must define all 3 before I see the parse error:
svlint-parseonly foo.sv -D DIRECTIVE_RESETALL -D SECOND_PARAM -D KEYWORD_PARAMETER ->

Error: parse error
   --> foo.sv:5:1
  |
5 | #(
  | ^

Output from the preprocessor looks good:
svlint-parseonly foo.sv -D DIRECTIVE_RESETALL -D SECOND_PARAM -D KEYWORD_PARAMETER -E ->

`resetall
// DIRECTIVE_RESETALL
module M
#(
P
,
parameter
// KEYWORD_PARAMETER
Q
// SECOND_PARAM
) () ; endmodule

Sorry @charletes, I don't know why this happens, but hopefully it's good to know that it's not just you.

@charletes
Copy link
Author

Thanks for looking into it! I'll try to catch where the tool breaks down but I'm not familiar with the code so it may take a while.

@charletes
Copy link
Author

Unfortunately I don't understand enough of the internals to figure out where things go awry. I had a look at the parsing process and it seems to follow the syntax definition to a tee, but somehow the "resetall" gets things in the wrong state.

I did a really ugly workaround that works for me, using the preprocessor first, removing all the resetall statements, and then parsing the resulting string.

@yousifBilal
Copy link

Any progress on this? I also encountered an issue with an internal design using `resetall macro. But the error position points to random things.

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

3 participants