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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.74/] [tools/] [bin/] [vbomconv] - Blame information for rev 29

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

Line No. Rev Author Line
1 2 wfjm
#!/usr/bin/perl -w
2 29 wfjm
# $Id: vbomconv 646 2015-02-15 12:04:55Z mueller $
3 2 wfjm
#
4 29 wfjm
# Copyright 2007-2015 by Walter F.J. Mueller 
5 2 wfjm
#
6
# This program is free software; you may redistribute and/or modify it under
7
# the terms of the GNU General Public License as published by the Free
8
# Software Foundation, either version 2, or at your option any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY
12
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
# for complete details.
14
#
15
#  Revision History:
16
# Date         Rev Version  Comment
17 29 wfjm
# 2015-02-15   646   1.11   add vivado support: add -xlpath, use instead
18
#                           of XTWI_PATH; drop --ise_path; add @lib:unimacro;
19
#                           drop --viv_vhdl; add --vsyn_prj, --dep_vsyn;
20
#                           drop cygwin support;
21 25 wfjm
# 2014-07-26   575   1.10.1 use XTWI_PATH now (ise/vivado switch done later)
22 22 wfjm
# 2013-10-20   543   1.10   add --viv_vhdl
23 17 wfjm
# 2012-02-05   456   1.9.4  redo filename substitution (= and :); add --get_top
24
# 2012-01-02   448   1.9.3  use in ghdl_m -fexplicit also when simprim used
25 15 wfjm
# 2011-11-27   433   1.9.2  use in ghdl_m -fexplicit when unisim used
26 12 wfjm
# 2011-08-13   405   1.9.1  always write 'vhdl' into xst prj files again; for
27
#                           -xst_export: remove opt file export, add ucf_cpp
28
#                           handling
29
# 2011-06-26   385   1.9    add --ise_path, pass it to vbomconv --xst_prj
30
# 2011-06-09   383   1.8.6  fix xst_vhdl.opt logic (use rtl/vlib now)
31 2 wfjm
# 2010-07-03   312   1.8.5  add --flist action
32
# 2010-06-03   299   1.8.4  generate ucf->ncd dependencies in dep_xst
33
# 2010-04-26   284   1.8.3  add _[sft]sim support for ISim
34
# 2009-11-28   253   1.8.2  fixup print_help...;
35
# 2009-11-22   252   1.8.1  add (export|dep)_isim, full ISim support;
36
#                           add [isim] [sim], allow tag lists like [ghdl,isim];
37
#                           --trace and messages to STDERR;
38
# 2009-11-20   251   1.8    add isim_prj, first ISim support
39
# 2008-03-09   124   1.7.3  add in .dep_(ghdl|xst) all dep on vbom dependencies
40
#                           target now also dependant on .dep_ file
41
# 2008-03-02   122   1.7.2  add @lib: directive to include UNISIM
42
# 2007-12-17   102   1.7.1  fix @ucf_cpp logic.
43
# 2007-12-16   101   1.7    add @ucf_cpp pseudo tag (handle cpp'ed ucf files)
44
# 2007-11-25    98   1.6.1  drop trailing blanks on input lines
45
# 2007-11-02    94   1.6    added (xst|ghdl)_export
46
# 2007-10-26    92   1.5.1  emit '--no-vital-checks' for --ghdl_m for _[sft]sim
47 29 wfjm
# 2007-10-14    98   1.5    handle .exe files under cygwin properly
48 2 wfjm
# 2007-09-15    82   1.4    handle C source objects properly
49
# 2007-08-10    72   1.3    add [xst], [ghdl] prefix support
50
# 2007-07-22    68   1.2    add "tag = val"; list files in 'ready to analyse'
51
#                           order; add --ghdl_a option
52
# 2007-07-08    65   1.1    add "tag : names"; inferral of _[ft]sim vboms
53
# 2007-07-06    64   1.0    Initial version
54
 
55
use 5.005;                                  # require Perl 5.005 or higher
56
use strict;                                 # require strict checking
57
use FileHandle;
58
 
59
use Getopt::Long;
60
 
61
my %opts = ();
62
 
63 29 wfjm
GetOptions(\%opts, "help", "trace", "xlpath=s",
64
                   "dep_ghdl", "dep_xst", "dep_isim", "dep_vsyn",
65 2 wfjm
                   "xst_prj", "isim_prj",
66 29 wfjm
                   "vsyn_prj",
67 2 wfjm
                   "ghdl_a", "ghdl_a_cmd",
68
                   "ghdl_i", "ghdl_i_cmd",
69
                   "ghdl_m", "ghdl_m_cmd",
70 29 wfjm
                   "ghdl_export=s",
71 2 wfjm
                   "xst_export=s",
72
                   "isim_export=s",
73 17 wfjm
                   "get_top",
74 2 wfjm
                   "flist") || exit 1;
75
 
76
sub print_help;
77
sub read_vbom;
78
sub scan_vbom;
79
sub copy_edir;
80
sub write_vbomdep;
81 17 wfjm
sub canon_fname;
82 2 wfjm
 
83 29 wfjm
my @vbom_queue;                             # list of pending vbom's
84
my @srcfile_list;                           # list of sources in compile order
85
my @xdcfile_list;                           # list of xdc files
86
my %vbom_files;                             # key=vbom; val=full file list
87
my %vbom_xdc;                               # key=vbom; val=xdc spec list
88
my %vbom_done;                              # key=vbom; val=done flags
89
my %vbom_rank;                              # key=vbom; val=vbom ranks
90
my %srcfile_rank;                           # key=source file; val=file rank
91
my %para_tbl;                               # substitution table
92 2 wfjm
my @ucf_cpp_list;
93 29 wfjm
my $is_ghdl = 0;                            # ghdl simulation target
94 2 wfjm
my $is_xst  = 0;                            # XST synthesis target
95
my $is_isim = 0;                            # ISim simulation target
96 29 wfjm
my $is_vsyn = 0;                            # vivado synthesis target
97
my $is_vsim = 0;                            # vivado simulation target
98 2 wfjm
my $is_sim  = 0;                            # simulation target (generic)
99 29 wfjm
my $is_any  = 0;                            # ignore tags (for --flist)
100
my $nactions = 0;                           # number of action commands
101
my $top_vbom;                               # top level vbom (from argv)
102
my $stem;                                   # stem of $top_vbom
103
my $top;                                    # top level entity name
104
my $top_done = 0;                           # @top seen
105
my $has_unisim;                             # @lib:unisim seen or implied
106
my $has_unimacro;                           # @lib:unimacro seen
107
my $has_simprim;                            # @lib:simprim seen or implied
108 2 wfjm
my $is_ssim;
109
my $is_fsim;
110
my $is_tsim;
111
my $do_trace = exists $opts{trace};
112 29 wfjm
my $level = 0;                              # vbom nesting level
113 12 wfjm
my $xst_writevhdl = 1;
114 29 wfjm
my $xlpath=$opts{xlpath};
115
my $no_xlpath = ! defined $xlpath || $xlpath eq "";
116 2 wfjm
 
117 29 wfjm
autoflush STDOUT 1;             # autoflush, so nothing lost on exec later
118 12 wfjm
 
119 2 wfjm
if (exists $opts{help}) {
120
  print_help;
121
  exit 0;
122
}
123
 
124
# ensure that one and only one vbom is specified
125
 
126
if (scalar(@ARGV) != 1) {
127 29 wfjm
  print STDERR "vbomconv-E: only one vbom file name allowed\n\n";
128 2 wfjm
  print_help;
129
  exit 1;
130
}
131
 
132
# check that only one action is defined, mark xst, gdhl, or isim class
133
 
134
foreach (keys %opts) {
135 29 wfjm
  $nactions += 1 unless ($_ eq "trace" || $_ eq "xlpath");
136
  $is_ghdl = 1   if ($_ eq "dep_ghdl");
137
  $is_ghdl = 1   if ($_ =~ /^ghdl_/);
138
 
139 2 wfjm
  $is_xst  = 1   if ($_ eq "dep_xst");
140 29 wfjm
  $is_xst  = 1   if ($_ =~ /^xst_/);
141
 
142 2 wfjm
  $is_isim = 1   if ($_ eq "dep_isim");
143
  $is_isim = 1   if ($_ =~ /^isim_/);
144 29 wfjm
 
145
  $is_vsyn = 1   if ($_ eq "dep_vsyn");
146
  $is_vsyn = 1   if ($_ =~ /^vsyn_/);
147
 
148 2 wfjm
  $is_any  = 1   if ($_ eq "flist");
149
}
150
 
151 29 wfjm
$is_sim = $is_ghdl | $is_isim | $is_vsim;
152 2 wfjm
 
153 29 wfjm
print STDERR "-- [ghdl] active\n" if $do_trace && $is_ghdl;
154 2 wfjm
print STDERR "-- [xst] active\n"  if $do_trace && $is_xst;
155
print STDERR "-- [isim] active\n" if $do_trace && $is_isim;
156 29 wfjm
print STDERR "-- [vsyn] active\n" if $do_trace && $is_vsyn;
157
print STDERR "-- [vsim] active\n" if $do_trace && $is_vsim;
158 2 wfjm
print STDERR "-- [sim] active\n"  if $do_trace && $is_sim;
159
 
160
if ($nactions > 1) {
161 29 wfjm
  print STDERR "vbomconv-E: only one action qualifier allowed\n\n";
162 2 wfjm
  print_help;
163
  exit 1;
164
}
165
 
166
$top_vbom = $ARGV[0];
167
 
168
$top_vbom .= ".vbom" unless $top_vbom =~ m{\.vbom$};
169
 
170
$stem = $top_vbom;
171
$stem =~ s{\..*$}{};
172
 
173
$top = $stem;
174
$top =~ s{^.*/}{};
175
 
176
# now prepare virtual _fsim and _tsim vbom's
177
# they are inferred from the _ssim vbom's
178
 
179
if ($top_vbom =~ m{_ssim\.vbom$}) { # detect _ssim
180
  $is_ssim = 1;
181
}
182
if ($top_vbom =~ m{_fsim\.vbom$}) { # map _fsim -> _ssim
183
  $is_fsim = 1;
184
  $top_vbom =~ s{_fsim\.vbom$}{_ssim.vbom};
185
}
186
if ($top_vbom =~ m{_tsim\.vbom$}) { # map _tsim -> _ssim
187
  $is_tsim = 1;
188
  $top_vbom =~ s{_tsim\.vbom$}{_ssim.vbom};
189
}
190
 
191
# traverse all vbom's start with command line argument
192
 
193 29 wfjm
push @vbom_queue, $top_vbom;
194 2 wfjm
 
195 29 wfjm
while (@vbom_queue) {
196
  my $cur_vbom = shift @vbom_queue;
197 2 wfjm
  read_vbom($cur_vbom);
198
}
199
 
200
# traverse internal vbom representation to build file table
201
 
202 29 wfjm
$vbom_rank{$top_vbom} = {min=>1, max=>1};
203 2 wfjm
scan_vbom($top_vbom);
204
 
205
# sort file table, build file list (decreasing rank)
206 29 wfjm
#   sort first by decreasing rank and second by filename
207
#   second sort only to get stable sequence, independent of hash keys
208 2 wfjm
 
209 29 wfjm
my @srcpair_list;
210
foreach (keys %srcfile_rank) {
211
  push @srcpair_list, [$srcfile_rank{$_}, $_];
212 2 wfjm
}
213
 
214 29 wfjm
@srcfile_list = map {$_->[1]}
215
                sort {$b->[0] <=> $a->[0] || $a->[1] cmp $b->[1]}
216
                @srcpair_list;
217 2 wfjm
 
218 29 wfjm
# setup vbom list by rank
219
my @vbom_rank_list;
220
foreach (sort keys %vbom_rank) {
221
  push @vbom_rank_list, [$vbom_rank{$_}{min}, $vbom_rank{$_}{max}, $_];
222
}
223
my @vbomfile_list_min = map {$_->[2]}
224
                        sort {$a->[0] <=> $b->[0] || $a->[1] cmp $b->[1]}
225
                        @vbom_rank_list;
226
 
227
# setup xdc files list (if one @xdc: seen)
228
foreach (@vbomfile_list_min) {
229
  push @xdcfile_list, @{$vbom_xdc{$_}} if exists $vbom_xdc{$_};
230
}
231
 
232 2 wfjm
# now generate output and actions, depending on options given
233
 
234
# --trace ------------------------------------------------------------
235
 
236
if ($do_trace) {
237
  print STDERR "\n";
238 17 wfjm
  print STDERR "filename substitution table:\n";
239
  foreach (sort keys %para_tbl) {
240
    print STDERR "  $_ = $para_tbl{$_}\n";
241 2 wfjm
  }
242 29 wfjm
 
243
  print STDERR "\n";
244
  print STDERR "final vbom_rank table (sort by min rank):\n";
245
  print STDERR "  min  max  var  vbom-name:\n";
246
  foreach (sort {$a->[0] <=> $b->[0] || $a->[2] cmp $b->[2]} @vbom_rank_list) {
247
    printf STDERR "  %3d  %3d  %3d  %s\n",
248
      $_->[0], $_->[1], $_->[1]-$_->[0], $_->[2];
249 2 wfjm
  }
250 29 wfjm
 
251
  print STDERR "\n";
252
  print STDERR "final srcfile_rank table (sort by rank):\n";
253
  foreach (sort {$b->[0] <=> $a->[0] || $a->[1] cmp $b->[1]} @srcpair_list) {
254
    printf STDERR "  %5d  %s\n", $_->[0], $_->[1];
255
  }
256
 
257
  print STDERR "\n";
258 2 wfjm
  print STDERR "properties:\n";
259
  print STDERR "  \@top: $top\n";
260
}
261
 
262
# --ghdh_a -- ghdl analysis command ----------------------------------
263
 
264
if (exists $opts{ghdl_a} || exists $opts{ghdl_a_cmd}) {
265 29 wfjm
  if ($no_xlpath && ($has_unisim || $has_unimacro || $has_simprim) ) {
266
    print STDERR "vbomconv-E: --xlpath required with ghdl_a or ghdl_a_cmd";
267
    exit 1;
268
  }
269
 
270
  foreach (@srcfile_list) {
271 2 wfjm
    my $file = $_;
272
    my $cmd = "ghdl -a";
273 29 wfjm
    $cmd .= " -P$xlpath/unisim"    if $has_unisim;
274
    $cmd .= " -P$xlpath/unimacro"  if $has_unimacro;
275
    $cmd .= " -P$xlpath/simprim"   if $has_simprim;
276 2 wfjm
    $cmd .= " --ieee=synopsys";
277
    $cmd .= " $file";
278
    print "$cmd\n";
279
    if (exists $opts{ghdl_a}) {
280
      my $wrc = system "/bin/sh", "-c", $cmd;
281
      if ($wrc != 0) {
282
        my $rc = int($wrc/256);
283
        if ($rc == 0) {
284
          my $sig = $wrc % 256;
285 29 wfjm
          print STDERR "vbomconv-I: compilation aborted by signal $sig\n";
286 2 wfjm
          exit(1);
287
        } else {
288 29 wfjm
          print STDERR "vbomconv-I: compilation failed (rc=$rc) $?\n";
289 2 wfjm
          exit($rc);
290
        }
291
      }
292
    }
293
  }
294
}
295
 
296
# --ghdh_i -- ghdl inspection command --------------------------------
297
 
298
if (exists $opts{ghdl_i} || exists $opts{ghdl_i_cmd}) {
299
  my %ghdl_work;
300
 
301
  # read ghdl "work-obj93.cf" file. It has the format
302
  #   file . "" "" "ghdl -i or -a date>":
303
  #     entity  at nn( nn) + nn on nn;
304
  #     architecture  of  at nn( nn) + nn on nn;
305
 
306
  if (-r "work-obj93.cf") {
307 21 wfjm
    open (WFILE, "work-obj93.cf") or
308 2 wfjm
      die "can't open for read work-obj93.cf: $!";
309
    while () {
310
      if (m{^file \. \"(.*?)\"}) {
311
        $ghdl_work{$1} = 1;
312
      }
313
    }
314
    close (WFILE);
315
  }
316
 
317
  my $cmd = "ghdl -i";
318
  my $nfile = 0;
319
 
320 29 wfjm
  foreach (@srcfile_list) {
321 2 wfjm
    next if /\.c$/;                         # skip C sources, only vhd handled
322
    if (not exists $ghdl_work{$_}) {
323
      $cmd .= " \\\n  $_";
324
      $nfile += 1;
325
    }
326
  }
327
 
328
  if ($nfile) {
329
    print "$cmd\n";
330
    if (exists $opts{ghdl_i}) {
331
      exec "/bin/sh", "-c", $cmd;
332
      die "failed to exec /bin/sh -c $cmd: $!";
333
    }
334
  } else {
335
    print "# $cmd  ## all files already inspected\n";
336
  }
337
}
338
 
339
# --ghdh_m -- ghdl make command --------------------------------------
340
# Note: the 'buildin' make used by the -m option of ghdl does not
341
#       check for object files linked with -Wl, e.g. vhpi objects.
342
#       To force a re-elaboration the old executable is deleted first.
343
#       If used from make with proper dependencies, this will just do
344
#       the right thing.
345
 
346
if (exists $opts{ghdl_m} || exists $opts{ghdl_m_cmd} ) {
347
  my $cmd = "";
348
 
349 29 wfjm
  if ($no_xlpath && ($has_unisim || $has_unimacro || $has_simprim) ) {
350
    print STDERR "vbomconv-E: --xlpath required with ghdl_m or ghdl_m_cmd";
351
    exit 1;
352 2 wfjm
  }
353
 
354 29 wfjm
  if  (-r $stem) {              # check for old executable
355
    $cmd .= "rm $stem\n" ;      # rm to force elaboration
356
  }
357
 
358 2 wfjm
  $cmd .= "ghdl -m";
359
  $cmd .= " -o $stem";
360 29 wfjm
                                 # -fexplicit needed for ISE 13.1,13.3
361
  $cmd .= ' -fexplicit'          if $has_unisim or $has_unimacro or $has_simprim;
362
  $cmd .= " -P$xlpath/unisim"    if $has_unisim;
363
  $cmd .= " -P$xlpath/unimacro"  if $has_unimacro;
364
  $cmd .= " -P$xlpath/simprim"   if $has_simprim;
365 2 wfjm
  $cmd .= " --ieee=synopsys";
366
  $cmd .= " --no-vital-checks"      if $is_ssim or $is_fsim or $is_tsim;
367
 
368 29 wfjm
  foreach (@srcfile_list) {
369 2 wfjm
    next unless /\.c$/;         # C source ?
370
    my $ofile = $_;             # copy to break alias for following s///
371
    $ofile =~ s{^.*/}{};        # remove directory path
372
    $ofile =~ s/\.c$/.o/;       # add clause to link C source object file
373
    $cmd .= " -Wl,$ofile";
374
  }
375
  $cmd .= " $top";
376
  print "$cmd\n";
377
  if (exists $opts{ghdl_m}) {
378
    exec "/bin/sh", "-c", $cmd;
379
    die "failed to exec /bin/sh -c $cmd: $!";
380
  }
381
}
382
 
383
# --xst_prj ----------------------------------------------------------
384
 
385
if (exists $opts{xst_prj}) {
386 29 wfjm
  foreach (@srcfile_list) {
387 12 wfjm
    if ($xst_writevhdl) {
388
      print "vhdl work $_\n";
389
    } else {
390
      print "work $_\n";       # for ISE S-6/V-6 compilations with '-ifmt VHDL'
391
    }
392 2 wfjm
  }
393
}
394
 
395
# --isim_prj ---------------------------------------------------------
396
 
397
if (exists $opts{isim_prj}) {
398 29 wfjm
  foreach (@srcfile_list) {
399 2 wfjm
    print "vhdl work $_\n";
400
  }
401
}
402
 
403 29 wfjm
# --vsyn_prj ---------------------------------------------------------
404 22 wfjm
 
405 29 wfjm
if (exists $opts{vsyn_prj}) {
406
  # setup sources
407
  print "#\n";
408
  print "# setup sources\n";
409
  print "#\n";
410
  print "set src_files {\n";
411
  foreach (@srcfile_list) {
412 22 wfjm
    print "    $_\n";
413
  }
414
  print "}\n";
415 29 wfjm
  print "\n";
416 22 wfjm
 
417 29 wfjm
  print "set obj [get_filesets sources_1]\n";
418
  print "add_files -norecurse -fileset \$obj \$src_files\n";
419
  print "set_property \"top\" \"$top\" \$obj\n";
420 2 wfjm
 
421 29 wfjm
  # setup constraints
422 2 wfjm
  print "#\n";
423 29 wfjm
  print "# setup constraints\n";
424 2 wfjm
  print "#\n";
425 29 wfjm
 
426
  print "set xdc_files {\n";
427
  foreach (@xdcfile_list) {
428
    print "    $_\n";
429 2 wfjm
  }
430 29 wfjm
  print "}\n";
431
  print "\n";
432
 
433
  print "set obj [get_filesets constrs_1]\n";
434
  print "add_files -norecurse -fileset \$obj \$xdc_files\n";
435
 
436
  print "\n";
437 2 wfjm
}
438
 
439
# --dep_ghdl ---------------------------------------------------------
440
 
441
if (exists $opts{dep_ghdl}) {
442
 
443
  my $stem_fsim = $stem;
444
  my $stem_tsim = $stem;
445
  $stem_fsim =~ s/_ssim$/_fsim/;
446
  $stem_tsim =~ s/_ssim$/_tsim/;
447
 
448
  print "#\n";
449
  print "$stem : $stem.dep_ghdl\n";
450
  if ($is_ssim) {
451
    print "$stem_fsim : $stem.dep_ghdl\n";
452
    print "$stem_tsim : $stem.dep_ghdl\n";
453
  }
454
  print "#\n";
455
 
456 29 wfjm
  foreach (@srcfile_list) {
457 2 wfjm
    if (/\.c$/) {
458
      my $ofile = $_;           # copy to break alias for following s///
459
      $ofile =~ s{^.*/}{};      # remove directory path
460
      $ofile =~ s/\.c$/.o/;     # object file name
461
      print "$stem : $ofile\n"; # depend on C source object file
462
                                # C source object compilation dependence
463
      open (ODEPFILE, ">$ofile.dep_ghdl") or
464
        die "can't write $ofile.dep_ghdl: $!";
465
      print ODEPFILE "$ofile : $_\n";
466
      print ODEPFILE "\t\$(COMPILE.c) \$(OUTPUT_OPTION) \$<\n";
467
      close ODEPFILE;
468
    } else {
469
      print "$stem : $_\n";
470
    }
471
  }
472
 
473
  if ($is_ssim) {
474
 
475 29 wfjm
    foreach (@srcfile_list) {
476 2 wfjm
      my $file = $_;            # copy to break alias for following s///
477
      if (/\.c$/) {
478
        $file =~ s{^.*/}{};     # remove directory path
479
        $file =~ s/\.c$/.o/;    # depend on object file for C sources
480
      } else {
481
        $file =~ s/_ssim\.vhd$/_fsim.vhd/;
482
      }
483
      print "$stem_fsim : $file\n";
484
    }
485
 
486 29 wfjm
    foreach (@srcfile_list) {
487 2 wfjm
      my $file = $_;            # copy to break alias for following s///
488
      if (/\.c$/) {
489
        $file =~ s{^.*/}{};     # remove directory path
490
        $file =~ s/\.c$/.o/;    # depend on object file for C sources
491
      } else {
492
        $file =~ s/_ssim\.vhd$/_tsim.vhd/;
493
      }
494
      print "$stem_tsim : $file\n";
495
    }
496
 
497
  }
498
 
499
  write_vbomdep("$stem.dep_ghdl");
500
 
501
}
502
 
503 29 wfjm
# --dep_xst ----------------------------------------------------------
504
 
505
if (exists $opts{dep_xst}) {
506
  print "#\n";
507
  print "$stem.ngc : $stem.dep_xst\n";
508
  print "#\n";
509
  foreach (@srcfile_list) {
510
    print "$stem.ngc : $_\n";
511
  }
512
  # handle cpp preprocessed ucf's
513
  foreach (@ucf_cpp_list) {
514
    my $file = $_;
515
    $file =~ s/\.ucf$//;
516
    print "#\n";
517
    print "$file.ncd : $file.ucf\n";
518
    print "include $file.dep_ucf_cpp\n";
519
  }
520
  # handle plain ucf's
521
  if (scalar(@ucf_cpp_list)==0 && -r "$stem.ucf") {
522
    print "#\n";
523
    print "$stem.ncd : $stem.ucf\n";
524
  }
525
  write_vbomdep("$stem.dep_xst");
526
}
527
 
528 2 wfjm
# --dep_isim ---------------------------------------------------------
529
 
530
if (exists $opts{dep_isim}) {
531
  my $stem_isim = $stem . "_ISim";
532
 
533
  $stem_isim =~ s/_ssim_ISim$/_ISim_ssim/ if ($is_ssim);
534
 
535
  my $stem_fsim_isim = $stem_isim;
536
  my $stem_tsim_isim = $stem_isim;
537
  $stem_fsim_isim =~ s/_ssim$/_fsim/;
538
  $stem_tsim_isim =~ s/_ssim$/_tsim/;
539
 
540
  print "#\n";
541
  print "$stem_isim : $stem.dep_isim\n";
542
  if ($is_ssim) {
543
    print "$stem_fsim_isim : $stem.dep_isim\n";
544
    print "$stem_tsim_isim : $stem.dep_isim\n";
545
  }
546
  print "#\n";
547
 
548 29 wfjm
  foreach (@srcfile_list) {
549 2 wfjm
    print "$stem_isim : $_\n";
550
  }
551
 
552
  if ($is_ssim) {
553
 
554 29 wfjm
    foreach (@srcfile_list) {
555 2 wfjm
      my $file = $_;            # copy to break alias for following s///
556
      $file =~ s/_ssim\.vhd$/_fsim.vhd/;
557
      print "$stem_fsim_isim : $file\n";
558
    }
559
 
560 29 wfjm
    foreach (@srcfile_list) {
561 2 wfjm
      my $file = $_;            # copy to break alias for following s///
562
      $file =~ s/_ssim\.vhd$/_tsim.vhd/;
563
      print "$stem_tsim_isim : $file\n";
564
    }
565
 
566
  }
567
 
568
  write_vbomdep("$stem.dep_isim");
569
}
570
 
571 29 wfjm
# --dep_vsyn ---------------------------------------------------------
572 2 wfjm
 
573 29 wfjm
if (exists $opts{dep_vsyn}) {
574
  print "#\n";
575
  print "$stem.bit : $stem.dep_vsyn\n";
576
  print "#\n";
577
  my @files;
578
  push @files, @srcfile_list;
579
  push @files, @xdcfile_list;
580
  foreach (@files) {
581
    print "$stem.bit : $_\n";
582
  }
583
  print "#\n";
584
  foreach (@files) {
585
    print "${stem}_syn.dcp : $_\n";
586
  }
587
  print "#\n";
588
  foreach (@files) {
589
    print "${stem}_rou.dcp : $_\n";
590
  }
591
  write_vbomdep("$stem.dep_vsyn");
592
}
593
 
594
# --ghdl_export or xst_export or isim_export -------------------------
595
 
596
if (exists $opts{ghdl_export}  or
597
    exists $opts{xst_export} or
598 2 wfjm
    exists $opts{isim_export}) {
599
  my $edir;
600 29 wfjm
  $edir = $opts{ghdl_export} if exists $opts{ghdl_export};
601 2 wfjm
  $edir = $opts{xst_export}  if exists $opts{xst_export};
602
  $edir = $opts{isim_export} if exists $opts{isim_export};
603
 
604
  if (not -d $edir) {
605 29 wfjm
    print STDERR "vbomconv-I: create target directory $edir\n";
606 2 wfjm
    system("mkdir -p $edir") == 0 or die "mkdir failed: $?";
607
  } else {
608 29 wfjm
    print STDERR "vbomconv-I: target directory $edir already exists\n";
609 2 wfjm
  }
610
 
611
  open(PFILE, ">$edir/$stem.prj") or die "can't write open $edir/$stem.prj: $!";
612
 
613 29 wfjm
  foreach (@srcfile_list) {
614 2 wfjm
    my $fname  = $_;
615
    my $fdpath = ".";
616
    if (m{(.*)/(.*)}) {
617
      $fname  = $2;
618
      $fdpath = $1;
619
    }
620
    copy_edir($_, $edir);
621
    print PFILE "vhdl work $fname\n";
622
  }
623
 
624
  close(PFILE);
625
 
626 12 wfjm
  # Note: currently no xflow opt files exported !!
627 2 wfjm
  if (exists $opts{xst_export}) {
628
    open(XFILE, ">$edir/$stem.xcf") or
629
      die "can't write open $edir/$stem.xcf: $!";
630
    close(XFILE);
631 12 wfjm
 
632 2 wfjm
    foreach(glob("*.xcf")) { copy_edir($_, $edir); }
633
 
634 12 wfjm
    if (-r "$stem.ucf_cpp") {
635
      system "/bin/sh", "-c", "make $stem.ucf";
636
    }
637
 
638 2 wfjm
    foreach(glob("*.ucf")) { copy_edir($_, $edir); }
639
  }
640
 
641
}
642
 
643 17 wfjm
# --get_top ----------------------------------------------------------
644
 
645
if (exists $opts{get_top}) {
646
  print "$top\n";
647
}
648
 
649 2 wfjm
# --flist ------------------------------------------------------------
650
 
651
if (exists $opts{flist}) {
652
 
653
  my @flist;
654
 
655 29 wfjm
  push @flist, @srcfile_list;
656
  push @flist, sort keys %vbom_done;
657 2 wfjm
 
658
  if (scalar(@ucf_cpp_list)) {
659
    foreach (@ucf_cpp_list) {
660
      push @flist, $_."_cpp";
661
    }
662
  } else {
663
    if (-r "$stem.ucf") {
664
      push @flist, "$stem.ucf";
665
    }
666
  }
667
 
668 29 wfjm
  push @flist, @xdcfile_list;
669
 
670 2 wfjm
  foreach (sort @flist) {
671
    my $fname  = $_;
672
    my $fdpath = ".";
673
    if (m{(.*)/(.*)}) {
674
      $fname  = $2;
675
      $fdpath = $1;
676
    }
677
    print "$fdpath/$fname\n";
678
  }
679
 
680
}
681
 
682
#-------------------------------------------------------------------------------
683
 
684
sub read_vbom {
685
  my ($vbom) = @_;
686
 
687
  print STDERR "-- open $vbom\n" if $do_trace;
688
 
689
  open (IFILE, $vbom)    or die "can't open for read $vbom: $!";
690
 
691
  my $vbom_path = "";
692
  my $vbom_file = $vbom;
693
  if ($vbom =~ m{^(.*)/([a-zA-Z0-9_.]*)$}) {
694
    $vbom_path = $1;
695
    $vbom_file = $2;
696
  }
697
 
698 29 wfjm
  $vbom_done{$vbom} += 1;                   # mark this vbom already read
699 2 wfjm
 
700
  while () {
701
    chomp;
702
    next if /^\s*#/;                        # drop comments
703
    next if /^\s*$/;                        # drop empty lines
704
 
705
    s/\s*$//;                               # drop trailing blanks
706
 
707 17 wfjm
    # process parameter definitions
708
    if (m{([\w]+)\s*=\s*(.*)}) {
709
      my $para = $1;
710
      my $val  = $2;
711
      if ($val eq "") {
712 29 wfjm
        print STDERR "vbomconv-E: invalid \'$_\' in $vbom_file\n";
713 17 wfjm
        exit 1;
714
      }
715
      if (not exists $para_tbl{$para}) {
716
        $para_tbl{$para} = canon_fname($vbom_path, $val);
717
        print STDERR "--- define \${$para} = $val\n" if $do_trace;
718
      } else {
719
        print STDERR "--- ignore \${$para} = $val\n" if $do_trace;
720
      }
721
      next;
722
    }
723
 
724
    # process parameter substitutions
725
    while (m{\$\{([\w]+)\s*(:=)?\s*(.*?)\}}) {
726
      my $para = $1;
727
      my $del  = $2;
728
      my $val  = $3;
729
      my $pre  = $`;
730
      my $post = $';
731
      if (defined $del && $del eq ":=") {
732
        if (not exists $para_tbl{$para}) {
733
          $para_tbl{$para} = canon_fname($vbom_path, $val);
734
          print STDERR "--- define \${$para := $val}\n" if $do_trace;
735
        } else {
736
          print STDERR "--- ignore \${$para := $val}\n" if $do_trace;
737
        }
738
      }
739
      if (defined $para_tbl{$para}) {
740
        if ($do_trace) {
741
          print STDERR "--- use    \${$para} -> $para_tbl{$para}\n";
742
        } else {
743 29 wfjm
          ## print STDERR "vbomconv-I: \${$para} -> $para_tbl{$para}\n";
744 17 wfjm
        }
745
        $_ = $pre . "!" . $para_tbl{$para} . $post;
746
      } else {
747 29 wfjm
        print STDERR "vbomconv-E: undefined \${$para} in $vbom_file\n";
748 17 wfjm
        exit 1;
749
      }
750
    }
751
 
752 2 wfjm
    if (/^\[([a-z,]+)\]\s*(.+)$/) {         # [xxx,yyy] tag seen
753
      my $qual = $1;
754
      my $name = $2;
755
      my $keep = $is_any;
756
      ## print STDERR "+++1 |$qual|$name|$vbom|\n";
757
      foreach my $pref (split /,/,$qual) {
758 29 wfjm
        if ($pref =~ /^(ghdl|xst|isim|vsyn|vsim|sim)$/) {
759
          $keep = 1 if ($pref eq "ghdl" && $is_ghdl);
760 2 wfjm
          $keep = 1 if ($pref eq "xst"  && $is_xst);
761
          $keep = 1 if ($pref eq "isim" && $is_isim);
762 29 wfjm
          $keep = 1 if ($pref eq "vsyn" && $is_vsyn);
763
          $keep = 1 if ($pref eq "vsim" && $is_vsim);
764 2 wfjm
          $keep = 1 if ($pref eq "sim"  && $is_sim);
765
        } else {
766 29 wfjm
          print STDERR "vbomconv-W: unknown tag [$pref] in $vbom_file\n";
767 2 wfjm
        }
768
      }
769
      if (not $keep) {
770
        print STDERR "--- drop \"$_\"\n" if $do_trace;
771
        next;
772
      }
773
      $_ = $name;                           # remove [xxx] tag
774
    }
775
 
776
    my $tag;
777
    my $val = $_;
778
 
779 17 wfjm
    # detect tag:val lines
780
    if (m{^\s*(.*?)\s*:\s*(.*?)\s*$}) {
781 2 wfjm
      $tag = $1;
782 17 wfjm
      $val = $2;
783 2 wfjm
 
784 17 wfjm
      # process @top: lines
785
      if ($tag eq '@top') {
786
        $top = $val unless $top_done;
787 2 wfjm
 
788 17 wfjm
      # process @ucf_cpp: lines
789
      } elsif ($tag eq '@ucf_cpp') {
790
        push @ucf_cpp_list, $val;
791 2 wfjm
 
792 29 wfjm
      # process @xdc: lines
793
      } elsif ($tag eq '@xdc') {
794
        push @{$vbom_xdc{$vbom}}, canon_fname($vbom_path, $val);
795
 
796 17 wfjm
      # process @lib: lines
797
      } elsif ($tag eq '@lib') {
798
        if ($val eq 'unisim') {
799
          $has_unisim = 1;
800 29 wfjm
        } elsif ($val eq 'unimacro') {
801
          $has_unimacro = 1;
802 17 wfjm
        } elsif ($val eq 'simprim') {
803
          $has_simprim = 1;
804
        } else {
805 29 wfjm
          print STDERR "vbomconv-E: invalid lib type \'$tag\' in $vbom_file\n";
806 17 wfjm
          exit 1;
807
        }
808 29 wfjm
 
809
      # catch invalid @ tags
810 2 wfjm
      } else {
811 29 wfjm
        print STDERR "vbomconv-E: invalid \'$tag:\' line in $vbom_file\n";
812 17 wfjm
        exit 1;
813 2 wfjm
      }
814
      next;
815
    }
816
 
817
    # now do _fsim, _tsim mapping
818
    $val =~ s{_ssim\.vhd$}{_fsim.vhd} if $is_fsim;
819
    $val =~ s{_ssim\.vhd$}{_tsim.vhd} if $is_tsim;
820
 
821
    # process normal .vhd or .vbom file lines
822 17 wfjm
    # canonize file name unless not already done by filename substitution
823
    my $fullname;
824
    if ($val =~ m{^!(.*)$}) {
825
      $fullname = $1;
826
    } else {
827
      $fullname = canon_fname($vbom_path, $val);
828 2 wfjm
    }
829
 
830
    # determine whether additional libs needed
831
    if ($fullname =~ m{_ssim\.vhd$}) {      # ends in _ssim.vhd
832
      $has_unisim = 1;
833
    }
834
    if ($fullname =~ m{_[ft]sim\.vhd$}) {   # ends in _fsim.vhd or _tsim.vhd
835
      $has_simprim = 1;
836
    }
837
 
838
    # build vbom table
839 29 wfjm
    push @{$vbom_files{$vbom}}, $fullname;
840
    print STDERR "--- add    $fullname\n" if $do_trace;
841 2 wfjm
 
842
    # if a vbom, queue if not not already read
843 29 wfjm
    if ($fullname =~ m{\.vbom$} && not exists $vbom_done{$fullname} ) {
844
       push @vbom_queue, $fullname;
845
       print STDERR "--- queue  $fullname\n" if $do_trace;
846 2 wfjm
    }
847
 
848
  }
849
 
850
  $top_done = 1;
851
 
852
  close (IFILE);
853
}
854
 
855
#-------------------------------------------------------------------------------
856
 
857
sub scan_vbom {
858
  my ($vbom) = @_;
859
 
860
  $level += 1;
861 29 wfjm
  my $rank = 1000*$level + scalar(@{$vbom_files{$vbom}});
862 2 wfjm
  print STDERR "--> $level: $vbom\n" if $do_trace;
863
 
864 29 wfjm
  die "vbomcov-E excessive vbom stack depth \n" if $level>=1000;
865 2 wfjm
 
866 29 wfjm
  if (exists $vbom_rank{$vbom}) {
867
    $vbom_rank{$vbom}{min} = $level if $level < $vbom_rank{$vbom}{min};
868
    $vbom_rank{$vbom}{max} = $level if $level > $vbom_rank{$vbom}{max};
869
  } else {
870
    $vbom_rank{$vbom} = {min=>$level, max=>$level};
871
  }
872
 
873
  foreach (@{$vbom_files{$vbom}}) {
874 2 wfjm
    my $file = $_;
875
    $rank -= 1;
876
    if (m{\.vbom$}) {
877
      scan_vbom($file);
878
    } else {
879 29 wfjm
      if (exists $srcfile_rank{$file}) {
880
        if ($rank > $srcfile_rank{$file}) {
881
          print STDERR "   $file   $srcfile_rank{$file} -> $rank\n" if $do_trace;
882
          $srcfile_rank{$file} = $rank;
883 2 wfjm
        } else {
884 29 wfjm
          print STDERR "   $file   $srcfile_rank{$file} (keep)\n" if $do_trace;
885 2 wfjm
        }
886
      } else {
887 29 wfjm
         $srcfile_rank{$file} = $rank;
888
         print STDERR "   $file   $srcfile_rank{$file} (new)\n" if $do_trace;
889 2 wfjm
      }
890
    }
891
  }
892
 
893
  print STDERR "<-- $level: $vbom\n" if $do_trace;
894
  $level -= 1;
895
 
896
}
897
 
898
#-------------------------------------------------------------------------------
899
 
900
sub copy_edir {
901
  my ($file, $edir) = @_;
902
  print "cp -p $file $edir\n";
903
  system("cp -p $file $edir")==0 or die "cp -p failed: $?";
904
}
905
 
906
#-------------------------------------------------------------------------------
907
 
908
sub write_vbomdep {
909
  my ($target) = @_;
910
  print "#\n";
911 29 wfjm
  print "# .dep_* on .vbom dependencies\n";
912 2 wfjm
  print "#\n";
913 29 wfjm
  foreach (sort keys %vbom_done) {
914 2 wfjm
    print "$target : $_\n";
915
  }
916
}
917
 
918
#-------------------------------------------------------------------------------
919 17 wfjm
sub canon_fname {
920
  my ($vpath,$fname) = @_;
921
    # get full relative file name (relative to cwd)
922
    $fname = "$vpath/$fname" if $vpath ne "";
923 2 wfjm
 
924 17 wfjm
    # remove 'inner' .., e.g.  ../x/../y -->  ../y
925
    # this will also canonize the file names, thus same file same name
926
 
927
    my @flist;
928
    foreach (split "/",$fname) {
929
      if (scalar(@flist) && $flist[$#flist] ne ".." && $_ eq "..") {
930
        pop @flist;
931
      } else {
932
        push @flist, $_;
933
      }
934
    }
935
 
936
    return join "/", @flist;
937
}
938
 
939
#-------------------------------------------------------------------------------
940
 
941 2 wfjm
sub print_help {
942
  print "usage: vbomconf  file.vbom\n";
943
  print "  --help           this message\n";
944
  print "  --trace          trace recursive processing of vbom's\n";
945 29 wfjm
  print "  --dep_ghdl       generate ghdl dependencies for make\n";
946
  print "  --dep_xst        generate xst  dependencies for make\n";
947
  print "  --dep_isim       generate isim dependencies for make\n";
948
  print "  --dep_vsyn       generate vsyn dependencies for make\n";
949 2 wfjm
  print "  --ghdl_a         generate and execute ghdl -a  (analyse)\n";
950
  print "  --ghdl_a_cmd     like ghdl_a, but only print command, no exec\n";
951
  print "  --ghdl_i         generate and execute ghdl -i  (inspect)\n";
952
  print "  --ghdl_i_cmd     like ghdl_i, but only print command, no exec\n";
953
  print "  --ghdl_m         generate and execute ghdl -m  (make)\n";
954
  print "  --ghdl_m_cmd     like ghdl_m, but only print command, no exec\n";
955 29 wfjm
  print "  --xst_prj        generate xst project file\n";
956
  print "  --isim_prj       generate isim project file\n";
957
  print "  --vsyn_prj       generate vivado synthesis project definition\n";
958
  print "  --ghdl_export=s  export all ghdl source files into directory s\n";
959 2 wfjm
  print "  --xst_export=s   export all xst source files into directory s\n";
960
  print "  --isim_export=s  export all isim source files into directory s\n";
961 23 wfjm
  print "  --get_top        return top level entity name\n";
962 2 wfjm
  print "  --flist          list all files touched by vbom for all tags\n";
963
}

powered by: WebSVN 2.1.0

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