Академический Документы
Профессиональный Документы
Культура Документы
of the tools and flows you will use or contribute to are written in
perl
Quick
Provide some basic software concepts that will stay with you long
after perl and tcl are historical footnotes.
Next
References
Larry Wall, Tom Christiansen & Jon Orwant, Programming
Perl, OReilly
Perl personality
Perl has a laissez-faire attitude it pretty much lets you be
No
need to declare variables before you use them, but you can require
yourself to do so:
use strict;
It
tries to behave like a natural language ascertaining what you are trying
to do based on context
scalar (dealing with singular things)
$n = @net_names
list (dealing with plural things)
sort @net_names
Type
Character
Example
Description
Scalar
$net_name
An individual number or
string
Array
@nets
Hash
%wire_length
Subroutine
&
&find_net
Typeglob
*.def
Multi-Valued variables
Value
Key
Value
ckfub1_fiducial_bl
ckfub1_fiducial_bl
R63C4FID
ckfub1_fiducial_tr
ckfub1_fiducial_tr
R63C4FID
:
$k
$components[$k]
crst2d1/tvfunit1/cache0
crsthsiopxp1/dt_scan_buf
$macro{$comp}
$comp
:
:
$n-1
ram64x256
$macro_ref->{$comp}
crsthsiopxp1/dt_scan_buf
R63BF00HX05
rectangle
# array of hashes
my @rects; # array of rectangles
my $rects_ref = \@rects
Index
(x1, y1)
:
$k
$rects[$k]{y2}
{x1 => 1000, y1 => 1000, x2 => 2000, y2 => 2000}
:
$n-1
$rects_ref->[$k]{y2}
{x1 => 2000, y1 => 1000, x2 => 2100, y2 => 2000}
first
data => {}
n ext
data => {}
n ext
null
Running perl
On the command line:
perl -e print Hello world\n;
Create a file, make it executable and run:
xemacs hello_world.pl &
#!/usr/intel/bin/perl
print Hello world\n;
chmod +x hello_world.pl
10
Program structure
Create a template for a main program
#!/usr/intel/bin/perl
require 5;
<header>
<modules>
use module_template;
use strict;
<user inputs>
<log set up>
<banner>
my $object_ref = new module_template($opt_file, $log);
<clean up>
############ end of main ################
sub usage {
:
}
####### end of main_template.pl ##########
################################
#
# Author:
Mark Clark
# Date:
June 27, 2011
# Description: Perl module template.
#
##################################
##################################
#Data Members:
#
# 'file': dummy input
# 'log':
log object
#
##############################
####### public routines #########
sub new {
my $class = shift;
my $file = shift;
my $log = shift;
scripts
bin
my $self = {
'file' => $file,
'log' => $log
};
bless($self, $class);
return $self;
lib
}
11
Program structure
Parts of typical template
#!/usr/intel/bin/perl
require 5;
<header>
<modules>
use module_template;
<user inputs>
<log set up>
<banner>
<header>
##########################################################
#
# Program:
main_template.tcl
# Author:
Mark Clark
# Date:
June 27, 2011
# Description: Template for a main program.
##########################################################
#
use strict;
<modules>
se FindBin qw($Bin);
use lib "$Bin/../lib";
use Getopt::Long;
use File::Path;
use File::Copy;
use LogData;
use std;
sub usage {
:
}
####### end of main_template.pl ##########
<user inputs>
<banner>
12
"------------------------------------\n");
"
$script executing\n");
"
Author: Mark Clark, Intel
\n");
"------------------------------------\n");
"
$n_args arg(s) processed\n\n");
<clean up>
#!/usr/intel/bin/perl
$log->global_end_msg();
$log->info_msg ("All Done\n");
require 5;
$log->move_log("logs");
<header>
<modules>
use module_template;
my $log_file = $log->{'log_file'};
my $log_copied = copy($log_file, "main_template.log");
<user inputs>
<log set up>
<banner>
my $object_ref = new module_template($opt_file, $log);
<clean up>
############ end of main ################
<usage>
sub usage {
print "
Usage:
$0 -file <file> [-h]
Where:
-file
-h
sub usage {
:
}
options
Description:
";
exit (0);
}
13
Lab 1: 15 minutes
Set up:
1. Create a work area: e.g. mkdir ${USER}_perl_tcl_lab
2. cd ${USER}_perl_tcl_lab
3. Copy lab collateral: cp /nfs/fm/disks/fm_cse_n71105/quantum/perl_tcl_lab/* .
4. Follow instructions in perl_tcl_lab.txt
14
Filehandles
Another of perls data types is the filehandle which is the name you
give to a file, device, socket or pipe
open(DEF,
open(DEF,
open(DEF,
You read from the handle using the reading operator, <>
You can set the record delimiter:
my
$/
15
$save_delim = $/;
= "\n";
$/ = $save_delim;
# restore delimiter
Parsing
package std;
:
sub open_gz_in {
my $file = shift;
my $gzfile = $file . ".gz";
local *FH;
Regular
expression
if ($file =~ /\.gz$/) {
open(*FH,"gzcat $file |") || read_death("$file");
} elsif(-e $file) {
open(*FH, "$file") || read_death("$file");
} elsif(-e $gzfile) {
open(*FH, "gzcat $gzfile |") || read_death("$file");
} else {
read_death("$file")
}
return *FH;
}
package LogData;
require 5.003;
require Exporter;
@ISA=qw(Exporter);
:
### Print an informational message to the local log and to the screen
###
sub info_msg {
my $self = shift;
my $msg = shift;
my $fh = $self->{'fh'};
if(defined $fh) {
print $fh "-I- INFO:
print $fh "$msg";
}
print "-I- INFO: ";
print "$msg";
";
}
16
17
Regular expressions
Regular expressions are used in pattern matching:
if($line =~ /MACRO/) {print Found a macro\n}
if($line !~ /MACRO/) {print Macro not found\n}
Substitution
$line =~ s/macro/MACRO/;
Splitting strings
@fields = split(/,/, $line);
Character class shortcuts
Name
Definition
Match
Dont
match
Whitespace
[ \t\n\r\f]
\s
\S
Word char.
[a-zA-Z_0-9]
\w
\W
[0-9]
\d
\D
Any char.
NA
Digit
Anything
18
Definition
Code
Example
Zero or more
{0,}
\w*
Zero or one
(0,1}
a?
One or more
{1,}
\d+
Anchors:
Match at word boundary: \b -- /\b\w+\b/
Match at beginning: ^ -- /^\w+/
Match at end: $ -- /\w+$/
Back references: Parentheses around a part of a pattern will cause matches to
that part to be stored in special variables, $1, $2,
Swap first two words of a string: s/(\S+)\s+(\S+)/$2 $1/
19
Perl objects
Object Oriented Programming (OOP)
Encapsulation: Combining a data structure with the functions dedicated to
manipulating the data. (class)
Inheritance: Building derived classes that inherit the data and functions from
previously defined base classes.
Polymorphism: Giving an action one name or symbol that is shared up and
down a class hierarchy. (e.g. computing area for rectangles, circles, etc.)
Perls Object System
An object is a scalar reference
A class is a package
A method is a subroutine
20
use strict;
Inheritance list
################################
#
# Author:
Mark Clark
# Date:
June 27, 2011
# Description: macro class
#
##################################
##################################
#Data Members:
#
# 'file': dummy input
# 'log':
log object
#
##############################
####### public routines #########
sub new {
my $class = shift;
my $log = shift;
my $self = {
names' => {}, # macro names
'log' => $log
};
bless($self, $class);
return $self;
}
sub get_names {
return $self->{names};
}
######## private routines #########
22
perlmodinstall
Getting help
Use man or perldoc
Go to CPAN
Look at prior code for examples
e.g.
23
Break: 5 minutes
Lab 2: 15 minutes
24
/p/cse/asic/quantum/6.0.a/tcl/stcl/addFillToLeftAndRightOfEbbs.tcl
braces for grouping
proc addFillToLeftAndRightOfEbbs { cell celledge power ground fill_area fill_hieght}
{
#--------------------------------------------------------------------------# Get all the embedded blocks.
#--------------------------------------------------------------------------set ebbs [filter_collection [get_fp_cells *] "is_hard_macro==true"]
set ebbs [filter_collection $ebbs "ref_name!=euunit"]
:
foreach_in_collection ebb $ebbs {
#----------------------------------------------------------------------# Get the ebb's information.
#----------------------------------------------------------------------set ebb_name [get_object_name $ebb]
:
}
Basic syntax:
command arg1 arg2 arg3
Shebang for stand-alone tcl program:
#!/usr/intel/bin/tclsh
25
Requirements
Definition
Design
Maintenance
Maintenance
QA
Code reviews
Analyze test coverage and
create test cases
xemacs or vi
perl -d <full path>/<program>
-w option
27
Lab 3: 15 minutes
28
Q&A