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

define is not properly considering #2033

Open
justincdas opened this issue Oct 28, 2023 · 1 comment
Open

define is not properly considering #2033

justincdas opened this issue Oct 28, 2023 · 1 comment
Labels
formatter Verilog code formatter issues preprocessor anything related to preprocessing (conditionals, macros, etc.)

Comments

@justincdas
Copy link

justincdas commented Oct 28, 2023

Code

`include "defines.svh"

module top (
                                       clk,
                                       rst_n_sync,
                                       in,
                                       out
);

   input                                clk;
   input 			        rst_n_sync;
   input                                in;
   output reg                           out;

`ifdef ASYNC_RESET_N
   always@(posedge clk or negedge rst_n_sync)begin
`else   
   always@(posedge clk)begin
`endif
     if(!rst_n_sync) begin
       out <= 1'b0;
     end else begin
`include "defines.svh"

module top (
                                       clk,
                                       rst_n_sync,
                                       in,
                                       out
);

   input                                clk;
   input 			        rst_n_sync;
   input                                in;
   output reg                           out;

`ifdef ASYNC_RESET_N
   always@(posedge clk or negedge rst_n_sync)begin
`else   
   always@(posedge clk)begin
`endif
     if(!rst_n_sync) begin
       out <= 1'b0;
     end else begin
`include "defines.svh"

module top (
                                       clk,
                                       rst_n_sync,
                                       in,
                                       out
);

   input                                clk;
   input 			        rst_n_sync;
   input                                in;
   output reg                           out;

`ifdef ASYNC_RESET_N
   always@(posedge clk or negedge rst_n_sync)begin
`else   
   always@(posedge clk)begin
`endif
     if(/*!rst_n*/!rst_n_sync) begin
       out <= 1'b0;
     end else begin
       out <= in;
     end
   end //always
endmodule

Command used
verible-verilog-format --inplace temp.v

**Error **
temp.v: temp.v:18:1-5: syntax error at token "`else"
temp.v:23:10-13: syntax error at token "else"
temp.v:25:6-8: syntax error at token "end"

@justincdas justincdas added the formatter Verilog code formatter issues label Oct 28, 2023
@hzeller
Copy link
Collaborator

hzeller commented Oct 28, 2023

Yes, handling of preprocessing is not stellar currently and this is essentially #228 (there are other, similar issues like #241, #267). The problem you run into is that the formatter looks at the tokens as if they where in sequence without considering the branches, so sees two consecutive stars of always blocks and gets confused.

There is work in progress on this in PR #1898 - but since this project is driven by volunteers, it is moving at the pace at which there is free time.

@hzeller hzeller added the preprocessor anything related to preprocessing (conditionals, macros, etc.) label Oct 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
formatter Verilog code formatter issues preprocessor anything related to preprocessing (conditionals, macros, etc.)
Projects
None yet
Development

No branches or pull requests

2 participants