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

Subversion Repositories socgen

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

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

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

powered by: WebSVN 2.1.0

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