Automation of Electronic Change configuration (ECO) script generator to create netlist
This script is my hobby project which generates netlist for a given logical expression in verilog,
1. Parses the given logical expression
2. Imports gate strength from environment variable
3. Opens GATE_TABLE and identifies the required gate
4. Generates a netlist
The script is not modular and doesn't use powerful perl capability to parse input expressions.So it may require further fine tuning.
#################################################################################
#!/usr/bin/perl #
#Author: chandrashekarbs.1985@gmail.com #
###############################################################################
sub search_strength{
#print "$search\n";
$min = @temp_search[0];
foreach $j(0 .. $search-1){
$min = @temp_search[0];
if(@temp_search[$j] < $min){
$min = @temp_search[$j];
# print"$min\n";
$index_search = $j;
}
}
$exist_strength1 = 0;
$exist_strength2 = 0;
#print $index_search,"hi\n";
#print @temp_search,"tmp_search\n";
#print @temp_search_gate,"\n";
return (@temp_search_gate[$index_search]);
}
sub sub_search_parser{
local ($temp1);
$_ = @_[0];
#print "sub_search_parser$_\n";
s/ //g;
$gate = $_;
@gate_search = split /,/, $gate;
$gate_table = $ENV{'GATE_TABLE'}; #FILE OPEN USING ENVIRONMENT VARIABLE
$script_format = $ENV{'SCRIPT_FORMAT'};
open(GATE, $gate_table) or die "unable to open file";
$strength_available = 0;
$found = 0;
while(($_ = ) && ($count == 1)){
chomp($_);
s/ //g;
@gate_table = split /,/, $_;
# #print @gate_table[1],"\n",$strength,"\n";
if(($gate_table[0]=~ /(@gate_search[0])/i)&&(@gate_table[1] =~ /$strength$/))
{
# print "hi goin for available strength\n";
@gate_table = split /,/, $_;
$strength_available = 1;
if(@gate_table[2] =~ /@gate_search[1]/){ #GATE SEARCH
#print "\n\nFOUND\t ",$_,"\n";
$found = 1;
@script_info[0] = @gate_table[1];
$inputs = @inputs_search = split /-/, @gate_search[2];
@inputs_table = split /-/,@gate_table[3];
#print @gate_search[2],"\n",@gate_table[3],"\n";
for($i = 0 ; $i < $inputs;$i++){
$script = join "-",@inputs_search[$i],@inputs_table[$i];
@temp[$i] = $script;
}
if(!(@gate_search[0] =~ /INV/i)){
$_ = join "*", @temp;#MAPPINNG OUTPUTS OF GATE_SEARCH WITH GATE_TABLE
s/ //g;
@script_info[1] = $_;
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
@script_info[2] = $_;
$gate = join ",", @script_info;
#print "\n\n",$gate,"\n";
}
else{
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
#print "inv hino strength @script_info[0]\n";
$_ = join ",", @script_info[0],@temp[0],$_;
s/ //g;
$gate = $_;
#print $gate;
}
}
}
}
close (GATE);
open(GATE, $gate_table) or die "unable to open file";
while(($_ = ) && ($count == 1) && !$strength_available){
chomp($_);
s/ //g;
@gate_table = split /,/, $_;
#$search = 0;
$exist_strength2 = 0;
#print "exist_strength1\n","hi goin for default strength\n";
if($_ =~ /(@gate_search[0])/i)
{
#print "exist_strength1\n","hi goin for default strength\n";
if(!(@gate_search[0] =~ /MUX/i)){
@temp_strength = split/x/,@gate_table[1];
$exist_strength1 = @temp_strength[1];
@temp_search_gate[$k] = @gate_table[1];
$k++;
if(!$strength){
if($exist_strength1 >= $exist_strength2){
$max_strength = @gate_table[1];
}
}
else
{
$exist_strength2 = $strength;
#print "$exist_strength1 asdsa\n";
#print "$exist_strength2 sadsad\n";
if($strength > $exist_strength1){
@temp_search[$search++] = $strength - $exist_strength1;
}
else{
@temp_search[$search++] = $exist_strength1 - $strength;
}
}
#print @temp_search,"\n";
}
if((@gate_search[0] =~ /MUX/i)){
@temp_strength = split/x/,@gate_table[1];
$exist_strength1 = @temp_strength[2];
@temp_search_gate[$k] = @gate_table[1];
$k++;
if(!$strength){
#print "$exist_strength1\n","hi goin for default strength\n";
if($exist_strength1 >= $exist_strength2){
$max_strength = @gate_table[1];
}
}
else
{
$exist_strength2 = $strength;
if($strength > $exist_strength1){
#print "$exist_strength1 asdsa\n";
#print "$exist_strength2 sadsad\n";
#print "$strength sadsad\n";
@temp_search[$search++] = $exist_strength2 - $exist_strength1;
#$search = $search +1;
}
else{
#print "$exist_strength1\n","hi goin for default strength\n";
@temp_search[$search++] = $exist_strength1 - $exist_strength2;
#$search = $search +1;
}
}
}
@gate_table = split /\,/, $_;
if(@gate_table[2] =~ /@gate_search[1]/){ #GATE SEARCH
# if($strength)
# {
# @gate_table[1] = &search_strength();
#
# }
#else{
@gate_table[1] = $max_strength;
#} #print"$max_strength\n";
#print "\n\nFOUND\t ",$_,"\n";
$found = 1;
@script_info[0] = @gate_table[1];
$inputs = @inputs_search = split /-/, @gate_search[2];
@inputs_table = split /-/,@gate_table[3];
#print @gate_search[2],"\n",@gate_table[3],"\n";
for($i = 0 ; $i < $inputs;$i++){
$script = join "-",@inputs_search[$i],@inputs_table[$i];
@temp[$i] = $script;
}
if(!(@gate_search[0] =~ /INV/i)){
if(!$strength_available)
{
@script_info[0] = &search_strength();
}
$_ = join "*", @temp;#MAPPINNG OUTPUTS OF GATE_SEARCH WITH GATE_TABLE
s/ //g;
@script_info[1] = $_;
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
@script_info[2] = $_;
$gate = join ",", @script_info;
#print "\n",$gate,"\n";
}
else{
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
#print "inv hi@script_info,@gate_table\n";
$_ = join ",", @script_info[0],@temp[0],$_;
s/ //g;
$gate = $_;
#print $gate,"\n";
}
}
}
}
#if($strength && !strength_available)
if(!$strength_available)
{
@script_info[0] = &search_strength();
}
close(GATE);
$exist_strength1 = 0;
$exist_strength2 = 0;
#print @temp_search,"\n";
#print "$max_strength\n\n";
if((!$found) ){
print "\n\nNOT FOUND\n\n";
die "\nEXITING......\n"
}
else {
open(SCRIPT,$script_format); # open the file to read format
while($_ =
1. Parses the given logical expression
2. Imports gate strength from environment variable
3. Opens GATE_TABLE and identifies the required gate
4. Generates a netlist
The script is not modular and doesn't use powerful perl capability to parse input expressions.So it may require further fine tuning.
#################################################################################
#!/usr/bin/perl #
#Author: chandrashekarbs.1985@gmail.com #
###############################################################################
sub search_strength{
#print "$search\n";
$min = @temp_search[0];
foreach $j(0 .. $search-1){
$min = @temp_search[0];
if(@temp_search[$j] < $min){
$min = @temp_search[$j];
# print"$min\n";
$index_search = $j;
}
}
$exist_strength1 = 0;
$exist_strength2 = 0;
#print $index_search,"hi\n";
#print @temp_search,"tmp_search\n";
#print @temp_search_gate,"\n";
return (@temp_search_gate[$index_search]);
}
sub sub_search_parser{
local ($temp1);
$_ = @_[0];
#print "sub_search_parser$_\n";
s/ //g;
$gate = $_;
@gate_search = split /,/, $gate;
$gate_table = $ENV{'GATE_TABLE'}; #FILE OPEN USING ENVIRONMENT VARIABLE
$script_format = $ENV{'SCRIPT_FORMAT'};
open(GATE, $gate_table) or die "unable to open file";
$strength_available = 0;
$found = 0;
while(($_ = ) && ($count == 1)){
chomp($_);
s/ //g;
@gate_table = split /,/, $_;
# #print @gate_table[1],"\n",$strength,"\n";
if(($gate_table[0]=~ /(@gate_search[0])/i)&&(@gate_table[1] =~ /$strength$/))
{
# print "hi goin for available strength\n";
@gate_table = split /,/, $_;
$strength_available = 1;
if(@gate_table[2] =~ /@gate_search[1]/){ #GATE SEARCH
#print "\n\nFOUND\t ",$_,"\n";
$found = 1;
@script_info[0] = @gate_table[1];
$inputs = @inputs_search = split /-/, @gate_search[2];
@inputs_table = split /-/,@gate_table[3];
#print @gate_search[2],"\n",@gate_table[3],"\n";
for($i = 0 ; $i < $inputs;$i++){
$script = join "-",@inputs_search[$i],@inputs_table[$i];
@temp[$i] = $script;
}
if(!(@gate_search[0] =~ /INV/i)){
$_ = join "*", @temp;#MAPPINNG OUTPUTS OF GATE_SEARCH WITH GATE_TABLE
s/ //g;
@script_info[1] = $_;
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
@script_info[2] = $_;
$gate = join ",", @script_info;
#print "\n\n",$gate,"\n";
}
else{
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
#print "inv hino strength @script_info[0]\n";
$_ = join ",", @script_info[0],@temp[0],$_;
s/ //g;
$gate = $_;
#print $gate;
}
}
}
}
close (GATE);
open(GATE, $gate_table) or die "unable to open file";
while(($_ = ) && ($count == 1) && !$strength_available){
chomp($_);
s/ //g;
@gate_table = split /,/, $_;
#$search = 0;
$exist_strength2 = 0;
#print "exist_strength1\n","hi goin for default strength\n";
if($_ =~ /(@gate_search[0])/i)
{
#print "exist_strength1\n","hi goin for default strength\n";
if(!(@gate_search[0] =~ /MUX/i)){
@temp_strength = split/x/,@gate_table[1];
$exist_strength1 = @temp_strength[1];
@temp_search_gate[$k] = @gate_table[1];
$k++;
if(!$strength){
if($exist_strength1 >= $exist_strength2){
$max_strength = @gate_table[1];
}
}
else
{
$exist_strength2 = $strength;
#print "$exist_strength1 asdsa\n";
#print "$exist_strength2 sadsad\n";
if($strength > $exist_strength1){
@temp_search[$search++] = $strength - $exist_strength1;
}
else{
@temp_search[$search++] = $exist_strength1 - $strength;
}
}
#print @temp_search,"\n";
}
if((@gate_search[0] =~ /MUX/i)){
@temp_strength = split/x/,@gate_table[1];
$exist_strength1 = @temp_strength[2];
@temp_search_gate[$k] = @gate_table[1];
$k++;
if(!$strength){
#print "$exist_strength1\n","hi goin for default strength\n";
if($exist_strength1 >= $exist_strength2){
$max_strength = @gate_table[1];
}
}
else
{
$exist_strength2 = $strength;
if($strength > $exist_strength1){
#print "$exist_strength1 asdsa\n";
#print "$exist_strength2 sadsad\n";
#print "$strength sadsad\n";
@temp_search[$search++] = $exist_strength2 - $exist_strength1;
#$search = $search +1;
}
else{
#print "$exist_strength1\n","hi goin for default strength\n";
@temp_search[$search++] = $exist_strength1 - $exist_strength2;
#$search = $search +1;
}
}
}
@gate_table = split /\,/, $_;
if(@gate_table[2] =~ /@gate_search[1]/){ #GATE SEARCH
# if($strength)
# {
# @gate_table[1] = &search_strength();
#
# }
#else{
@gate_table[1] = $max_strength;
#} #print"$max_strength\n";
#print "\n\nFOUND\t ",$_,"\n";
$found = 1;
@script_info[0] = @gate_table[1];
$inputs = @inputs_search = split /-/, @gate_search[2];
@inputs_table = split /-/,@gate_table[3];
#print @gate_search[2],"\n",@gate_table[3],"\n";
for($i = 0 ; $i < $inputs;$i++){
$script = join "-",@inputs_search[$i],@inputs_table[$i];
@temp[$i] = $script;
}
if(!(@gate_search[0] =~ /INV/i)){
if(!$strength_available)
{
@script_info[0] = &search_strength();
}
$_ = join "*", @temp;#MAPPINNG OUTPUTS OF GATE_SEARCH WITH GATE_TABLE
s/ //g;
@script_info[1] = $_;
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
@script_info[2] = $_;
$gate = join ",", @script_info;
#print "\n",$gate,"\n";
}
else{
$_ = join "-", @gate_search[3],@gate_table[4];
s/ //g;
#print "inv hi@script_info,@gate_table\n";
$_ = join ",", @script_info[0],@temp[0],$_;
s/ //g;
$gate = $_;
#print $gate,"\n";
}
}
}
}
#if($strength && !strength_available)
if(!$strength_available)
{
@script_info[0] = &search_strength();
}
close(GATE);
$exist_strength1 = 0;
$exist_strength2 = 0;
#print @temp_search,"\n";
#print "$max_strength\n\n";
if((!$found) ){
print "\n\nNOT FOUND\n\n";
die "\nEXITING......\n"
}
else {
open(SCRIPT,$script_format); # open the file to read format
while($_ =
Comments
Post a Comment