2017-05-18 8 views
0

私はTCLスクリプトの初心者です。私は、Verilogファイルからxlsファイルへのデータを以下のように解析しています。Verilogファイルからのデータの解析

 
===================================================================================================== 
apn 
u_apn_start_ctrl_final_adder_add_212_41 
module:add_unsigned_carry_882 
very_fast    +  unsigned 32x32x1 32  120.39 212 41 feu_start_ctrl.v 
===================================================================================================== 

私が抽出したい:解析が最後のセクションの後に終了します

 
Inferred components 
Operator Signedness Inputs Outputs CellArea Line Col  Filename  
===================================================================================================== 
apn 
u_apn_ttp_logic 
abc 
u_apn_wgt_op_rd_u_apn_sca_u_part_sel1_sl_69_33 
module:shift_right_vlog_unsigned_4662_7709 
very_fast/barrel  >>  x   25x5  25  223.02 69 33 part_select.v 
===================================================================================================== 
apn 
u_apn_ttp_logic 
u_apn_wgt_op_rd_u_apn_scale_u_part_sel1_sub00283545 
module:sub_signed_4513_5538 
very_fast    -  signed  11x24  25  152.80 0 0 a     
===================================================================================================== 

(これは...長いファイルである)

:入力Verilogファイルは、データを次のものが含ま

以下のデータは、最初のセクションを検討する

 
Top name=apn 
Instance=u_apn_ttp_logic/abc/u_apn_wgt_op_rd_u_feu_scale_u_part_select1_srl_69_33 
Module = shift_right_vlog_unsigned_4662_7709 
Architecture=very_fast/barrel 
Operator = >> 
Sign=x 
Input Size = 25x5 
Output = 25 
Area = 223.02 
Column = 69 
Row = 33 
File Name = part_select.v 

これを実装しているうちに、私は悩んでいます。以下

は同じのために私のアプローチです:

set fd "[open "path_data.v" r]" 
set flag 0 
    while {[gets $fd line] !=-1} { 
     if {[regexp "\===*" $line]} { 
     while {[gets $fd line] >= 0} { 
      append data "$line " 
      if {[regexp "\====*" $line]} { 
       break 
      } } 
set topname [lindex $data 0] 
regexp {(^[a-z]*) (.*) (.*module)} $data match topname instance sub3 
puts "top name :$topname " 
puts "instance: $instance" 

} 

close $fd 

は、私はまた、私は、これらの値を抽出助けてください 他の値、出力だけtopnameinstance名前にはできませんよ。

答えて

0

このような種類のタスクでは、は実際にはとなり、タスクの一部を単純なビットだけの手順に入れると便利です。たとえば、単一のセクションの処理を独自のプロシージャに分割するとします。 1つのセクションだけを処理するので(おそらく全体のファイルよりもずっと短くなる)、行で処理する代わりに文字列(または文字列のリスト)を扱うことができるため、作業を大幅に理解しやすくなります。

例えば、それだけで、この入力テキストを処理します:

 
apn 
u_apn_ttp_logic 
abc 
u_apn_wgt_op_rd_u_apn_sca_u_part_sel1_sl_69_33 
module:shift_right_vlog_unsigned_4662_7709 
very_fast/barrel  >>  x   25x5  25  223.02 69 33 part_select.v 

我々はこのようなものを扱うことがあります

proc processSection {sectionText} { 
    set top "" 
    set instance "" 
    set module "" 
    set other {} 
    foreach line [split $sectionText "\n"] { 
     if {$top eq ""} { 
      set top [string trim $line] 
      continue 
     } 
     if {$module eq ""} { 
      # This regular expression matches lines starting with “module:” and 
      # extracts the rest of the line 
      if {[regexp {^module:(.*)} $line -> tail]} { 
       set module [string trim $tail] 
      } else { 
       append instance [string trim $line] "/" 
      } 
      continue 
     } 
     # This regular expression matches a sequence of non-space characters, and 
     # the -all -inline options make regexp return a list of all such matches. 
     lappend other {*}[regexp -all -inline {\S+} $line] 
    } 
    # Remember to remove trailing “/” character of the instance 
    set instance [string trimright $instance /] 

    # Note that this splits apart the list in $other 
    outputSectionInfo $top $instance $module {*}$other 
} 

は、我々はまた、出力を生成するために何かを必要としています。私はそれを独自のプロシージャに分割しました。なぜなら、パースを出力から分離しておくことがしばしば役に立ちます。

proc outputSectionInfo {top instance module arch op sgn in out area col row file} { 
    # Output the variables 
    foreach {label varname} { 
     "Top name" top 
     "Instance" instance 
     "Module" module 
     "Architecture" arch 
     "Operator" op 
     "Sign"  sgn 
     "Input Size" in 
     "Output" out 
     "Area"  area 
     "Column" col 
     "Row"  row 
     "File Name" file 
    } { 
     # Normally, best to avoid using variables whose names are in variables, but 
     # for printing out like this, this is actually really convenient. 
     puts "$label = [set $varname]" 
    } 
} 

今、私たちはセクションハンドラと出力発電機を持っている(とあなたは、彼らはあなたが一度にやろうとしていたものよりもかなり単純だとして、これらは、賢明なことを行うことを自分のために検証できること)、ヘッダーをスキップしてファイルからセクションをフィードするだけで済みます。コードはそれを行い、ちょうどを行います。

set fd [open "path_data.v"] 
set flag 0 
while {[gets $fd line] >= 0} { 
    if {[regexp {^=====+$} $line]} { 
     if {$flag} { 
      processSection [string trimright $accumulator "\n"] 
     } 
     set flag 1 
     set accumulator "" 
    } else { 
     append accumulator $line "\n" 
    } 
} 
close $fd 

あなたの当面の問題は、あなたのコードがあまりにも早くチャネルを閉じたということでしたが、それはインデントの上に混乱によって引き起こされる順番にあった、それが今度はあなたがあまりにも多くを行うことを試みることによって引き起こされました一箇所。コードをもっと分かりやすくするために分割することは、この種の問題の修正です。コードが間違っている(または間違っている)ことがはるかに簡単に分かります。

+0

これは実際のデータではうまくいかないとは思いますが、間違っていることを確認してその部分を確認するのは簡単です。 –

+0

こんにちはドナル、私はあなたのコードを試みたが、エラーが来ている ご支援のための おかげで、私も最初の場合はループ内でフラグを設定してみました、 も私を助けてくださいは 「outputSectionInfo、コマンドの下に理解します$ top $ instance $ module {*} $その他の " – Krishh

0

私は上記のスクリプトに取り組んでいましたが、これは私のコードです。"========"の後に空白行がある場合、このコードは機能しません。

しかし、私はあなたのコードをうまく整理してみたいと思います。

set fd "[open "path_data.v" r]" 

set fd1 "[open ./data_path_rpt.xls w+]" 
puts $fd1 "Top Name\tInstance\tModule\tArchitecture\tOperator\tSign\tInput Size\tOutput size\tArea\tLine number\tColumn number\tFile Name" 
set data {} 
while {[gets $fd line] !=-1} { 
if {[regexp "\===*" $line]} { 
     set data {}; set flag 0 
     while {[gets $fd line] >= 0} { append data "$line " 
       if {[regexp {[a-z]\.v} $line]} { set flag 1;break} } 
puts "$data\n\n" 
    if {$flag} { 
     set topname [lindex $data 0] 
     regexp {(^[a-z]*) (.*) (.*module\:)(.*)} $data match topname instance sub3 sub4 
     set inst_name {} ; 
     foreach txt $instance { 
     append inst_name "$txt\/" 
     } 
     set instance [string trim $inst_name "\/"] 
     set module [lindex $sub4 0] 
     set architecture [lindex $sub4 1] 
     set operator [lindex $sub4 2] 
     set sign [lindex $sub4 3] 
     set input_size [lindex $sub4 4] 
     set output_size [lindex $sub4 5] 
     set area [lindex $sub4 6] 
     set linenum [lindex $sub4 7] 
     set col_num [lindex $sub4 8] 
     set file_name [lindex $sub4 9] 
     puts $fd1 "$topname\t$instance\t$module\t$architecture\t$operator\t$sign\t$input_size\t$output_size\t$area\t$linenum\t$col_num\t$file_name" 
     set data {} ; set flag 0 
}} 
} 
close $fd1 
close $fd 
関連する問題