1

I am newbie in TCL scripting. Just wish to get some advice from experts here.

I wish to process the report with format as below. I am thinking to print the report without the header and with just single line like -

Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh' :: Driver a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par) :: Load  b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2' :: Driver d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par) :: Load  e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Input Pin (e_par), f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)  
<more . . .>

Really appreciate if anyone can give some light and idea to me. Thanks much!

****************************************
Report : net
        -connections
Design : soc
Version: G-2012.06-SP2
Date   : Sun Apr  7 22:56:33 2013
****************************************


Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh`:

Driver Pins         Type                
------------        ----------------    
a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par)

Load Pins           Type                
------------        ----------------    
b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)  

1  


Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2`:

Driver Pins         Type                
------------        ----------------    
d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par)

Load Pins           Type                
------------        ----------------    
e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par)
f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)  

1

<more . . .>
  • 2
    A general comment: it's best to assemble the information you want to print out first (e.g., in a Tcl associative array) and then print it. Like that, you can check that you've got the two parts correct independently of each other. The only time you really think in terms of mushing it all together is when the amount of data is so large in a real report that holding it all in memory is a bottleneck (or total blocker). – Donal Fellows Apr 08 '13 at 08:28
  • @DonalFellows Could you look into the issue we're having? The script works for me (I'm using Tcl 8.5) but something doesn't seem to be working for the OP. Could it be about version differences I'm not aware about? – Jerry Apr 10 '13 at 10:16

1 Answers1

0

If I'm understanding your requirements correctly, I would do something like this:

Input file contains:

****************************************
Report : net
        -connections
Design : soc
Version: G-2012.06-SP2
Date   : Sun Apr  7 22:56:33 2013
****************************************


Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh`:

Driver Pins         Type                
------------        ----------------    
a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par)

Load Pins           Type                
------------        ----------------    
b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)  

1  


Connections for net `pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2`:

Driver Pins         Type                
------------        ----------------    
d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par)

Load Pins           Type                
------------        ----------------    
e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par)
f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)  

1

<more . . .>

The script:

# Read file containing input
set inputfile [open "inputfile.txt" r]
# File where output will be written in
set outputfile [open "outputfile.txt" w]

# $type will contain the Pin Type and $outputline will contain the final
# line to be written
set type ""
set outputline ""

# Read each line in the inputfile
while {[gets $inputfile line] != -1} {
    # If first word in line is "Connections" execute
    if {[lindex [split $line " "] 0] == "Connections"} {
        # If $outputline not empty while in this if, it means that we have
        # reached a new connection. So print out the current connection
        # after joining all its elements by " :: " and reset the output line.
        if {$outputline != ""} {
            puts $outputfile [join $outputline " :: "]
            set outputline ""
        }
        # Replacing the ` by ' and removing the end ":" and then putting
        # the full thing into $output line as an element of a list
        regsub -all {\`} $line "\'" newline
        set newline [string trimright $newline "\:"]
        lappend outputline $newline
    }
    # If there is "Pins" in the line, this means we have a header. The regexp
    # captures the pin type by looking for any alphanumeric characters before
    # "Pins"
    regexp -- {([\w]+) Pins} $line - type

    # If there is " Pin " in the line, it means we are in a row of the
    # different 'Pins' type. Here, we put the while line after removing
    # the extra white spaces into the $outputline list.
    if {[regexp -- { Pin } $line]} {
        lappend outputline "$type [string trim $line]"
    }
}
# We reached the end of the document. So, add the last line into the outputfile.
puts $outputfile [join $outputline " :: "]

# Close the files we opened.
close $inputfile
close $outputfile

The output:

Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh' :: Driver a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par) :: Load b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par)
Connections for net 'pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2' :: Driver d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par) :: Load e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par) :: Load f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par)

This script will take 'Driver Type' or 'Load Type' in any order they come (and you can add new types as well). Are there any other possible variations in your in your input?

EDIT: You can change the switch block into this and it will take any type of Pins

if {[regexp -- {([\w]+) Pins} $line - type]} {
    set counter 0
}

reEDIT: Added -- to the regexp.

rereEDIT: Matched edit in question.

Jerry
  • 70,495
  • 13
  • 100
  • 144
  • Thank you Jerry for the answer. I am not sure what am I missing and I got the error below. Error: bad option "------------": must be -exact, -glob, -regexp, or -- Use error_info for more info. (CMD-013) – user2256288 Apr 08 '13 at 12:57
  • If let say the full input file is with headers (text within ****..) as above), how can I skip the header? Thanks much for your help. Appreciate that! – user2256288 Apr 08 '13 at 13:02
  • @user2256288: Hmm, I'm not sure why you're getting this on your machine since I don't have it on mine. Try using this instead `[regexp -- {([\w]+) Pins} $line - type]`. As for the next part about the headers, my script is ignoring any line without 'Pins' and as soon as it sees one, it waits 2 lines before taking the information. I know your original question was edited once, but is the current post as it should be? I'm treating each 'block' of text with blue background as one file, or should it start at the "***.." and end with '1'? Could you first try the amendment to the regexp? – Jerry Apr 08 '13 at 15:38
  • It is working perfectly now. Thanks much Jerry... BTW, if let say I have a input file with similar format as above BUT with multiple nets with headers. How can I modify the code to fit that. Thanks! – user2256288 Apr 08 '13 at 23:56
  • I am trying to modify the code to fit to the requirement I needed (just modified the question...) but I failed to get the output as I wish... Really appreciate your help. Thanks much! – user2256288 Apr 09 '13 at 03:11
  • @user2256288: Hi! I amended the main code I posted earlier to match the new requirements. Could you look into the output? I noted that in your required result, the last part has a comma `,` instead of a `::` and am not sure if that was intended or not. Also note that the script is depending on `Pins` in the header and `Pin` in each of the detailed lines. If there's a different word, it won't work. – Jerry Apr 09 '13 at 09:09
  • Jerry, really appreciate your work on helping this. I have more idea on how your script work now.. BTW, I got the output like below, connection name is missing and both connections in single line instead of separate line somehow... Driver a_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Output Pin (a_par) :: Load b_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh Input Pin (b_par) :: Driver d_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_2 Output Pin (d_par) :: Load e_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (e_par) :: Load f_par/pmg_ccu_ot2_tam_50mhz_sel_xainfwh_3 Input Pin (f_par) – user2256288 Apr 10 '13 at 05:16
  • Hmm that's working fine for me. Maybe there's something to do with the version of Tcl. Could you try the code again? I changed the `[split $line]` to `[split $line " "]` which makes the split more specific, although the default is white space. – Jerry Apr 10 '13 at 10:14