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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.61/] [tools/] [bin/] [vbomconv] - Blame information for rev 26

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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