# ========== Copyright Header Begin ==========================================
# OpenSPARC T2 Processor File: Objects.pm
# Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved
# 4150 Network Circle, Santa Clara, California 95054, U.S.A.
# * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
# For the avoidance of doubt, and except that if any non-GPL license
# choice is available it will apply instead, Sun elects to use only
# the General Public License version 2 (GPLv2) at this time for any
# software where a choice of GPL license versions is made
# available with the language indicating that GPLv2 or any later version
# may be used, or where a choice of which version of the GPL is applied is
# Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
# CA 95054 USA or visit www.sun.com if you need additional information or
# ========== Copyright Header End ============================================
package DiagList
::Objects
;
###############################################################################
our $COMMENT_RE = qr
|\
/\/|;
#############################################################################
tie
my %buildtags, 'Tie::IxHash';
$this->{buildtags
} = \
%buildtags;
tie
my %groups, 'Tie::IxHash';
$this->{groups
} = \
%groups;
$this->parse($file, $fh) if defined $file;
#############################################################################
if(defined $fh and not (ref $fh and $fh->isa('IO::File'))) {
$fh->fdopen(fileno($handle), "r") or
fatal
"Cannot create IO::File object from handle $handle\n";
$fh = IO
::File
->new("<$file") or fatal
"Cannot open $file: $!";
if(/^\#\s*(\d+)\s*\"(.*)\"/) {
my ($tag, $args) = ($1, $2);
fatal
"Nesting error, </runargs> with no matching beginning",
$file, $line unless @runarg_stack;
} elsif($tag eq 'debugowner') {
fatal
"Nesting error, </debugowners> with no matching beginning",
$file, $line unless @owner_stack;
my $group = pop @group_stack;
fatal
"Nesting error: /$tag found, /$group->{name} expected",
$file, $line unless $tag eq $group->{name
};
undef $cur_build_tag if $group->compile_tag;
undef $cur_name_tag if $group->name_tag;
delete $group_args{$group->{name
}};
push @runarg_stack, $args;
} elsif($tag eq 'debugowner') {
push @owner_stack, $args;
my $buildtag = ($args =~ /\bsys=(\S+)/);
$buildtag = $1 if $buildtag;
my $nametag = ($args =~ s/\bname=(\S+)\s*//);
$nametag = $1 if $nametag;
fatal
"Build tag $tag multiply defined." , $file, $line
if exists $this->{buildtags
}{$tag};
chat
"Inserting tags: $tag=$buildtag\n";
(my $buildargs = $args) =~ s/\b(sys=\S+)/-$1/;
$this->{buildtags
}{$tag} = $buildargs;
# Strip sys= argument for use in group args
$args =~ s/\bsys=(\S)+\s*//;
fatal
"Nametag $nametag defined within nametag $cur_name_tag",
$file, $line if defined $cur_name_tag;
$cur_name_tag = $nametag;
if(exists $this->{groups
}{$tag}) {
fatal
"Group $tag is nested inside itself", $file, $line
if exists $group_args{$tag};
$group = $this->{groups
}{$tag};
$group = DiagList
::Group
->new(name
=> $tag);
$group->compile_tag($buildtag) if $buildtag;
$group->name_tag($nametag) if $nametag;
$this->{groups
}{$group->{name
}} = $group;
$group_args{$group->{name
}} = $args;
push @group_stack, $group;
my $diag = DiagList
::Diag
->new_from_line($_, $cur_name_tag);
fatal
"Diag $diag->{alias} appears outside any group.", $file, $line
fatal
"Diag $diag->{alias} appears outside any name tag.", $file, $line
unless defined $cur_name_tag;
fatal
"Diag $diag->{name} appears outside any build tag.", $file, $line
unless defined $cur_build_tag;
foreach my $group (@group_stack) {
my $group_diag = $diag->new(); # Clone diag object
$group_diag->prepend_args([@runarg_stack,
$group_args{$group->{name
}}]);
$group_diag->set_group($group->{name
});
$group->add_diag($group_diag, $cur_build_tag);
my $owner = $owner_stack[$#owner_stack];
$group_diag->add_owner($owner) unless
defined $group_diag->get_owner(); # diag has owner on cmdline
fatal
"End of file with <runargs> still open!" if @runarg_stack;
#############################################################################
return $this->{buildtags
};
#############################################################################
return keys %{$this->{buildtags
}};
#############################################################################
return unless exists $this->{buildtags
}{$build_tag};
return $this->{buildtags
}{$build_tag};
#############################################################################
#############################################################################
return keys %{$this->{groups
}};
#############################################################################
return unless exists $this->{groups
}{$group};
return $this->{groups
}{$group};
#############################################################################
###############################################################################
##############################################################################
############################################################################
$this = fields
::new
($this);
foreach my $arg (keys %args) {
$this->{$arg} = $args{$arg};
$this->{tags
} = {} unless defined $this->{tags
};
############################################################################
$this->{name
} = $name if defined $name;
############################################################################
$this->{compile_tag
} = undef unless exists $this->{compile_tag
};
$this->{compile_tag
} = $tag if defined $tag;
return $this->{compile_tag
};
############################################################################
$this->{name_tag
} = undef unless exists $this->{name_tag
};
$this->{name_tag
} = $tag if defined $tag;
return $this->{name_tag
};
############################################################################
return keys %{$this->{tags
}};
############################################################################
return unless exists $this->{tags
}{$buildtag};
return keys %{$this->{tags
}{$buildtag}};
############################################################################
return unless exists $this->{tags
}{$buildtag};
return $this->{tags
}{$buildtag};
############################################################################
return unless exists $this->{tags
}{$buildtag};
return unless exists $this->{tags
}{$buildtag}{$diagname};
return $this->{tags
}{$buildtag}{$diagname};
############################################################################
if(not defined $this->{tags
}{$buildtag}) {
tie
my %sys, 'Tie::IxHash';
$this->{tags
}{$buildtag} = \
%sys;
my $gname = $this->{name
};
warn "WARNING: Diag $key multiply defined in group $gname\n"
if (exists $this->{tags
}{$buildtag}{$key} and display_warnings
());
$this->{tags
}{$buildtag}{$key} = $diag;
############################################################################
##############################################################################
our @FILE_SUFFIXES = qw(s pal vr tpt);
############################################################################
$this = fields
::new
(ref $that);
foreach my $field (keys %$that) {
if(ref $that->{$field} eq 'ARRAY') {
$this->{$field} = [ @
{$that->{$field}} ];
} elsif(ref $that->{$field}) {
die "Don't know how to clone non-array ref field $field in ".
$this->{$field} = $that->{$field};
$this = fields
::new
($this);
foreach my $arg (keys %args) {
$this->{$arg} = $args{$arg};
$this->{args
} = [] unless defined $this->{args
};
$this->{files
} = [] unless defined $this->{files
};
############################################################################
$nametag = '' unless defined $nametag;
my @fields = split ' ', $line;
my $alias = shift @fields;
my $suffix_re = join '|', @FILE_SUFFIXES;
$suffix_re = qr/($suffix_re)/;
foreach my $field (@fields) {
if($field !~ /^[-+]/ and $field =~ /\.$suffix_re$/o) {
if($field =~ /^debugowner=(\S+)$/) {
name
=> "$alias:$nametag",
$diag->{debugowner
} = $debugowner if defined $debugowner;
############################################################################
return $this->{files
}[0];
############################################################################
unshift @
{$this->{args
}}, @
$args;
############################################################################
$this->{debugowner
} = $owner;
############################################################################
return $this->{debugowner
} if defined $this->{debugowner
};
############################################################################
my @args = grep { $_ =~ /\S/ } @
{$this->{args
}};
my $args = (scalar @args) ?
join ' ', @args : '';
my $files = join ' ', @
{$this->{files
}};
my $sep = (length $args) ?
' ' : '';
my $cmdline = "$args$sep$files";
############################################################################
my $line = $this->get_cmdline;
my @words = `showargv $line`;
# Strip off ARGV stuff at beginning of line
# If next line doesn't start with /^ARGV/, then there must be an
$word =~ s/^ARGV\[\d+\]\://;
while($words[$i] !~ /^ARGV/) {
my $new_word = $words[$i];
$word .= "\n" . $new_word;
# get rid of argv[0] (showargv executable)
############################################################################
############################################################################
############################################################################
############################################################################
$this->{group
} = $group if defined $group;
############################################################################
############################################################################
my $fullname = $this->{alias
} . ':' . $this->{nametag
} . ':' .
############################################################################
############################################################################
##############################################################################