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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [verilog/] [gen_verilog] - Rev 126

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 XML::LibXML;
use lib './tools';
use sys::lib;
use yp::lib;

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


############################################################################
### Process the options
############################################################################
Getopt::Long::config("require_order", "prefix=-");
GetOptions("h","help",
           "view=s" => \$view,
           "prefix=s" => \$prefix,
           "vendor=s" => \$vendor,
           "project=s" => \$project,
           "version=s" => \$version,
           "component=s" => \$component,
           "dest_dir=s" => \$dest_dir,
           "destination=s" => \$destination,
           "configuration=s" => \$configuration,
           "fragment","no_port","local_parameters","tb","debug","verbose"
) || die "(use '$program_name -h' for help)";


##############################################################################
## Help option
##############################################################################
if ( $opt_h  or $opt_help  ) 
  { print "\n gen_verilog -view {sim/syn}  -prefix /work -vendor vendor_name -project project_name  -component component_name  -version version_name -fragment -no_port -local_parameters -destination destination -configuration configuration -dest_dir  ../verilog";
    print "\n";
    exit 1;
  }

#print "\n WARNING  GEN_verilog  $view  $prefix $vendor $project $component $version $configuration      $dest_dir  $destination   \n";

my $main_module_name = yp::lib::get_module_name($vendor,$project,$component,$version) ;




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


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




my $lib_comp_sep    = yp::lib::find_lib_comp_sep($vendor,$project);
my $comp_xml_sep    = yp::lib::find_ipxact_component_path("spirit:component",$vendor,$project,$component,$version);




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


my $path  = "${home}${prefix}/${vendor}__${project}${lib_comp_sep}/${component}${comp_xml_sep}/${dest_dir}";
mkdir $path,0755             unless( -e $path );

my $path  = "${home}${prefix}/${vendor}__${project}${lib_comp_sep}/${component}${comp_xml_sep}/${dest_dir}/${view}";
mkdir $path,0755             unless( -e $path );

my   @filelist_hier     =       ();
my   @instantiations    =       ();
my   @parameters        =       ();
my   %parameter_values  =       ();




my $sogen_file               = $parser->parse_file(yp::lib::find_socgen("socgen:componentConfiguration",$vendor,$project,$component));
my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact("spirit:component",$vendor,$project,$component,$version));
my $lib_sim_sep              = $sogen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:library_path/text()")->to_literal;







#if( ($prefix eq "/work")  && ($lib_sim_sep)         ){$opt_tb = 1;}


if($opt_tb )
{
   print "Creating testbench for   $vendor $project $component  $version \n";


   my $path  ="${home}/projects/${vendor}/${project}${lib_sim_sep}";
   mkdir $path,0755             unless( -e $path );

   my $path  ="${home}/projects/${vendor}/${project}${lib_sim_sep}/testbenches";
   mkdir $path,0755             unless( -e $path );

      $path  ="${home}/projects/${vendor}/${project}${lib_sim_sep}/testbenches/xml";
   mkdir $path,0755             unless( -e $path );


   $outfile ="${home}/projects/${vendor}/${project}/ip/${component}/sim/testbenches/xml/${variant}_dut.params.xml";
   open TB_COMP_FILE,">$outfile" or die "unable to open $outfile";

   $outfile ="${home}/projects/${vendor}/${project}/ip/${component}/sim/testbenches/xml/${variant}_dutg.design.xml";
   open TB_DESIGN_FILE,">$outfile" or die "unable to open $outfile";


   print TB_COMP_FILE  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   print TB_COMP_FILE  "<!--                                                \n";
   print TB_COMP_FILE  "//                                                //\n";
   print TB_COMP_FILE  "// Generated File Do Not EDIT                     //\n";
   print TB_COMP_FILE  "//                                                //\n";
   print TB_COMP_FILE  "// regen by adding -tb to gen_verilog script      //\n";
   print TB_COMP_FILE  "//                                                //\n";
   print TB_COMP_FILE  "-->                                                 \n";     
   print TB_COMP_FILE  "<spirit:component\n"; 
   print TB_COMP_FILE  "xmlns:spirit=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\"\n";
   print TB_COMP_FILE  "xmlns:socgen=\"http://opencores.org\"\n";
   print TB_COMP_FILE  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
   print TB_COMP_FILE  "xsi:schemaLocation=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\n";
   print TB_COMP_FILE  "http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009/index.xsd\">\n";
   print TB_COMP_FILE  "<spirit:vendor>${vendor}</spirit:vendor>\n";
   print TB_COMP_FILE  "<spirit:library>${project}</spirit:library>\n";
   print TB_COMP_FILE  "<spirit:name>${component}</spirit:name>\n";
   print TB_COMP_FILE  "<spirit:version>${version}_dut.params</spirit:version>\n";  


   print TB_DESIGN_FILE  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
   print TB_DESIGN_FILE  "<!--                                                \n";
   print TB_DESIGN_FILE  "//                                                //\n";
   print TB_DESIGN_FILE  "// Generated File Do Not EDIT                     //\n";
   print TB_DESIGN_FILE  "//                                                //\n";
   print TB_DESIGN_FILE  "// regen by adding -tb to gen_verilog script      //\n";
   print TB_DESIGN_FILE  "//                                                //\n";
   print TB_DESIGN_FILE  "-->                                                 \n";     
   print TB_DESIGN_FILE  "<spirit:design\n"; 
   print TB_DESIGN_FILE  "xmlns:spirit=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\"\n";
   print TB_DESIGN_FILE  "xmlns:socgen=\"http://opencores.org\"\n";
   print TB_DESIGN_FILE  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
   print TB_DESIGN_FILE  "xsi:schemaLocation=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\n";
   print TB_DESIGN_FILE  "http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009/index.xsd\">\n";
   print TB_DESIGN_FILE  "<spirit:vendor>${vendor}</spirit:vendor>\n";
   print TB_DESIGN_FILE  "<spirit:library>${project}</spirit:library>\n";
   print TB_DESIGN_FILE  "<spirit:name>${component}</spirit:name>\n";
   print TB_DESIGN_FILE  "<spirit:version>${version}_dutg.design</spirit:version>\n";  

}


     #/**********************************************************************/
     #/*                                                                    */
     #/* if configuration set then read parameters from socgen:componentConfiguration file      */
     #/*                                                                    */
     #/**********************************************************************/

    if($configuration)
      {
      # print "XXX Reading configuration   $configuration \n";
      unless ($sogen_file)      { print "No socgen ip file \n";};

      foreach my $socgen_cfg ($sogen_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 ;
                if($config_name eq $configuration  )
                  {
                  unless(defined $parameter_values{$param_name}) {push ( @parameters,  "$param_name");};
                  $parameter_values{$param_name} = ${param_value};
                  }
                }

      }




#/**********************************************************************/
#/*                                                                    */
#/* Every hier cell is constructed from the ipxact file with seperate  */
#/* version  for each view                                             */
#/*                                                                    */
#/* Start by opening the output file                                   */
#/* get fileset name                                                   */
#/* check that requested view exists                                   */
#/*                                                                    */
#/**********************************************************************/

foreach my $comp_view ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:name[text() = '$view']"             )) 
   {
   my($view_fileset_name)  = $comp_view->findnodes('../spirit:fileSetRef/spirit:localName/text()')->to_literal ;
   $outfile ="${home}${prefix}/${vendor}__${project}${lib_comp_sep}/${component}${comp_xml_sep}/${dest_dir}/${view}/${destination}";
   open DEST_FILE,">$outfile" or die "unable to open $outfile";
   unless ($opt_fragment){     print DEST_FILE  "\n module \n\n  $main_module_name \n ";}

   #/*****************************************************************************/
   #/*  wire_decs array holds all port and signal declarations                   */
   #/*  :::name:::node_input_output:::wire_reg:::scaler_vector:::left:::right::: */   
   #/*****************************************************************************/

   @wire_decs = (  );


   #/**********************************************************************/
   #/*  inst_conns holds all instance connections                         */
   #/**********************************************************************/

   @inst_conns = (  );

   my @decl_names  = (); 
   my %decl_dirs  = ();
   my %decl_types  = ();
   my %decl_vector = ();
   my %decl_lefts  = ();
   my %decl_rights = ();

   #  component file

   parse_component_file($spirit_component_file);
  if($opt_verbose){print "parse design files \n"; }
   parse_design_files($spirit_component_file);
  if($opt_verbose){print "process design files \n"; }
   process_design_files($spirit_component_file);
  if($opt_verbose){print "process wire_decs \n"; }

   #/**********************************************************************/
   #/*                                                                    */
   #/* pack ports and nodes into hashes                                   */
   #/*                                                                    */
   #/**********************************************************************/


   @wire_decs      = sys::lib::trim_sort(@wire_decs);
   foreach $line (@wire_decs)  
     { 
     $_ = $line;
        if(/:::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::/) 
          { 
          $q_index               = $1;
          $q_node_name           = $2;
          $q_direction           = $3;
          $q_type                = $4;
          $q_vector              = $5;        
          $q_left                = $6;        
          $q_right               = $7;
          $q_instance            = $8;
          $q_depth               = $9;
          $q_phy_name            = $10;
          $q_busref_name         = $11;          
          $q_abslog_name         = $12;          


  if($opt_debug ){print  "XXXXX--    $line \n  ";}

         push ( @decl_names,$q_index);


          if(  $decl_pnames{$q_index})
            {
            if(  $decl_pnames{$q_index} eq ${q_index})
              {
              $decl_pnames{$q_index}  = "${q_node_name}";
              }
            } 
          else
            {
            $decl_pnames{$q_index}  = "${q_node_name}";
            }


          if(  $decl_dirs{$q_index})
            {
            if(  $decl_dirs{$q_index} eq "node")
              {
              $decl_dirs{$q_index}  = "${q_direction}";
              }
            } 
          else
            {
            $decl_dirs{$q_index}  = "${q_direction}";
            }



            if(  $decl_types{$q_index})
              {
              if(  $decl_types{$q_index} eq "wire")
                {
                $decl_types{$q_index}  = "${q_type}";
                }
              } 
            else
              {
              $decl_types{$q_index}  = "${q_type}";
              }





          if(  $decl_vector{$q_index})
            {  unless(  $decl_vector{$q_index} eq "vector"){ $decl_vector{$q_index}  = "${q_vector}";  }} 
          else  { $decl_vector{$q_index}  = "${q_vector}"; }

          if( $q_vector eq "vector" )
            {
            if ( defined $decl_lefts{$q_index})
               {


                $_ = $q_left;
                if(/(\D+)/) 
                { 
                $_ = $decl_lefts{$q_index};
                   if(/(\D+)/) 
                   {
                   print "WARNING  $variant :: $q_node_name :    $q_left   is NOT  a number            $decl_lefts{$q_index}    is NOT  a number \n";
                   #if($decl_lefts{$q_index}   <= $q_left  ) {$decl_lefts{$q_index}   = $q_left;}
                   }
                   else
                   {
                   #print "WARNING  $variant :: $q_node_name :    $q_left   is NOT  a number            $decl_lefts{$q_index}    is a number \n";
                   #if($decl_lefts{$q_index}   <= $q_left  ) {$decl_lefts{$q_index}   = $q_left;}
                   $decl_lefts{$q_index}   = $q_left;
                   }
                }
                else
 
                {
 
                $_ = $decl_lefts{$q_index};
                   if(/(\D+)/) 
                   {
                   #print "WARNING  $variant :: $q_node_name :    $q_left   is   a number            $decl_lefts{$q_index}    is NOT  a number \n";
                   #if($decl_lefts{$q_index}   <= $q_left  ) {$decl_lefts{$q_index}   = $q_left;}
                   }
                   else
                   {
                   #print "WARNING  $variant :: $q_node_name :    $q_left   is   a number            $decl_lefts{$q_index}    is   a number \n";
                   if($decl_lefts{$q_index}   <= $q_left  ) {$decl_lefts{$q_index}   = $q_left;}
                   }
                }
 

               if($decl_rights{$q_index}  >= $q_right ) {$decl_rights{$q_index}  = $q_right;}
               }
            else
               {
               $decl_lefts{$q_index}   = $q_left;
               $decl_rights{$q_index}  = $q_right;
               }
            }
          }
        }
     @decl_names      = sys::lib::trim_sort(@decl_names);





     #/**********************************************************************/
     #/*                                                                    */
     #/* All port and signal info is now loaded in hashes                   */
     #/* Resort on physical name                                            */
     #/* Print out module header , parameters and ports                     */
     #/*                                                                    */
     #/**********************************************************************/




   foreach my $decl_name (@decl_names)

     {

     my $phy_name = $decl_pnames{$decl_name};

     unless ($phy_name) {$phy_name =$decl_name }

     push ( @phy_names,$phy_name);

     if(  $phy_dirs{$phy_name})
            {
            if(  $phy_dirs{$phy_name} eq "node")
              {
              $phy_dirs{$phy_name}   = "$decl_dirs{$decl_name}";
              }
            } 
          else
            {
            $phy_dirs{$phy_name}  = "$decl_dirs{$decl_name}";
            }

            if(  $phy_types{$phy_name})
              {
              if(  $phy_types{$phy_name} eq "wire")
                {
                $phy_types{$phy_name}  = "$decl_types{$decl_name}";
                }
              } 
            else
              {
              $phy_types{$phy_name}  = "$decl_types{$decl_name}";
              }

          if(  $phy_vector{$phy_name})
            {  unless(  $phy_vector{$phy_name} eq "vector"){ $phy_vector{$phy_name}  = "$decl_vector{$decl_name}";  }} 
          else  { $phy_vector{$phy_name}  = "$decl_vector{$decl_name}"; }

          if( $phy_vector{$phy_name} eq "vector" )
            {
            if ( defined $phy_lefts{$phy_name})
               {
                $_ = $phy_lefts{$phy_name};
                if(/(\D+)/) 
                { 
                $_ = $phy_lefts{$phy_name};
                   if(/(\D+)/) 
                   {
                   }
                   else
                   {
                   $phy_lefts{$phy_name}   = $decl_lefts{$decl_name};
                   }
                }
                else
                {
                $_ = $phy_lefts{$phy_name};
                   if(/(\D+)/) 
                   {
                   }
                   else
                   {
                   if($phy_lefts{$phy_name}   <= $decl_lefts{$decl_name}  ) {$phy_lefts{$phy_name}   = $decl_lefts{$decl_name};}
                   }
                }
 
               if($phy_rights{$phy_name}  >= $decl_rights{$decl_name} ) {$phy_rights{$phy_name}  = $decl_rights{$decl_name};}
               }
            else
               {
               $phy_lefts{$phy_name}   = $decl_lefts{$decl_name};
               $phy_rights{$phy_name}  = $decl_rights{$decl_name};
               }
            }
          
   }




     @phy_names      = sys::lib::trim_sort(@phy_names);







     #/**********************************************************************/
     #/*                                                                    */
     #/* Add any and all global parameters with their default values        */
     #/*                                                                    */
     #/**********************************************************************/
      
     unless ($opt_local_parameters)
     {
     my $first = 1;
     foreach my $parameter_name (@parameters)  
        {
        my $parameter_value = $parameter_values{$parameter_name};
        if($first)
          {
          print DEST_FILE  "   #( parameter \n      ${parameter_name}=${parameter_value}";
          $first=0;
          }
        else  { print DEST_FILE  ",\n      ${parameter_name}=${parameter_value}";}
        }
      
     if    ($first == 0)   { print DEST_FILE  ")\n"; }
       }
      

     #/**********************************************************************/
     #/*                                                                    */
     #/* sort all  ports  with their type, size and direction               */
     #/*                                                                    */
     #/**********************************************************************/


     my @port_list  = (); 


     foreach $x_name (@phy_names)  
        {
        my $q_width  = "     ";
        if( $phy_vector{$x_name} eq "vector" )  { $q_width = "[ $phy_lefts{$x_name} :  $phy_rights{$x_name}]"}

        if( $phy_dirs{$x_name} ne "node" )                
          {
          push (@port_list,  "$phy_dirs{$x_name}   $phy_types{$x_name}    $q_width        ${x_name}");
          }
        }

     @port_list      = sys::lib::trim_sort(@port_list);


     #/**********************************************************************/
     #/*                                                                    */
     #/* Now add all ports  with their type, size and direction             */
     #/*                                                                    */
     #/**********************************************************************/
      
      
     print DEST_FILE  "\n    ";
     $first = 1;
      
     foreach $port_line (@port_list)  
        {
          if($first)
            {
            print DEST_FILE  " (\n ${port_line}";
            $first=0;
            }
          else
            {
            print DEST_FILE  ",\n ${port_line}";
            }
          
        }

     if    ($first == 0)   { print DEST_FILE  ");\n\n\n\n"; }
     elsif ($opt_no_port)  { print DEST_FILE  "\n\n\n\n";  }
     else                  { print DEST_FILE  "();\n\n\n\n";}





     #/**********************************************************************/
     #/*                                                                    */
     #/* print wire decs for testbench                                      */
     #/*                                                                    */
     #/**********************************************************************/


     foreach $x_name (@phy_names)  
        {

        if( $phy_dirs{$x_name} ne "node" )                
          {
    if ( $phy_vector{$x_name} eq "vector" ) 
             {
             push (@tb_adhoc_list,  "<spirit:adHocConnection>\n<spirit:name>${x_name}<\/spirit:name>\n<spirit:externalPortReference spirit:portRef=\"${x_name}\" spirit:left=\"${phy_lefts{$x_name}}\" spirit:right=\"${phy_rights{$x_name}}\" \/>\n<spirit:internalPortReference  spirit:componentRef=\"dut\" spirit:portRef=\"${x_name}\" \/>\n<\/spirit:adHocConnection>\n"     );
             }
             else
            {
            push (@tb_adhoc_list,  "<spirit:adHocConnection>\n<spirit:name>${x_name}<\/spirit:name>\n<spirit:externalPortReference  spirit:portRef=\"${x_name}\" \/>\n<spirit:internalPortReference  spirit:componentRef=\"dut\" spirit:portRef=\"${x_name}\" \/>\n<\/spirit:adHocConnection>\n"     );
             }

         }

        }

     @tb_adhoc_list      = sys::lib::trim_sort(@tb_adhoc_list); 
     print TB_DESIGN_FILE  "<spirit:adHocConnections>\n\n";

     foreach $adhoc_line (@tb_adhoc_list)  
        {

            print TB_DESIGN_FILE  "${adhoc_line}\n";

          
        }

     print TB_DESIGN_FILE  "\n</spirit:adHocConnections>\n";






     #/**********************************************************************/
     #/*                                                                    */
     #/* Add parameters  to dut      */
     #/*                                                                    */
     #/**********************************************************************/
print TB_DESIGN_FILE    "<spirit:componentInstances>\n\n";




print TB_DESIGN_FILE    "<spirit:componentInstance>\n";
print TB_DESIGN_FILE    "<spirit:instanceName>dut</spirit:instanceName>\n";
print TB_DESIGN_FILE    "<spirit:componentRef spirit:vendor=\"${vendor}\" spirit:library=\"${project}\" spirit:name=\"$component\" spirit:version=\"${version}\" />\n";
print TB_DESIGN_FILE    "<spirit:configurableElementValues>\n";


     foreach my $parameter_name (@parameters)  
        {
        print TB_DESIGN_FILE  " <spirit:configurableElementValue spirit:referenceId=\"${parameter_name}\">${parameter_name}<\/spirit:configurableElementValue>\n";
        }
      
print TB_DESIGN_FILE    "</spirit:configurableElementValues>\n";
print TB_DESIGN_FILE    "</spirit:componentInstance>\n";
print TB_DESIGN_FILE    "</spirit:componentInstances>\n";
print TB_DESIGN_FILE    "</spirit:design>\n";




     #/**********************************************************************/
     #/*                                                                    */
     #/* Add parameters  to comp      */
     #/*                                                                    */
     #/**********************************************************************/
print TB_COMP_FILE    "<spirit:model>\n\n";
print TB_COMP_FILE    "      <spirit:views>                                            \n";  
print TB_COMP_FILE    "                                   \n";  
print TB_COMP_FILE    "              <spirit:view>                                   \n";  
print TB_COMP_FILE    "              <spirit:name>Dut</spirit:name>                                   \n";  
print TB_COMP_FILE    "              <spirit:envIdentifier></spirit:envIdentifier>                                   \n";  
print TB_COMP_FILE    "              <spirit:hierarchyRef spirit:vendor=\"${vendor}\"                                    \n";  
print TB_COMP_FILE    "                                   spirit:library=\"${project}\"                                    \n";  
print TB_COMP_FILE    "                                   spirit:name=\"${component}\"                                    \n";  
print TB_COMP_FILE    "                                   spirit:version=\"${version}_dutg.design\"/>                                   \n";  
print TB_COMP_FILE    "              </spirit:view>                                   \n";  
print TB_COMP_FILE    "      </spirit:views>                                   \n";  
print TB_COMP_FILE    "<spirit:modelParameters>\n";





     foreach my $parameter_name (@parameters)  
        {
        my $parameter_value = $parameter_values{$parameter_name};
        print TB_COMP_FILE  "    <spirit:modelParameter><spirit:name>${parameter_name}</spirit:name><spirit:value>${parameter_value}</spirit:value></spirit:modelParameter>\n";
        }
      
print TB_COMP_FILE    "</spirit:modelParameters>\n";
print TB_COMP_FILE    "</spirit:model>\n";




   print TB_COMP_FILE  "</spirit:component>\n";









     #/**********************************************************************/
     #/*                                                                    */
     #/* Add any and all local parameters with their default values         */
     #/*                                                                    */
     #/**********************************************************************/
      
     if ($opt_local_parameters)
     {
     foreach my $parameter_name (@parameters)  
        {
        my $parameter_value = $parameter_values{${parameter_name}};
        print DEST_FILE  "parameter ${parameter_name} = ${parameter_value};\n";
        }
     }
      
     #/**********************************************************************/
     #/*                                                                    */
     #/* Add all internal wires and regs with their sizes                   */
     #/*                                                                    */
     #/**********************************************************************/
   
     my @wire_nodes = ();


     foreach $x_name (@phy_names)  
        {
        my $q_width  = "     ";
        if( $phy_vector{$x_name} eq "vector" ){ $q_width = "[ $phy_lefts{$x_name} :  $phy_rights{$x_name}]"}
        if( $phy_dirs{$x_name} eq "node" )    { push @wire_nodes,     "$phy_types{$x_name}     $q_width              ${x_name};";}
        }

     @wire_nodes      = sys::lib::trim_sort(@wire_nodes);

     foreach my $wire_node (@wire_nodes)
     {
     print DEST_FILE  "${wire_node}\n";
     }

     print DEST_FILE  "\n\n\n";
     

     while(   my $line_out      = shift(@instantiations))             {  print DEST_FILE  "$line_out";}

     #/**********************************************************************/
     #/*                                                                    */
     #/* After all the data from the ip-xact file has been entered we now   */
     #/* insert any and all verilog fragments at the end before closing     */
     #/* the module                                                         */
     #/*                                                                    */
     #/**********************************************************************/
      
      
     foreach  my   $i_name ($spirit_component_file->findnodes("//spirit:fileSets/spirit:fileSet/spirit:file/spirit:name"))
        {
        my($rtl_file)       = $i_name ->findnodes('./text()')->to_literal;
        my($file_type)      = $i_name ->findnodes('../spirit:userFileType/text()')->to_literal;
        my($view_file)      = $i_name ->findnodes('../../spirit:name/text()')->to_literal ;
 
        if(($file_type eq "fragment")&& (($view_file eq $view_fileset_name)))
          {
          $SRCFILE ="${home}${prefix}/${vendor}__${project}${lib_comp_sep}/${component}${comp_xml_sep}/${rtl_file}";
          open(SRCFILE) or die("Could not open src file.  $SRCFILE ");
          foreach $line (<SRCFILE>) 
             {
             chomp($line);   
             print DEST_FILE  "${line}\n";
             }
          }
        }
     unless ($opt_fragment ) {print DEST_FILE  "\n\n\n  endmodule\n\n";}   
     
   }











#/*********************************************************************************************/
#/                                                                                            */
#/ this routine does not follow busses down into componentRef                                 */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/                                                                                            */
#/*********************************************************************************************/




sub parse_busInterface 
   {
   my @params     = @_;
   my $depth      = pop(@params);
   my $busref     = pop(@params);
   my $version    = pop(@params);
   my $component  = pop(@params);
   my $project    = pop(@params);
   my $vendor     = pop(@params);

   my $home = cwd();

   my @out_stack  = ();

  if($opt_verbose){print "parse_busInterface $vendor $project $component $version \n"; }

   my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact("spirit:component",$vendor,$project,$component,$version));



   my $busInterfaceTest = 0;

   my @mas_slave;
     push @mas_slave  , "master"; 
     push @mas_slave  , "slave"; 

     foreach my $seek_type (@mas_slave) 
        { 


     foreach my $bus_iface ($spirit_component_file->findnodes("//spirit:component/spirit:busInterfaces/spirit:busInterface/spirit:${seek_type}")) 
        {
        my($fff_cname)         = $bus_iface->findnodes('../spirit:name/text()')->to_literal ;
        my($fff_vendor)        = $bus_iface->findnodes('../spirit:abstractionType/@spirit:vendor')->to_literal ;
        my($fff_library)       = $bus_iface->findnodes('../spirit:abstractionType/@spirit:library')->to_literal ;
        my($fff_name)          = $bus_iface->findnodes('../spirit:abstractionType/@spirit:name')->to_literal ;
        my($fff_version)       = $bus_iface->findnodes('../spirit:abstractionType/@spirit:version')->to_literal ;


        foreach my $port_face ($spirit_component_file->findnodes('//spirit:component/spirit:busInterfaces/spirit:busInterface/spirit:portMaps/spirit:portMap/spirit:logicalPort')) 
           {

           my($fff_xxx_name)      = $port_face->findnodes('../../../spirit:name/text()')->to_literal ;

           my($fff_log_name)      = $port_face->findnodes('./spirit:name/text()')->to_literal ;
           my($fff_phy_name)      = $port_face->findnodes('../spirit:physicalPort/spirit:name/text()')->to_literal ;
           my($fff_type_name)     = $port_face->findnodes('../spirit:physicalPort/spirit:wireTypeDefs/spirit:wireTypeDef/spirit:typeName/text()')->to_literal ;
           my($fff_int_name)      = $port_face->findnodes('../../../spirit:name/text()')->to_literal ;

           my($fff_left_value)    = $port_face->findnodes('../spirit:physicalPort/spirit:wire/spirit:vector/spirit:left/text()')->to_literal ;
           my($fff_right_value)   = $port_face->findnodes('../spirit:physicalPort/spirit:wire/spirit:vector/spirit:right/text()')->to_literal ;

           unless ($fff_type_name)  {$fff_type_name = "wire";};

           if(  ( $fff_xxx_name  eq  $busref) && (  $busref eq   $fff_cname  )       )
             {
             $busInterfaceTest = 1;
             my $busdef_parser = XML::LibXML->new();


             my $spirit_abstractor_filename     = yp::lib::find_ipxact("spirit:abstractionDefinition",$fff_vendor,$fff_library,$fff_name,$fff_version);

             unless($spirit_abstractor_filename){
              #print "  $fff_vendor $fff_library $fff_name $fff_version  \n";

            }


             my $spirit_abstractor_file     = ($parser->parse_file(yp::lib::find_ipxact("spirit:abstractionDefinition",$fff_vendor,$fff_library,$fff_name,$fff_version))


                ) || die "(OOPs $fff_vendor $fff_library $fff_name $fff_version )";



             foreach my $abstr_view ($spirit_abstractor_file->findnodes("//spirit:abstractionDefinition/spirit:ports/spirit:port/spirit:logicalName[text() = '$fff_log_name']")) 
                {
                my($sss_m_dir)         = $abstr_view->findnodes('../spirit:wire/spirit:onMaster/spirit:direction/text()')->to_literal ;
                my($sss_s_dir)         = $abstr_view->findnodes('../spirit:wire/spirit:onSlave/spirit:direction/text()')->to_literal ;

                    if    ($sss_m_dir eq "in")  { $sss_m_dir = "input";}
                    elsif ($sss_m_dir eq "out") { $sss_m_dir = "output";}

                    if    ($sss_s_dir eq "in")  { $sss_s_dir = "input";}
                    elsif ($sss_s_dir eq "out") { $sss_s_dir = "output";}


                my $fff_direction = "";
                
                  
                  if    ( $seek_type eq "master")  { $fff_direction = $sss_m_dir;     }
                  elsif ( $seek_type eq "slave" )  { $fff_direction = $sss_s_dir;     }

                  my $fff_dir = "";
                  if   ($fff_direction  eq "in" )  {$fff_dir = "input" ;}
                  elsif($fff_direction  eq "out" ) {$fff_dir = "output" ;}
                  else                             {$fff_dir = $fff_direction;     }

                  if($fff_left_value ne "") { push @out_stack, ":::${depth}:::${fff_log_name}:::${fff_phy_name}:::${fff_dir}:::${fff_type_name}:::vector:::${fff_left_value}:::${$fff_right_value}:::"; }
                  else                { push @out_stack, ":::${depth}:::${fff_log_name}:::${fff_phy_name}:::${fff_dir}:::${fff_type_name}:::scaler:::none:::none:::";    }

                  
                }
             }

           }
       }

}





       if ( $busInterfaceTest){
                              @out_stack      = sys::lib::trim_sort(@out_stack);      
                              return(@out_stack);
                              }


     my @spirit_design_files       = yp::lib::find_ipxact_design_files($vendor,$project,$component,$version);

     foreach  my   $sd_file (@spirit_design_files)
     {

     $_ = $sd_file;
        if(/:::(\S+):::(\S+):::(\S+):::(\S+):::/) 
          { 
          $q_vendor            = $1;
          $q_library           = $2;
          $q_design            = $3;
          $q_version           = $4;
          $sd_file             = $parser->parse_file(yp::lib::find_ipxact("spirit:design",$q_vendor,$q_library,$q_design,$q_version));
          }

     foreach  my   $x_name ($sd_file->findnodes('//spirit:hierConnections/spirit:hierConnection/@spirit:interfaceRef'))
        {
        my($hierConn_name)                   = $x_name ->to_literal ;
        my($hierConn_comref_name)            = $x_name ->findnodes('../spirit:interface/@spirit:componentRef')->to_literal ;
        my($hierConn_busref_name)            = $x_name ->findnodes('../spirit:interface/@spirit:busRef')->to_literal ;
        if($busref eq  $hierConn_name)   
          {
          foreach  my   $x_name ($sd_file->findnodes("//spirit:design/spirit:componentInstances/spirit:componentInstance/spirit:instanceName[text() = '$hierConn_comref_name']"))
            {
            #/**********************************************************************/
            #/*                                                                    */
            #/* Lookup VLNV for each instantiated component                        */
            #/*                                                                    */
            #/**********************************************************************/

            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 ;
            $depth = $depth +1;
            @out_stack = parse_busInterface ($vendor_name, $library_name,$component_name,$version_name,$hierConn_busref_name,$depth );
            }
          }
        }

     }

        @out_stack      = sys::lib::trim_sort(@out_stack);      
        return(@out_stack);
     

   }














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




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

   #print "\n";






  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 ;
            parse_design_files($parser->parse_file(yp::lib::find_ipxact("spirit:component",$new_vendor,$new_library,$new_name,$new_version )) );
   }




  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 ;
            my $hier_ref_type = yp::lib::find_file_type($new_vendor,$new_library,$new_name,$new_version) ;



     if($hier_ref_type eq "spirit:component")
     {

     }


     elsif($hier_ref_type eq "spirit:designConfiguration")
     {

        my $spirit_designCfg_file    
         = $parser->parse_file(yp::lib::find_ipxact("spirit:designConfiguration",$new_vendor,$new_library,$new_name,$new_version )); 

        foreach my $design_ref_view ($spirit_designCfg_file->findnodes('//spirit:designConfiguration')) 
           {
            $new_vendor          = $design_ref_view->findnodes('./spirit:designRef/@spirit:vendor')->to_literal ;
            $new_library         = $design_ref_view->findnodes('./spirit:designRef/@spirit:library')->to_literal ;
            $new_name            = $design_ref_view->findnodes('./spirit:designRef/@spirit:name')->to_literal ;
            $new_version         = $design_ref_view->findnodes('./spirit:designRef/@spirit:version')->to_literal ;
            $hier_ref_type       = "spirit:design" ;
           }
     }


    if($hier_ref_type eq "spirit:design")
     {
        parse_design_file($parser->parse_file(yp::lib::find_ipxact("spirit:design",$new_vendor,$new_library,$new_name,$new_version )) );
      }





  }

}







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




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

   #print "\n";







  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 ;
            process_design_files($parser->parse_file(yp::lib::find_ipxact("spirit:component",$new_vendor,$new_library,$new_name,$new_version )) );
    }






  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 ;
            my $hier_ref_type = yp::lib::find_file_type($new_vendor,$new_library,$new_name,$new_version) ;


     if($hier_ref_type eq "spirit:component")
     {
     }



     elsif($hier_ref_type eq "spirit:designConfiguration")
     {

        my $spirit_designCfg_file    
         = $parser->parse_file(yp::lib::find_ipxact("spirit:designConfiguration",$new_vendor,$new_library,$new_name,$new_version )); 

        foreach my $design_ref_view ($spirit_designCfg_file->findnodes('//spirit:designConfiguration')) 
           {
           ($new_vendor)         = $design_ref_view->findnodes('./spirit:designRef/@spirit:vendor')->to_literal ;
           ($new_library)        = $design_ref_view->findnodes('./spirit:designRef/@spirit:library')->to_literal ;
           ($new_name)           = $design_ref_view->findnodes('./spirit:designRef/@spirit:name')->to_literal ;
           ($new_version)        = $design_ref_view->findnodes('./spirit:designRef/@spirit:version')->to_literal ;
           $hier_ref_type = "spirit:design";

           }
     }


     if($hier_ref_type eq "spirit:design")
     {
     if($opt_verbose){print "process_design_file  $new_vendor $new_library $new_name $new_version  \n"; }
        process_design_file($parser->parse_file(yp::lib::find_ipxact("spirit:design",$new_vendor,$new_library,$new_name,$new_version )) );
     }
  }

}










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




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





#print "\n";
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";
   }




     #/**********************************************************************/
     #/*                                                                    */
     #/* Add all internal wires and regs with their sizes                   */
     #/*                                                                    */
     #/**********************************************************************/
          
     foreach  my   $i_name ($spirit_design_file->findnodes("//spirit:design/spirit:vendorExtensions/socgen:nodes/socgen:node/spirit:name"))
        {
        my($node_name)       = $i_name ->findnodes('./text()')->to_literal ;
        my($node_busdef)     = $i_name ->findnodes('../socgen:busDef/text()')->to_literal ;
        my($node_left)       = $i_name ->findnodes('../spirit:wire/spirit:vector/spirit:left/text()')->to_literal ;
        my($node_right)      = $i_name ->findnodes('../spirit:wire/spirit:vector/spirit:right/text()')->to_literal ; 
        my($node_type)       = $i_name ->findnodes('../spirit:typeName/text()')->to_literal ;
      
        unless($node_busdef){   $node_busdef =    $node_name;     }

        if(  $node_left ne "" ) { push @wire_decs , ":::${node_busdef}:::${node_name}:::node:::${node_type}:::vector:::${node_left}:::${$node_right}:::none:::0:::${node_name}:::XXX:::${node_name}:::"; }
        else                     { push @wire_decs , ":::${node_busdef}:::${node_name}:::node:::${node_type}:::scaler:::none:::none:::none:::0:::${node_name}:::XXX:::${node_name}:::";   }

        }








     #/**********************************************************************/
     #/*                                                                    */
     #/* Read each hierConnection and enter signals into wire_decs          */
     #/*                                                                    */
     #/**********************************************************************/
     foreach  my   $x_name ($spirit_design_file->findnodes('//spirit:hierConnections/spirit:hierConnection/@spirit:interfaceRef'))
        {
        my($hierConn_name)                   = $x_name ->to_literal ;
        my($hierConn_comref_name)            = $x_name ->findnodes('../spirit:interface/@spirit:componentRef')->to_literal ;
        my($hierConn_busref_name)            = $x_name ->findnodes('../spirit:interface/@spirit:busRef')->to_literal ;

        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 ;

           if( "$instance_name" eq  "$hierConn_comref_name"     )
             {
             my  @filelist_sub = parse_busInterface($vendor_name, $library_name,$component_name,$version_name,$hierConn_busref_name,"1" );
           #/**********************************************************************/
           #/*                                                                    */
           #/* follow bus all the way to it's source                              */
           #/*                                                                    */
           #/**********************************************************************/

             foreach $xxline (@filelist_sub) 
                { 
                $_ = $xxline;
                if(/:::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::/) 
                  { 
                  $k_depth               = $1;
                  $k_log_name            = $2;
                  $k_phy_name            = $3;
                  $k_direction           = $4;
                  $k_type                = $5;
                  $k_vector              = $6;        
                  $k_left                = $7;        
                  $k_right               = $8;
                  push  @wire_decs,":::${hierConn_name}_${k_log_name}:::${hierConn_name}_${k_log_name}:::${k_direction}:::wire:::${k_vector}:::${k_left}:::${k_right}:::${hierConn_comref_name}:::${k_depth}:::${k_phy_name}:::${hierConn_busref_name}:::${k_log_name}:::";
                  }
                }
             }
           }
        }





     #/**************************************************************************/
     #/*                                                                        */
     #/* Read each  interconnection and enter sub signals into wire_decs        */
     #/*                                                                        */
     #/**************************************************************************/




     foreach  my   $x_name ($spirit_design_file->findnodes('//spirit:interconnections/spirit:interconnection/spirit:activeInterface/@spirit:componentRef'))
        {
        my($hierConn_comref_name)            = $x_name ->to_literal;
        my($hierConn_busref_name)            = $x_name ->findnodes('../@spirit:busRef')->to_literal ;
        my($hierConn_name)                   = $x_name ->findnodes('../../spirit:name/text()')->to_literal ;

        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 ;



           if( "$instance_name" eq  "$hierConn_comref_name"     )
             {



           #/**********************************************************************/
           #/*                                                                    */
           #/* follow bus all the way to it's source                              */
           #/*                                                                    */
           #/**********************************************************************/


             my  @filelist_sub = parse_busInterface($vendor_name, $library_name,$component_name,$version_name,$hierConn_busref_name,"1" );
             foreach $xxline (@filelist_sub) 
                { 


                $_ = $xxline;
                if(/:::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::/) 
                  { 
                  $k_depth               = $1;
                  $k_log_name            = $2;
                  $k_phy_name            = $3;
                  $k_direction           = $4;
                  $k_type                = $5;
                  $k_vector              = $6;        
                  $k_left                = $7;        
                  $k_right               = $8;
     
                  
                  push  @wire_decs,":::${hierConn_name}_${k_log_name}:::${hierConn_name}_${k_log_name}:::node:::wire:::${k_vector}:::${k_left}:::${k_right}:::${hierConn_comref_name}:::${k_depth}:::${k_phy_name}:::${hierConn_busref_name}:::${k_log_name}:::";
                  }
                }
             }
           }
        }



     #/*******************************************************************************/
     #/*                                                                             */
     #/* Read each  interconnection and enter modified signals into wire_decs        */
     #/*                                                                             */
     #/*******************************************************************************/





        foreach  my  $k_name ($spirit_design_file->findnodes('//spirit:interconnections/spirit:interconnection/spirit:activeInterface/spirit:portMaps/spirit:portMap/spirit:logicalPort/spirit:name'))
           {
           my($lp_name)                = $k_name ->to_literal;
           my($lp_pname)               = $k_name ->findnodes('../../spirit:physicalPort/spirit:name/text()')->to_literal ;
           my($lp_left)                = $k_name ->findnodes('../../spirit:physicalPort/spirit:wire/spirit:vector/spirit:left/text()')->to_literal ;
           my($lp_right)               = $k_name ->findnodes('../../spirit:physicalPort/spirit:wire/spirit:vector/spirit:right/text()')->to_literal ;
           my($lp_componentref_name)   = $k_name ->findnodes('../../../../@spirit:componentRef')->to_literal ;
           my($lp_busref_name)         = $k_name ->findnodes('../../../../@spirit:busRef')->to_literal ;
           my($lp_interconnect_name)   = $k_name ->findnodes('../../../../../spirit:name/text()')->to_literal ;


           if ( $lp_pname eq '' ) { $lp_pname ="${lp_interconnect_name}_${lp_name}";}
           if ( $lp_left  eq '' ) { $lp_left ="none";}
           if ( $lp_right eq '' ) { $lp_right ="none";}



          if ( $lp_left  eq 'none' ) 
          { 
           push  @wire_decs,":::${lp_interconnect_name}_${lp_name}:::${lp_pname}:::node:::wire:::scaler:::none:::none:::${lp_componentref_name}:::0:::${lp_interconnect_name}_${lp_name}:::${lp_busref_name}:::${lp_pname}:::";
          }
          else
          { 
           push  @wire_decs,":::${lp_interconnect_name}_${lp_name}:::${lp_pname}:::node:::wire:::vector:::${lp_left}:::${lp_right}:::${lp_componentref_name}:::0:::${lp_interconnect_name}_${lp_name}:::${lp_busref_name}:::${lp_pname}:::";
          }
           }








     #/**********************************************************************/
     #/*                                                                    */
     #/* Read all adHocConnections and load instance connect info into array*/
     #/*                                                                    */
     #/**********************************************************************/


     foreach  my   $i_xame ($spirit_design_file->findnodes('//spirit:adHocConnections/spirit:adHocConnection/spirit:internalPortReference/@spirit:componentRef'))
        {
        my($comp_name)    = $i_xame ->to_literal;
        my($int_value)    = $i_xame ->findnodes('../../spirit:name/text()')->to_literal ;
        my($tied_value)   = $i_xame ->findnodes('../../@spirit:tiedValue')->to_literal ;
        my($int_name)     = $i_xame ->findnodes('../@spirit:portRef')->to_literal ;
        my($vec_name)     = $i_xame ->findnodes('../../spirit:externalPortReference/@spirit:portRef')->to_literal ;
        my($vec_left)     = $i_xame ->findnodes('../../spirit:externalPortReference/@spirit:left')->to_literal ;
        my($vec_right)    = $i_xame ->findnodes('../../spirit:externalPortReference/@spirit:right')->to_literal ;


# print "XXXXXX  $comp_name  $int_name  ( $int_value  $tied_value  )   $vec_name $vec_left $vec_right  \n";


        unless ($int_value)  
         {$int_value = "_DUMMY_";
         }


        if($tied_value )
          { 
          push @inst_conns , ":::${comp_name}:::adhoc:::${int_name}:::${tied_value}:::scaler:::none:::none:::";         
          }
        elsif($vec_left ne "")
          {
          push @inst_conns , ":::${comp_name}:::adhoc:::${int_name}:::${int_value}:::vector:::${vec_left}:::${vec_right}:::";
          push @wire_decs  , ":::${vec_name}:::${int_value}:::node:::wire:::vector:::${vec_left}:::${$vec_right}:::none:::0:::${int_value}:::XXX:::${vec_name}:::";
          }
        else
          {
          push @inst_conns , ":::${comp_name}:::adhoc:::${int_name}:::${int_value}:::scaler:::none:::none:::";         
          push @wire_decs  , ":::${vec_name}:::${int_value}:::node:::wire:::scaler:::none:::none:::none:::0:::${int_value}:::XXX:::${vec_name}:::";
          }           


        }












           






     #/**********************************************************************/
     #/*                                                                    */
     #/* extract bus instance connections from wire_decs                    */
     #/*                                                                    */
     #/**********************************************************************/

     #print "+-+";      

     

     my @inst_names  = (); 
     my @inst_Inames  = (); 
     my %inst_ports  = ();
     my %inst_sigs   = ();
     my %inst_vector = ();
     my %inst_left   = ();
     my %inst_right  = ();


     foreach $line (@wire_decs)  
        { 
        $_ = $line;
        if(/:::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::/) 
          { 
          my $t_index               = $1;
          my $t_node_name           = $2;
          my $t_direction           = $3;
          my $t_type                = $4;
          my $t_vector              = $5;        
          my $t_left                = $6;        
          my $t_right               = $7;
          my $t_instance            = $8;
          my $t_depth               = $9;
          my $t_phy_name            = $10;
          my $t_busref_name         = $11;
          my $t_abslog_name         = $12;

        if( 1)
          {

         push ( @inst_names, "${t_instance}_${t_busref_name}_${t_index}");

         $inst_Inames{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_instance}";

         if(  $inst_sigs{"${t_instance}_${t_busref_name}_${t_index}"})
            {
            if(  $inst_sigs{"${t_instance}_${t_busref_name}_${t_index}"} eq ${t_index})
              {
              $inst_sigs{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_node_name}";
              }
            } 
         else
            {
            $inst_sigs{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_node_name}";
            }

         if   ($t_depth >= 2 )      { $inst_ports{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_busref_name}_${t_abslog_name}" ;}
         elsif($t_depth == 1 )      { $inst_ports{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_phy_name}";}

         if(  $inst_vector{"${t_instance}_${t_busref_name}_${t_index}"})
            {
            if(  $inst_vector{"${t_instance}_${t_busref_name}_${t_index}"} eq "scaler")
              {$inst_vector{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_vector}";}
            } 
         else
            {$inst_vector{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_vector}";}

         unless(  $inst_left{"${t_instance}_${t_busref_name}_${t_index}"} eq '')
            {
            if(  $inst_left{"${t_instance}_${t_busref_name}_${t_index}"} eq "none")
              {
              $inst_left{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_left}";
              }
            elsif(  $inst_left{"${t_instance}_${t_busref_name}_${t_index}"} < ${t_left})
              {
              $inst_left{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_left}";
              }
            } 
          else
            {
            $inst_left{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_left}";
            }

          unless(  $inst_right{"${t_instance}_${t_busref_name}_${t_index}"} eq '')
            {
            if(  $inst_right{"${t_instance}_${t_busref_name}_${t_index}"} eq "none")
              {
              $inst_right{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_right}";
              }
            elsif(  $inst_right{"${t_instance}_${t_busref_name}_${t_index}"} < ${t_right})
              {
              $inst_right{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_right}";
              }
            } 
          else {$inst_right{"${t_instance}_${t_busref_name}_${t_index}"}  = "${t_right}";}

        }
      }
     }
     @inst_names = sys::lib::trim_sort(@inst_names); 
     foreach $i_name (@inst_names)  
         {
        unless($inst_Inames{$i_name} eq "none")
         {
         if($inst_vector{$i_name} eq "vector"  )
           {
          push @inst_conns ,":::$inst_Inames{$i_name}:::adhoc:::$inst_ports{$i_name}:::$inst_sigs{$i_name}:::vector:::$inst_left{$i_name}:::$inst_right{$i_name}:::";
          }
        else
          {
          push @inst_conns ,":::$inst_Inames{$i_name}:::adhoc:::$inst_ports{$i_name}:::$inst_sigs{$i_name}:::scaler:::none:::none:::";         

           }
         }
         }
     }









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




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





#print "\n";
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 "XXXXXX-  $new_vendor $new_library $new_name $new_version  DESIGN \n";
   }





     #/**********************************************************************/
     #/*                                                                    */
     #/* Instantiate each component with parameters and port connections    */
     #/*                                                                    */
     #/* If the component doesn't have a instance name then this is skipped */
     #/*                                                                    */
     #/**********************************************************************/
      
     #print "+-+";      
      
     push @instantiations  , "////////////////////////////////////////////////////////////////\n"; 


     @inst_conns = sys::lib::trim_sort(@inst_conns);






     foreach  my   $i_name ($spirit_design_file->findnodes("//spirit:design/spirit:componentInstances/spirit:componentInstance/spirit:instanceName"))
        {
        my($instance_name)       = $i_name ->findnodes('./text()')->to_literal ;
        my($vendor_name)         = $i_name  ->findnodes('../spirit:componentRef/@spirit:vendor')->to_literal ;
        my($library_name)        = $i_name  ->findnodes('../spirit:componentRef/@spirit:library')->to_literal ;
        my($component_name)      = $i_name  ->findnodes('../spirit:componentRef/@spirit:name')->to_literal ;
        my($version_name)        = $i_name  ->findnodes('../spirit:componentRef/@spirit:version')->to_literal ;

        my $module_name = yp::lib::get_module_name($vendor_name,$library_name,$component_name,$version_name) ;







        if($instance_name)
          {
          push @instantiations  , "$module_name\n";         
          $first = 1;

          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 ;




             if($first)
               {
               push @instantiations  , "#( .${foo_name} (${foo_value})";
               $first = 0;         
               }  
             else  {push @instantiations  , ",\n   .${foo_name} (${foo_value})";}  
             }

             if($first == 0)  { push @instantiations  , ")\n";}
             push @instantiations  , "$instance_name \n   (\n ";
             $first = 1;




             foreach $line (@inst_conns) 
                {
                $_ = $line;

                if(/:::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::(\S+):::/) 
                  { 
                  my $z_instance_name           = $1;
                  my $z_busRef_name   = $2;
                  my $z_port_name           = $3;
                  my $z_signal_name           = $4;        
                  my $z_vecscal           = $5;
                  my $z_left           = $6;
                  my $z_right           = $7;

                  if($opt_debug ){print  "YYYYYY--    $line  \n";}

                  if($z_vecscal eq "vector")
                    {
                    if($z_left eq $z_right){$z_signal_name =  "${z_signal_name}[${z_left}]" ;}
                    else    {$z_signal_name =  "${z_signal_name}[${z_left}:${z_right}]" ;}
                    }

                  if ($z_signal_name eq "_DUMMY_")  {$z_signal_name = "      ";}     

                  if($instance_name eq  $z_instance_name ) 
                    {
                    if($first)
                      {
                      push @instantiations  ,          "  .${z_port_name}         (${z_signal_name})";
                      $first =0;
                      }
                    else   {           push @instantiations  , ",\n   .${z_port_name}         (${z_signal_name})";}
                    }
                  }
                }

     #print ".";      
     push @instantiations  , ");\n\n";         
     }
     }
     }









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




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


#print "\n";
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 ;
   if($opt_verbose){print "parse_component_file   $new_vendor $new_library $new_name $new_version  COMPONENT \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 ;

        unless(defined $parameter_values{$parameter_name}) 
         {
         push ( @parameters,  "$parameter_name");
         $parameter_values{$parameter_name} = ${parameter_default};
         };

        }
      






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 ;
    my $hier_ref_type = yp::lib::find_file_type($new_vendor,$new_library,$new_name,$new_version) ;
    if($hier_ref_type eq "spirit:component")
     {
     my $spirit_sub_component_file           = $parser->parse_file(yp::lib::find_ipxact("spirit:component",$new_vendor,$new_library,$new_name,$new_version));
     parse_component_file($spirit_sub_component_file);
     }

   }





     #/**********************************************************************/
     #/*                                                                    */
     #/* Read each  busInterface and save master/slave direction            */
     #/*                                                                    */
     #/**********************************************************************/

     my @mas_slave;

     push @mas_slave  , "master"; 
     push @mas_slave  , "slave"; 

     foreach $seek_type (@mas_slave) 
        { 

         foreach my $bus_iface ($spirit_component_file->findnodes("//spirit:component/spirit:busInterfaces/spirit:busInterface/spirit:${seek_type}")) 
            {
            my($mmm_cname)         = $bus_iface->findnodes('../spirit:name/text()')->to_literal ;
            my($mmm_vendor)        = $bus_iface->findnodes('../spirit:abstractionType/@spirit:vendor')->to_literal ;
            my($mmm_library)       = $bus_iface->findnodes('../spirit:abstractionType/@spirit:library')->to_literal ;
            my($mmm_name)          = $bus_iface->findnodes('../spirit:abstractionType/@spirit:name')->to_literal ;
            my($mmm_version)       = $bus_iface->findnodes('../spirit:abstractionType/@spirit:version')->to_literal ;
   
            foreach my $port_face ($spirit_component_file->findnodes('//spirit:component/spirit:busInterfaces/spirit:busInterface/spirit:portMaps/spirit:portMap/spirit:logicalPort')) 
               {
               my($rrr_log_name)      = $port_face->findnodes('./spirit:name/text()')->to_literal ;
               my($rrr_phy_name)      = $port_face->findnodes('../spirit:physicalPort/spirit:name/text()')->to_literal ;
               my($rrr_type_name)     = $port_face->findnodes('../spirit:physicalPort/spirit:wireTypeDefs/spirit:wireTypeDef/spirit:typeName/text()')->to_literal ;
               my($rrr_int_name)      = $port_face->findnodes('../../../spirit:name/text()')->to_literal ;
               my($rrr_left_value)    = $port_face->findnodes('../spirit:physicalPort/spirit:wire/spirit:vector/spirit:left/text()')->to_literal ;
               my($rrr_right_value)   = $port_face->findnodes('../spirit:physicalPort/spirit:wire/spirit:vector/spirit:right/text()')->to_literal ;
    
               unless ($rrr_type_name)  {$rrr_type_name = "wire";}
    
               if(   $mmm_cname  eq  $rrr_int_name )
                 {
    
                 my $busdef_parser = XML::LibXML->new();


                 my $spirit_abstractor_filename    = yp::lib::find_ipxact("spirit:abstractionDefinition",$mmm_vendor,$mmm_library,$mmm_name,$mmm_version);

                 unless($spirit_abstractor_filename) 

                 {#print "  $mmm_vendor $mmm_library $mmm_name $mmm_version  \n";
}

                 my $spirit_abstractor_file    = ($parser->parse_file(yp::lib::find_ipxact("spirit:abstractionDefinition",$mmm_vendor,$mmm_library,$mmm_name,$mmm_version))

                ) || die "(OOPs $mmm_vendor $mmm_library $mmm_name $mmm_version )";



                 foreach my $abstr_view ($spirit_abstractor_file->findnodes("//spirit:abstractionDefinition/spirit:ports/spirit:port/spirit:logicalName[text() = '$rrr_log_name']")) 
                    {
                    my($sss_m_dir)         = $abstr_view->findnodes('../spirit:wire/spirit:onMaster/spirit:direction/text()')->to_literal ;
                    my($sss_s_dir)         = $abstr_view->findnodes('../spirit:wire/spirit:onSlave/spirit:direction/text()')->to_literal ;
    
                    if    ($sss_m_dir eq "in")  { $sss_m_dir = "input";}
                    elsif ($sss_m_dir eq "out") { $sss_m_dir = "output";}

                    if    ($sss_s_dir eq "in")  { $sss_s_dir = "input";}
                    elsif ($sss_s_dir eq "out") { $sss_s_dir = "output";}

                    my $rrr_direction = "";
               
                    if( $seek_type eq "master") {        $rrr_direction = $sss_m_dir;}   
                    else                        {        $rrr_direction = $sss_s_dir;}   
    
                    my $rrr_dir = "";
                    if   ($rrr_direction  eq "in" )  {$rrr_dir = "input" ;}
                    elsif($rrr_direction  eq "out" ) {$rrr_dir = "output" ;}
                    else                             {$rrr_dir = $rrr_direction;     }
    
                    if($rrr_left_value ne "") 
                        { 
                        push @wire_decs , ":::${mmm_cname}_${rrr_log_name}:::${rrr_phy_name}:::${rrr_dir}:::${rrr_type_name}:::vector:::${rrr_left_value}:::${$rrr_right_value}:::none:::0:::${rrr_phy_name}:::XXX:::${rrr_log_name}:::"; 
                        }
                      else                
                        { 
                        push @wire_decs , ":::${mmm_cname}_${rrr_log_name}:::${rrr_phy_name}:::${rrr_dir}:::${rrr_type_name}:::scaler:::none:::none:::none:::0:::${rrr_phy_name}:::XXX:::${rrr_log_name}:::";    
                        }               
                    }
                 }
               }
        }
     }




     #/**********************************************************************/
     #/*                                                                    */
     #/* Read all ports and store into array                                */
     #/*                                                                    */
     #/**********************************************************************/

     foreach  my   $i_name ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:ports/spirit:port/spirit:name"))
        {
        my($port_name)       = $i_name ->findnodes('./text()')->to_literal ;
        my($direction)       = $i_name ->findnodes('../spirit:wire/spirit:direction/text()')->to_literal ;
        my($left)            = $i_name ->findnodes('../spirit:wire/spirit:vector/spirit:left/text()')->to_literal ;
        my($right)           = $i_name ->findnodes('../spirit:wire/spirit:vector/spirit:right/text()')->to_literal ;
        my($type)            = $i_name ->findnodes('../spirit:wireTypeDefs/spirit:wireTypeDef/spirit:typeName/text()')->to_literal ;


        if    ($direction eq "in")  { $direction = "input";}
        elsif ($direction eq "out") { $direction = "output";}


        if($left ne "")  { push @wire_decs , ":::${port_name}:::${port_name}:::${direction}:::${type}:::vector:::${left}:::${right}:::none:::0:::${port_name}:::XXX:::${port_name}:::";  }
        else       { push @wire_decs , ":::${port_name}:::${port_name}:::${direction}:::${type}:::scaler:::none:::none:::none:::0:::${port_name}:::XXX:::${port_name}:::";          }
        }

 


}


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.