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

Subversion Repositories w11

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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