1

こんにちは、

入力ファイルを指定して Tcl スクリプトを作成しようとしています。

input               hreadyin;
input  wire         htrans;       
input  wire [7:0]   haddr;   
output logic [31:0] hrdata;
output              hreadyout;

生産します

hreadyin(hreadyin),
htrans(htrans),
haddr(haddr[7:0]),
hrdata(hrdata[31:0]),
hready(hreadyout)

つまり、フォーマットは次のとおりです。

<input/output> <wire/logic optional> <width, optional> <paramName>;

それぞれの間の空白の数に制限はありません。

入力ファイルからの読み取りに問題はなく、各行を$line要素に入れることができました。今、私は次のようなことを試みています:

  set param0 [split $line "input"]
  set param1 [lindex $param0 1]

しかし、すべての行に "input"行が含まれているわけではないため、必要な要素 (存在する場合は名前と幅) を取得できません。

この種の解析を実行できる Tcl の別のコマンドはありますか?

4

3 に答える 3

2

regexp コマンドは、任意の空白で区切られた単語を見つけるのに役立ちます。

while {[gets $fh line] != -1} {
    # get all whitespace-separated words in the line, ignoring the semi-colon
    set i [string first ";" $line]
    set fields [regexp -inline -all {\S+} [string range $line 0 $i-1]]

    switch -exact -- [llength $fields] {
        2 - 3 {
            set name [lindex $fields end]
            puts [format "%s(%s)," $name $name]
        }
        4 {
            lassign $fields - - width name
            puts [format "%s(%s%s)," $name $name $width]
        }
    }
}
于 2013-06-04T18:00:40.397 に答える