URL
https://opencores.org/ocsvn/socgen/socgen/trunk
Subversion Repositories socgen
[/] [socgen/] [trunk/] [tools/] [verilog/] [gen_testbench] - Rev 134
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
) || die "(use '$program_name -h' for help)";
##############################################################################
## Help option
##############################################################################
if ( $opt_h or $opt_help )
{ print "\n gen_testbench -vendor vendor_name -library library_name -component component_name -version version_name \n";
exit 1;
}
#############################################################################
##
##
#############################################################################
$home = cwd();
my $variant;
if($version) {$variant = "${component}_${version}";}
else {$variant = "${component}";}
my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version) ;
my $parser = XML::LibXML->new();
my $spirit_component_file = $parser->parse_file(yp::lib::find_ipxact_component($vendor,$library,$component,$version));
if($opt_verbose) {print "\n READ_ports $vendor $library $component $version \n";}
my $io_ports = yp::lib::get_io_ports() ;
my $gen_port_outfile = yp::lib::get_io_ports_db_filename($vendor,$library,$component,$version);
print "$gen_port_outfile \n";
$ports_db = new BerkeleyDB::Hash( -Filename => $gen_port_outfile, -Flags => DB_CREATE ) or die "Cannot open ${gen_port_outfile}: $!";
my $key;
my $value;
my @adhoc_list;
my @parameter_list;
$cursor = $ports_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0)
{
my $key_type;
my $busref;
my $conn;
print " $key $value \n";
( ${key_type},${busref},${conn}) = split( /\./ , $key);
( ${log_name},${direction},${type},${vector},${left},${right},${phy_name}) = split ':', $value;
if(($key_type eq "BusRef"))
{
}
else
{
# print " $value \n";
if($direction eq "input")
{
push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
}
if($direction eq "output")
{
push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
}
if($direction eq "inout")
{
push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
}
}
}
my $status = $cursor->c_close() ;
$ports_db -> db_close();
#############################################################################
$home = cwd();
unless ($prefix)
{
$prefix = yp::lib::get_workspace();
$prefix = "/${prefix}";
}
my $variant;
my $configuration;
my $destination = "${component}_${version}";
my $root = "root";
if($version) {$variant = "${component}_${version}";}
else {$variant = "${component}";}
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 $elab_db_file = yp::lib::get_elab_db_filename($vendor,$library,$component,$version,"default");
if(-e $elab_db_file )
{
print "$elab_db_file does exist \n";
}
my $elab_db = new BerkeleyDB::Hash( -Filename => "$elab_db_file", -Flags => DB_CREATE ) or die "Cannot open $elab_db_file: $!";
$cursor = $elab_db ->db_cursor() ;
while ($cursor->c_get($key, $value, DB_NEXT) == 0)
{
my $index;
my $param;
( $index,$param) = split( /\__/ , $key);
if($index eq "parameter_root")
{
print "$key $param \n";
push (@parameter_list,"${param}");
}
}
my $status = $cursor->c_close() ;
$elab_db->db_close();
@adhoc_list = sys::lib::trim_sort(@adhoc_list);
@parameter_list = sys::lib::trim_sort(@parameter_list);
my @tb_adhoc_list;
foreach my $list (@adhoc_list)
{
my $name;
my $vector;
my $index;
my $left;
my $right;
if($opt_verbose) { print "-- ${list}||| \n"; }
( $name,$vector,$index) = split( /\::/ , $list);
( $left,$right) = split( /\:/ , $index);
if ( $vector eq "vector" )
{
print " $name [${index}] \n";
push (@tb_adhoc_list, "<spirit:adHocConnection>\n<spirit:name>${name}<\/spirit:name>\n<spirit:externalPortReference spirit:portRef=\"${name}\" spirit:left=\"${left}\" spirit:right=\"${right}\" \/>\n<spirit:internalPortReference spirit:componentRef=\"dut\" spirit:portRef=\"${name}\" \/>\n<\/spirit:adHocConnection>\n" );
}
else
{
print " $name \n";
push (@tb_adhoc_list, "<spirit:adHocConnection>\n<spirit:name>${name}<\/spirit:name>\n<spirit:externalPortReference spirit:portRef=\"${name}\" \/>\n<spirit:internalPortReference spirit:componentRef=\"dut\" spirit:portRef=\"${name}\" \/>\n<\/spirit:adHocConnection>\n" );
}
}
my $repo = yp::lib::find_component_repo($vendor,$library,$component) ;
my $variant;
my $view;
if($version) {$variant = "${component}_${version}";}
else {$variant = "${component}";}
unless($destination) { $destination = $variant;}
print "\n GENERATE $prefix $vendor $library $component $version $configuration $destination \n";
my $lib_comp_sep = yp::lib::find_lib_comp_sep($vendor,$library,$component);
my $comp_xml_sep = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
my $parser = XML::LibXML->new();
my $socgen_file = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));
my $spirit_component_file = $parser->parse_file(yp::lib::find_ipxact_component($vendor,$library,$component,$version));
my $doc_library_path = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:doc/socgen:library_path/text()")->to_literal;
my $sim_library_path ;
my $sim_comp_path = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:comp_path/text()")->to_literal;
if ($sim_comp_path) {$sim_library_path ="${lib_comp_sep}${sim_comp_path}";}
else {$sim_library_path = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:library_path/text()")->to_literal;}
print "Creating testbench for $vendor $library $component $version \n";
my $path ="${home}${repo}/${vendor}/${library}${sim_library_path}";
mkdir $path,0755 unless( -e $path );
my $path ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches";
mkdir $path,0755 unless( -e $path );
$path ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches/xml";
mkdir $path,0755 unless( -e $path );
$outfile ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches/xml/${variant}_duth.design.xml";
open TB_DESIGN_FILE,">$outfile" or die "unable to open $outfile";
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 "// ./tools/verilog/gen_tb -vendor $vendor -library $library -component $component -version $version //\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>${library}</spirit:library>\n";
print TB_DESIGN_FILE "<spirit:name>${component}</spirit:name>\n";
print TB_DESIGN_FILE "<spirit:version>${version}_duth.design</spirit:version>\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";
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=\"${library}\" spirit:name=\"$component\" spirit:version=\"${version}\" />\n";
print TB_DESIGN_FILE "<spirit:configurableElementValues>\n";
foreach my $parameter_name (@parameter_list)
{
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";
1
Go to most recent revision | Compare with Previous | Blame | View Log