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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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