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

Subversion Repositories w11

[/] [w11/] [tags/] [w11a_V0.7/] [tools/] [bin/] [vbomconv] - Blame information for rev 36

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

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

powered by: WebSVN 2.1.0

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