Необходимо сохранить одну строку от удаления на некоторых особых условиях - PullRequest
1 голос
/ 26 марта 2019

Я написал Perl-код, который может искать и удалять строки из файла (IN_FILE), который содержит «max_transition», когда условие «direction: output» будет удовлетворять.После удаления строки код записывает измененный файл в другое место.

Теперь мне нужно удалить строку «max_transition», когда условие «direction: output» будет удовлетворять, а также где он найдет слово »Синхронизация "в этой конкретной группе выводов.

IN_FILE, имеет выходной вывод" HIZIBI_79 ", HIZIBI_78 и HIZIBI.После запуска сценария строку «max_transition» не следует удалять с вывода «HIZIBI_79», HIZIBI_78 », поскольку в этой группе выводов отсутствует« синхронизация ». Только строка« max_transition »будет удалена с вывода« HIZIBI », у нее есть«группа "хронометраж".

Есть идеи, как это реализовать?

Выходной файл должен выглядеть следующим образом: OUT_FILE

use warnings;
use strict;
my $inputfile = $ARGV[0]; # input lib FILE

if ($#ARGV!=0)
{
  print "USAGE :: perl max_tran_update.pl <<LIB_FILE>>  \n\n" ;
  exit(1);   
}

my $cmd = "mkdir  tmpdir;";
system ($cmd);

my $iline;
my $flag_outpin = 0;
my $out_pin_flag = 0;

open (INFILE,"<","$inputfile") || die "Can not open Input LIB File";
open (my $OPFILE,">","tmpdir/input_lib.lib") || die "Can not open Input Text File";

while ($iline = <INFILE>)
{
  chomp $iline;
  print $OPFILE "$iline\n";
  if (($iline =~m/^\s*direction\s*:\s*output\s*;/g))
  {
    $flag_outpin=1;
    while ($iline = <INFILE>)
    {
      if (($iline =~m/^\s*direction\s*:\s*input\s*;/g))
      {
        $flag_outpin=0;
      }
      if (($iline =~m/^\s*direction\s*:\s*output\s*;/g))
      {
        $flag_outpin=1;
      }
      if (($iline =~m/^\s*max_transition\s*:/g) && ($flag_outpin == 1))
      {
        $iline =~ s/$iline//g ;
      }
      else 
      {
        print $OPFILE "$iline";
      }
    }
  }
}      
close INFILE;
close $OPFILE;

IN_FILE

  cell (lib_1) {
    dont_use : true ;
    dont_touch : true ;
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 12 ;
    }  
    pin ("HIZIBI_79")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 3 ;
    }              
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 1 ;
    }  
    pin ("HIZIBI_78")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 34 ;
      capacitance : 34 ;
    }            
    pin ("HIZIBI")    {
      direction : output ;
      clock : true ;
      max_transition : 20;
      related_power_pin : VDD ;
      related_ground_pin : VSS ;
      timing () {
        cell_fall (into_f1) {
          index_1("1,2,3,4,5") ;
          index_2("1,2,3,4,5") ;
          values("13, 13, 14, 16, 18",\
                 "13, 14, 15, 16, 19",\
                 "14, 15, 16, 17, 20",\
                 "15, 15, 16, 18, 20",\
                 "15, 16, 17, 18, 21") ;
        }  
      }  
    }
  }

OUT_FILE


  cell (lib_1) {
    dont_use : true ;
    dont_touch : true ;
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 12 ;
    }  
    pin ("HIZIBI_79")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 3 ;
    }              
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 1 ;
    }  
    pin ("HIZIBI_78")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 34 ;
      capacitance : 34 ;
    }            
    pin ("HIZIBI")    {
      direction : output ;
      clock : true ;
      related_power_pin : VDD ;
      related_ground_pin : VSS ;
      timing () {
        cell_fall (into_f1) {
          index_1("1,2,3,4,5") ;
          index_2("1,2,3,4,5") ;
          values("13, 13, 14, 16, 18",\
                 "13, 14, 15, 16, 19",\
                 "14, 15, 16, 17, 20",\
                 "15, 15, 16, 18, 20",\
                 "15, 16, 17, 18, 21") ;
        }  
      }  
    }
  }

Ответы [ 2 ]

1 голос
/ 26 марта 2019

Это становится намного проще, если вы анализируете файл для работы с одним разделом pin { ... } за раз. Этот код, кажется, делает свое дело, но он, вероятно, хрупок и вполне может сломаться при более сложном вводе.

#!/usr/bin/perl

use strict;
use warnings;

# $counter will contain the number of unmatched { characters
# we have seen. If it's a positive number then we are in a
# pin section and we won't output anything until we get to
# the end of that section.
my $counter;
# Contains the contents of our current pin section.
my $pin = '';

# Read a line at a time from STDIN
while (<>) {
  # If we're not in a pin block, then
  # just print the line.
  if (!$counter and !/\bpin\b/) {
    print;
    next;
  }

  # Increment $counter by the number of { characters in the line
  $counter += tr/{/{/;
  # Decrement $counter by the number of } characters in the line
  $counter -= tr/}/}/;

  # Append the current line to $pin
  $pin .= $_;

  # If $counter is 0 then we've just got to the end of a pin
  # block. The text of that block will be in $pin.
  if (!$counter) {
    # If $pin contains "directions : output" and "timings"...
    if ($pin =~ /direction\s*:\s*output/ and $pin =~ /timing\s*/) {
      # ... then remove the "max_transitions" line from $pin
      $pin =~ s/\s*max_transition\s*:.*\n//;
    }
    # Print the current $pin section
    print $pin;
    # And reset $pin to start the next section.
    $pin = '';
  }
}

Я также написал это как фильтр Unix. То есть он читает из STDIN и пишет в STDOUT. Это более гибко, чем жестко закодированные имена файлов. Вы бы запустили это так:

$ my_pin_filter < in_file > tmpdir/input_lib.lib
1 голос
/ 26 марта 2019

Попробуйте эту командную строку Perl

 perl -0777 -ne ' s/(pin\s*\(".+?"?\)\s+\{.+?\})/$x=$1;if($x=~m!timing\s*\(\)! and $x=~m!direction : output!){$x=~s!^\s*max_transition.+?\n!!mg};$x/gse ; print ' anny_in.txt

Результаты:

 cell (lib_1) {
    dont_use : true ;
    dont_touch : true ;
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 12 ;
    }
    pin ("HIZIBI_79")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 3 ;
    }
    pin ("HIZIBI_IN_1") {
      direction : input ;
      clock : true ;
      max_transition : 1 ;
      capacitance : 1 ;
    }
    pin ("HIZIBI_78")    {
      direction : output ;
      max_transition : 10;
      min_capacitance : 34 ;
      capacitance : 34 ;
    }
    pin ("HIZIBI")    {
      direction : output ;
      clock : true ;
      related_power_pin : VDD ;
      related_ground_pin : VSS ;
      timing () {
        cell_fall (into_f1) {
          index_1("1,2,3,4,5") ;
          index_2("1,2,3,4,5") ;
          values("13, 13, 14, 16, 18",\
                 "13, 14, 15, 16, 19",\
                 "14, 15, 16, 17, 20",\
                 "15, 15, 16, 18, 20",\
                 "15, 16, 17, 18, 21") ;
        }
      }
    }
  }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...