#!/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: perl vlsi program for Design Rule Checker