Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / sam / cpus / vonk / n2 / lib / ras / bin / process_xml
CommitLineData
920dae64
AT
1# process_xml - process xml dispatches xml files to the correct
2# xml-processing program. All xml files should begin with a comment
3# line like the following:
4#
5# <!-- interpreter=program_name -->
6#
7# where program_name is the name of the program that should process
8# the xml file. process_xml assumes that the program is located in
9# the bin/ directory of the Riesling workspace, so only the name of
10# the program needs to be provided.
11use strict;
12use Getopt::Std;
13use vars qw( $opt_S $opt_I );
14
15my $perl_interpreter = $^X;
16
17
18getopts('S:I:');
19# S - source file destination path
20# I - include file destination path
21
22$opt_S = '-S ' . $opt_S if defined $opt_S;
23$opt_I = '-I ' . $opt_I if defined $opt_I;
24
25my $xmlFile = $ARGV[$#ARGV];
26open ( XML_FILE, "$xmlFile" ) || die "Can't open XML file: $xmlFile\n";
27while( <XML_FILE> ){
28 chomp;
29 if( /interpreter=([\w\d\.]+)/ ){
30 my $extra_args;
31 my $line = $_;
32 close( XML_FILE );
33 my $fullpath = $0;
34 my $program = $1;
35 $extra_args = $1 if $line =~ /args=\'([\w\d\s\-]+)\'/;
36 my $perl_lib;
37 ( $perl_lib = $fullpath ) =~ s#bin/process_xml#lib/perl#g;
38 $fullpath =~ s/process_xml/$program/g;
39
40 my $r = system( "$perl_interpreter -I$perl_lib $fullpath $opt_S $opt_I $extra_args @ARGV " );
41 if( $r != 0 ){
42 die "$program returned with status $r\n";
43 } else {
44 exit 0;
45 }
46 }
47}
48
49die "Couldn't locate an interpreter in $xmlFile\n";
50
51__END__
52
53=head1 NAME
54
55process_xml - A frontend to all Riesling XML-processing scripts.
56
57=head1 SYNOPSYS
58
59process_xml [script arguments] xml file
60
61=head1 DESCRIPTION
62
63process_xml is a frontend to all Rielsing XML-processing scripts. All XML specification
64files written for Riesling must have the following XML comment as their first nonblank line.
65
66<!-- interpreter=I<script_name> -->
67
68process_xml reads the XML file whose name was specified on the command line and invokes the
69the appropriate interpreter specified in the the XML comment line. The interpreter is assumed
70to be in the Riesling workspace's bin directory.
71
72Extra arguments can be passed to a script using the optional I<args> directive provided in
73an XML file's interpreter line. See the example below. This should be used to pass
74script-specific or file-specific arguments.
75
76<!-- interpreter=I<script_name> args='<extra_args>' -->
77
78If process_xml successfully invokes the specified interpreter, it will return the exit status
79of the interpreter. If the interpreter is not found, is not executable, or the interpretation
80directive in the XML file cannot be located, process_xml will issue and error message to
81stderr and exit with nonzero status.
82
83
84=head1 OPTIONS
85
86=item I<script arguments>
87
88All arguments passed to process_xml are passed-on to the specified interpreter.
89
90=head1 EXAMPLES
91
92 process_xml -n Mmu -I /src/Riesling/include/mmu -S /src/Riesling/src/mmu MmuConfigReg.xml
93
94Here, process_xml is being invoked on the file MmuConfigReg.xml which is processes by xml2reg.
95All of the arguments passed to process_xml are passed on to xml2reg.