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