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

Subversion Repositories socgen

[/] [socgen/] [trunk/] [tools/] [verilog/] [gen_elab_verilog] - Blame information for rev 134

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

Line No. Rev Author Line
1 134 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
           "version=s"        => \$version,
75
           "component=s"      => \$component,
76
           "configuration=s"  => \$configuration,
77
           "destination=s"    => \$destination,
78
           "local_parameters"
79
) || die "(use '$program_name -h' for help)";
80
 
81
 
82
##############################################################################
83
## Help option
84
##############################################################################
85
if ( $opt_h  or $opt_help  )
86
  { print "\n gen_verilog -envidentifier :*Simulation:*  -prefix /work/children -vendor vendor_name -library library_name  -component component_name  -version version_name -destination destination -configuration configuration -local_parameters  \n";
87
    exit 1;
88
  }
89
 
90
 
91
 
92
#############################################################################
93
##
94
##
95
#############################################################################
96
 
97
$home = cwd();
98
 
99
 
100
my $variant;
101
my $view;
102
 
103
if($version)       {$variant   = "${component}_${version}";}
104
else               {$variant   = "${component}";}
105
 
106
my $dest_dir = "../verilog";
107
 
108
 
109
unless (defined $destination && length $destination > 0)
110
{$destination = $variant;}
111
 
112
if(defined $configuration && length $configuration > 0)
113
{
114
#print "QQQQQQQQQQQQW  Configuration  $vendor $library $component $version  $configuration \n";
115
}
116
else
117
{ $configuration = "default";}
118
 
119
 
120
if($opt_local_parameters)
121
{
122
#print "QQQQQQQQQQQQW  Local_Parameters  $vendor $library $component $version   \n";
123
}
124
 
125
 
126
 
127
 
128
 
129
 
130
print "\n---GEN_elab_verilog    -envidentifier $envidentifier -prefix  $prefix -vendor $vendor -library $library -component $component -version $version -configuration $configuration -dest_dir     $dest_dir -destination  $destination   \n";
131
 
132
my $main_module_name = yp::lib::get_module_name($vendor,$library,$component,$version) ;
133
my $lib_comp_sep     = yp::lib::find_lib_comp_sep($vendor,$library,$component);
134
my $comp_xml_sep     = yp::lib::find_comp_xml_sep($vendor,$library,$component,$version);
135
 
136
my $parser = XML::LibXML->new();
137
 
138
my $socgen_file              = $parser->parse_file(yp::lib::find_componentConfiguration($vendor,$library,$component));
139
my $spirit_component_file    = $parser->parse_file(yp::lib::find_ipxact_component($vendor,$library,$component,$version));
140
 
141
my $sim_library_path ;
142
 
143
my $sim_comp_path            = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:comp_path/text()")->to_literal;
144
 
145
if ($sim_comp_path)  {$sim_library_path  ="${lib_comp_sep}${sim_comp_path}";}
146
else                 {$sim_library_path  = $socgen_file->findnodes("//socgen:componentConfiguration/socgen:sim/socgen:library_path/text()")->to_literal;}
147
 
148
 
149
foreach my $X_view ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:envIdentifier[text() = '$envidentifier']"))
150
         {
151
         $view   = $X_view->findnodes('../spirit:name/text()')->to_literal ;
152
         }
153
 
154
my $path  = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/${dest_dir}";
155
mkdir $path,0755             unless( -e $path );
156
 
157
my $path  = "${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/${dest_dir}/${view}";
158
mkdir $path,0755             unless( -e $path );
159
 
160
 
161
my   @instantiations    =       ();
162
my   @parameters        =       ();
163
my   %parameter_values  =       ();
164
my   %parameter_descriptions  = ();
165
 
166
unless ($socgen_file)      { print "No socgen ip file   \n";};
167
 
168
#/******************************************************************************************/
169
#/*                                                                                        */
170
#/* get parameters                                                                         */
171
#/*                                                                                        */
172
#/******************************************************************************************/
173
 
174
 
175
my @Pams = yp::lib::get_parameters($vendor,$library,$component,$version,$configuration);
176
 
177
foreach my $Pam (@Pams)
178
{
179
my $param_name;
180
my $param_value;
181
 
182
( $param_name,$param_value) = split( /\::/ , $Pam);
183
unless(defined $parameter_values{$param_name}) {push ( @parameters,  "$param_name");};
184
$parameter_values{$param_name} = $param_value;
185
}
186
 
187
 
188
 
189
 
190
my @signals = yp::lib::get_signals($vendor,$library,$component,$version);
191
 
192
 
193
 
194
#/**********************************************************************/
195
#/*                                                                    */
196
#/* Every hier cell is constructed from the ipxact file with seperate  */
197
#/* version  for each view                                             */
198
#/*                                                                    */
199
#/* Start by opening the output file                                   */
200
#/* get fileset name                                                   */
201
#/* check that requested view exists                                   */
202
#/*                                                                    */
203
#/**********************************************************************/
204
 
205
foreach my $comp_view ($spirit_component_file->findnodes("//spirit:component/spirit:model/spirit:views/spirit:view/spirit:name[text() = '$view']"             ))
206
   {
207
   my($view_fileset_name)  = $comp_view->findnodes('../spirit:fileSetRef/spirit:localName/text()')->to_literal ;
208
 
209
   if($configuration eq "default")
210
   {
211
   $outfile ="${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/${dest_dir}/${view}/${destination}";
212
   }
213
   else
214
   {
215
   $outfile ="${home}${prefix}/${vendor}__${library}${lib_comp_sep}${component}${comp_xml_sep}/${dest_dir}/${view}/${destination}_${configuration}";
216
   }
217
 
218
 
219
   open DEST_FILE,">$outfile" or die "unable to open $outfile";
220
 
221
   if($configuration eq "default")
222
   {
223
   print DEST_FILE  "\n module \n\n  $main_module_name \n ";
224
   }
225
   else
226
   {
227
   print DEST_FILE  "\n module \n\n  ${main_module_name}_${configuration} \n ";
228
   }
229
 
230
 
231
   my @I_names = yp::lib::get_instance_names($vendor,$library,$component,$version,$configuration);
232
 
233
   foreach my $I_name (@I_names)
234
        {
235
        my $foo_ven;
236
        my $foo_lib;
237
        my $foo_cmp;
238
        my $foo_ver;
239
        my $foo_cfg;
240
 
241
        my $vlnvc  = yp::lib::get_instance_vlnvc($vendor,$library,$component,$version,$I_name,$configuration );
242
 
243
          ( $foo_ven,$foo_lib,$foo_cmp,$foo_ver,$foo_cfg) = split( /\:/ , $vlnvc);
244
 
245
 
246
        push @instantiations  , "/*  ${vlnvc}  */ \n";
247
        my $module_name  = yp::lib::get_instance_module_name($vendor,$library,$component,$version,$I_name,$configuration);
248
        if(defined $foo_cfg && length $foo_cfg > 0)
249
          {
250
          push @instantiations  ,          "${module_name}_${foo_cfg}\n";
251
          }
252
        else
253
          {
254
          push @instantiations  ,          "${module_name}\n";
255
          $first = 1;
256
          my @Pams = yp::lib::get_Parameters($vendor,$library,$component,$version,"root.${I_name}",$configuration);
257
          foreach my $pam (@Pams)
258
            {
259
            ( $foo_name,$foo_value) = split( /\::/ , $pam);
260
            if($first)
261
              {
262
              push @instantiations  , "#( .${foo_name} (${foo_value})";
263
              $first = 0;
264
              }
265
            else  {push @instantiations  , ",\n   .${foo_name} (${foo_value})";}
266
            }
267
 
268
          if($first == 0)  { push @instantiations  , ")\n";}
269
          }
270
 
271
 
272
 
273
 
274
 
275
 
276
          push @instantiations  , "$I_name \n   (\n ";
277
          $first = 1;
278
 
279
          my @Inst_conns = yp::lib::get_instance_adhoc_conns($vendor,$library,$component,$version,$I_name);
280
          my @Buss_conns = yp::lib::get_instance_conns($vendor,$library,$component,$version,$I_name);
281
          foreach my $Buss_conn (@Buss_conns)
282
             {
283
             if($first)
284
               {
285
               push @instantiations  ,          "  $Buss_conn";
286
               $first =0;
287
               }
288
             else
289
               {
290
               push @instantiations  , ",\n   $Buss_conn";
291
               }
292
             }
293
          foreach my $Inst_conn (@Inst_conns)
294
             {
295
             if($first)
296
               {
297
               push @instantiations  ,          "  $Inst_conn";
298
               $first =0;
299
               }
300
             else
301
               {
302
               push @instantiations  , ",\n   $Inst_conn";
303
               }
304
             }
305
        push @instantiations  , ");\n\n";
306
        }
307
 
308
 
309
 
310
 
311
 
312
 
313
 
314
 
315
   #/**********************************************************************/
316
   #/*                                                                    */
317
   #/* Add any and all global parameters with their default values        */
318
   #/*                                                                    */
319
   #/**********************************************************************/
320
 
321
   unless ($opt_local_parameters)
322
     {
323
     my $first = 1;
324
     foreach my $parameter_name (@parameters)
325
        {
326
        my $parameter_value = $parameter_values{$parameter_name};
327
        if($first)
328
          {
329
          print DEST_FILE  "   #( parameter \n      ${parameter_name}=${parameter_value}";
330
          $first=0;
331
          }
332
        else  { print DEST_FILE  ",\n      ${parameter_name}=${parameter_value}";}
333
        }
334
 
335
     if    ($first == 0)   { print DEST_FILE  ")\n"; }
336
       }
337
 
338
 
339
 
340
  foreach my $Pam (@Pams)
341
      {
342
#      print DEST_FILE  "//*** $Pam  ***/ \n";
343
      }
344
 
345
 
346
 
347
   #/**********************************************************************/
348
   #/*                                                                    */
349
   #/* sort all  ports  with their type, size and direction               */
350
   #/*                                                                    */
351
   #/**********************************************************************/
352
 
353
   my @port_list  = ();
354
   my @wire_nodes = ();
355
   my $key;
356
   my $value;
357
 
358
   foreach my $signal (@signals)
359
         {
360
         ( ${port_name},${direction},${type},${vector},${left},${right}) = split ':', $signal;
361
 
362
            if(  $direction ne "node"   )
363
              {
364
              my $q_width  = "     ";
365
              if( ${vector} eq "vector" )  { $q_width = "[ ${left} :  ${right}]";             }
366
              push (@port_list,  "${direction}   ${type}    $q_width        ${port_name}");
367
              }
368
            else
369
              {
370
              my $q_width  = "     ";
371
              if( ${vector} eq "vector" )   { $q_width = "[ $left :  $right]";}
372
              if( $direction eq "node" )    { push @wire_nodes,     "$type     $q_width              ${port_name};";}
373
              }
374
         }
375
 
376
   @port_list      = sys::lib::trim_sort(@port_list);
377
 
378
   #/**********************************************************************/
379
   #/*                                                                    */
380
   #/* Now add all ports  with their type, size and direction             */
381
   #/*                                                                    */
382
   #/**********************************************************************/
383
 
384
   print DEST_FILE  "\n    ";
385
   $first = 1;
386
 
387
   foreach $port_line (@port_list)
388
        {
389
          if($first)
390
            {
391
            print DEST_FILE  " (\n ${port_line}";
392
            $first=0;
393
            }
394
          else
395
            {
396
            print DEST_FILE  ",\n ${port_line}";
397
            }
398
 
399
        }
400
 
401
   if    ($first == 0)   { print DEST_FILE  ");\n\n\n\n"; }
402
   else                  { print DEST_FILE  "();\n\n\n\n";}
403
 
404
 
405
   #/**********************************************************************/
406
   #/*                                                                    */
407
   #/* Add any and all local parameters with their default values         */
408
   #/*                                                                    */
409
   #/**********************************************************************/
410
 
411
   if ($opt_local_parameters)
412
     {
413
     foreach my $parameter_name (@parameters)
414
        {
415
        my $parameter_value = $parameter_values{${parameter_name}};
416
        print DEST_FILE  "parameter     ${parameter_name} = ${parameter_value};\n";
417
        }
418
     }
419
 
420
   @wire_nodes      = sys::lib::trim_sort(@wire_nodes);
421
 
422
   foreach my $wire_node (@wire_nodes)
423
       {
424
       print DEST_FILE  "${wire_node}\n";
425
       }
426
 
427
 
428
     #/**********************************************************************/
429
     #/*                                                                    */
430
     #/* Dump everything from the ip-xact files into component              */
431
     #/*                                                                    */
432
     #/**********************************************************************/
433
 
434
     print DEST_FILE  "\n\n\n";
435
     while(   my $line_out      = shift(@instantiations))             {  print DEST_FILE  "$line_out";}
436
 
437
 
438
     #/**********************************************************************/
439
     #/*                                                                    */
440
     #/* After all the data from the ip-xact file has been entered we now   */
441
     #/* insert any and all verilog fragments at the end before closing     */
442
     #/* the module                                                         */
443
     #/*                                                                    */
444
     #/**********************************************************************/
445
 
446
 
447
      my @fragments = yp::lib::get_files($vendor,$library,$component,$version,$view_fileset_name,"fragment") ;
448
 
449
      foreach my $fragment(@fragments)
450
      {
451
          $SRCFILE ="${home}${prefix}/${fragment}";
452
          open(SRCFILE) or die("Could not open src file.  $SRCFILE ");
453
          foreach $line ()
454
             {
455
             chomp($line);
456
             print DEST_FILE  "${line}\n";
457
             }
458
 
459
     }
460
 
461
 
462
 
463
   print DEST_FILE  "\n\n\n  endmodule\n\n";
464
   }
465
 
466
1
467
 

powered by: WebSVN 2.1.0

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