VOOZH about

URL: https://qiita.com/kkumt9993/items/70766645c07c298d19c3

⇱ Verilogでコード整形 #Verilog - Qiita


👁 Image
5

Go to list of users who liked

2

Share on X(Twitter)

Share on Facebook

Add to Hatena Bookmark

More than 5 years have passed since last update.

@kkumt9993(かす)

Verilogでコード整形

5
Last updated at Posted at 2017-12-23

はじめに

Verilogのコード整形ソフトを公開しているのを見つけたのでやってみました。

導入

導入方法はGitHubからcloneしてmakeする方法か、実行ファイルを落としてそのまま使用する方法があります。どちらの方法もパスを通して使えるようにします。
GitHub
https://github.com/thomasrussellmurphy/istyle-verilog-formatter
実行ファイル
https://code.google.com/archive/p/istyle-verilog-formatter/

オプション

オプションを数パターン試したものを以下に記載します。
入力テキスト

reg [3:0] cnt;
always @(posedge clk or posedge rst) begin
if(rst) begin
cnt<=4'h0;
end else begin
cnt<=cnt+4'h1;
end
end

--style

ANSI style

./iStyle --style=ansi test.v
reg [3:0] cnt;
always @(posedge clk or posedge rst)
begin
 if(rst)
 begin
 cnt<=4'h0;
 end
 else
 begin
 cnt<=cnt+4'h1;
 end
end

Kernighan&Ritchie style

./iStyle --style=kr test.v
reg [3:0] cnt;
always @(posedge clk or posedge rst) begin
 if(rst) begin
 cnt<=4'h0;
 end
 else begin
 cnt<=cnt+4'h1;
 end
end

GNU style

./iStyle --style=gnu test.v
reg [3:0] cnt;
always @(posedge clk or posedge rst)
 begin
 if(rst)
 begin
 cnt<=4'h0;
 end
 else
 begin
 cnt<=cnt+4'h1;
 end
 end

-s

./iStyle -s2 test.v

スペース挿入オプションで**-s2で各インデントをスペース2で指定する(-s4**ならスペース4)

reg [3:0] cnt;
always @(posedge clk or posedge rst) begin
 if(rst) begin
 cnt<=4'h0;
 end else begin
 cnt<=cnt+4'h1;
 end
end

-p

オペレータの周りだけにスペースパディングを挿入する。

reg [3: 0] cnt;
always @(posedge clk or posedge rst) begin
 if (rst)
 begin
 cnt <= 4'h0;
 end else
 begin
 cnt <= cnt + 4'h1;
 end
end

-P

オペレータと括弧の周囲にスペースパディングを挿入する。

reg [ 3: 0 ] cnt;
always @( posedge clk or posedge rst ) begin
 if ( rst )
 begin
 cnt <= 4'h0;
 end else
 begin
 cnt <= cnt + 4'h1;
 end
end

おわりに

ここには載せてはいませんが、module宣言のインデントがいい感じになりませんでした。Verilogは色々な書き方が出来るので何か強力なformatterがあると便利かもしれません。

5

Go to list of users who liked

2
2

Go to list of comments

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5

Go to list of users who liked

2