opentitan icon indicating copy to clipboard operation
opentitan copied to clipboard

[tool] Use Verible's verilog_format as automatic code formatter

Open sjgitty opened this issue 7 years ago • 10 comments

This is in the works, just making an official request for it to the current owner within Google. @fangism

sjgitty avatar May 26 '19 00:05 sjgitty

Related question: Are there any emacs modefiles that OT people can share? Or scripts (even bad ones)? Cleaning code for a PR takes too much time for me right now.

Even if there are no "final" solutions yet (and I'm not pushing for active development between now and launch) I'd like to hear what stopgap solutions people are using for cleaning their code to match the style guide. @eunchan @asb @tjaychen

martin-lueker avatar Oct 05 '19 13:10 martin-lueker

I'm VIM person (not trying to debating VIM vs emac :) ). But I don't have any vim configuration for verilog style.

eunchan avatar Oct 07 '19 16:10 eunchan

Just a note that there is an open request for a Verilog format tool like exists for C and python. There are some in the works, but have not been staffed heavily due to priorities.

I'm also a vim'r

On Mon, Oct 7, 2019 at 9:37 AM Eunchan Kim [email protected] wrote:

I'm VIM person (not trying to debating VIM vs emac :) ). But I don't have any vim configuration for verilog style.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lowRISC/opentitan/issues/56?email_source=notifications&email_token=AJZQKVJC6TCIYWAAN5BUMHTQNNQVVA5CNFSM4ISTJWFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEARABZI#issuecomment-539099365, or mute the thread https://github.com/notifications/unsubscribe-auth/AJZQKVIMX33SIG5ASMQALGTQNNQVVANCNFSM4ISTJWFA .

sjgitty avatar Oct 07 '19 16:10 sjgitty

IIRC @mdhayter has an verilog-mode based emacs config that gets you close to our formatting, but not quite there. Going beyond that is the purpose of this issue.

imphil avatar Oct 07 '19 16:10 imphil

Thanks @imphil. I'll ask Mark. Honestly any better approximation would be an improvement to what I have now.

martin-lueker avatar Oct 09 '19 16:10 martin-lueker

There's https://github.com/google/verible now. It's not quite there yet in terms of what we need, @tomroberts-lowrisc can you fill in things that are not working yet for the OT use caes?

imphil avatar Nov 12 '19 21:11 imphil

@fangism for visibility.

On Tue, Nov 12, 2019 at 01:18:34PM -0800, Philipp Wagner wrote:

There's https://github.com/google/verible now. It's not quite there yet in terms of what we need, @tomroberts-lowrisc can you fill in things that are not working yet for the OT use caes?

eunchan avatar Nov 12 '19 22:11 eunchan

I have only had a quick look at the tool. It probably has some further configuration that I haven't figured out yet, but a couple of issues are:

  1. Horizontal spacing - most (but not all) of the aligned blocks of code get blown away e.g. port list
    output logic [31:0]          csr_depc_o,
    output logic                 debug_single_step_o,
    output logic                 debug_ebreakm_o,
    output logic                 debug_ebreaku_o,

    input  logic [31:0]          pc_if_i,

Becomes

   output logic [31:0]          csr_depc_o,
    output logic debug_single_step_o,
    output logic debug_ebreakm_o,
    output logic debug_ebreaku_o,

    input logic [31:0]          pc_if_i,
  1. Assignment of structs gets dragged onto a single line
          mstatus_d = '{
              mie:  csr_wdata_int[CSR_MSTATUS_MIE_BIT],
              mpie: csr_wdata_int[CSR_MSTATUS_MPIE_BIT],
              mpp:  priv_lvl_e'(csr_wdata_int[CSR_MSTATUS_MPP_BIT_HIGH:CSR_MSTATUS_MPP_BIT_LOW]),
              mprv: csr_wdata_int[CSR_MSTATUS_MPRV_BIT],
              tw:   csr_wdata_int[CSR_MSTATUS_TW_BIT]
          };

Becomes

          mstatus_d = '{mie:  csr_wdata_int[CSR_MSTATUS_MIE_BIT], mpie: csr_wdata_int[CSR_MSTATUS_MPIE_BIT], mpp:  priv_lvl_e'(csr_wdata_int[CSR_MSTATUS_MPP_BIT_HIGH:CSR_MSTATUS_MPP_BIT_LOW]), mprv: csr_wdata_int[CSR_MSTATUS_MPRV_BIT], tw:   csr_wdata_int[CSR_MSTATUS_TW_BIT]};
  1. Some other issues like line breaks getting lost
        endcase
      end
      assign pmp_cfg_wdata[i].exec  = csr_wdata_int[(i%4)*PMP_CFG_W+2];
      // W = 1, R = 0 is a reserved combination. For now, we force W to 0 if R == 0

Becomes

        endcase
      end assign pmp_cfg_wdata[i].exec = csr_wdata_int[(i%4) * PMP_CFG_W + 2];  // W = 1, R = 0 is a reserved combination. For now, we force W to 0 if R == 0

tomeroberts avatar Nov 13 '19 10:11 tomeroberts

Thanks, Tom, for giving it an initial whirl. To set expectations, the Verible formatter is far from a production quality tool at this time. We will happy accept issues filed against it, including comments about severity. But please file at http://github.com/google/verible/issues .

fangism avatar Nov 13 '19 21:11 fangism

We are now using Ibex as a test bed for Verible format, see lowrisc/ibex#687. Since Ibex and OT use the same coding style, but is significantly smaller, we should be able to iron out the main issues there before doing the same for OpenTitan.

imphil avatar Jul 06 '20 09:07 imphil