iTranslated by AI

The content below is an AI-generated translation. This is an experimental feature, and may contain errors. View original article
💎

A New Hardware Description Language (HDL): Veryl

に公開3

Introduction

As I wrote in the following article, I decided to create a new hardware description language.

https://zenn.dev/dalance/articles/17017b7b95b2ca

After working on it for about a week, it has reached a state where it's somewhat functional. Since I wanted a place to note down and discuss ideas for syntax and features, I've decided to release it even though it's still a work in progress.

Veryl

The name of the new language is "Veryl." Following the common trend of gemstone-themed programming languages, it is named after "beryl + V from Verilog = Veryl." The file extension for source code is ".vl."

https://github.com/dalance/veryl

If you have any features you'd like to see added, please submit an Issue. Since this is partly a hobby project, I might not incorporate every suggestion, but I will consider them as much as possible.

What you can do

At this stage, I haven't released pre-built binaries, so please install it in an environment where Rust can be built using the following commands:

$ cargo install veryl
$ cargo install veryl-ls    # When using the Language Server

The veryl command is used to execute various processes. Running the command by itself will process all ".vl" files under the current directory, but you can also process a specific file by providing its name.

veryl check

This checks the source code. It checks not only for syntax errors but also for semantic errors. Currently, it checks for:

  • Invalid numbers in numeric literals (e.g., 10'b3)
  • Bit width overflow in numeric literals (e.g., 8'hffff)
  • Use of invalid syntax elements (e.g., if_reset used outside of always_ff)
  • Duplicate identifiers

veryl fmt

This formats the source code. Please be careful as it overwrites files without any specific warning.
The --check option only performs a format check and displays the differences. This is intended for use in CI environments.

veryl build

This generates SystemVerilog source code. I have confirmed that it is at least syntactically correct, but I haven't verified if it will be accepted correctly by various third-party tools.

Language Server

Among the commands mentioned above, check and format can also be executed via the Language Server. Errors are checked and displayed in real-time as you type. Formatting is supported via the Language Server's formatting command.

Source Code Examples

Examples of source code that can be processed at this time are available below. Since there is no language reference yet, please read through them to get a feel for the language...

https://github.com/dalance/veryl/tree/master/testcases

The vl directory contains the Veryl source code, and the sv directory contains the corresponding converted SystemVerilog source code. These files also serve as examples for the formatter; even if you modify the spacing or indentation, running veryl fmt will always restore them to this specific format.

Discussion

Ryuz88Ryuz88

素晴らしい言語をありがとうございます。とても興味深く見させていただいております。
少し要望等を書かせて頂いても良いでしょうか?(我儘ばかりで恐縮なのですが)

all-x, all-z

localparam int unsigned f = '0;
localparam int unsigned ff = '1;

はあるようですが 'x や 'z も欲しいのですが難しいでしょうか?

ビット幅キャスト

ビット幅キャストとかは不要という考え方なのでしょうか? (個人的には欲しいです)
変換後の sv が verilator の lint に怒られがちな気がしています。

未定義変数

Verilog では未定義の変数が 1bit の wire になってしまうので、よく `default_nettype none 宣言するのですが、相当の機能があると嬉しいです。

属性の指定

FPGA開発で (* mark_debug="true" ) とか ( ram_style="block" *) などの指定を行いたいことがよくあるので、コメント同様にそのままSVにスルーしてもらえると嬉しいです。

ちなみにFPGAでメモリを推論させるのに

(* ram_style="block" *) logic  [15:0]   mem  [0:4093];

のような書き方をするのですが、veryl でも 可能でしょうか?

dalancedalance

ご提案ありがとうございます。
1人で考えていると自分の使っている記述に関するアイデアしか出ないので、たくさん出していただけるのはとても助かります。

all-x, all-z

これは問題ありません。
(普段使わないので存在を忘れていました…)

ビット幅キャスト

ビット幅チェックはやりたいと思っています。
これから式の評価を実装するのでそのあとになる予定です。
キャスト方法や演算によるビット幅増加をどう扱うかなどはまだあまりイメージできていません。

未定義変数

当初やる予定だったのですが、SV側のパッケージを参照している場合など、疑似エラーが出そうだったのでいったん取りやめていました。
階層参照しない単体の識別子なら誤判定もしないと思うので限定して実装しようと思います。

属性の指定

もともと ifdef 関連をRustのようにアトリビュートにしたいと思っていまして、それと一緒に解決できるかな、と思っています。

#[sv(ram_style="block")]
var mem: logic[4096][16];

みたいなイメージです。
(コメントは実は結構扱いが難しいので、できるだけ正式な構文要素としておきたいです)

Ryuz88Ryuz88

ありがとうございます。いろいろと理解できました(勉強になります)。

ビット幅チェックはやりたいと思っています。

Veryl の段階でチェックできると一番嬉しいですね。ただ parameter の bit 幅が決まらないと判定できないところとかは残りそうな気もするので、変換後のSVも lint 通るように二重チェックしたくなる気もします。

階層参照しない単体の識別子なら誤判定もしないと思うので限定して実装しようと思います。

これは有難いです。

もともと ifdef 関連をRustのようにアトリビュートにしたいと思っていまして、それと一緒に解決できるかな、と思っています。

たしかにアトリビュートの方が良い方法に思いました。

コメントは実は結構扱いが難しいので、

なるほど、勉強になります。

今後の進化がとても楽しみです。 よろしくお願いします。