OpenCores
URL https://opencores.org/ocsvn/socgen/socgen/trunk

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [verilog/] [elab_verilog] - Rev 131

Go to most recent revision | Compare with Previous | Blame | View Log

eval 'exec `which perl` -S $0 ${1+"$@"}'
   if 0;
#/**********************************************************************/
#/*                                                                    */
#/*             -------                                                */
#/*            /   SOC  \                                              */
#/*           /    GEN   \                                             */
#/*          /    TOOL    \                                            */
#/*          ==============                                            */
#/*          |            |                                            */
#/*          |____________|                                            */
#/*                                                                    */
#/*                                                                    */
#/*                                                                    */
#/*                                                                    */
#/*  Author(s):                                                        */
#/*      - John Eaton, jt_eaton@opencores.org                          */
#/*                                                                    */
#/**********************************************************************/
#/*                                                                    */
#/*    Copyright (C) <2010-2011>  <Ouabache Design Works>              */
#/*                                                                    */
#/*  This source file may be used and distributed without              */
#/*  restriction provided that this copyright statement is not         */
#/*  removed from the file and that any derivative work contains       */
#/*  the original copyright notice and the associated disclaimer.      */
#/*                                                                    */
#/*  This source file is free software; you can redistribute it        */
#/*  and/or modify it under the terms of the GNU Lesser General        */
#/*  Public License as published by the Free Software Foundation;      */
#/*  either version 2.1 of the License, or (at your option) any        */
#/*  later version.                                                    */
#/*                                                                    */
#/*  This source is distributed in the hope that it will be            */
#/*  useful, but WITHOUT ANY WARRANTY; without even the implied        */
#/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR           */
#/*  PURPOSE.  See the GNU Lesser General Public License for more      */
#/*  details.                                                          */
#/*                                                                    */
#/*  You should have received a copy of the GNU Lesser General         */
#/*  Public License along with this source; if not, download it        */
#/*  from http://www.opencores.org/lgpl.shtml                          */
#/*                                                                    */
#/**********************************************************************/


############################################################################
# General PERL config
############################################################################
use Getopt::Long;
use English;
use File::Basename;
use Cwd;
use Scalar::Util qw(looks_like_number);
use XML::LibXML;
use lib './tools';
use sys::lib;
use yp::lib;
use BerkeleyDB;


$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.


############################################################################
### Process the options
############################################################################
Getopt::Long::config("require_order", "prefix=-");
GetOptions("h","help",
           "envidentifier=s" => \$envidentifier,
           "prefix=s" => \$prefix,
           "vendor=s" => \$vendor,
           "library=s" => \$library,
           "component=s" => \$component,
           "version=s" => \$version,
           "env=s" => \$env,
           "tool=s" => \$tool,
           "unit=s" => \$unit,
           "name=s" => \$name

) || die "(use '$program_name -h' for help)";


##############################################################################
## Help option
##############################################################################
if ( $opt_h  or $opt_help  ) 
  { print "\n elab_verilog -envidentifier {sim/syn}  -prefix /work -vendor vendor_name -library library_name  -component component_name  -version version_name -env env -tool tool -unit unit -name name     \n";
    exit 1;
  }



#############################################################################
## 
## 
#############################################################################

$home = cwd();

unless ($prefix)
 {
 $prefix   = yp::lib::get_workspace();
 $prefix   =  "/${prefix}";
 }


my   $variant;
my   $configuration;

my $dest_dir            = "elab";
my $destination         = "${component}_${version}";

unless ($env ) {$env = "none";}
unless ($tool ){$tool = "none";}
unless ($unit ){$unit = "none";}

if($name)
  {
  $destination   = "${destination}_${name}";
  }
else
  {
  $name          = $version;
  $destination   = "${destination}";
  }




my $root                =      "root";

if($version)       {$variant   = "${component}_${version}";}
else               {$variant   = "${component}";}

#print "elab_verilog -prefix $prefix -vendor $vendor -library $library -component $component -version $version -env $env -tool $tool -unit $unit -name $name     \n";


my $parser = XML::LibXML->new();


my $socgen_file              = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));

unless ($socgen_file)      { print "No socgen ip file   \n";};


my $comp_xml_sep    = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
my $lib_comp_sep    = yp::lib::find_lib_comp_sep($vendor,$library,$component);


#print "lib_comp_sep   $lib_comp_sep \n";
#print "comp_xml_sep   $comp_xml_sep \n";




my $path  = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/../${dest_dir}";

unless( -e $path )
        {
        print "$path does not exist... creating \n";
        my $cmd = "mkdir $path \n";
        if(system($cmd)){};
        }



$data_db_dir  = "${path}/${destination}";




unless(-e  $data_db_dir  )
        {
        my $cmd = "mkdir  $data_db_dir \n";
        if(system($cmd)){};
        }


$data_db_file  = "${path}/${destination}/${root}.db";




if(-e  $data_db_file  )
        {
        print "$data_db_file  does exist... removing  \n";
        my $cmd = "rm  $data_db_file \n";
        if(system($cmd)){};
        }


print "ELAB  $data_db_file  \n";


my $elab_db  = new BerkeleyDB::Hash( -Filename => "$data_db_file", -Flags => DB_CREATE ) or die "Cannot open $data_db_file: $!";
$elab_db->db_put( "component_${root}","${vendor}:${library}:${component}:${version}"  );
$elab_db->db_put( "component___root" ,"${vendor}:${library}:${component}:${version}"  );



foreach  my   $socgen_cfg ($socgen_file->findnodes("//socgen:componentConfiguration/socgen:${env}/socgen:${tool}/socgen:${unit}/socgen:parameters/socgen:parameter"))
          {
          my($ise_param)             = $socgen_cfg ->findnodes('./socgen:value/text()')->to_literal ;
          my($ise_param_name)        = $socgen_cfg ->findnodes('./socgen:name/text()')->to_literal ;
          my($ise_new_name   )    = $socgen_cfg ->findnodes('../../socgen:name/text()')->to_literal ;
          if($name eq "${ise_new_name}")
             {         
             if($ise_param_name)
               {
               $elab_db->db_put( "parameter_${root}__${ise_param_name}","${ise_param}"  );
               #print "XXXXXXXA $ise_param_name  $ise_param           $ise_new_name    \n";
               }
             }
          }




foreach my $socgen_cfg ($socgen_file->findnodes("//socgen:componentConfiguration/socgen:${env}/socgen:${tool}/socgen:${unit}/socgen:variant")) 
     {
     my($variant_name)     = $socgen_cfg->findnodes('./text()')->to_literal ;
     $configuration        = $socgen_cfg->findnodes('../socgen:configuration/text()')->to_literal ;

     #/**********************************************************************/
     #/*                                                                    */
     #/* if configuration set then read parameters from socgen:componentConfiguration file      */
     #/*                                                                    */
     #/**********************************************************************/
     if($variant_name eq $variant)
        {
        #print "XXXXXXXQ $variant_name  configuration $configuration  \n";  
        foreach my $socgen_cfg ($socgen_file->findnodes("//socgen:componentConfiguration/socgen:configurations/socgen:configuration/socgen:parameters/socgen:parameter/socgen:name")) 
          {
          my($param_name)         = $socgen_cfg->findnodes('./text()')->to_literal ;
          my($param_value)        = $socgen_cfg->findnodes('../socgen:value/text()')->to_literal ;
          my($config_name)        = $socgen_cfg->findnodes('../../../socgen:name/text()')->to_literal ;
          #print "XXXXXXXQQ  $config_name  $param_name $param_value  \n";  


          if($config_name eq $configuration  )
            {
            my $repo_data;
            $elab_db->db_get("parameter_${root}__${param_name}", $repo_data );
            unless ($repo_data)
              {
              #print "XXXXXXXB $param_name ${param_value} \n";
              $elab_db->db_put( "parameter_${root}__${param_name}","${param_value}"  );
              }
            }
          }
     }
}






elaborate( "${root}","${vendor}","${library}","${component}","${version}"  );

my $root                =      "root";

my $key;
my $value;


my @elab_list;

my $cursor = $elab_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0) 
   {
   #print "ELAB  $key,   $value  \n";
   ( ${key_type},@elab_list) = split( /\./ , $key);

   if(($key_type eq "component___${root}"))
      {
      #print "Component  $key -- $value @elab_list  \n"; 
      build_hierarchy ($value,"${path}/${destination}",$root,@elab_list);
      }
   }
my $status = $cursor->c_close() ;




$cursor = $elab_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0) 
   {
   $_ = $key;
   if(/parameter_${root}(\S+)__(\S+)/) 
    { 
    my $xpath = $1; 
    my $parname = $2;
    $xpath =~ s/\./\//g;
    my $file_name = "${path}/${destination}/${root}/${xpath}/Index.db";
    my $param_db  = new BerkeleyDB::Hash( -Filename => "$file_name", -Flags => DB_CREATE ) or die "Cannot open ${file_name}: $!";
       $param_db->db_put( "$key","${value}");
       $param_db->db_close();
    #print "Parameter $key      ---  ${file_name}   $parname  $value \n";
    }
   }
$status = $cursor->c_close() ;



$cursor = $elab_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0) 
   {
   $_ = $key;
   if(/busInterface_${root}(\S+)__(\S+)/) 
    { 
    my $xpath = $1; 
    my $parname = $2;
    $xpath =~ s/\./\//g;
    my $file_name = "${path}/${destination}/${root}/${xpath}/Index.db";
    my $param_db  = new BerkeleyDB::Hash( -Filename => "$file_name", -Flags => DB_CREATE ) or die "Cannot open ${file_name}: $!";
       $param_db->db_put( "$key","${value}");
       $param_db->db_close();
    #print "busInterface $key      ---  ${file_name}   $parname  $value \n";
    }
   }
$status = $cursor->c_close() ;















$elab_db->db_close();











#/*********************************************************************************************/
#/                                                                                            */
#/  Recursive entry point for all lower levels                                                */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/

sub elaborate
   {
   my @params     = @_;
   my $elab_version        = pop(@params);
   my $elab_component      = pop(@params);
   my $elab_library        = pop(@params);
   my $elab_vendor         = pop(@params);
   my $elab_root           = pop(@params);

   my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact_component($elab_vendor,$elab_library,$elab_component,$elab_version));

   #print "ELABORATING $elab_root  $elab_vendor $elab_library $elab_component $elab_version \n";
   parse_component_file($spirit_component_file,$elab_root);
   parse_design_files($spirit_component_file,$elab_root);
   #print "Exit $elab_root   \n";
   return;
}




#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/




sub parse_component_file
   {
   my @params     = @_;
   my $elab_root                 = pop(@params);
   my $spirit_component_file      = pop(@params);



foreach my $new_comp ($spirit_component_file->findnodes("//spirit:component/spirit:vendor")) 
   {
   my($new_vendor)          = $new_comp->findnodes('./text()')->to_literal ;
   my($new_library)         = $new_comp->findnodes('../spirit:library/text()')->to_literal ;
   my($new_name)            = $new_comp->findnodes('../spirit:name/text()')->to_literal ;
   my($new_version)         = $new_comp->findnodes('../spirit:version/text()')->to_literal ;
 #  print "PARSE component file $elab_root $new_vendor $new_library $new_name    $new_version         \n";





     #/**********************************************************************/
     #/*                                                                    */
     #/* parse parameters and values                                        */
     #/*                                                                    */
     #/**********************************************************************/
         
     foreach  my   $i_name ($spirit_component_file->findnodes('//spirit:model/spirit:modelParameters/spirit:modelParameter/spirit:name'))
        {
        my($parameter_name)     = $i_name ->to_literal;
        my($parameter_default)  = $i_name ->findnodes('../spirit:value/text()')->to_literal ;
        my $repo_data;
        $elab_db->db_get("parameter_${elab_root}__${parameter_name}", $repo_data );
        unless ($repo_data)
            {
            #print "XXXXXXXC $parameter_name ${parameter_default} \n";
            $elab_db->db_put( "parameter_${elab_root}__${parameter_name}","${parameter_default}"  );
            }
        }

   

     #/**********************************************************************/
     #/*                                                                    */
     #/* parse businterfaces                                                */
     #/*                                                                    */
     #/**********************************************************************/
         

    my $main_module_name = yp::lib::get_module_name($new_vendor,$new_library,$new_name,$new_version);

    if($main_module_name)
    {
    my $io_busses_filename = yp::lib::get_io_busses_db_filename($new_vendor,$new_library,$new_name,$new_version);
    $comp_io_busses_db  = new BerkeleyDB::Hash( -Filename => "$io_busses_filename", -Flags => DB_CREATE ) or die "Cannot open $io_busses_filename    : $!";
    my $cursor = $comp_io_busses_db ->db_cursor() ;
    while ($cursor->c_get($key, $value, DB_NEXT) == 0) 
      {
      ( ${key_type},${name},${sense}) = split( /\./ , $key);
      if($key_type eq "AbsDef")
        {
#        print "BUS-- ${elab_root}  |||  $name $sense  ===   $value  \n";
        my $repo_data;
        $elab_db->db_get("businterface_${elab_root}__${name}", $repo_data );
        unless ($repo_data)
            {
#            print "BUS--:::  \n";
            $elab_db->db_put( "busInterface_${elab_root}__${name}","busInterface:${sense}:${value}"  );
            }
        }
      }
    my $status = $cursor->c_close() ;
    }





        }








foreach my $new_comp ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:vendorExtensions/spirit:componentRef")) 
   {
    my($new_vendor)        = $new_comp->findnodes('./@spirit:vendor')->to_literal ;
    my($new_library)       = $new_comp->findnodes('./@spirit:library')->to_literal ;
    my($new_name)          = $new_comp->findnodes('./@spirit:name')->to_literal ;
    my($new_version)       = $new_comp->findnodes('./@spirit:version')->to_literal ;
    if(yp::lib::find_ipxact_component($new_vendor,$new_library,$new_name,$new_version))
     {
     parse_component_file($parser->parse_file(yp::lib::find_ipxact_component($new_vendor,$new_library,$new_name,$new_version)),$elab_root    );
     }

   }
}






#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/




sub parse_design_files
   {
   my @params     = @_;
   my $elab_root    = pop(@params);
   my $spirit_component_file      = pop(@params);




  foreach my $new_comp ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:vendorExtensions/spirit:componentRef")) 
    {
            my($new_vendor)        = $new_comp->findnodes('./@spirit:vendor')->to_literal ;
            my($new_library)       = $new_comp->findnodes('./@spirit:library')->to_literal ;
            my($new_name)          = $new_comp->findnodes('./@spirit:name')->to_literal ;
            my($new_version)       = $new_comp->findnodes('./@spirit:version')->to_literal ;
            #print "PARSE design files $elab_root $new_vendor $new_library $new_name    $new_version         \n";
            parse_design_files($parser->parse_file(yp::lib::find_ipxact_component($new_vendor,$new_library,$new_name,$new_version )),$elab_root );
   }




  foreach my $new_comp ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:hierarchyRef")) 
    {
            my($new_vendor)        = $new_comp->findnodes('./@spirit:vendor')->to_literal ;
            my($new_library)       = $new_comp->findnodes('./@spirit:library')->to_literal ;
            my($new_name)          = $new_comp->findnodes('./@spirit:name')->to_literal ;
            my($new_version)       = $new_comp->findnodes('./@spirit:version')->to_literal ;
            if(yp::lib::find_ipxact_design($new_vendor,$new_library,$new_name,$new_version ))
              {
              #print "PARSE DESIGN file $elab_root $new_vendor $new_library $new_name    $new_version         \n";
              parse_design_file($parser->parse_file(yp::lib::find_ipxact_design($new_vendor,$new_library,$new_name,$new_version )),$elab_root   );
              }
  }

}



































#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/




sub parse_design_file
   {
   my @params     = @_;
   my $elab_root               = pop(@params);
   my $spirit_design_file      = pop(@params);

   foreach my $new_comp ($spirit_design_file->findnodes("//spirit:design/spirit:vendor")) 
     {
     my($new_vendor)          = $new_comp->findnodes('./text()')->to_literal ;
     my($new_library)         = $new_comp->findnodes('../spirit:library/text()')->to_literal ;
     my($new_name)            = $new_comp->findnodes('../spirit:name/text()')->to_literal ;
     my($new_version)         = $new_comp->findnodes('../spirit:version/text()')->to_literal ;
     #print "WARNING  $new_vendor $new_library $new_name $new_version  DESIGN \n";

     foreach  my   $x_name ($spirit_design_file->findnodes("//spirit:design/spirit:componentInstances/spirit:componentInstance/spirit:instanceName"))
            {
            #/**********************************************************************/
            #/*                                                                    */
            #/* Lookup VLNV for each instantiated component                        */
            #/*                                                                    */
            #/**********************************************************************/
            my($instance_name)       = $x_name   ->findnodes('./text()')->to_literal ;
            my($vendor_name)         = $x_name  ->findnodes('../spirit:componentRef/@spirit:vendor')->to_literal ;
            my($library_name)        = $x_name  ->findnodes('../spirit:componentRef/@spirit:library')->to_literal ;
            my($component_name)      = $x_name  ->findnodes('../spirit:componentRef/@spirit:name')->to_literal ;
            my($version_name)        = $x_name  ->findnodes('../spirit:componentRef/@spirit:version')->to_literal ;
            #print "INSTANCED $instance_name  $vendor_name $library_name $component_name $version_name   \n";
            $elab_db->db_put( "component___${elab_root}.${instance_name}","${vendor_name}:${library_name}:${component_name}:${version_name}"  );

            if  ($instance_name)
              {  

            

            foreach  my   $i_parameter ($spirit_design_file->findnodes("//spirit:componentInstance[spirit:instanceName/text() = '$instance_name']/spirit:configurableElementValues/spirit:configurableElementValue/\@spirit:referenceId"))
             {
             my($foo_name)       = $i_parameter ->to_literal ;
             my($foo_value)      = $i_parameter ->findnodes('../text()')->to_literal ;
             my $repo_data;
             $elab_db->db_get("parameter_${elab_root}__${foo_value}", $repo_data );
             unless ($repo_data) {$repo_data = $foo_value};
             #print "PARAMETERE  $foo_name  $foo_value  $repo_data  \n";
             $elab_db->db_put( "parameter_${elab_root}.${instance_name}__${foo_name}","${repo_data}"  );
             }

             elaborate( "${elab_root}.${instance_name}","${vendor_name}","${library_name}","${component_name}","${version_name}"  );

             }


            }
      }
   }







           











     






















#/*********************************************************************************************/
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/

sub build_hierarchy
   {
   my @params     = @_;
   my $vlnv       = shift(@params);
   my $path       = shift(@params);
   my $root       = shift(@params);
   my $top        = shift(@params);
   my $new_elab_db ;
   my $new_elab_db_file_name ;



   #print "Hier  $path \nHier- $root       $top    --- @params  \n";
   $path ="${path}/${root}";
   unless(-e $path)
     {
     $cmd ="mkdir ${path} \n";
     if(system($cmd)){}
     #print "Create Dir  ${path} \n";
     }

   unless (-e "${path}/${top}")
     {
     $cmd ="mkdir ${path}/${top} \n";
     if(system($cmd)){}
     }

   $new_elab_db_file_name  = "${path}/${top}/Index.db";

   if(@params)
     {
     build_hierarchy ("$vlnv","${path}","${top}",@params);
     }
   else
     {
     #print "CREATE $new_elab_db_file_name  \n";
     $new_elab_db  = new BerkeleyDB::Hash( -Filename => "$new_elab_db_file_name", -Flags => DB_CREATE ) or die "Cannot open $new_elab_db_file_name    : $!";
     $new_elab_db->db_put( "VLNV","${vlnv}"  );
#     print "VLNV  $vlnv \nVLNV -> $new_elab_db_file_name  \n";
     }

   return(0);

   }




1

Go to most recent revision | Compare with Previous | Blame | View Log

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.