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

Subversion Repositories veristruct

[/] [veristruct/] [trunk/] [Verilog/] [Veristruct/] [Structlib.pm] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 julius
#######################################################################
2
# 
3
# This file is a part of the Rachael SPARC project accessible at
4
# https://www.rachaelsparc.org. Unless otherwise noted code is released
5
# under the Lesser GPL (LGPL) available at http://www.gnu.org.
6
#
7
# Copyright (c) 2005: 
8
#   Michael Cowell
9
#
10
# Rachael SPARC is based heavily upon the LEON SPARC microprocessor
11
# released by Gaisler Research, at http://www.gaisler.com, under the
12
# LGPL. Much of the architectural work on Rachael was done by g2
13
# Microsystems. Contact michael.cowell@g2microsystems.com for more
14
# information.
15
#
16
#######################################################################
17
# $Id: Structlib.pm,v 1.1 2008-10-10 21:13:56 julius Exp $
18
# $URL: $ 
19
# $Rev: $
20
# $Author: julius $
21
######################################################################
22
#
23
# Class for a collection of structs
24
#
25
######################################################################
26
 
27
use Verilog::Veristruct::Struct;
28
 
29
package Verilog::Veristruct::Structlib;
30
 
31
sub new {
32
    $classobject = {};
33
    local %structs;
34
    $classobject->{"structs"} = \%structs;
35
    bless($classobject);
36
    return $classobject;
37
}
38
 
39
# Parses a string (that should contain multiple struct defns)
40
sub parse {
41
    my ($self, $struct_string, $string_position) = @_;
42
 
43
    # Set search to begin at the relevant point in the buffer
44
    pos($$struct_string) = $string_position;
45
 
46
    # Replace comments with nothing
47
    # Line comments:
48
    $$struct_string =~ s/\s*\/\/.*?$//mg;
49
    # Block comments:
50
    $$struct_string =~ s/\s*\/\*.*?\*\///gs;
51
 
52
    while ($$struct_string =~ m/\G\s*struct/is) {
53
        $local_struct = new Verilog::Veristruct::Struct;
54
        $pos = $local_struct->parse($struct_string,
55
                                    pos($$struct_string));
56
        if (!$pos) {
57
            print "Struct failed to parse.\n";
58
            return;
59
        }
60
        $self->{"structs"}->{$local_struct->get_name()}
61
          = $local_struct;
62
        pos($$struct_string) = $pos;
63
    }
64
 
65
    # This should be the end of the buffer - check
66
    if ($$struct_string !~ m/\G\s*$/mc) {
67
        print "EOF expected - not found: ",
68
        substr($$struct_string, pos($$struct_string)), "\n";
69
        return;
70
    }
71
 
72
    return pos($$struct_string);
73
}
74
 
75
# Load structs from a file (should already be opened)
76
sub load {
77
    my ($self, $handle) = @_;
78
    # Read in the whole file
79
    while ($line = <$handle>) {
80
        $buffer .= $line;
81
    }
82
    $self->parse(\$buffer, 0);
83
}
84
 
85
# For debugging:
86
sub print_info {
87
    my ($self) = @_;
88
    foreach $name (keys (%{$self->{"structs"}})) {
89
        print "Info for struct named: ", $name, "\n";
90
        $self->{"structs"}->{$name}->print_elem_info();
91
    }
92
}
93
 
94
# Returns the names of the structs that we know
95
sub get_struct_names {
96
    my ($self) = @_;
97
    return keys (%{$self->{"structs"}});
98
}
99
 
100
1;

powered by: WebSVN 2.1.0

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