Thursday 21 November 2019

what is perl chomp-chomp command-chomp Example-chomp function-chomp string?

Perl Chomp:

Chomp removes value of $/. normally $/ variable will have \n(newline) as its default variable. But we can change that to some other values for major level of stuffs, if we want.

Unix/Linux  Kind of File formats will be separated based on newlines
like,

1st line \n
2nd line  \n

those two lines will be separated based on newline that is input record separator. in perl its defined using $/ variable.

Read more »

Labels: , , , , , , , ,

Thursday 9 June 2022

perl vlsi program for Design Rule Checker


#!/usr/bin/perl


use strict;

use warnings;


# Read design rules from file

my $rule_file = shift;

open my $fh, "<", $rule_file or die "Error: Could not open rule file: $!\n";

my $rules = do { local $/; <$fh> };

close $fh;


# Read layout design from file

my $design_file = shift;

open $fh, "<", $design_file or die "Error: Could not open design file: $!\n";

my $design = do { local $/; <$fh> };

close $fh;


# Check design against rules

my $errors = 0;

foreach my $rule (split /\n/, $rules) {

    chomp $rule;

    $rule =~ s/^\s+|\s+$//g;

    next if $rule =~ /^#/;

    if ($rule =~ /^(\S+)\s+(.*?)$/) {

        my $rule_type = $1;

        my $rule_pattern = $2;

        if ($rule_type eq "layer") {

            # Check for correct layer usage

            my @matches = $design =~ /$rule_pattern/g;

            if (@matches) {

                print "Error: Found $rule_type \"$rule_pattern\" in layout design\n";

                $errors++;

            }

        }

        elsif ($rule_type eq "spacing") {

            # Check for minimum spacing between objects

            my $spacing = $rule_pattern;

            my $pattern = "\\s*[Mm]\\s*\\(\\s*\\d+\\s*\\)\\s*[Mm]"; # matches two adjacent metal layers

            my @matches = $design =~ /$pattern/g;

            foreach my $match (@matches) {

                if ($match =~ /($pattern){0,$spacing-1}/) {

                    print "Error: Found adjacent objects with spacing less than $spacing in layout design\n";

                    $errors++;

                    last; # exit loop once an error is found

                }

            }

        }

        else {

            print "Warning: Unknown design rule type \"$rule_type\"\n";

        }

    }

}


if ($errors == 0) {

    print "Design passed all design rule checks.\n";

}

else {

    print "Design failed $errors design rule checks.\n";

}


 it will print out any errors or warnings that are detected during the design rule checking process. If there are no errors, it will print a message indicating that the design has passed all design rule checks.

design rules are specified in a file, where each rule is a line that starts with a rule type ("layer" or "spacing"), followed by a rule pattern that specifies the layer or spacing requirements. 

For example:

# Design rules file

layer M1

layer M2

spacing 3 

run it from the command line and specify the design rules file and layout design file as arguments. For example:

$ perl design_rule_checker.pl design_rules.txt layout_design.gds

 design_rule_checker.pl is the name of the Perl program, design_rules.txt is the name of the file containing the design rules, and layout_design.gds is the name of the layout design file to be checked.

example design rules file that checks for some common design rule violations:

# Design Rules File



# Define spacing rules

spacing metal1_metal1 0.12

spacing metal1_via1 0.12

spacing metal2_metal2 0.15

spacing metal2_via2 0.15



# Define width rules

width metal1 0.25

width metal2 0.4



# Define enclosure rules

enclosure metal1_via1 0.1

enclosure metal2_via2 0.2

The spacing rule checks the minimum distance between two layers, while the width rule checks the minimum width of a metal layer. The enclosure rule checks the minimum amount of metal surrounding a via.

The metal1_metal1, metal1_via1, metal2_metal2, and metal2_via2 keywords are the layer types that the rules apply to. These keywords should match the layer names used in the layout design file.

To use this design rules file with the design_rule_checker.pl program, you would specify the filename as the first argument when running the program:

$ perl design_rule_checker.pl design_rules.txt layout_design.gds


#!/usr/bin/perl
use strict;
use warnings;

# Read in the design rules file
my $rules_file = $ARGV[0];
open(my $rules_fh, '<', $rules_file) or die "Could not open $rules_file: $!";

# Parse the design rules and store them in a hash
my %rules;
while (my $line = <$rules_fh>) {
    chomp $line;
    my ($rule_type, $layer_type, $value) = split ' ', $line;
    $rules{$rule_type}{$layer_type} = $value;
}
close $rules_fh;

# Read in the layout design file
my $layout_file = $ARGV[1];
open(my $layout_fh, '<', $layout_file) or die "Could not open $layout_file: $!";

# Parse the layout design and check against the design rules
my $line_number = 0;
while (my $line = <$layout_fh>) {
    $line_number++;
    chomp $line;

    # Check for minimum spacing violations
    if ($line =~ /^S\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/) {
        my ($type1, $layer1, $type2, $layer2, $distance, $extension) = ($1, $2, $3, $4, $5, $6);
        if ($rules{'spacing'}{"$layer1\_$layer2"} && $distance < $rules{'spacing'}{"$layer1\_$layer2"}) {
            print "Error: Minimum spacing violation on line $line_number\n";
        }
    }

    # Check for minimum width violations
    if ($line =~ /^W\s(\S+)\s(\S+)/) {
        my ($layer, $width) = ($1, $2);
        if ($rules{'width'}{$layer} && $width < $rules{'width'}{$layer}) {
            print "Error: Minimum width violation on line $line_number\n";
        }
    }

    # Check for minimum enclosure violations
    if ($line =~ /^E\s(\S+)\s(\S+)\s(\S+)\s(\S+)\s(\S+)/) {
        my ($type1, $layer1, $type2, $layer2, $distance) = ($1, $2, $3, $4, $5);
        if ($rules{'enclosure'}{"$layer1\_$layer2"} && $distance < $rules{'enclosure'}{"$layer1\_$layer2"}) {
            print "Error: Minimum enclosure violation on line $line_number\n";
        }
    }
}
close $layout_fh;

The design rules file should contain the following information:

  • Minimum spacing between two layers
  • Minimum width for a layer
  • Minimum enclosure of one layer around another layer

The layout design file should contain the following information for each component:

  • Type of component
  • Layer of component
  • Position of component
  • Dimensions of component

The design_rule_checker.pl program will output an error message for any violations of the design rules, indicating the type of violation and the line number in the layout design file where the violation occurred.


Labels:

Tuesday 7 February 2023

Regular expression to match a line that doesn't contain a word

 


Read more »

Labels: , ,

Wednesday 23 October 2019

place and plays $_ in perl?

Method 1:


while(<>)
{
    print;
}

Method 2:


for ('l','s','h','c','g')
{
   print;
   print "\n";
}

Method 3:

@a=split //,'hello';

Method 4:


$_="hello";
$_=~s/he/she/g;

print $_;

Method 5:


$_="he l lo";
for (split)
{
   print;
   print "\n";
}

Method 6:


$_='perlbot';

print if /p/;

Method 7:

foreach ('l','s','h','c','g')
{
   print;
   print "\n";
}

Method 8:


$_ = "prlbot";

print /perl/ ?'perlbot':'normalbot',"\n";

Method 9:


$_="perl";
$_=~tr/p/P/;

print $_;

Method 10:


@a=('l','s','h','c','g');

print grep $_,@a;

Method 11:


@a=('l','s','h','c','g');

print map $_,@a;

Method 12:


%hash=(1,2,7,4,9,6);

while (each %hash) {

 print "$_=$hash{$_}\n";

    }

Method 13:


opendir($_,"/tmp") || die "Can't open dir $!";

@array =readdir($_);

closedir $_;

print @array;

Method 14:

while(<>)
{
    chomp($_);
     print $_;
}

Method 15:


while(<>)
{
    chop($_);
    print $_;
}

Method 16:


while(<>)
{
   chomp($_);
   $output = eval $_;
   print $output;
}

Method 17:


$_="he l lo";

print length($_);

Method 18:


$_="he l k lo";
$v=reverse $_;

print $v;

Method 19:


$_ = 9.0;

print exp $_;

Method 20:


$_ = "10";

print hex $_;

Method 21:


$_ = "Hello Perl Bot";

print index $_, 'Perl';

Method 22:


$_="he l k lo";
$v=lc $_;

print $v;

Method 23:


$_="he l k lo";
$v=uc $_;

print $v;

Method 24:


$_="he l k lo";
$v=ucfirst $_;

print $v;

Method 25:


$_="he l k lo";
$v=lcfirst $_;

print $v;

Method 26:


$_ = "144";

print sqrt $_;

Method 27:


$_ = "Hello Perl Bot Perl";

print rindex $_, 'Perl';

Method 28:


while(($_ = getc) eq 'yes')
{
   print $_;
}

Method 29:


$_ = "Hello Perl Bot Perl";

if (defined $_) {
    print "$_ is defined";
}

Method 30:

$_ = "Hello Perl Bot Perl";

print $_;