svRegex SystemVerilog 正規表現パッケージ v0.1.0

はじめに

UVMにはDPI-Cを使用した正規表現メソッドuvm_re_matchがあります。

uvm_re_matchはDPI-Cを使用しないとglobで動作するため、DPI-Cを使用しない正規表現メソッドを作りたいと思いsvRegexを作成しました。

GitHub – tnkmemo/svRegex
Contribute to tnkmemo/svRegex development by creating an account on GitHub.

使い方

GithubのReleaseからZIP/アーカイブファイルをダウンロードします。

Releases · tnkmemo/svRegex
Contribute to tnkmemo/svRegex development by creating an account on GitHub.

解凍したら、ファイルリストにsvRegex/srcをインクルードディレクトリとして追加します。

+incdir+./svRegex/src

後は使用したいmodule等で下記のようにinclude/importすることでメソッドを使用できます。

`include "svRegex_pkg.svh" // Packageなので、module外でinclude

module tb;
  import svRegex_pkg::*;  // メソッドを使用するスコープでimport

  int s, e; // s=Start position, e=end position.
  string pattern = "a+?";
  string text    = "aaaa";

  bit ok = match(pattern, text, s, e);  // substring match → OK

  initial $display("match = %0d (%0d, %0d)", ok, s, e);
endmodule

リファレンス

function bit match(string pattern, string text, output int s, output int e);

正規表現で文字列探索を行うメソッドです。マッチすれば1、そうでないと0を返します。
また、一番最初にマッチした位置を取得します。

Parameters

NameTypeDescription
patternstringRegular expression pattern
textstringInput text to be matched
soutput intStart position
eoutput intEnd position

Return Value

TypeDescription
bitReturns 1 on match success, 0 on failure

まとめ

SystemVerilogの正規表現パッケージsvRegexを紹介しました。

コメント

タイトルとURLをコピーしました