summaryrefslogtreecommitdiffstats
path: root/src/tools/scripts/ppeParseProcSbeFixed.pl
blob: f58a0ef5f339f35b15486d5a3aa700d329521591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
#!/usr/bin/perl
# IBM_PROLOG_BEGIN_TAG
# This is an automatically generated prolog.
#
# $Source: src/tools/scripts/ppeParseProcSbeFixed.pl $
#
# OpenPOWER sbe Project
#
# Contributors Listed Below - COPYRIGHT 2015,2016
# [+] International Business Machines Corp.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied. See the License for the specific language governing
# permissions and limitations under the License.
#
# IBM_PROLOG_END_TAG
# Purpose:  This perl script will parse HWP Attribute XML files and
# initfile attr files and create the fapiGetInitFileAttr() function
# in a file called fapiAttributeService.C

use strict;

#------------------------------------------------------------------------------
# Print Command Line Help
#------------------------------------------------------------------------------
my $numArgs = $#ARGV + 1;
if ($numArgs < 3)
{
    print ("Usage: ppeParseProcSbeFixed.pl <output dir>\n");
    print ("           [<if-attr-file1> <if-attr-file2> ...]\n");
    print ("           -a <attr-xml-file1> [<attr-xml-file2> ...]\n");
    print ("  This perl script will parse if-attr files (containing the\n");
    print ("  attributes used by the initfile) and attribute XML files\n");
    print ("  (containing all HWPF attributes) and create the\n");
    print ("  fapiGetInitFileAttr() function in a file called\n");
    print ("  fapiAttributeService.C. Only the attributes specified in\n");
    print ("  the if-attr files are supported. If no if-attr files are\n");
    print ("  specified then all attributes are supported\n");
    exit(1);
}

#------------------------------------------------------------------------------
# Specify perl modules to use
#------------------------------------------------------------------------------
use XML::Simple;
my $xml = new XML::Simple (KeyAttr=>[]);

# Uncomment to enable debug output
#use Data::Dumper;

#------------------------------------------------------------------------------
# Open output file for writing
#------------------------------------------------------------------------------
my $sysFile = $ARGV[0];
$sysFile .= "/";
$sysFile .= "proc_sbe_fixed_system.H";
open(SYFILE, ">", $sysFile);

my $chipFile = $ARGV[0];
$chipFile .= "/";
$chipFile .= "proc_sbe_fixed_proc_chip.H";
open(CHFILE, ">", $chipFile);

my $exFile = $ARGV[0];
$exFile .= "/";
$exFile .= "proc_sbe_fixed_ex.H";
open(EXFILE, ">", $exFile);

my $coreFile = $ARGV[0];
$coreFile .= "/";
$coreFile .= "proc_sbe_fixed_core.H";
open(COFILE, ">", $coreFile);

my $eqFile = $ARGV[0];
$eqFile .= "/";
$eqFile .= "proc_sbe_fixed_eq.H";
open(EQFILE, ">", $eqFile);

my $pervFile = $ARGV[0];
$pervFile .= "/";
$pervFile .= "proc_sbe_fixed_perv.H";
open(PEFILE, ">", $pervFile);



my $xmlFiles = 0;
my $attCount = 0;
my $numIfAttrFiles = 0;
my @attrSystemIds;
my @attrChipIds;
my @attrExIds;
my @attrCoreIds;
my @attrEqIds;
my @attrPervIds;



#------------------------------------------------------------------------------
# Element names
#------------------------------------------------------------------------------
my $attribute = 'attribute';

#------------------------------------------------------------------------------
# For each argument
#------------------------------------------------------------------------------
my $argfile = $ARGV[1];
my $entries = $xml->XMLin($argfile, ForceArray => ['entry']);
foreach my $entr (@{$entries->{entry}}) {

    my $inname = $entr->{name};

    # Skip virtual attributes
    if(exists $entr->{virtual})
    {
        next;
    }

    # read XML file. The ForceArray option ensures that there is an array of
    # elements even if there is only one such element in the file

    foreach my $argnum (2 .. $#ARGV)
    {
        my $infile = $ARGV[$argnum];

        my $attributes = $xml->XMLin($infile, ForceArray => ['attribute']);

        # Uncomment to get debug output of all attributes
        #print "\nFile: ", $infile, "\n", Dumper($attributes), "\n";

        #--------------------------------------------------------------------------
        # For each Attribute
        #--------------------------------------------------------------------------
        foreach my $attr (@{$attributes->{attribute}})
        {

            if($attr->{id} eq $inname) {

                #------------------------------------------------------------------
                # Check that the AttributeId exists
                #------------------------------------------------------------------
                if (! exists $attr->{id})
                {
                    print ("fapiParseAttributeInfo.pl ERROR. Att 'id' missing\n");
                    exit(1);
                }

                my @targets = split(",", $attr->{targetType});
                my $targetTypeMatched = 0;

                foreach my $target (@targets)
                {

                    if ($target eq "TARGET_TYPE_SYSTEM") {

                        push(@attrSystemIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } elsif ($target eq "TARGET_TYPE_PROC_CHIP") {

                        push(@attrChipIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } elsif ($target eq "TARGET_TYPE_CORE") {

                        push(@attrCoreIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } elsif ($target eq "TARGET_TYPE_EQ") {

                        push(@attrEqIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } elsif ($target eq "TARGET_TYPE_EX") {

                        push(@attrExIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } elsif ($target eq "TARGET_TYPE_PERV") {

                        push(@attrPervIds, $attr);
                        $targetTypeMatched = 1;
                        last;

                    } else {

                        print ("ppeParseProcSbeFixed.pl WARNING. Unsupported ".
                            "target type: $target for attribute $inname in $infile\n");
                        next;

                    }
                }
                if($targetTypeMatched eq 0)
                {
                        print ("ppeParseProcSbeFixed.pl ERROR. Unsupported ".
                            "target type: $attr->{targetType} for attribute $inname in $infile\n");
                        exit(1);
                }
            }
        }
    }
}


print SYFILE "// proc_sbe_fixed_system.H\n";
print SYFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print SYFILE "#ifndef __PROC_SBE_FIXED_SYSTEM_H__\n";
print SYFILE "#define __PROC_SBE_FIXED_SYSTEM_H__\n\n";
foreach my $attr (@attrSystemIds)
{

    my $value = uc $attr->{valueType};
    print SYFILE "PROC_SBE_FIXED_$value($attr->{id});\n"


}
print SYFILE "\n#endif  // __PROC_SBE_FIXED_SYSTEM_H__";

print CHFILE "// proc_sbe_fixed_proc_chip.H\n";
print CHFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print CHFILE "#ifndef __PROC_SBE_FIXED_PROC_CHIP_H__\n";
print CHFILE "#define __PROC_SBE_FIXED_PROC_CHIP_H__\n\n";
foreach my $attr (@attrChipIds)
{

    my $value = uc $attr->{valueType};
    print CHFILE "PROC_SBE_FIXED_$value($attr->{id});\n"


}
print CHFILE "\n#endif  // __PROC_SBE_FIXED_PROC_CHIP_H__";

print EXFILE "// proc_sbe_fixed_ex.H\n";
print EXFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print EXFILE "#ifndef __PROC_SBE_FIXED_EX_H__\n";
print EXFILE "#define __PROC_SBE_FIXED_EX_H__\n";
foreach my $attr (@attrExIds)
{

    my $value = uc $attr->{valueType};
    print EXFILE "PROC_SBE_FIXED_TARGET_$value($attr->{id}, EX_TARGET_COUNT);\n"


}
print EXFILE "\n#endif  // __PROC_SBE_FIXED_EX_H__";


print COFILE "// proc_sbe_fixed_co.H\n";
print COFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print COFILE "#ifndef __PROC_SBE_FIXED_CO_H__\n";
print COFILE "#define __PROC_SBE_FIXED_CO_H__\n";
foreach my $attr (@attrCoreIds)
{

    my $value = uc $attr->{valueType};
    print COFILE "PROC_SBE_FIXED_TARGET_$value($attr->{id}, CORE_TARGET_COUNT);\n"


}
print COFILE "\n#endif  // __PROC_SBE_FIXED_CO_H__";



print EQFILE "// proc_sbe_fixed_eq.H\n";
print EQFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print EQFILE "#ifndef __PROC_SBE_FIXED_EQ_H__\n";
print EQFILE "#define __PROC_SBE_FIXED_EQ_H__\n";
foreach my $attr (@attrEqIds)
{

    my $value = uc $attr->{valueType};
    print EQFILE "PROC_SBE_FIXED_TARGET_$value($attr->{id}, EQ_TARGET_COUNT);\n"


}
print EQFILE "\n#endif  // __PROC_SBE_FIXED_EQ_H__";



print PEFILE "// proc_sbe_fixed_perv.H\n";
print PEFILE "// This file is generated by perl script ppeParseProcSbeFixed.pl\n\n";
print PEFILE "#ifndef __PROC_SBE_FIXED_PERV_H__\n";
print PEFILE "#define __PROC_SBE_FIXED_PERV_H__\n";
foreach my $attr (@attrPervIds)
{

    my $value = uc $attr->{valueType};
    print PEFILE "PROC_SBE_FIXED_TARGET_$value($attr->{id}, PERV_TARGET_COUNT);\n"


}
print PEFILE "\n#endif  // __PROC_SBE_FIXED_PERV_H__";


#print ASFILE "#endif  // __PROC_SBE_FIXED_H__";


#------------------------------------------------------------------------------
# Close output file
#------------------------------------------------------------------------------
close(CHFILE);
close(COFILE);
close(EXFILE);
close(PEFILE);
close(EQFILE);

OpenPOWER on IntegriCloud