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

Subversion Repositories veristruct

[/] [veristruct/] [trunk/] [veristruct.pl] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 julius
#!/usr/bin/perl
2
#######################################################################
3
# 
4
# This file is a part of the Rachael SPARC project accessible at
5
# https://www.rachaelsparc.org. Unless otherwise noted code is released
6
# under the Lesser GPL (LGPL) available at http://www.gnu.org.
7
#
8
# Copyright (c) 2005: 
9
#   Michael Cowell
10
#
11
# Rachael SPARC is based heavily upon the LEON SPARC microprocessor
12
# released by Gaisler Research, at http://www.gaisler.com, under the
13
# LGPL. Much of the architectural work on Rachael was done by g2
14
# Microsystems. Contact michael.cowell@g2microsystems.com for more
15
# information.
16
#
17
#######################################################################
18 3 julius
# $Id: veristruct.pl,v 1.2 2008-10-10 21:09:26 julius Exp $
19
# $URL: $
20
# $Rev: $
21 2 julius
# $Author: julius $
22
######################################################################
23
#
24
# This file is the main module of the Veristruct Perl program.
25
#
26
# Veristruct provides (some) struct support for the Verilog language
27
# by pre-processing Veristruct (.vs) files to produce IEEE1364.1995
28
# (Verilog 1995) compliant source code.
29
#
30
# All structs are defined in seperate (.struct) files, that use a
31
# syntax very similar to C. Please see attached documentation (in the
32
# doc folder) for more information.
33
#
34
######################################################################
35
 
36
use Verilog::Veristruct::Structlib;
37
use Verilog::Veristruct::File;
38
 
39
#
40
# Globals
41
#
42
$debug = 0;
43
$infile = '';
44
$outfile = '';
45
@libpaths;
46
$overwrite = '';
47
$makefile = 0;
48
$ignore = 0;
49
 
50
#
51
# Command line options processing
52
#
53
sub init()
54
{
55
    use Getopt::Long;
56
    my $help;
57
    GetOptions ("help" => \$help,
58
                "debug" => \$debug,
59
                "write" => \$overwrite,
60
                "infile=s" => \$infile,
61
                "outfile=s" => \$outfile,
62
                "libpath|l=s" => \@libpaths,
63
                "makefile" => \$makefile,
64
                "forget-unfound" => \$ignore) or usage();
65
    @libpaths = split(/,/,join(',',@libpaths));
66
    usage() if $help;
67
    if ((!($infile)) or (!($outfile))) {
68
        usage();
69
    } else {
70
        process();
71
    }
72
}
73
 
74
#
75
# Message about this program and how to use it
76
#
77
sub usage()
78
{
79
    print STDERR << "EOF";
80
 
81
  Veristruct parses .struct and .vs files to create IEEE1364.1995
82
  (Verilog) compliant .v files.
83
 
84
    usage: $0 [-h -d -w -L path] -i file -o file
85
 
86
      -h, --help               : this (help) message
87
      -d, --debug              : print debugging messages to stderr
88
      -w, --write              : overwrite output file
89
      -i file, --infile=file   : .vs file containing veristruct
90
      -o file, --outfile=file  : .v file that will be written
91
      -L path, --libpath=path  : library path for .struct files
92
                                 Note: multiple paths may be specified
93
      -m, --makefile           : Write a makefile to build a Verilog
94
                                 module from this Veristruct module.
95
                                 Dependencies are detected and included.
96
                                 The destination file is specified with
97
                                 the normal -o option.
98
      -f, --forget-unfound     : forget (ignore) unfound modules instead
99
                                 of error-ing.
100
 
101
    example: $0 -d -i module.vs -o module.v
102
 
103
EOF
104
    exit;
105
}
106
 
107
sub process() {
108
 
109
    open($ifh, "<$infile") or die
110
        "Couldn't open $infile.";
111
    if (-e $outfile and !($overwrite)) {
112
        die "$outfile exists (and -w not specified). Not overwriting.";
113
    }
114
    $myfile = new Verilog::Veristruct::File;
115
    $myfile->load($ifh) or die
116
        "Couldn't load $infile.";
117
    # Add the current folder to libpaths
118
    push(@libpaths, ".");
119
    if ($makefile) {
120
        $myfile->generate_makefile($debug, $ignore, \@libpaths, $infile) or die
121
            "Parsing of $infile failed";
122
    } else {
123
        $myfile->replace_structs($debug, $ignore, \@libpaths) or die
124
            "Parsing of $infile failed.";
125
    }
126
    open($ofh, ">$outfile") or die
127
        "Couldn't open $outfile for writing.";
128
    print $ofh ${$myfile->{"buffer"}};
129
 
130
}
131
 
132
init();
133
 

powered by: WebSVN 2.1.0

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