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

Subversion Repositories w11

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

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

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

powered by: WebSVN 2.1.0

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