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

Subversion Repositories or1200_soc

[/] [or1200_soc/] [trunk/] [boards/] [de1_board/] [sim/] [models/] [S29al032d_00/] [utilities/] [CreateSDF/] [mk_sdf_204.pl] - Blame information for rev 22

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 22 qaztronic
#!/usr/local/bin/perl
2
#
3
#   mk_sdf   : Perl replacement for C mk_sdf
4
#
5
#   Copyright (C) 2000, 1999 Free Model Foundry; http:/vhdl.org/fmf/
6
#   This program is free software; you can redistribute it and/or modify
7
#   it under the terms of the GNU General Public License version 2 as
8
#   published by the Free Software Foundation.
9
#
10
#   Author  : R. Munden
11
#   Date    : 20001115
12
#   Version : 2.0.4
13
#
14
#   Revision history:
15
#   2.0: 19990702
16
#      o Intial release of perl version
17
#   2.0.1: 19990722
18
#      o fixed problem with . in path for TimingModels
19
#   2.0.2: 20000616
20
#      o changed instance search to work with Mentor
21
#   2.0.3: 20001115
22
#      o changed to parse ":" without leading space
23
#      o fixed problem with . in path for TimingModels again
24
#   2.0.4: 20030405
25
#      o chaged SDF version to 3.0
26
#
27
#################################################################
28
#
29
# command line arguments:
30
 
31
# ARGV[0] - name of VHDL netlist
32
 
33
# global variables:
34
 
35
# %component_list - list of instance names by component name
36
# %instance_isin - list architectures by instances contained therein
37
# %instance_comp - list of component names by instance name
38
# %comp_lib - library each component (by name) is configured to
39
# @instance_list - array of all instance names in design in order found
40
 
41
$version = "2.0.4";
42
$design_name = '';
43
$timing_dir = '';
44
$diags = "off";
45
 
46
%keywords = (architecture => 1,
47
             component => 1,
48
             timingmodel => 1);
49
 
50
#    INPUT files
51
$CMD = "mk_sdf.cmd";
52
$VHD = '';  #  name of VHDL netlist
53
 
54
#    OUTPUT files
55
$RFV = "/tmp/short.vhd";  # reformatted VHDL
56
$sdf_file = '';   # name of SDF file
57
 
58
&read_cmd_file;
59
&get_names;
60
&reformat;
61
 
62
open INPUT, $RFV;
63
@lines = <INPUT>;
64
close INPUT;
65
 
66
$current_architecture = "";
67
 
68
foreach $line (@lines)
69
{
70
    @words = split / /, $line;
71
    foreach $word (@words)
72
    {
73
        $keywords{$word} == "1" and do { &$word(@words);};
74
        if ($component_list{$word})
75
        {
76
            $line =~ /(.+) : $word/ and do {
77
                if ($1 !~ /for/) {          # instantiation found
78
                $component_list{$word} = $component_list{$word} . $1;
79
                push (@instance_list, $1);
80
                $instance_name = $1;
81
                }
82
            };
83
            $instance_comp{$1} = $word;
84
            $instance_isin{$1} = $current_architecture;
85
            if ( $diags ne off ) {
86
                print "reading instance $instance_name: $word in $current_architecture\n";
87
            }
88
            $line =~ /for all : $word use entity (.+)/ and do
89
            {
90
                @config = split(/\./, $1);
91
                $comp_lib{$word} = $config[0];};
92
        }
93
    }
94
}
95
if ( $diags ne off ) {
96
    print "finished with netlist\n\n";
97
}
98
 
99
&begin_sdf;
100
&build_paths;
101
&close_sdf;
102
`rm $RFV`;
103
 
104
print "$time\n";
105
 
106
sub architecture
107
{
108
    $current_architecture = $_[3];
109
    push (@architectures, $current_architecture);
110
}
111
 
112
sub component
113
{
114
    if ($_[0] ne "end")
115
    {
116
        $name = $_[1];
117
        $arch_list{$current_architecture} =
118
            $arch_list{$current_architecture} . " " . $name;
119
    unless ($component_list{$name}) { $component_list{$name} = " ";}
120
    }
121
}
122
 
123
sub timingmodel
124
{
125
    $line =~ /timingmodel => \"(.+)\"/ and do {
126
        $model = $1;
127
        $model_name{$instance_name} = $model;
128
    };
129
}
130
 
131
sub begin_sdf
132
{
133
    if ( $diags ne off ) {
134
        print "writing SDF boilerplate\n";
135
    }
136
    $time = localtime;
137
    if (open(SDF, ">$sdf_file") !=1) { die "can't open $sdf_file\n";}
138
    print "Opening $sdf_file\n";
139
    print SDF "(DELAYFILE\n";
140
    print SDF " (SDFVERSION \"3.0\")\n";
141
    print SDF " (DESIGN \"$design_name\")\n";
142
    print SDF " (DATE \"$time\")\n";
143
    print SDF " (VENDOR \"Free Model Foundry\")\n";
144
    print SDF " (PROGRAM \"SDF timing utility(tm)\")\n";
145
    print SDF " (VERSION \"$version\")\n";
146
    print SDF " (DIVIDER /)\n";
147
    print SDF " (VOLTAGE)\n";
148
    print SDF " (PROCESS)\n";
149
    print SDF " (TEMPERATURE)\n";
150
    print SDF " (TIMESCALE 1ns)\n";
151
}
152
 
153
sub build_paths
154
{
155
    foreach $instance_list (@instance_list)
156
    {
157
        @instance = $instance_list;
158
        foreach $instance (@instance)
159
        {
160
            if ( $diags ne off ) {
161
                print "working on $instance\n";
162
            }
163
            if ($gtd =~ /true/i) {
164
                $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}/$timing_dir";
165
#                $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}./$timing_dir";
166
            } else {
167
                $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}/$timing_dir";
168
            }
169
            $timing_file = "$path/$instance_comp{$instance}_vhd.ftm";
170
            $timing_file =~ s/\s//;
171
            if ( $diags ne off ) {
172
                print "$instance should be in $timing_file\n";
173
            }
174
            if (-e $timing_file) {
175
                if ($model_name{$instance} ne "") {
176
                    print SDF " (CELL\n";
177
                    print SDF "  (CELLTYPE \"$instance_comp{$instance}\")\n";
178
                    $inst = $instance;
179
                    $full_inst = $instance;
180
                    while ($component_list{$instance_isin{$inst}}) {
181
                        $full_inst = "$component_list{$instance_isin{$inst}}/$full_inst";
182
                        $full_inst =~ s/\s+//;
183
                        $inst = $component_list{$instance_isin{$inst}};
184
                        $inst =~ s/\s+//;
185
#                print SDF "  (INSTANCE $component_list{$instance_isin{$instance}}/$instance)\n";
186
                    }
187
                    print SDF "  (INSTANCE $full_inst)\n";
188
                    &add_timing;
189
                }
190
            } else {
191
            if ( $diags ne off ) {
192
                print "$timing_file not found!\n";
193
            }
194
            }
195
        }
196
    }
197
}
198
 
199
sub add_timing
200
{
201
    $timing_found = "false";
202
    $part_found = "false";
203
#    unless ($lib_path{$comp_lib{$instance_comp{$instance}}})
204
    unless ($timing_file)
205
    {
206
        print "path to $timing_file not found\n";
207
        exit;
208
    }
209
    if ($gtd =~ /true/i) {
210
        $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}/$timing_dir";
211
#        $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}./$timing_dir";
212
    } else {
213
        $path = "$lib_path{$comp_lib{$instance_comp{$instance}}}/$timing_dir";
214
    }
215
    $timing_file = "$path/$instance_comp{$instance}_vhd.ftm";
216
    if (open(TF, "<$timing_file") !=1) { warn "can't open $timing_file\n"; }
217
    if ( $diags ne off ) {
218
        print "reading $timing_file\n";
219
    }
220
    $section_found = "false";
221
    while (<TF>)
222
    {
223
        next unless (/$model_name{$instance}/i || ($part_found eq "true"));
224
        $part_found = "true";
225
        if ( $diags ne off ) {
226
            print "found entry for $model_name{$instance}\n";
227
        }
228
        next unless (/<timing>/i || ($timing_found eq "true"));
229
        $timing_found = "true";
230
        next if (/<timing>/i);
231
        if (/<\/timing>/i)
232
        {
233
            print SDF " )\n";
234
            $timing_found = "false";
235
            $part_found = "false";
236
            $section_found = "true";
237
            last;
238
        } else {
239
            if (/%LABEL%/)
240
            {
241
                if ($component_list{$instance_isin{$instance}})
242
                {
243
                    $_ =~ s/%LABEL%/$component_list{$instance_isin{$instance}}\/$instance/;
244
                } else {
245
                    $_ =~ s/%LABEL%/$instance/;
246
                }
247
            }
248
            print SDF $_;
249
        }
250
    }
251
    unless ($section_found eq "true") {
252
        print "$model_name not found\n";
253
    }
254
}
255
 
256
sub close_sdf
257
{
258
    print SDF ")\n";
259
    print "closing $sdf_file\n";
260
    close(SDF);
261
}
262
 
263
# read mk_sdf.cmd
264
 
265
sub read_cmd_file {
266
 
267
    if (open(CMD, $CMD) !=1) { die "can't open $CMD\n"; }
268
    while (<CMD>) {
269
        chop;
270
        @fields = '';
271
        @fields = split;
272
        unless ($fields[0] =~ /#/) {
273
            if ($fields[0] =~ /SET/) {
274
                if ($fields[1] =~ /vhdl_file/) {$VHD = $fields[2]}
275
                if ($fields[1] =~ /sdffile_suffix/) {$suffix = $fields[2]}
276
                if ($fields[1] =~ /use_global_timing_dir/) {$gtd = $fields[2]}
277
                if ($fields[1] =~ /timingfile_dir/) {$timing_dir = $fields[2]}
278
                if ($fields[1] =~ /vendor/) {$vendor = $fields[2]}
279
                if ($fields[1] =~ /diagnostics/) {$diags = $fields[2]}
280
            }
281
        }
282
    }
283
    if ( $diags ne off ) {
284
        print "\nmk_sdf diagnostics on\n\n";
285
        print "vhdl_file $VHD\n";
286
        print "sdffile_suffix $suffix\n";
287
        print "use_global_timing_dir $gtd\n";
288
        print "timingfile_dir $timing_dir\n";
289
        print "vendor $vendor\n\n";
290
    }
291
}
292
#
293
 
294
# get name of netlist
295
 
296
sub get_names
297
{
298
 
299
    if ($ARGV[0] ne "") { $VHD = "$ARGV[0]"; }
300
 
301
    if ($ARGV[1] eq "")
302
    {
303
        @name = split(/\./,$VHD);
304
        $design_name = $name[0];
305
        } else {
306
        $design_name = "$ARGV[1]";
307
    }
308
    $sdf_file = $design_name . $suffix;
309
    if ($gtd =~ /false/i)
310
    {
311
        if ($vendor =~ /modeltech/i) { &read_mti; }
312
        if ($vendor =~ /cadence/i) { &read_cds; }
313
    }
314
    if ( $diags ne off ) {
315
        print "design name is $design_name\n\n";
316
    }
317
}
318
#
319
################################################################
320
#
321
 
322
# reformat netlist
323
 
324
sub reformat
325
{
326
    $entfound = false;
327
 
328
    if (open(VHD, $VHD) !=1) { die "can't open $VHD\n"; }
329
    if (open(OUT, ">$RFV") !=1) { die "can't open $OUT\n"; }
330
 
331
    while (<VHD>) {
332
        if (/^--|library|package/i) { next }
333
        if (/--/) {              # strip embeded comments
334
            @line = split("--");
335
            $_ = $line[0];
336
        }
337
        s/:/ : /g;
338
        s/;/ ;/g;
339
        s/\s+/ /g;      # reduces spaces and tabs
340
        s/^\s//g;        # no leading spaces
341
        if (/entity/i) {
342
            $entfound = "true";
343
        }
344
        chomp;
345
        if ( $entfound eq true ) {
346
            print OUT lc($_);
347
            if (/;|is|begin/i) { print OUT "\n"; }
348
        }
349
    }
350
 
351
    close OUT;
352
    if ( $diags ne off ) {
353
        print "reformatted netlist written to $RFV\n\n";
354
    }
355
 
356
}
357
 
358
# read ModelTech's modelsim.ini file
359
 
360
sub read_mti
361
{
362
    $lib_found = "false";
363
    if ($ENV{MODELPATH})
364
    {
365
        $ini_file = "$ENV{MODELPATH}/../modelsim.ini";
366
        if (open(INI, "$ini_file") !=1) { die "can't open $ini_file\n";}
367
        if ( $diags ne off ) {
368
            print "reading $ini_file\n\n";
369
        }
370
        while (<INI>)
371
        {
372
           if ($lib_found eq "true")
373
           {
374
               chomp;
375
               if (/\[.+\]/) { last; }
376
               s/\s+//;
377
               @lib_line = split(/=/);
378
               $lib_line[1] =~ s/\/work//;
379
               $lib_path{$lib_line[0]} = $lib_line[1];
380
           } elsif (/\[Library\]/i)
381
           {
382
               $lib_found = "true";
383
               next;
384
           }
385
        }
386
    } else {
387
        print "\$MODELPATH environment variable not found\n";
388
    }
389
    $lib_found = "false";
390
    if (-e "modelsim.ini")
391
    {
392
        $ini_file = "modelsim.ini";
393
        if (open(INI, "$ini_file") !=1) { die "can't open $ini_file\n";}
394
        if ( $diags ne off ) {
395
            print "reading $ini_file\n\n";
396
        }
397
        while (<INI>)
398
        {
399
           if ($lib_found eq "true")
400
           {
401
               chomp;
402
               if (/\[.+\]/) { last; }
403
               s/\s+//;
404
               @lib_line = split(/=/);
405
               $lib_line[1] =~ s/\/work//;
406
               $lib_path{$lib_line[0]} = $lib_line[1];
407
           } elsif (/\[Library\]/i)
408
           {
409
               $lib_found = "true";
410
               next;
411
           }
412
        }
413
    } else {
414
        print "local modelsim.ini file not found, may not be needed\n";
415
    }
416
}
417
 
418
# read Cadence's cds.lib file
419
 
420
sub read_cds
421
{
422
    if ($ENV{CDS_VHDL})
423
    {
424
        $ini_file = "$ENV{CDS_VHDL}/files/cds.lib";
425
        if (open(INI, "$ini_file") !=1) { die "can't open $ini_file\n";}
426
        if ( $diags ne off ) {
427
            print "reading $ini_file\n\n";
428
        }
429
        while (<INI>)
430
        {
431
           chomp;
432
           s/\s+/ /;
433
           if (/define/i)
434
           {
435
               @lib_line = split;
436
               $lib_path{$lib_line[1]} = $lib_line[2];
437
           }
438
        }
439
    } else {
440
        print "\$CDS_VHDL environment variable not found\n";
441
    }
442
    if (-e "cds.lib")
443
    {
444
        $ini_file = "cds.lib";
445
        if (open(INI, "$ini_file") !=1) { die "can't open $ini_file\n";}
446
        if ( $diags ne off ) {
447
            print "reading $ini_file\n\n";
448
        }
449
        while (<INI>)
450
        {
451
           chomp;
452
           s/\s+/ /;
453
           if (/define/i)
454
           {
455
               @lib_line = split;
456
               $lib_path{$lib_line[1]} = $lib_line[2];
457
           }
458
        }
459
    } else {
460
        print "local cds.lib file not found, may not be needed\n";
461
    }
462
}

powered by: WebSVN 2.1.0

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