Creating .lib file from verilog

Creating a dummy .lib file is something every physical design engineer has done now and then. If you have a verilog model of the block available, your task gets easier. The following script automates .lib generation from your verilog netlist. Use this as a dummy .lib to get your design flow going or use it as a template for your analog blocks for modifying the values.

Customize, edit and use. The script creates a simple Data Structre. So any modification can be done pretty easily. The script parses the verilog for the module name specified, and collects the ports & directions. In the .lib file written out, a default capacitance and transition value is specified. This is a good starting point for your blocks.

`Usage: create_lib <verilog_netlist> <module_name> [transition_value] [capacitance_value]`

#!/usr/bin/perl

use strict;

if ($#ARGV < 1 ) {
	print "usage: create_lib   \n";
	exit;
}

my $netlist = $ARGV[0] ;
my $module  = $ARGV[1] ;
my $tran = 2.5 ;
my $cap = 0.001;
my $signal_level = "VDD" ;

if(defined $ARGV[2]) {$tran = $ARGV[2];}
if(defined $ARGV[3]) {$cap = $ARGV[3];}
if(defined $ARGV[4]) {$signal_level = $ARGV[4];}

my $FF;
my $FO;
open $FF, "< $ARGV[0]" or die "Can't open $ARGV[0] : $!";
open $FO, ">$module.lib" or die "Can't open $module.lib for write : $!";

my $db = createTopLevelDB(); 
createDotLib($db,$FO);

sub createDotLib
{
	my $topLevelDBRef = shift;
	my $FO = shift ;	
	### Header 
	print $FO "library\($topLevelDBRef->{'design'}->{'cell'}\) {\n";
	print $FO "\n /* unit attributes */\n";
	print $FO "  time_unit : \"1ns\"\;\n";
	print $FO "  voltage_unit : \"1V\"\;\n";
	print $FO "  current_unit : \"1uA\"\;\n";
	print $FO "  pulling_resistance_unit : \"1kohm\"\;\n";
	print $FO "  leakage_power_unit : \"1nW\"\;\n";
	print $FO "  capacitive_load_unit\(1,pf\)\;\n\n";
	foreach my $direction (keys(%{$topLevelDBRef->{'bus'}})) {
		foreach my $bus_type (keys %{$topLevelDBRef->{'bus'}->{$direction}}) {
			my @bus_width =  split(/_/, $bus_type); 
			my $bus_hi = $bus_width[1] ;
			my $bus_lo = $bus_width[2] ;
			my $bus_width = $bus_hi+1-$bus_lo;
			print $FO " type \($bus_type\) { \n";
			print $FO "   base_type : array ; \n" ;
    			print $FO "   data_type : bit  \n" ;;
    			print $FO "   bit_width : $bus_width   \n" ;;
    			print $FO "   bit_from : $bus_hi  \n" ;;
    			print $FO "   bit_to : $bus_lo ; \n" ;
    			print $FO "   downto : true ; \n" ;
    			print $FO " } \n" ;
		}
	}
	print $FO "\n  cell\($topLevelDBRef->{'design'}->{'cell'}\) {\n";
	foreach my $direction (keys(%{$topLevelDBRef->{'pins'}})) {
		foreach my $pin_name (@{$topLevelDBRef->{'pins'}->{$direction}}) {
			print $FO ("    pin\($pin_name\) { \n");
			print $FO ("\tdirection : $direction ;\n");
			if($direction eq "input") {
				print $FO ("\tmax_transition : $tran;\n");
			}
			print $FO ("\tcapacitance : $cap; \n");  	
			print $FO ("    } \n") ;
		}
	}
	foreach my $direction (keys(%{$topLevelDBRef->{'bus'}})) {
		foreach my $bus_type (keys %{$topLevelDBRef->{'bus'}->{$direction}}) {
			my @bus_width =  split(/_/, $bus_type); 
			my $bus_hi = $bus_width[1] ;
			my $bus_lo = $bus_width[2] ;
			foreach my $bus_name (@{$topLevelDBRef->{'bus'}->{$direction}{$bus_type}}) {
                                        chomp($bus_name);
				print "BUS $bus_name : $bus_type : $direction \n" ;
				print $FO ("    bus\($bus_name\) { \n");
				print $FO ("\tbus_type : $bus_type ;\n");
				print $FO ("\tdirection : $direction ;\n");
				if($direction eq "input") {
					print $FO ("\tmax_transition : $tran;\n");
				}	
				for(my $i=$bus_lo; $i<=$bus_hi; $i++) {
					print $FO ("\tpin\($bus_name\[$i\]\) { \n");
					print $FO ("\t\tcapacitance : $cap; \n");  
					print $FO ("\t} \n") ;
				}
				print $FO ("    } \n") ;
			}
		}
	}
	print $FO ("  } \n") ;
	print $FO ("} \n") ;
}

sub createTopLevelDB 
{
	my $find_top_module = 0; 
	my %topLevelDB = () ;
	my %pins = () ;
	my %bus = () ;
	my @input_pins ;
	my @output_pins ;
	my @inout_pins ;
	my @bus_types ; 
	my %input_bus = () ;
	my %output_bus = () ;
	my %inout_bus = () ;
	my %design = ();
	$design{'cell'} = $module; 
	$design{'tran'} = $tran; 
	$design{'cap'} = $cap; 
	$design{'signal_level'} = $signal_level; 
	while(my $line = <$FF>) {
		last if($find_top_module == 1);
		if($line=~/module\s+$module/) {
			$find_top_module = 1 ;
			while(my $line = <$FF>) {
				next if($line =~ "\s*//" );
				chomp($line);
				if ($line =~/input\s+/ ) {
					$line=~s/\s*input\s+//;
					$line=~s/;//;
					if($line =~/\[(\d+):(\d+)\]/) { 
						my $bus_type = "bus_$1_$2";
						$line=~s/\[(\d+):(\d+)\]//;
						my @line =  split(/,/, $line); 
						unless(grep {$_ eq $bus_type} @bus_types) {  
							push(@bus_types,$bus_type);
						}
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@{$input_bus{$bus_type}}, $pin );
						}
					}
					else {
						my @line =  split(/,/, $line); 
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@input_pins, $pin); 
						}
					}
				}
				if ($line =~/output\s+/ ) {
					$line=~s/\s*output\s+//;
					$line=~s/;//;
					if($line =~/\[(\d+):(\d+)\]/) { 
						my $bus_type = "bus_$1_$2";
						$line=~s/\[(\d+):(\d+)\]//;
						my @line =  split(/,/, $line); 
						unless(grep {$_ eq $bus_type} @bus_types) {  
							push(@bus_types,$bus_type);
						}
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@{$output_bus{$bus_type}}, $pin );
						}
					}
					else {
						my @line =  split(/,/, $line); 
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@output_pins, $pin); 
						}
					}

				}
				if ($line =~/inout\s+/ ) {
					$line=~s/\s*inout\s+//;
					$line=~s/;//;
					if($line =~/\[(\d+):(\d+)\]/) { 
						my $bus_type = "bus_$1_$2";
						$line=~s/\[(\d+):(\d+)\]//;
						my @line =  split(/,/, $line); 
						unless(grep {$_ eq $bus_type} @bus_types) {  
							push(@bus_types,$bus_type);
						}
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@{$inout_bus{$bus_type}}, $pin );
						}
					}
					else {
						my @line =  split(/,/, $line); 
						foreach my $pin (@line) {
							$pin=~s/\s+//;
							push(@inout_pins, $pin); 
						}
					}

				}

				last if($line=~/endmodule/);
			}

		}
	}
	$pins{'input'} = \@input_pins;
	$pins{'output'} = \@output_pins;
	$pins{'inout'} = \@inout_pins;
	$bus{'input'} = \%input_bus;
	$bus{'output'} = \%output_bus;
	$bus{'inout'} = \%inout_bus;
	$topLevelDB{'pins'} = \%pins;
	$topLevelDB{'bus'} = \%bus;
	$topLevelDB{'design'} = \%design;
	return \%topLevelDB;
}

21 comments on “Creating .lib file from verilog

  1. Nizam

    Hi Sini,
    script is very good.
    I tried to run by using simple Verilog netlist.
    perl yourscript.pl
    The usage is not clean for.
    If I run ur usage I am getting create_lib is not recognized as internal or external command.
    Please help to get a dummy .lib for my simple Verilog netlist by providing execution/usage

    Reply
    1. Sini Mukundan Post author

      Nizam,

      Type ” which perl” from your terminal. In this script there is #!/usr/bin/perl at line1. Replace the /usr/bin/perl part with your “which perl” result. Then you should be able to run it without perl command.
      Sini

      Reply
  2. vinay kumar

    The script is very useful but i am getting an error
    “: bus_7_0 : input
    : bus_7_0 : input

    What changes need to be made in script to avoid this

    Reply
  3. Sarath

    Hi Sini,
    Could you please give me a perl script to reduce maxcap violations.
    If possible just give me an overview of maxcap violations and methods to reduce them.

    Reply
  4. Sandeep

    Hi madam,
    I have a doubt in timing, if u have time just look it and give me some suggestion…
    1.How can “setup and hold” violations happen in the same path…? What are the reasons for it and how can that issue be solved?

    Reply
  5. Yuvi

    setup & hold are mutually exclusive, but they can occur for same endpoints in different corners due to variation exhibiting by std cells.

    Reply
  6. Kunal

    Hi Sini,
    My name is Kunal Ghosh. I run online VLSI courses on https://www.udemy.com/user/anagha/

    Nice script to start with.

    I wanted to ask, if its ok to modify and use your above dummy lib generation script in one of my courses. I will acknowledge you in my course work for the same

    Hoping to collaboratively work with you

    Thanks
    Kunal

    Reply
    1. Sini Mukundan Post author

      Hi Kunal,

      We are licensed under CC-BY-NC. While your usage might be commercial, please consider this mail as approval to use with attribution.

      Thanks,
      Sini

      Reply
  7. jayant saxena

    i have used ur scripts to generate .lib from verilog ,its working fine but now i want to modify this script such that my .lib should also contain information of power pin eg
    pg_pin(gnd){
    pg_type : primary_ground;
    voltage_name : gnd;
    }
    pg_pin(gnds){
    pg_type : internal_ground;
    voltage_name : gnds;
    }
    pg_pin(vdd){
    pg_type : primary_power;
    voltage_name : vdd;
    }
    pg_pin(vdds){
    pg_type : internal_power;
    voltage_name : vdds;
    }
    this type of information i want to add alonfg with cell name how to do this can u tell me ?

    Reply
    1. Sini Mukundan Post author

      You need a pattern.
      Do you have supply1/supply0 statements for you power pins in the verilog files? If so, use that for another level of parsing.

      Reply
  8. Apurv

    Hello,
    Its great blog…
    i have one questions, can u tell me how we can extract net length from def file without loading it in tool using any perl or tcl??

    like m1 layer net length is this
    m2 layer net length is that..like wise

    Reply
  9. Mahendra Reddy

    Hi Sini,

    This script does not work if the input|output|inout signals are defined in multiple lines in the verilog.

    For example:
    input a,b,
    c;

    Script generates pin attributes only for “a” & “b” pins in .lib, but not for “c”.

    Please look into the same.

    Thanks,
    Mahendra

    Reply
  10. nageswar

    Hi Sini,

    as part of my project work,I have standard cells .libs info, using this info I need generate Verilog code with dummy connections and not required functionally . It is like your above script that has to generate dummy verilog or RTL code based on .libs cell info to just run through synthesis flows.Can you please help me to provide script may help me to do this if you have it? i have seen above your script does reverse way.

    Thanks,

    Nageswar

     

    Reply
  11. shaik sharief

    Hi mam,

    I have some questions which were asked  by interviewer  ….i am not finding the answers for this Questions. could you please reply  answers  for this Questions .

    if you are unable to answer at a time you can do 10 Questions per each time ……………………

    Thank you,

    sharief

     

    How Double width  impact delay/Timing?
    What is the CPPR value for half cycle hold check? (Max delay 20ps and min delay 10ps for common cell).
    What happens if we have more ID in our design?
    What are modes in MMMC?
    What internal power structure is seen inside macros? How you connect power supply to macro?
    Why tool doesn’t fix all DRCs?
    What all things is there in the LEF, after Tape out?
    I have 2 designs one is having more ID with less skew and another with less ID and large skew. Which design is best and why?
    I have two macros with different families, can we abutt them or not? And two macros with same family, can we abutt them or not?
    Unconstrained End points need to be zero. But how they are constraining all endpoints?
    Why HFNS are doing at placement stage only? Why can’t we do along with CTS?
    I have hold of 50ps after base freeze. How will you fix this violation?
    I have setup and hold for the same simple REG2REG path, same scenario. What may be the reasons? How will you resolve it?
    What AOCV file contains?
    I have two nets, one is having net length of 300um and having 300ps delay, second net having net length of 150um what is the delay value for this net?
    I have a macro whose pins are in the left side, having routing congestion so how to fix that?
    While doing optimization, whether those techniques are applied on all cells or it just perform on buffers and Inverters?
    In lower technologies, why resistance and capacitance increases? And via size increases?
    If cell name was not given? Then how to identify the type of cell?
    How we will get target skew values? (How target skew will define).
    If time period of 1.25ns and lib input transition is 800ps. This you will accept or reject it?
    How to balance skew and latency?
    I have setup and hold for the same simple REG2REG path, different scenarios. What may be the reasons? How will you resolve it?
    Is metal layers colors defined in tech file or not?
    What is the difference between CTS done with 150ps clock transition for 500 Mhz clock and CTS done with addressing trans against lib limit?
    I checked setup for ss corner I have +ve slack and for the same simple reg2reg path in typical corner I got –ve slack. Why?
    How does clock been built for ICG based design in case ICG source and leaf have data paths?
    What are the uncertainty values for PNR and signoff? How to derive that numbers?
    Two Macros have same family and these don’t have any functional & logical connectivity can we abutt them? And these macros does not have pins in between.
    Two Macros have different family and these don’t have any functional & logical connectivity can we abutt them. And these macros does not have pins in between.
    I have one design with 2 clocks having 1ns of clk period and another of 4ns, which clock will get more hold violations. Why?
    Why macro have halos on four sides, but my pins are at one side?
    Difference between a power domain and voltage domain in UPF?
    How you build Clock tree?
    Which is preferred location (On/OFF domain or Always on) for placing an isolation cell? Why?
    Command for half cycle paths?
    Why finfet is low Vt, compared to CMOS?
    What are the floor plan rules for 7NM?
    Why cut metal is introduced from 7nm only?
    What is color conflict error?
    What is PNet violation?

    Reply

Leave a Reply to Sini Mukundan Cancel reply

Your email address will not be published. Required fields are marked *