0

I did a little reading up and realized the pipe symbol | can be used like "or" logic when matching. I've tried to incorporate this in my following code but it doesn't work in doing some text processing that follows regexp (see snippet code below file format) . First here's my file type (.lib used in chip design)

pin (d) {
  direction : input;
  nextstate_type : data;
  related_ground_pin : vss;
  related_power_pin : vcc;
  max_transition : 0.4;
  capacitance : 0.000719782;
  rise_capacitance : 0.000719782;
  rise_capacitance_range (0.000462301, 0.000719782);
  fall_capacitance : 0.000569233;
  fall_capacitance_range (0.000459043, 0.000569233);
  timing () {
    related_pin : "clk";
    timing_type : setup_rising;
    rise_constraint (constraint_template_5X5) {
      index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
      index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
      index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
      values ( \
        "5.1,1.2,1.3,1.4,1.5", \
        "9.1,2.2,2.3,2.4,2.5", \
        "3.1,3.2,3.3,3.4,3.5", \
        "4.1,4.2,4.3,4.4,4.5", \
        "5.1,5.2,5.3,5.4,5.5", \
        "6.1,6.2,6.3,6.4,6.5", \
        "7.1,7.2,7.3,7.4,7.5", \
        "8.1,8.2,8.3,8.4,8.5", \
        "9.1,9.2,9.3,9.4,9.5", \
        "10.1,10.2,10.3,10.4,10.5", \
        "11.1,11.2,11.3,11.4,11.5", \
        "12.1,12.2,12.3,12.4,12.5", \
        "13.1,13.2,13.3,13.4,13.5", \
        "14.1,14.2,14.3,14.4,14.5", \
        "15.1,15.2,15.3,15.4,15.5", \
        "16.1,16.2,16.3,16.4,16.5", \
        "17.1,17.2,17.3,17.4,17.5", \
        "18.1,18.2,18.3,18.4,18.5", \
        "19.1,19.2,19.3,19.4,19.5", \
        "20.1,20.2,20.3,20.4,20.5", \
        "21.1,21.2,21.3,21.4,21.5", \
        "22.1,22.2,22.3,22.4,22.5", \
        "23.1,23.2,23.3,23.4,23.5", \
        "24.1,24.2,24.3,24.4,24.5", \
        "25.1,25.2,25.3,25.4,25.5", \
      );
    }
    fall_constraint (constraint_template_5X5) {
      index_1 ("0.01, 0.05, 0.12, 0.2, 0.4");
      index_2 ("0.005, 0.025, 0.06, 0.1, 0.3");
      index_3 ("0.084, 0.84, 3.36, 8.4, 13.44") ;
      values ( \
        "1.1,1.2,1.3,1.4,1.5", \
        "2.1,2.2,2.3,2.4,2.5", \
        "3.1,3.2,3.3,3.4,3.5", \
        "4.1,4.2,4.3,4.4,4.5", \
        "5.1,5.2,5.3,5.4,5.5", \
        "6.1,6.2,6.3,6.4,6.5", \
        "7.1,7.2,7.3,7.4,7.5", \
        "8.1,8.2,8.3,8.4,8.5", \
        "9.1,9.2,9.3,9.4,9.5", \
        "10.1,10.2,10.3,10.4,10.5", \
        "11.1,11.2,11.3,11.4,11.5", \
        "12.1,12.2,12.3,12.4,12.5", \
        "13.1,13.2,13.3,13.4,13.5", \
        "14.1,14.2,14.3,14.4,14.5", \
        "15.1,15.2,15.3,15.4,15.5", \
        "16.1,16.2,16.3,16.4,16.5", \
        "17.1,17.2,17.3,17.4,17.5", \
        "18.1,18.2,18.3,18.4,18.5", \
        "19.1,19.2,19.3,19.4,19.5", \
        "20.1,20.2,20.3,20.4,20.5", \
        "21.1,21.2,21.3,21.4,21.5", \
        "22.1,22.2,22.3,22.4,22.5", \
        "23.1,23.2,23.3,23.4,23.5", \
        "24.1,24.2,24.3,24.4,24.5", \
        "25.1,25.2,25.3,25.4,25.5", \
      );
    }
  }
}

Ok, so I have to do some text processing (aided by Brad Lanam - user of SO) which is done as follows. The aim of this piece of code is to zero in on the right types of constraints (in my .lib) to do text processing.

set inFile [open "C:/Tcl/official/ref.lib" r]

set inval false
set foundValues 0
set found_setup 0
set found_fall 0
set extract1 0
set extract2 0
set DETECT_END_SYNTAX {\);}

while { [gets $inFile line] >= 0 } {

  if { [regexp {setup_rising;} $line] } { set found_setup 1 }
  if { [regexp {hold_rising;} $line] } { set found_setup 0 }

  if { $found_setup } {

    if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }
    if { $found_fall } {

      if {[regexp {values} $line]} {
        set foundValues 1
      }
      if {$foundValues} {
        if { [regexp $DETECT_END_SYNTAX $line] } {
          if { $inval } {
            set inval false
            set foundValues 0
            set found_fall 0
          }
        }
      }
    }
  }
}

# { Do text processing after this }

But

if { [regexp {rise_constraint|fall_constraint} $line] } 
# Does NOT work 

in matching either rise_constraint or fall_constraint to do some regsub commands. My code only ends up processing values for rise_constraint in the modified file written out. I need the values of both constraint types to be changed. Am I doing something wrong in the regexp? Thanks!

Should I just do this:

if { [regexp {rise_constraint} $line] } { set found_fall 1 }
if { [regexp {fall_constraint} $line] } { set found_fall 1 }

Instead of:

if { [regexp {rise_constraint|fall_constraint} $line] } { set found_fall 1 }

Note: found_fall actually will find even the rise_constraint values, it's just a variable.

Reference: tcl text processing - rearrange values in rows and columns based on user defined value

Community
  • 1
  • 1
edaloke
  • 31
  • 6
  • Your code works for me. Just checked. I only had to remove `if { $inval } {` because I do not see where `inval` is set to `true`. – GrAnd Apr 28 '14 at 20:16

1 Answers1

0
if { [regexp {rise_constraints|fall_constraint} $line] } 

Doesn't work because there is no rise_constraints in the lines. There is rise_constraint with no s.

Also, try to better indent your code next time.

Jerry
  • 70,495
  • 13
  • 100
  • 144
  • Thanks for that, noted. Actually, I did rectify that before and it still did not work. Is there an alternative way of matching 2 regular expressions other than using the pipe symbol? – edaloke Apr 28 '14 at 19:43
  • @edaloke The `|` is exactly how to match one of two alternative sub-REs; that's what that operator does in the RE language. You could also use `(rise|fall)_constraints?` but the effect would be similar. (The `s?` is an _optional_ `s`, i.e., it deals with inadvertent plurals.) That said, I can't shake the feeling that you're going about the parsing and transformation in completely the wrong way: the input looks like it could be treated as an (unusual) Tcl script… – Donal Fellows Apr 28 '14 at 20:11
  • @edaloke If one doesn't work, what about two? I'm almost certain that won't work either, meaning that the problem you're getting is elsewhere. How do you know that it's not working? *That* would be useful to know. – Jerry Apr 28 '14 at 20:36
  • If you're going to be doing this a lot, @Donal's idea of a generic .lib to tcl dictionary converter is a good project that will work well for you in the future. From your sample it appears that a .lib file has dictionaries (pin, timing, rise_constraint, etc.), values (direction, related_pin, etc.) and lists (rise_capacitance_range, index_1, values). There are some other issues, as the index strings and value strings should be further broken down so the numeric values can be accessed. Once you have the dictionary, the data is easy to access and can be written out to your new files. – Brad Lanam Apr 28 '14 at 20:43
  • Thanks for the advice everyone, I realized there was a problem with another part of my code that was causing problems. @Brad: Great idea, that's exactly what I've been up to and I cannot thank you enough for your coding help in my earlier post. It helped me a lot in creating the right structure for my code. – edaloke May 06 '14 at 22:27