Parse::Liberty - Parser for Synopsys Liberty files
use Parse::Liberty; my $parser = new Parse::Liberty (verbose=>0, indent=>4, file=>"test.lib"); print 'indent: ', $parser->{indent}, "\n"; ## get root 'library' group my $library = $parser->library; print $library->type; # => library print $library->get_names; # => testlib ## set new name for group $library->set_names('my_testlib'); ## all 'cell'-type groups my @cells = $library->get_groups('cell'); ## or my @cells = grep {$_->type eq 'cell'} $library->get_groups; ## get cells by name my @cells = $library->get_groups('cell', 'SDFFRHQX2', 'NAND.*X4'); ## get one cell my $cell = $library->get_groups('cell', 'NAND2X1'); ## cell attributes my @attributes = $cell->get_attributes; ## by name my @attributes = $cell->get_attributes(qw(area cell_leakage_power), 'dont_.*'); my $area = $cell->get_attributes('area'); print $area->get_values->value; ## cell 'pin'-type groups my @pins = $cell->get_groups('pin'); my $pin = $cell->get_groups('pin', 'Y'); ## pin function my $function = $pin->get_attributes('function')->get_values; print $function->type # => string print $function->value # => "(!(A B))"
Parse::Liberty may be used to extract and modify information from Synopsys Liberty files. Liberty format is widely used standard for keeping various information for EDA applications.
Parse::Liberty build on top Perl-C SWIG interface to Open Source Liberty liberty_parse functions.
To use Parse::Liberty, we need to build liberty_parse package from Open Source Liberty (links in "SEE ALSO" section).
Type of object (string, see "Object types")
Reference to main parser object (Parse::Liberty)
Parse::Liberty
Reference to parent object (Parse::Liberty::Attribute or Parse::Liberty::Group)
Parse::Liberty::Attribute
Parse::Liberty::Group
Reference to underlying SWIG-C object (SI2DR object)
Object depth (integer >= 0)
Return object avaible methods (string)
Return line number, associated with object (integer)
Return comment, associated with object or undef (string, without /**/)
/**/
Remove object, return 1
Return object representation string (with indentation = indent*depth and trailing newline)
Create new Parse::Liberty object
Arguments:
path to Liberty file (string, mandatory)
intent to write out Liberty portions (integer, default 2)
enable verbose messages (any True or False value, default 0)
Return root group (Parse::Liberty::Group object)
Write library to a file. This is preferred and much faster way to output the full library, than extract method
extract
path to the file to write
Return attribute type - simple or complex (string)
Return attribute name (string)
Return true if simple attribute is variable declaration (boolean)
Return attribute values (list of Parse::Liberty::Value objects, or 1st object in scalar context)
Parse::Liberty::Value
Set attribute values. Input format: (type1, value1[, type2, value2, ...]). Return 1
(type1, value1[, type2, value2, ...])
Return define type (string, see "Value types")
Return define name (string)
Return define allowed group name (string)
Return group type (string)
Return group names (list of strings, or string of names joined with comma in scalar context, or '' if nameless group)
Set group names. Input format: (name1[, name2, ...]). Return 1
(name1[, name2, ...])
Get group attributes (list of matched Parse::Liberty::Attribute objects, or 1st matched object in scalar context, or empty list if no attributes in group)
return all Parse::Liberty::Attribute objects
return all matched objects by name(s)
Get group attributes (list of matched Parse::Liberty::Define objects, or 1st matched object in scalar context, or empty list if no defines in group)
Parse::Liberty::Define
return all Parse::Liberty::Define objects
Get group subgroups (list of matched Parse::Liberty::Group objects, or 1st matched object in scalar context, or empty list if no subgroups in group)
return all Parse::Liberty::Group objects
return all matched objects by type 'type'
return all matched objects by type 'type' and first name(s) 'name1'(, 'name2', ...)
This expression placed into m/^ $/, so pattern NAND.* correspond to names, started with 'NAND'
m/^ $/
NAND.*
Return value type (string, see "Value types")
Return value value (string)
sub transpose { my $columns = shift; my @list = @_; map { my $i = $_; [map $_->[$i], @list] } 0 .. $columns-1; } sub process_values { my @table = @_; my @values; foreach my $row (@table) { $row =~ s/\s+//g; # remove spaces $row =~ s/"(.*)"/$1/; # remove first and last '"' my @row = split /\s*,\s*/, $row; # values in row delimeted by ',' push @values, \@row; } my $columns = scalar @{$values[0]}; # length of first row my @values_transposed = transpose($columns, @values); ## get list of strings instead arrays map {$_ = join ', ', @{$_}} @values_transposed; } sub process_group { my $group = shift; ## process templates if($group->type =~ m/.*_template/) { if(!$group->get_attributes('variable_3') && (my $variable_2_attr = $group->get_attributes('variable_2'))) { my $variable_1_attr = $group->get_attributes('variable_1'); my $index_1_attr = $group->get_attributes('index_1'); my $index_2_attr = $group->get_attributes('index_2'); my $variable_1 = $variable_1_attr->get_values->value; my $variable_2 = $variable_2_attr->get_values->value; $variable_1_attr->set_values('string', $variable_2); $variable_2_attr->set_values('string', $variable_1); my $index_1 = $index_1_attr->get_values->value; my $index_2 = $index_2_attr->get_values->value; $index_1_attr->set_values('string', $index_2); $index_2_attr->set_values('string', $index_1); } } ## process values tables elsif(my $values_attr = $group->get_attributes('values')) { if(!$group->get_attributes('index_3') && (my $index_2_attr = $group->get_attributes('index_2'))) { my $index_1_attr = $group->get_attributes('index_1'); my $index_1 = $index_1_attr->get_values->value; my $index_2 = $index_2_attr->get_values->value; $index_1_attr->set_values('string', $index_2); $index_2_attr->set_values('string', $index_1); my @values = map {$_->value} $values_attr->get_values; my @values_transposed = process_values(@values); $values_attr->set_values(map {('string', $_)} @values_transposed); } } process_group($_) for $group->get_groups; } use Parse::Liberty; my $parser = new Parse::Liberty (file=>"test.lib"); my $library = $parser->library; process_group($library); print OUT $library->extract;
foreach my $cell ($library->get_groups('cell')) { if(my $attr = $cell->get_attributes('dont_touch')) { printf "%15s: %s %s\n", $cell->get_names, $attr->name, $attr->get_values->value; } }
Eugene Gagarin <mosfet07@ya.ru>
Copyright 2013 Eugene Gagarin
This library is free software; you may redistribute it and/or modify it under the same terms as Perl itself.
http://www.opensourceliberty.org - Open Source Liberty
http://www.si2.org - Silicon Integration Initiative
Liberty::Parser - Liberty parser with different approach (probably faster)
To install Parse::Liberty, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Parse::Liberty
CPAN shell
perl -MCPAN -e shell install Parse::Liberty
For more information on module installation, please visit the detailed CPAN module installation guide.