URL
https://opencores.org/ocsvn/socgen/socgen/trunk
Subversion Repositories socgen
[/] [socgen/] [trunk/] [tools/] [verilog/] [gen_testbench] - Rev 135
Compare with Previous | Blame | View Log
eval 'exec `which perl` -S $0 ${1+"$@"}'if 0;#/****************************************************************************/#/* */#/* SOCGEN Design for Reuse toolset */#/* */#/* Version 1.0.0 */#/* */#/* Author(s): */#/* - John Eaton, z3qmtr45@gmail.com */#/* */#/****************************************************************************/#/* */#/* */#/* Copyright 2016 John T Eaton */#/* */#/* Licensed under the Apache License, Version 2.0 (the "License"); */#/* you may not use this file except in compliance with the License. */#/* You may obtain a copy of the License at */#/* */#/* http://www.apache.org/licenses/LICENSE-2.0 */#/* */#/* Unless required by applicable law or agreed to in writing, software */#/* distributed under the License is distributed on an "AS IS" BASIS, */#/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */#/* See the License for the specific language governing permissions and */#/* limitations under the License. */#/* */#/* */#/****************************************************************************/############################################################################# 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, "<ipxact:adHocConnection>\n<ipxact:name>${name}<\/ipxact:name>\n<ipxact:externalPortReference ipxact:portRef=\"${name}\" ipxact:left=\"${left}\" ipxact:right=\"${right}\" \/>\n<ipxact:internalPortReference ipxact:componentRef=\"dut\" ipxact:portRef=\"${name}\" \/>\n<\/ipxact:adHocConnection>\n" );}else{print " $name \n";push (@tb_adhoc_list, "<ipxact:adHocConnection>\n<ipxact:name>${name}<\/ipxact:name>\n<ipxact:externalPortReference ipxact:portRef=\"${name}\" \/>\n<ipxact:internalPortReference ipxact:componentRef=\"dut\" ipxact:portRef=\"${name}\" \/>\n<\/ipxact: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 "<ipxact: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 "<ipxact:vendor>${vendor}</ipxact:vendor>\n";print TB_DESIGN_FILE "<ipxact:library>${library}</ipxact:library>\n";print TB_DESIGN_FILE "<ipxact:name>${component}</ipxact:name>\n";print TB_DESIGN_FILE "<ipxact:version>${version}_duth.design</ipxact:version>\n";@tb_adhoc_list = sys::lib::trim_sort(@tb_adhoc_list);print TB_DESIGN_FILE "<ipxact:adHocConnections>\n\n";foreach $adhoc_line (@tb_adhoc_list){print TB_DESIGN_FILE "${adhoc_line}\n";}print TB_DESIGN_FILE "\n</ipxact:adHocConnections>\n";print TB_DESIGN_FILE "<ipxact:componentInstances>\n\n";print TB_DESIGN_FILE "<ipxact:componentInstance>\n";print TB_DESIGN_FILE "<ipxact:instanceName>dut</ipxact:instanceName>\n";print TB_DESIGN_FILE "<ipxact:componentRef ipxact:vendor=\"${vendor}\" ipxact:library=\"${library}\" ipxact:name=\"$component\" ipxact:version=\"${version}\" />\n";print TB_DESIGN_FILE "<ipxact:configurableElementValues>\n";foreach my $parameter_name (@parameter_list){print TB_DESIGN_FILE " <ipxact:configurableElementValue ipxact:referenceId=\"${parameter_name}\">${parameter_name}<\/ipxact:configurableElementValue>\n";}print TB_DESIGN_FILE "</ipxact:configurableElementValues>\n";print TB_DESIGN_FILE "</ipxact:componentInstance>\n";print TB_DESIGN_FILE "</ipxact:componentInstances>\n";print TB_DESIGN_FILE "</ipxact:design>\n";1
