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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [verilog/] [gen_tb] - Blame information for rev 133

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

Line No. Rev Author Line
1 133 jt_eaton
eval 'exec `which perl` -S $0 ${1+"$@"}'
2
   if 0;
3
#/**********************************************************************/
4
#/*                                                                    */
5
#/*             -------                                                */
6
#/*            /   SOC  \                                              */
7
#/*           /    GEN   \                                             */
8
#/*          /    TOOL    \                                            */
9
#/*          ==============                                            */
10
#/*          |            |                                            */
11
#/*          |____________|                                            */
12
#/*                                                                    */
13
#/*                                                                    */
14
#/*                                                                    */
15
#/*                                                                    */
16
#/*  Author(s):                                                        */
17
#/*      - John Eaton, jt_eaton@opencores.org                          */
18
#/*                                                                    */
19
#/**********************************************************************/
20
#/*                                                                    */
21
#/*    Copyright (C) <2010-2011>                */
22
#/*                                                                    */
23
#/*  This source file may be used and distributed without              */
24
#/*  restriction provided that this copyright statement is not         */
25
#/*  removed from the file and that any derivative work contains       */
26
#/*  the original copyright notice and the associated disclaimer.      */
27
#/*                                                                    */
28
#/*  This source file is free software; you can redistribute it        */
29
#/*  and/or modify it under the terms of the GNU Lesser General        */
30
#/*  Public License as published by the Free Software Foundation;      */
31
#/*  either version 2.1 of the License, or (at your option) any        */
32
#/*  later version.                                                    */
33
#/*                                                                    */
34
#/*  This source is distributed in the hope that it will be            */
35
#/*  useful, but WITHOUT ANY WARRANTY; without even the implied        */
36
#/*  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR           */
37
#/*  PURPOSE.  See the GNU Lesser General Public License for more      */
38
#/*  details.                                                          */
39
#/*                                                                    */
40
#/*  You should have received a copy of the GNU Lesser General         */
41
#/*  Public License along with this source; if not, download it        */
42
#/*  from http://www.opencores.org/lgpl.shtml                          */
43
#/*                                                                    */
44
#/**********************************************************************/
45
 
46
 
47
############################################################################
48
# General PERL config
49
############################################################################
50
use Getopt::Long;
51
use English;
52
use File::Basename;
53
use Cwd;
54
use Scalar::Util qw(looks_like_number);
55
use XML::LibXML;
56
use lib './tools';
57
use sys::lib;
58
use yp::lib;
59
use BerkeleyDB;
60
 
61
 
62
$OUTPUT_AUTOFLUSH = 1; # set autoflush of stdout to TRUE.
63
 
64
 
65
############################################################################
66
### Process the options
67
############################################################################
68
Getopt::Long::config("require_order", "prefix=-");
69
GetOptions("h","help",
70
           "envidentifier=s" => \$envidentifier,
71
           "prefix=s" => \$prefix,
72
           "vendor=s" => \$vendor,
73
           "library=s" => \$library,
74
           "component=s" => \$component,
75
           "version=s" => \$version,
76
           "tb=s" => \$tb,
77
           "verbose"
78
) || die "(use '$program_name -h' for help)";
79
 
80
 
81
##############################################################################
82
## Help option
83
##############################################################################
84
if ( $opt_h  or $opt_help  )
85
  { print "\n gen_tb    -vendor vendor_name -library library_name  -component component_name  -version version_name -tb tb  verbose \n";
86
    exit 1;
87
  }
88
 
89
 
90
 
91
 
92
 
93
 
94
#############################################################################
95
##
96
##
97
#############################################################################
98
 
99
 
100
$home = cwd();
101
 
102
 
103
my $variant;
104
 
105
if($version)       {$variant   = "${component}_${version}";}
106
else               {$variant   = "${component}";}
107
 
108
 
109
unless($tb)       {$tb   = "tb";}
110
 
111
my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version) ;
112
my $parser = XML::LibXML->new();
113
my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact_component($vendor,$library,$component,$version));
114
 
115
if($opt_verbose) {print "\n READ_ports     $vendor $library $component $version         \n";}
116
 
117
 
118
 
119
my $io_ports  = yp::lib::get_io_ports() ;
120
 
121
   my $gen_port_outfile = yp::lib::get_io_ports_db_filename($vendor,$library,$component,$version);
122
   $ports_db   = new BerkeleyDB::Hash( -Filename => $gen_port_outfile, -Flags => DB_CREATE ) or die "Cannot open ${gen_port_outfile}: $!";
123
 
124
   my $key;
125
   my $value;
126
 
127
   my @adhoc_list;
128
   my @parameter_list;
129
 
130
   $cursor = $ports_db ->db_cursor() ;
131
   while ($cursor->c_get($key, $value, DB_NEXT) == 0)
132
 
133
   {
134
    my $key_type;
135
    my $busref;
136
    my $conn;
137
 
138
   print " $key   $value   \n";
139
 
140
   ( ${key_type},${busref},${conn}) = split( /\./ , $key);
141
 
142
   ( ${log_name},${direction},${type},${vector},${left},${right},${phy_name}) = split ':', $value;
143
                 if(($key_type eq "BusRef"))
144
                    {
145
                    }
146
                 else
147
                    {
148
#                    print " $value \n";
149
                    if($direction eq "input")
150
                      {
151
                      push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
152
                      }
153
                    if($direction eq "output")
154
                      {
155
                      push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
156
                      }
157
                    if($direction eq "inout")
158
                      {
159
                      push (@adhoc_list,"${log_name}::${vector}::${left}:${right}");
160
                      }
161
 
162
                    }
163
   }
164
 
165
   my $status = $cursor->c_close() ;
166
 
167
 
168
   $ports_db   -> db_close();
169
 
170
 
171
 
172
 
173
 
174
 
175
 
176
 
177
 
178
 
179
 
180
#############################################################################
181
 
182
$home = cwd();
183
 
184
unless ($prefix)
185
 {
186
 $prefix   = yp::lib::get_workspace();
187
 $prefix   =  "/${prefix}";
188
 }
189
 
190
 
191
my   $variant;
192
my   $configuration;
193
 
194
my $dest_dir            = "elab";
195
my $destination         = "${component}_${version}_${tb}";
196
 
197
 
198
 
199
 
200
 
201
 
202
my $root                =      "root";
203
 
204
if($version)       {$variant   = "${component}_${version}";}
205
else               {$variant   = "${component}";}
206
 
207
 
208
 
209
 
210
my $parser = XML::LibXML->new();
211
 
212
 
213
my $socgen_file              = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));
214
 
215
unless ($socgen_file)      { print "No socgen ip file   \n";};
216
 
217
 
218
my $comp_xml_sep    = yp::lib::find_comp_xml_sep($vendor,$library,$component,"${version}_${tb}");
219
my $lib_comp_sep    = yp::lib::find_lib_comp_sep($vendor,$library,$component);
220
 
221
 
222
 
223
 
224
 
225
my $path  = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/../${dest_dir}";
226
 
227
unless( -e $path )
228
        {
229
        print "$path does not exist... creating \n";
230
        my $cmd = "mkdir $path \n";
231
        if(system($cmd)){};
232
        }
233
 
234
 
235
 
236
$data_db_dir  = "${path}/${destination}";
237
 
238
 
239
unless(-e  $data_db_dir  )
240
        {
241
        my $cmd = "mkdir  $data_db_dir \n";
242
        if(system($cmd)){};
243
        }
244
 
245
 
246
$data_db_file  = "${path}/${destination}/${root}.db";
247
 
248
 
249
if(-e  $data_db_file  )
250
        {
251
        print "$data_db_file  does exist  \n";
252
        }
253
 
254
 
255
 
256
 
257
 
258
   my $elab_db  = new BerkeleyDB::Hash( -Filename => "$data_db_file", -Flags => DB_CREATE ) or die "Cannot open $data_db_file: $!";
259
 
260
 
261
   $cursor = $elab_db ->db_cursor() ;
262
   while ($cursor->c_get($key, $value, DB_NEXT) == 0)
263
   {
264
   my $index;
265
   my $param;
266
 
267
  ( $index,$param) = split( /\__/ , $key);
268
 
269
  if($index eq "parameter_root.dut")
270
    {
271
        print   "$key  $param            \n";
272
    push (@parameter_list,"${param}");
273
    }
274
   }
275
 
276
   my $status = $cursor->c_close() ;
277
 
278
   $elab_db->db_close();
279
 
280
 
281
 
282
   @adhoc_list        = sys::lib::trim_sort(@adhoc_list);
283
   @parameter_list    = sys::lib::trim_sort(@parameter_list);
284
my @tb_adhoc_list;
285
 
286
 
287
    foreach my $list (@adhoc_list)
288
     {
289
     my $name;
290
     my $vector;
291
     my $index;
292
     my $left;
293
     my $right;
294
 
295
if($opt_verbose) {   print "-- ${list}|||  \n"; }
296
 
297
    ( $name,$vector,$index) = split( /\::/ , $list);
298
    ( $left,$right) = split( /\:/ , $index);
299
 
300
 
301
 
302
          if ( $vector eq "vector" )
303
             {
304
        print   "  $name  [${index}]          \n";
305
             push (@tb_adhoc_list,  "\n${name}<\/spirit:name>\n\n\n<\/spirit:adHocConnection>\n"     );
306
             }
307
             else
308
            {
309
        print   "  $name           \n";
310
            push (@tb_adhoc_list,  "\n${name}<\/spirit:name>\n\n\n<\/spirit:adHocConnection>\n"     );
311
             }
312
 
313
 
314
     }
315
 
316
 
317
 
318
 
319
 
320
 
321
 
322
 
323
 
324
 
325
 
326
 
327
 
328
 
329
 
330
my $repo = yp::lib::find_component_repo($vendor,$library,$component) ;
331
 
332
 
333
my $variant;
334
my $view;
335
 
336
 
337
 
338
 
339
if($version)       {$variant   = "${component}_${version}";}
340
else               {$variant   = "${component}";}
341
 
342
unless($destination) { $destination = $variant;}
343
unless($autodoc)     { $autodoc     = "/Geda";}
344
 
345
print "\n GENERATE    $prefix $vendor $library $component $version $configuration      $dest_dir  $destination   \n";
346
 
347
my $lib_comp_sep    = yp::lib::find_lib_comp_sep($vendor,$library,$component);
348
my $comp_xml_sep    = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
349
 
350
my $parser = XML::LibXML->new();
351
 
352
my $socgen_file              = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));
353
my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact_component($vendor,$library,$component,$version));
354
my $doc_library_path         = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:doc/socgen:library_path/text()")->to_literal;
355
 
356
 
357
my $sim_library_path ;
358
 
359
my $sim_comp_path            = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:comp_path/text()")->to_literal;
360
 
361
if ($sim_comp_path)  {$sim_library_path  ="${lib_comp_sep}${sim_comp_path}";}
362
else                 {$sim_library_path  = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:library_path/text()")->to_literal;}
363
 
364
 
365
 
366
 
367
 
368
   print "Creating testbench for   $vendor $library $component  $version \n";
369
 
370
 
371
   my $path  ="${home}${repo}/${vendor}/${library}${sim_library_path}";
372
   mkdir $path,0755             unless( -e $path );
373
 
374
   my $path  ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches";
375
   mkdir $path,0755             unless( -e $path );
376
 
377
      $path  ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches/xml";
378
   mkdir $path,0755             unless( -e $path );
379
 
380
 
381
 
382
   $outfile ="${home}${repo}/${vendor}/${library}${sim_library_path}/testbenches/xml/${variant}_duth.design.xml";
383
   open TB_DESIGN_FILE,">$outfile" or die "unable to open $outfile";
384
 
385
 
386
   print TB_DESIGN_FILE  "\n";
387
   print TB_DESIGN_FILE  "           \n";
394
   print TB_DESIGN_FILE  "
395
   print TB_DESIGN_FILE  "xmlns:spirit=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\"\n";
396
   print TB_DESIGN_FILE  "xmlns:socgen=\"http://opencores.org\"\n";
397
   print TB_DESIGN_FILE  "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n";
398
   print TB_DESIGN_FILE  "xsi:schemaLocation=\"http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009\n";
399
   print TB_DESIGN_FILE  "http://www.spiritconsortium.org/XMLSchema/SPIRIT/1685-2009/index.xsd\">\n";
400
   print TB_DESIGN_FILE  "${vendor}\n";
401
   print TB_DESIGN_FILE  "${library}\n";
402
   print TB_DESIGN_FILE  "${component}\n";
403
   print TB_DESIGN_FILE  "${version}_duth.design\n";
404
 
405
 
406
 
407
 
408
 
409
     @tb_adhoc_list      = sys::lib::trim_sort(@tb_adhoc_list);
410
     print TB_DESIGN_FILE  "\n\n";
411
 
412
     foreach $adhoc_line (@tb_adhoc_list)
413
        {
414
 
415
            print TB_DESIGN_FILE  "${adhoc_line}\n";
416
 
417
 
418
        }
419
 
420
     print TB_DESIGN_FILE  "\n\n";
421
 
422
 
423
 
424
 
425
 
426
 
427
print TB_DESIGN_FILE    "\n\n";
428
 
429
 
430
 
431
 
432
print TB_DESIGN_FILE    "\n";
433
print TB_DESIGN_FILE    "dut\n";
434
print TB_DESIGN_FILE    "\n";
435
print TB_DESIGN_FILE    "\n";
436
 
437
 
438
    foreach my $parameter_name (@parameter_list)
439
 
440
 
441
        {
442
        print TB_DESIGN_FILE  " ${parameter_name}<\/spirit:configurableElementValue>\n";
443
        }
444
 
445
print TB_DESIGN_FILE    "\n";
446
print TB_DESIGN_FILE    "\n";
447
print TB_DESIGN_FILE    "\n";
448
print TB_DESIGN_FILE    "\n";
449
 
450
 
451
 
452
 
453
 
454
 
455
 
456
 
457
 
458
 
459
 
460
 
461
 
462
 
463
 
464
 
465
 
466
 
467
 
468
 
469
 
470
 
471
 
472
 
473
 
474
 
475
 
476
 
477
 
478
 
479
 
480
 
481
 
482
 
483
 
484
 
485
1
486
 
487
 

powered by: WebSVN 2.1.0

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