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

Indentation gets stuck with nested else statements #2

Open
jweng2 opened this issue May 14, 2019 · 1 comment
Open

Indentation gets stuck with nested else statements #2

jweng2 opened this issue May 14, 2019 · 1 comment

Comments

@jweng2
Copy link

jweng2 commented May 14, 2019

Multi-line "if" statements that have "else" clauses will be formatted with increasingly deep indentation which fails to reset back after closure of the "if" conditional

As an example, consider the following snippet of code which sits within a "case" statement implementing an FSM. As you can see, the first "end else begin" about midway through is indented, with all following "end" statements held to a similar indentation. This misrepresents the association of "if" statement "begins" against the closing "ends". Furthermore, the following state ADDR_SETUP is now mistakenly indented. Subsequent states in the FSM experience the same over-indentation.

        // Waiting for AHB traffic
        IDLE: begin
          // Clear out status
          xfer_done    <= 0;
          o_wrprot_err <= 0;
          
          // Filter out writes to invalid address space
          if (we || re) begin
            if (mr_sel[0] || mr_sel[1]) begin
              
              // Writes with wrprot asserted will be killed
              if (we) begin
                if (i_wr_prot) begin
                  o_wrprot_err <= 1;
                  xfer_done    <= 1;
                  end else begin
                    cs <= ADDR_SETUP;
                  end
                  end else if (re) begin
                    cs <= ADDR_SETUP;
                  end
                  end else begin
                    // release slave on invalid addr so AHB doesn't hang
                    xfer_done <= 1;
                    cs        <= AHB_DELAY;
                  end
                end
              end
              
              // 1st Cycle - latch in addr, drive ctrls on read
              ADDR_SETUP: begin
                cs <= WR_RD_DELAY;
                ....

I believe a cleaner and more "correct" formatting would sit along the lines of the following:

        // Waiting for AHB traffic
        IDLE: begin
          // Clear out status
          xfer_done    <= 0;
          o_wrprot_err <= 0;
          
          // Filter out writes to invalid address space
          if (we || re) begin
            if (mr_sel[0] || mr_sel[1]) begin
              
              // Writes with wrprot asserted will be killed
              if (we) begin
                if (i_wr_prot) begin
                  o_wrprot_err <= 1;
                  xfer_done    <= 1;
                end else begin
                  cs <= ADDR_SETUP;
                end
              end else if (re) begin
                cs <= ADDR_SETUP;
              end
            end else begin
              // release slave on invalid addr so AHB doesn't hang
              xfer_done <= 1;
              cs        <= AHB_DELAY;
            end
          end
        end

        // 1st Cycle - latch in addr, drive ctrls on read
        ADDR_SETUP: begin
          cs <= WR_RD_DELAY;
          ....
@GitJer
Copy link

GitJer commented May 3, 2022

Same problem here. It helps if the "end else begin" is broken into two lines:
end
else begin

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

2 participants