Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / n2 / lib / ras / bin / process_xml
# process_xml - process xml dispatches xml files to the correct
# xml-processing program. All xml files should begin with a comment
# line like the following:
#
# <!-- interpreter=program_name -->
#
# where program_name is the name of the program that should process
# the xml file. process_xml assumes that the program is located in
# the bin/ directory of the Riesling workspace, so only the name of
# the program needs to be provided.
use strict;
use Getopt::Std;
use vars qw( $opt_S $opt_I );
my $perl_interpreter = $^X;
getopts('S:I:');
# S - source file destination path
# I - include file destination path
$opt_S = '-S ' . $opt_S if defined $opt_S;
$opt_I = '-I ' . $opt_I if defined $opt_I;
my $xmlFile = $ARGV[$#ARGV];
open ( XML_FILE, "$xmlFile" ) || die "Can't open XML file: $xmlFile\n";
while( <XML_FILE> ){
chomp;
if( /interpreter=([\w\d\.]+)/ ){
my $extra_args;
my $line = $_;
close( XML_FILE );
my $fullpath = $0;
my $program = $1;
$extra_args = $1 if $line =~ /args=\'([\w\d\s\-]+)\'/;
my $perl_lib;
( $perl_lib = $fullpath ) =~ s#bin/process_xml#lib/perl#g;
$fullpath =~ s/process_xml/$program/g;
my $r = system( "$perl_interpreter -I$perl_lib $fullpath $opt_S $opt_I $extra_args @ARGV " );
if( $r != 0 ){
die "$program returned with status $r\n";
} else {
exit 0;
}
}
}
die "Couldn't locate an interpreter in $xmlFile\n";
__END__
=head1 NAME
process_xml - A frontend to all Riesling XML-processing scripts.
=head1 SYNOPSYS
process_xml [script arguments] xml file
=head1 DESCRIPTION
process_xml is a frontend to all Rielsing XML-processing scripts. All XML specification
files written for Riesling must have the following XML comment as their first nonblank line.
<!-- interpreter=I<script_name> -->
process_xml reads the XML file whose name was specified on the command line and invokes the
the appropriate interpreter specified in the the XML comment line. The interpreter is assumed
to be in the Riesling workspace's bin directory.
Extra arguments can be passed to a script using the optional I<args> directive provided in
an XML file's interpreter line. See the example below. This should be used to pass
script-specific or file-specific arguments.
<!-- interpreter=I<script_name> args='<extra_args>' -->
If process_xml successfully invokes the specified interpreter, it will return the exit status
of the interpreter. If the interpreter is not found, is not executable, or the interpretation
directive in the XML file cannot be located, process_xml will issue and error message to
stderr and exit with nonzero status.
=head1 OPTIONS
=item I<script arguments>
All arguments passed to process_xml are passed-on to the specified interpreter.
=head1 EXAMPLES
process_xml -n Mmu -I /src/Riesling/include/mmu -S /src/Riesling/src/mmu MmuConfigReg.xml
Here, process_xml is being invoked on the file MmuConfigReg.xml which is processes by xml2reg.
All of the arguments passed to process_xml are passed on to xml2reg.