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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.6/] [tools/] [bin/] [vbomconv] - Blame information for rev 15

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

Line No. Rev Author Line
1 2 wfjm
#!/usr/bin/perl -w
2 15 wfjm
# $Id: vbomconv 433 2011-11-27 22:04:39Z mueller $
3 2 wfjm
#
4 12 wfjm
# Copyright 2007-2011 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 15 wfjm
# 2011-11-27   433   1.9.2  use in ghdl_m -fexplicit when unisim used
18 12 wfjm
# 2011-08-13   405   1.9.1  always write 'vhdl' into xst prj files again; for
19
#                           -xst_export: remove opt file export, add ucf_cpp
20
#                           handling
21
# 2011-06-26   385   1.9    add --ise_path, pass it to vbomconv --xst_prj
22
# 2011-06-09   383   1.8.6  fix xst_vhdl.opt logic (use rtl/vlib now)
23 2 wfjm
# 2010-07-03   312   1.8.5  add --flist action
24
# 2010-06-03   299   1.8.4  generate ucf->ncd dependencies in dep_xst
25
# 2010-04-26   284   1.8.3  add _[sft]sim support for ISim
26
# 2009-11-28   253   1.8.2  fixup print_help...;
27
# 2009-11-22   252   1.8.1  add (export|dep)_isim, full ISim support;
28
#                           add [isim] [sim], allow tag lists like [ghdl,isim];
29
#                           --trace and messages to STDERR;
30
# 2009-11-20   251   1.8    add isim_prj, first ISim support
31
# 2008-03-09   124   1.7.3  add in .dep_(ghdl|xst) all dep on vbom dependencies
32
#                           target now also dependant on .dep_ file
33
# 2008-03-02   122   1.7.2  add @lib: directive to include UNISIM
34
# 2007-12-17   102   1.7.1  fix @ucf_cpp logic.
35
# 2007-12-16   101   1.7    add @ucf_cpp pseudo tag (handle cpp'ed ucf files)
36
# 2007-11-25    98   1.6.1  drop trailing blanks on input lines
37
# 2007-11-02    94   1.6    added (xst|ghdl)_export
38
# 2007-10-26    92   1.5.1  emit '--no-vital-checks' for --ghdl_m for _[sft]sim
39
# 2007-10-14    98   1.5    handle .exe files under cycwin properly
40
# 2007-09-15    82   1.4    handle C source objects properly
41
# 2007-08-10    72   1.3    add [xst], [ghdl] prefix support
42
# 2007-07-22    68   1.2    add "tag = val"; list files in 'ready to analyse'
43
#                           order; add --ghdl_a option
44
# 2007-07-08    65   1.1    add "tag : names"; inferral of _[ft]sim vboms
45
# 2007-07-06    64   1.0    Initial version
46
 
47
use 5.005;                                  # require Perl 5.005 or higher
48
use strict;                                 # require strict checking
49
use FileHandle;
50
 
51
use Getopt::Long;
52
 
53
my %opts = ();
54
 
55 12 wfjm
GetOptions(\%opts, "help", "trace", "ise_path=s",
56 2 wfjm
                   "dep_xst", "dep_ghdl", "dep_isim",
57
                   "xst_prj", "isim_prj",
58
                   "ghdl_a", "ghdl_a_cmd",
59
                   "ghdl_i", "ghdl_i_cmd",
60
                   "ghdl_m", "ghdl_m_cmd",
61
                   "xst_export=s",
62
                   "ghdl_export=s",
63
                   "isim_export=s",
64
                   "flist") || exit 1;
65
 
66
sub print_help;
67
sub read_vbom;
68
sub scan_vbom;
69
sub copy_edir;
70
sub write_vbomdep;
71
 
72
my @vbom_list;
73
my @file_list;
74
my %vbom_tbl;
75
my %file_tbl;
76
my %read_tbl;
77
my %conf_tbl;
78
my @ucf_cpp_list;
79
my $is_xst  = 0;                            # XST synthesis target
80
my $is_ghdl = 0;                            # ghdl simulation target
81
my $is_isim = 0;                            # ISim simulation target
82
my $is_sim  = 0;                            # simulation target (generic)
83
my $is_any  = 0;
84
my $nactions = 0;
85
my $top_vbom;
86
my $stem;
87
my $top;
88
my $top_done = 0;
89
my $has_unisim;
90
my $has_simprim;
91
my $is_ssim;
92
my $is_fsim;
93
my $is_tsim;
94
my $do_trace = exists $opts{trace};
95
my $level;
96 12 wfjm
my $xst_writevhdl = 1;
97 2 wfjm
 
98 12 wfjm
# now using '-ifmt mixed', so language always needed (2011-08-13)
99
#if (defined $opts{ise_path}) {
100
#  if ($opts{ise_path} =~ /^xc6s/) {
101
#    $xst_writevhdl = 0;
102
#  }
103
#}
104
 
105 2 wfjm
autoflush STDOUT 1;             # autoflush, so noting lost on exec later
106
 
107
if (exists $opts{help}) {
108
  print_help;
109
  exit 0;
110
}
111
 
112
# ensure that one and only one vbom is specified
113
 
114
if (scalar(@ARGV) != 1) {
115
  print STDERR "%vbomconv-E: only one vbom file name allowed\n\n";
116
  print_help;
117
  exit 1;
118
}
119
 
120
# check that only one action is defined, mark xst, gdhl, or isim class
121
 
122
foreach (keys %opts) {
123 12 wfjm
  $nactions += 1 unless ($_ eq "trace" || $_ eq "ise_path");
124 2 wfjm
  $is_xst  = 1   if ($_ eq "dep_xst");
125
  $is_ghdl = 1   if ($_ eq "dep_ghdl");
126
  $is_isim = 1   if ($_ eq "dep_isim");
127
  $is_xst  = 1   if ($_ =~ /^xst_/);
128
  $is_ghdl = 1   if ($_ =~ /^ghdl_/);
129
  $is_isim = 1   if ($_ =~ /^isim_/);
130
  $is_any  = 1   if ($_ eq "flist");
131
}
132
 
133
$is_sim = $is_ghdl | $is_isim;
134
 
135
print STDERR "-- [xst] active\n"  if $do_trace && $is_xst;
136
print STDERR "-- [ghdl] active\n" if $do_trace && $is_ghdl;
137
print STDERR "-- [isim] active\n" if $do_trace && $is_isim;
138
print STDERR "-- [sim] active\n"  if $do_trace && $is_sim;
139
 
140
if ($nactions > 1) {
141
  print STDERR "%vbomconv-E: only one action qualifier allowed\n\n";
142
  print_help;
143
  exit 1;
144
}
145
 
146
$top_vbom = $ARGV[0];
147
 
148
$top_vbom .= ".vbom" unless $top_vbom =~ m{\.vbom$};
149
 
150
$stem = $top_vbom;
151
$stem =~ s{\..*$}{};
152
 
153
$top = $stem;
154
$top =~ s{^.*/}{};
155
 
156
# now prepare virtual _fsim and _tsim vbom's
157
# they are inferred from the _ssim vbom's
158
 
159
if ($top_vbom =~ m{_ssim\.vbom$}) { # detect _ssim
160
  $is_ssim = 1;
161
}
162
if ($top_vbom =~ m{_fsim\.vbom$}) { # map _fsim -> _ssim
163
  $is_fsim = 1;
164
  $top_vbom =~ s{_fsim\.vbom$}{_ssim.vbom};
165
}
166
if ($top_vbom =~ m{_tsim\.vbom$}) { # map _tsim -> _ssim
167
  $is_tsim = 1;
168
  $top_vbom =~ s{_tsim\.vbom$}{_ssim.vbom};
169
}
170
 
171
# traverse all vbom's start with command line argument
172
 
173
push @vbom_list, $top_vbom;
174
 
175
while (@vbom_list) {
176
  my $cur_vbom = shift @vbom_list;
177
  read_vbom($cur_vbom);
178
}
179
 
180
# traverse internal vbom representation to build file table
181
 
182
scan_vbom($top_vbom);
183
 
184
# sort file table, build file list (decreasing rank)
185
 
186
my @pair_list;
187
foreach (keys %file_tbl) {
188
  push @pair_list, [$file_tbl{$_}, $_];
189
}
190
 
191
@file_list = map {$_->[1]} sort {$b->[0] <=> $a->[0]} @pair_list;
192
 
193
# now generate output and actions, depending on options given
194
 
195
# --trace ------------------------------------------------------------
196
 
197
if ($do_trace) {
198
  print STDERR "\n";
199
  print STDERR "configuration table:\n";
200
  foreach (sort keys %conf_tbl) {
201
    print STDERR "  $_ = $conf_tbl{$_}\n";
202
  }
203
  print STDERR "final file_list:\n";
204
  foreach (@file_list) {
205
    print STDERR "  $_\n";
206
  }
207
  print STDERR "properties:\n";
208
  print STDERR "  \@top: $top\n";
209
}
210
 
211
# --ghdh_a -- ghdl analysis command ----------------------------------
212
 
213
if (exists $opts{ghdl_a} || exists $opts{ghdl_a_cmd}) {
214
  foreach (@file_list) {
215
    my $file = $_;
216
    my $cmd = "ghdl -a";
217
    $cmd .= ' -P$XILINX/ghdl/unisim'  if $has_unisim;
218
    $cmd .= ' -P$XILINX/ghdl/simprim' if $has_simprim;
219
    $cmd .= " --ieee=synopsys";
220
    $cmd .= " $file";
221
    print "$cmd\n";
222
    if (exists $opts{ghdl_a}) {
223
      my $wrc = system "/bin/sh", "-c", $cmd;
224
      if ($wrc != 0) {
225
        my $rc = int($wrc/256);
226
        if ($rc == 0) {
227
          my $sig = $wrc % 256;
228
          print STDERR "%vbomconv-I compilation aborted by signal $sig\n";
229
          exit(1);
230
        } else {
231
          print STDERR "%vbomconv-I compilation failed (rc=$rc) $?\n";
232
          exit($rc);
233
        }
234
      }
235
    }
236
  }
237
}
238
 
239
# --ghdh_i -- ghdl inspection command --------------------------------
240
 
241
if (exists $opts{ghdl_i} || exists $opts{ghdl_i_cmd}) {
242
  my %ghdl_work;
243
 
244
  # read ghdl "work-obj93.cf" file. It has the format
245
  #   file . "" "" "ghdl -i or -a date>":
246
  #     entity  at nn( nn) + nn on nn;
247
  #     architecture  of  at nn( nn) + nn on nn;
248
 
249
  if (-r "work-obj93.cf") {
250
    open (WFILE, "work-obj93.cf") or
251
      die "can't open for read work-obj93.cf: $!";
252
    while () {
253
      if (m{^file \. \"(.*?)\"}) {
254
        $ghdl_work{$1} = 1;
255
      }
256
    }
257
    close (WFILE);
258
  }
259
 
260
  my $cmd = "ghdl -i";
261
  my $nfile = 0;
262
 
263
  foreach (@file_list) {
264
    next if /\.c$/;                         # skip C sources, only vhd handled
265
    if (not exists $ghdl_work{$_}) {
266
      $cmd .= " \\\n  $_";
267
      $nfile += 1;
268
    }
269
  }
270
 
271
  if ($nfile) {
272
    print "$cmd\n";
273
    if (exists $opts{ghdl_i}) {
274
      exec "/bin/sh", "-c", $cmd;
275
      die "failed to exec /bin/sh -c $cmd: $!";
276
    }
277
  } else {
278
    print "# $cmd  ## all files already inspected\n";
279
  }
280
}
281
 
282
# --ghdh_m -- ghdl make command --------------------------------------
283
# Note: the 'buildin' make used by the -m option of ghdl does not
284
#       check for object files linked with -Wl, e.g. vhpi objects.
285
#       To force a re-elaboration the old executable is deleted first.
286
#       If used from make with proper dependencies, this will just do
287
#       the right thing.
288
 
289
if (exists $opts{ghdl_m} || exists $opts{ghdl_m_cmd} ) {
290
  my $cmd = "";
291
 
292
  if (-r "$stem.exe") {         # check for .exe, in case we are in cygwin
293
  $cmd .= "rm $stem.exe\n";     # rm old executable to force elaboration
294
  } elsif  (-r $stem) {         # otherwise
295
    $cmd .= "rm $stem\n" ;      # rm old executable to force elaboration
296
  }
297
 
298
  $cmd .= "ghdl -m";
299
  $cmd .= " -o $stem";
300 15 wfjm
  $cmd .= ' -fexplicit'             if $has_unisim;    # needed for ISE 13.1
301 2 wfjm
  $cmd .= ' -P$XILINX/ghdl/unisim'  if $has_unisim;
302
  $cmd .= ' -P$XILINX/ghdl/simprim' if $has_simprim;
303
  $cmd .= " --ieee=synopsys";
304
  $cmd .= " --no-vital-checks"      if $is_ssim or $is_fsim or $is_tsim;
305
 
306
  foreach (@file_list) {
307
    next unless /\.c$/;         # C source ?
308
    my $ofile = $_;             # copy to break alias for following s///
309
    $ofile =~ s{^.*/}{};        # remove directory path
310
    $ofile =~ s/\.c$/.o/;       # add clause to link C source object file
311
    $cmd .= " -Wl,$ofile";
312
  }
313
  $cmd .= " $top";
314
  print "$cmd\n";
315
  if (exists $opts{ghdl_m}) {
316
    exec "/bin/sh", "-c", $cmd;
317
    die "failed to exec /bin/sh -c $cmd: $!";
318
  }
319
}
320
 
321
# --xst_prj ----------------------------------------------------------
322
 
323
if (exists $opts{xst_prj}) {
324
  foreach (@file_list) {
325 12 wfjm
    if ($xst_writevhdl) {
326
      print "vhdl work $_\n";
327
    } else {
328
      print "work $_\n";       # for ISE S-6/V-6 compilations with '-ifmt VHDL'
329
    }
330 2 wfjm
  }
331
}
332
 
333
# --isim_prj ---------------------------------------------------------
334
 
335
if (exists $opts{isim_prj}) {
336
  foreach (@file_list) {
337
    print "vhdl work $_\n";
338
  }
339
}
340
 
341
# --dep_xst ----------------------------------------------------------
342
 
343
if (exists $opts{dep_xst}) {
344
  print "#\n";
345
  print "$stem.ngc : $stem.dep_xst\n";
346
  print "#\n";
347
  foreach (@file_list) {
348
    print "$stem.ngc : $_\n";
349
  }
350
  # handle cpp preprocessed ucf's
351
  foreach (@ucf_cpp_list) {
352
    my $file = $_;
353
    $file =~ s/\.ucf$//;
354
    print "#\n";
355
    print "$file.ncd : $file.ucf\n";
356
    print "include $file.dep_ucf_cpp\n";
357
  }
358
  # handle plain ucf's
359
  if (scalar(@ucf_cpp_list)==0 && -r "$stem.ucf") {
360
    print "#\n";
361
    print "$stem.ncd : $stem.ucf\n";
362
  }
363
  write_vbomdep("$stem.dep_xst");
364
}
365
 
366
# --dep_ghdl ---------------------------------------------------------
367
 
368
if (exists $opts{dep_ghdl}) {
369
 
370
  my $stem_fsim = $stem;
371
  my $stem_tsim = $stem;
372
  $stem_fsim =~ s/_ssim$/_fsim/;
373
  $stem_tsim =~ s/_ssim$/_tsim/;
374
 
375
  print "#\n";
376
  print "$stem : $stem.dep_ghdl\n";
377
  if ($is_ssim) {
378
    print "$stem_fsim : $stem.dep_ghdl\n";
379
    print "$stem_tsim : $stem.dep_ghdl\n";
380
  }
381
  print "#\n";
382
 
383
  foreach (@file_list) {
384
    if (/\.c$/) {
385
      my $ofile = $_;           # copy to break alias for following s///
386
      $ofile =~ s{^.*/}{};      # remove directory path
387
      $ofile =~ s/\.c$/.o/;     # object file name
388
      print "$stem : $ofile\n"; # depend on C source object file
389
                                # C source object compilation dependence
390
      open (ODEPFILE, ">$ofile.dep_ghdl") or
391
        die "can't write $ofile.dep_ghdl: $!";
392
      print ODEPFILE "$ofile : $_\n";
393
      print ODEPFILE "\t\$(COMPILE.c) \$(OUTPUT_OPTION) \$<\n";
394
      close ODEPFILE;
395
    } else {
396
      print "$stem : $_\n";
397
    }
398
  }
399
 
400
  if ($is_ssim) {
401
 
402
    foreach (@file_list) {
403
      my $file = $_;            # copy to break alias for following s///
404
      if (/\.c$/) {
405
        $file =~ s{^.*/}{};     # remove directory path
406
        $file =~ s/\.c$/.o/;    # depend on object file for C sources
407
      } else {
408
        $file =~ s/_ssim\.vhd$/_fsim.vhd/;
409
      }
410
      print "$stem_fsim : $file\n";
411
    }
412
 
413
    foreach (@file_list) {
414
      my $file = $_;            # copy to break alias for following s///
415
      if (/\.c$/) {
416
        $file =~ s{^.*/}{};     # remove directory path
417
        $file =~ s/\.c$/.o/;    # depend on object file for C sources
418
      } else {
419
        $file =~ s/_ssim\.vhd$/_tsim.vhd/;
420
      }
421
      print "$stem_tsim : $file\n";
422
    }
423
 
424
  }
425
 
426
  write_vbomdep("$stem.dep_ghdl");
427
 
428
}
429
 
430
# --dep_isim ---------------------------------------------------------
431
 
432
if (exists $opts{dep_isim}) {
433
  my $stem_isim = $stem . "_ISim";
434
 
435
  $stem_isim =~ s/_ssim_ISim$/_ISim_ssim/ if ($is_ssim);
436
 
437
  my $stem_fsim_isim = $stem_isim;
438
  my $stem_tsim_isim = $stem_isim;
439
  $stem_fsim_isim =~ s/_ssim$/_fsim/;
440
  $stem_tsim_isim =~ s/_ssim$/_tsim/;
441
 
442
  print "#\n";
443
  print "$stem_isim : $stem.dep_isim\n";
444
  if ($is_ssim) {
445
    print "$stem_fsim_isim : $stem.dep_isim\n";
446
    print "$stem_tsim_isim : $stem.dep_isim\n";
447
  }
448
  print "#\n";
449
 
450
  foreach (@file_list) {
451
    print "$stem_isim : $_\n";
452
  }
453
 
454
  if ($is_ssim) {
455
 
456
    foreach (@file_list) {
457
      my $file = $_;            # copy to break alias for following s///
458
      $file =~ s/_ssim\.vhd$/_fsim.vhd/;
459
      print "$stem_fsim_isim : $file\n";
460
    }
461
 
462
    foreach (@file_list) {
463
      my $file = $_;            # copy to break alias for following s///
464
      $file =~ s/_ssim\.vhd$/_tsim.vhd/;
465
      print "$stem_tsim_isim : $file\n";
466
    }
467
 
468
  }
469
 
470
  write_vbomdep("$stem.dep_isim");
471
}
472
 
473
# --xst_export or ghdl_export or isim_export -------------------------
474
 
475
if (exists $opts{xst_export}  or
476
    exists $opts{ghdl_export} or
477
    exists $opts{isim_export}) {
478
  my $edir;
479
  $edir = $opts{xst_export}  if exists $opts{xst_export};
480
  $edir = $opts{ghdl_export} if exists $opts{ghdl_export};
481
  $edir = $opts{isim_export} if exists $opts{isim_export};
482
 
483
  if (not -d $edir) {
484
    print STDERR "%vbomconv-I: create target directory $edir\n";
485
    system("mkdir -p $edir") == 0 or die "mkdir failed: $?";
486
  } else {
487
    print STDERR "%vbomconv-I: target directory $edir already exists\n";
488
  }
489
 
490
  open(PFILE, ">$edir/$stem.prj") or die "can't write open $edir/$stem.prj: $!";
491
 
492
  foreach (@file_list) {
493
    my $fname  = $_;
494
    my $fdpath = ".";
495
    if (m{(.*)/(.*)}) {
496
      $fname  = $2;
497
      $fdpath = $1;
498
    }
499
    copy_edir($_, $edir);
500
    print PFILE "vhdl work $fname\n";
501
  }
502
 
503
  close(PFILE);
504
 
505 12 wfjm
  # Note: currently no xflow opt files exported !!
506 2 wfjm
  if (exists $opts{xst_export}) {
507
    open(XFILE, ">$edir/$stem.xcf") or
508
      die "can't write open $edir/$stem.xcf: $!";
509
    close(XFILE);
510 12 wfjm
 
511 2 wfjm
    foreach(glob("*.xcf")) { copy_edir($_, $edir); }
512
 
513 12 wfjm
    if (-r "$stem.ucf_cpp") {
514
      system "/bin/sh", "-c", "make $stem.ucf";
515
    }
516
 
517 2 wfjm
    foreach(glob("*.ucf")) { copy_edir($_, $edir); }
518
  }
519
 
520
}
521
 
522
# --flist ------------------------------------------------------------
523
 
524
if (exists $opts{flist}) {
525
 
526
  my @flist;
527
 
528
  push @flist, @file_list;
529
  push @flist, sort keys %read_tbl;
530
 
531
  if (scalar(@ucf_cpp_list)) {
532
    foreach (@ucf_cpp_list) {
533
      push @flist, $_."_cpp";
534
    }
535
  } else {
536
    if (-r "$stem.ucf") {
537
      push @flist, "$stem.ucf";
538
    }
539
  }
540
 
541
  foreach (sort @flist) {
542
    my $fname  = $_;
543
    my $fdpath = ".";
544
    if (m{(.*)/(.*)}) {
545
      $fname  = $2;
546
      $fdpath = $1;
547
    }
548
    print "$fdpath/$fname\n";
549
  }
550
 
551
}
552
 
553
#-------------------------------------------------------------------------------
554
 
555
sub read_vbom {
556
  my ($vbom) = @_;
557
 
558
  print STDERR "-- open $vbom\n" if $do_trace;
559
 
560
  open (IFILE, $vbom)    or die "can't open for read $vbom: $!";
561
 
562
  my $vbom_path = "";
563
  my $vbom_file = $vbom;
564
  if ($vbom =~ m{^(.*)/([a-zA-Z0-9_.]*)$}) {
565
    $vbom_path = $1;
566
    $vbom_file = $2;
567
  }
568
 
569
  $read_tbl{$vbom} += 1;                    # mark this vbom already read
570
 
571
  while () {
572
    chomp;
573
    next if /^\s*#/;                        # drop comments
574
    next if /^\s*$/;                        # drop empty lines
575
 
576
    s/\s*$//;                               # drop trailing blanks
577
 
578
    if (/^\[([a-z,]+)\]\s*(.+)$/) {         # [xxx,yyy] tag seen
579
      my $qual = $1;
580
      my $name = $2;
581
      my $keep = $is_any;
582
      ## print STDERR "+++1 |$qual|$name|$vbom|\n";
583
      foreach my $pref (split /,/,$qual) {
584
        if ($pref =~ /^(xst|ghdl|isim|sim)$/) {
585
          $keep = 1 if ($pref eq "xst"  && $is_xst);
586
          $keep = 1 if ($pref eq "ghdl" && $is_ghdl);
587
          $keep = 1 if ($pref eq "isim" && $is_isim);
588
          $keep = 1 if ($pref eq "sim"  && $is_sim);
589
        } else {
590
          print STDERR "%vbomconv-W: unknown tag [$pref] in $vbom_file\n";
591
        }
592
      }
593
      if (not $keep) {
594
        print STDERR "--- drop \"$_\"\n" if $do_trace;
595
        next;
596
      }
597
      $_ = $name;                           # remove [xxx] tag
598
    }
599
 
600
    my $tag;
601
    my $val = $_;
602
    my $del;
603
 
604
    # detect tag=val or tag:val lines
605
    if (m{^\s*(.*?)\s*([=:])\s*(.*?)\s*$}) {
606
      $tag = $1;
607
      $del = $2;
608
      $val = $3;
609
    }
610
 
611
    # process @top: lines
612
    if (defined $del && $del eq ":" && $tag eq '@top') {
613
      $top = $val unless $top_done;
614
      next;
615
    }
616
 
617
    # process @ucf_cpp: lines
618
    if (defined $del && $del eq ":" && $tag eq '@ucf_cpp') {
619
      push @ucf_cpp_list, $val;
620
      next;
621
    }
622
 
623
    # process @lib: lines
624
    if (defined $del && $del eq ":" && $tag eq '@lib') {
625
      if ($val eq 'unisim') {
626
        $has_unisim = 1;
627
      } elsif ($val eq 'simprim') {
628
        $has_simprim = 1;
629
      } else {
630
        die "unknown library type: $val";
631
      }
632
      next;
633
    }
634
 
635
    # now do _fsim, _tsim mapping
636
    $val =~ s{_ssim\.vhd$}{_fsim.vhd} if $is_fsim;
637
    $val =~ s{_ssim\.vhd$}{_tsim.vhd} if $is_tsim;
638
 
639
    # process normal .vhd or .vbom file lines
640
    # get full relative file name (relative to cwd)
641
 
642
    my $fname = $val;
643
    $fname = "$vbom_path/$fname" if $vbom_path ne "";
644
 
645
    # remove 'inner' .., e.g.  ../x/../y -->  ../y
646
    # this will also canonize the file names, thus same file same name
647
 
648
    my @flist;
649
    foreach (split "/",$fname) {
650
      if (scalar(@flist) && $flist[$#flist] ne ".." && $_ eq "..") {
651
        pop @flist;
652
      } else {
653
        push @flist, $_;
654
      }
655
    }
656
 
657
    my $fullname = join "/", @flist;
658
 
659
    # determine whether additional libs needed
660
    if ($fullname =~ m{_ssim\.vhd$}) {      # ends in _ssim.vhd
661
      $has_unisim = 1;
662
    }
663
    if ($fullname =~ m{_[ft]sim\.vhd$}) {   # ends in _fsim.vhd or _tsim.vhd
664
      $has_simprim = 1;
665
    }
666
 
667
    # handle configuration statements (tag=val)
668
    if (defined $del && $del eq "=") {
669
      if (exists $conf_tbl{$tag}) {
670
        print STDERR "--- ignore $tag = $fullname\n" if $do_trace;
671
      } else {
672
        $conf_tbl{$tag} = $fullname;
673
        print STDERR "--- config $tag = $fullname\n" if $do_trace;
674
      }
675
      next;
676
    }
677
 
678
    # handle configurable lines (tag:val)
679
    if (defined $del && $del eq ":") {
680
      if (exists $conf_tbl{$tag}) {
681
        $fullname = $conf_tbl{$tag};
682
        print STDERR "--- use $tag = $fullname\n" if $do_trace;
683
      } else {
684
        print STDERR "--- use $tag = $fullname (default)\n" if $do_trace;
685
      }
686
    }
687
 
688
    # build vbom table
689
    push @{$vbom_tbl{$vbom}}, $fullname;
690
    print STDERR "--- add $fullname\n" if $do_trace;
691
 
692
    # if a vbom, queue if not not already read
693
    if ($fullname =~ m{\.vbom$} && not exists $read_tbl{$fullname} ) {
694
       push @vbom_list, $fullname;
695
       print STDERR "--- queue $fullname\n" if $do_trace;
696
    }
697
 
698
  }
699
 
700
  $top_done = 1;
701
 
702
  close (IFILE);
703
}
704
 
705
#-------------------------------------------------------------------------------
706
 
707
sub scan_vbom {
708
  my ($vbom) = @_;
709
 
710
  $level += 1;
711
  my $rank = 1000*$level + scalar(@{$vbom_tbl{$vbom}});
712
  print STDERR "--> $level: $vbom\n" if $do_trace;
713
 
714
  die "%vbomcov-E excessive vbom stack depth \n" if $level>=1000;
715
 
716
  foreach (@{$vbom_tbl{$vbom}}) {
717
    my $file = $_;
718
    $rank -= 1;
719
    if (m{\.vbom$}) {
720
      scan_vbom($file);
721
    } else {
722
      if (exists $file_tbl{$file}) {
723
        if ($rank > $file_tbl{$file}) {
724
          print STDERR "    $file   $file_tbl{$file} -> $rank\n" if $do_trace;
725
          $file_tbl{$file} = $rank;
726
        } else {
727
          print STDERR "    $file   $file_tbl{$file} (keep)\n" if $do_trace;
728
        }
729
      } else {
730
         $file_tbl{$file} = $rank;
731
         print STDERR "    $file   $file_tbl{$file} (new)\n" if $do_trace;
732
      }
733
    }
734
  }
735
 
736
  print STDERR "<-- $level: $vbom\n" if $do_trace;
737
  $level -= 1;
738
 
739
}
740
 
741
#-------------------------------------------------------------------------------
742
 
743
sub copy_edir {
744
  my ($file, $edir) = @_;
745
  print "cp -p $file $edir\n";
746
  system("cp -p $file $edir")==0 or die "cp -p failed: $?";
747
}
748
 
749
#-------------------------------------------------------------------------------
750
 
751
sub write_vbomdep {
752
  my ($target) = @_;
753
  print "#\n";
754
  print "# .dep_ on .vbom dependencies\n";
755
  print "#\n";
756
  foreach (sort keys %read_tbl) {
757
    print "$target : $_\n";
758
  }
759
}
760
 
761
#-------------------------------------------------------------------------------
762
 
763
sub print_help {
764
  print "usage: vbomconf  file.vbom\n";
765
  print "  --help           this message\n";
766
  print "  --trace          trace recursive processing of vbom's\n";
767
  print "  --dep_xst        generate xst dependencies for make (on stdout)\n";
768
  print "  --dep_ghdl       generate ghdl dependencies for make (on stdout)\n";
769
  print "  --dep_isim       generate isim dependencies for make (on stdout)\n";
770
  print "  --xst_prj        generate xst project file (on stdout)\n";
771
  print "  --isim_prj       generate isim project file (on stdout)\n";
772
  print "  --ghdl_a         generate and execute ghdl -a  (analyse)\n";
773
  print "  --ghdl_a_cmd     like ghdl_a, but only print command, no exec\n";
774
  print "  --ghdl_i         generate and execute ghdl -i  (inspect)\n";
775
  print "  --ghdl_i_cmd     like ghdl_i, but only print command, no exec\n";
776
  print "  --ghdl_m         generate and execute ghdl -m  (make)\n";
777
  print "  --ghdl_m_cmd     like ghdl_m, but only print command, no exec\n";
778
  print "  --xst_export=s   export all xst source files into directory s\n";
779
  print "  --ghdl_export=s  export all ghdl source files into directory s\n";
780
  print "  --isim_export=s  export all isim source files into directory s\n";
781
  print "  --flist          list all files touched by vbom for all tags\n";
782
}

powered by: WebSVN 2.1.0

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