#!/usr/bin/perl # IBM_PROLOG_BEGIN_TAG # This is an automatically generated prolog. # # $Source: src/usr/hwpf/fapi/fapiParseAttributeInfo.pl $ # # IBM CONFIDENTIAL # # COPYRIGHT International Business Machines Corp. 2011 # # p1 # # Object Code Only (OCO) source materials # Licensed Internal Code Source Materials # IBM HostBoot Licensed Internal Code # # The source code for this program is not published or other- # wise divested of its trade secrets, irrespective of what has # been deposited with the U.S. Copyright Office. # # Origin: 30 # # IBM_PROLOG_END # # Purpose: This perl script will parse HWP Attribute XML files # and add attribute information to a file called fapiAttributeIds.H # # Author: CamVan Nguyen # Last Updated: 06/23/2011 # # Version: 1.0 # # Change Log ********************************************************** # # Flag Track# Userid Date Description # ---- -------- -------- -------- ----------- # camvanng 06/03/11 Created # mjjones 06/06/11 Minor updates for integration # mjjones 06/10/11 Added "use strict;" # mjjones 06/23/11 Parse more info # mjjones 07/05/11 Take output dir as parameter # mjjones 09/06/11 Remove string/defaultVal support # mjjones 10/07/11 Create fapiAttributeService.C # mjjones 10/17/11 Support enums with values # mjjones 10/18/11 Support multiple attr files and # multi-line descriptions # camvanng 10/20/11 Changed i_pTarget to "const" ptr # # End Change Log ****************************************************** # # Usage: # fapiParseAttributeInfo.pl ... use strict; #------------------------------------------------------------------------------ # Print Command Line Help #------------------------------------------------------------------------------ my $numArgs = $#ARGV + 1; if ($numArgs < 2) { print ("Usage: fapiParseAttributeInfo.pl ...\n"); print (" This perl script will parse attribute XML files and add\n"); print (" attribute information to a file called fapiAttributeIds.H\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 files for writing #------------------------------------------------------------------------------ my $aiFile = $ARGV[0]; $aiFile .= "/"; $aiFile .= "fapiAttributeIds.H"; open(AIFILE, ">", $aiFile); my $asFile = $ARGV[0]; $asFile .= "/"; $asFile .= "fapiAttributeService.C"; open(ASFILE, ">", $asFile); #------------------------------------------------------------------------------ # Print Start of file information to fapiAttributeIds.H #------------------------------------------------------------------------------ print AIFILE "// fapiAttributeIds.H\n"; print AIFILE "// This file is generated by perl script fapiParseAttributeInfo.pl\n\n"; print AIFILE "#ifndef FAPIATTRIBUTEIDS_H_\n"; print AIFILE "#define FAPIATTRIBUTEIDS_H_\n\n"; print AIFILE "namespace fapi\n"; print AIFILE "{\n\n"; print AIFILE "\/**\n"; print AIFILE " * \@brief Enumeration of attribute IDs\n"; print AIFILE " *\/\n"; print AIFILE "enum AttributeId\n{\n"; #------------------------------------------------------------------------------ # Print Start of file information to fapiAttributeService.C #------------------------------------------------------------------------------ print ASFILE "// fapiAttributeService.C\n"; print ASFILE "// This file is generated by perl script fapiParseAttributeInfo.pl\n\n"; print ASFILE "#include \n\n"; print ASFILE "namespace fapi\n"; print ASFILE "{\n\n"; print ASFILE "ReturnCode fapiGetInitFileAttr(const AttributeId i_id,\n"; print ASFILE " const Target * i_pTarget,\n"; print ASFILE " uint64_t & o_val,\n"; print ASFILE " const uint32_t i_arrayIndex1,\n"; print ASFILE " const uint32_t i_arrayIndex2,\n"; print ASFILE " const uint32_t i_arrayIndex3,\n"; print ASFILE " const uint32_t i_arrayIndex4)\n"; print ASFILE "{\n"; print ASFILE " ReturnCode l_rc;\n\n"; #------------------------------------------------------------------------------ # For each XML file #------------------------------------------------------------------------------ foreach my $argnum (1 .. $#ARGV) { my $infile = $ARGV[$argnum]; # read XML file my $attributes = $xml->XMLin($infile); # Uncomment to get debug output of all attributes #print "\nFile: ", $infile, "\n", Dumper($attributes), "\n"; #-------------------------------------------------------------------------- # For each Attribute #-------------------------------------------------------------------------- foreach my $attr (@{$attributes->{attribute}}) { #---------------------------------------------------------------------- # Print the AttributeId to fapiAttributeIds.H #---------------------------------------------------------------------- if (! exists $attr->{id}) { print ("fapiParseAttributeInfo.pl ERROR. Att 'id' missing\n"); exit(1); } print AIFILE " ", $attr->{id}, ",\n"; }; } #------------------------------------------------------------------------------ # Print AttributeId enumeration end to fapiAttributeIds.H #------------------------------------------------------------------------------ print AIFILE "};\n\n"; #------------------------------------------------------------------------------ # Print Attribute Information comment to fapiAttributeIds.H #------------------------------------------------------------------------------ print AIFILE "\/**\n"; print AIFILE " * \@brief Attribute Information\n"; print AIFILE " *\/\n"; #------------------------------------------------------------------------------ # For each XML file #------------------------------------------------------------------------------ foreach my $argnum (1 .. $#ARGV) { my $infile = $ARGV[$argnum]; # read XML file my $attributes = $xml->XMLin($infile); #-------------------------------------------------------------------------- # For each Attribute #-------------------------------------------------------------------------- my $attCount = 0; foreach my $attr (@{$attributes->{attribute}}) { #---------------------------------------------------------------------- # Print a comment with the attribute description to fapiAttributeIds.H #---------------------------------------------------------------------- if ($attr->{description}) { print AIFILE "/* $attr->{id}: $attr->{description} */\n"; } #---------------------------------------------------------------------- # Figure out the attribute array dimensions (if array) #---------------------------------------------------------------------- my $arrayDimensions = ""; my $numArrayDimensions = 0; if ($attr->{array}) { # Figure out the array dimensions # Remove leading whitespace my $dimText = $attr->{array}; $dimText =~ s/^\s+//; # Split on commas or whitespace my @vals = split(/\s*,\s*|\s+/, $dimText); foreach my $val (@vals) { $arrayDimensions .= "[${val}]"; $numArrayDimensions++; } } #---------------------------------------------------------------------- # Print the typedef for each attribute's val type to fapiAttributeIds.H #---------------------------------------------------------------------- if (! exists $attr->{valueType}) { print ("fapiParseAttributeInfo.pl ERROR. Att 'valueType' missing\n"); exit(1); } if ($attr->{valueType} eq 'uint8') { print AIFILE "typedef uint8_t $attr->{id}_Type$arrayDimensions;\n"; } elsif ($attr->{valueType} eq 'uint32') { print AIFILE "typedef uint32_t $attr->{id}_Type$arrayDimensions;\n"; } elsif ($attr->{valueType} eq 'uint64') { print AIFILE "typedef uint64_t $attr->{id}_Type$arrayDimensions;\n"; } else { print ("fapiParseAttributeInfo.pl ERROR. valueType not recognized: "); print $attr->{valueType}, "\n"; exit(1); } #---------------------------------------------------------------------- # Print if the platform initializes the value to fapiAttributeIds.H #---------------------------------------------------------------------- if (exists $attr->{platInit}) { print AIFILE "#define $attr->{id}_PLATINIT true\n" } else { print AIFILE "#define $attr->{id}_PLATINIT false\n" } #---------------------------------------------------------------------- # Print the value enumeration (if specified) to fapiAttributeIds.H #---------------------------------------------------------------------- if (exists $attr->{enum}) { print AIFILE "enum $attr->{id}_Enum\n{\n"; # Values must be separated by commas to allow for values to be # specified: VAL_A = 3, VAL_B = 5, VAL_C = 0x23 my @vals = split(',', $attr->{enum}); foreach my $val (@vals) { # Remove leading spaces $val =~ s/^\s+//; print AIFILE " $attr->{id}_${val},\n"; } print AIFILE "};\n"; } #---------------------------------------------------------------------- # If the attribute is read-only then define the _SETMACRO to something # that will cause a compile failure if a set is attempted #---------------------------------------------------------------------- if (! exists $attr->{writeable}) { print AIFILE "#define $attr->{id}_SETMACRO ATTRIBUTE_NOT_WRITABLE\n"; } #---------------------------------------------------------------------- # Print newline between each attribute's info to fapiAttributeIds.H #---------------------------------------------------------------------- print AIFILE "\n"; #---------------------------------------------------------------------- # Print the attribute get code to fapiAttributeService.C # *** TODO *** # Currently, all attributes are supported in fapiGetInitFileAttr() in # fapiAttributeService.C. Ideally only the initfile attributes should # be supported to minimize code size. Need to figure out how to do this #---------------------------------------------------------------------- if ($attCount > 0) { print ASFILE " else "; } else { print ASFILE " "; } $attCount++; print ASFILE "if (i_id == $attr->{id})\n"; print ASFILE " {\n"; print ASFILE " $attr->{id}_Type l_attr;\n"; print ASFILE " l_rc = FAPI_ATTR_GET($attr->{id}, i_pTarget, l_attr);\n"; print ASFILE " o_val = l_attr"; if ($numArrayDimensions >= 5) { print ("fapiParseAttributeInfo.pl ERROR. More than 4 array dimensions!!\n"); exit(1); } else { for (my $i = 0; $i < $numArrayDimensions; $i++) { print ASFILE "[i_arrayIndex"; print ASFILE $i+1; print ASFILE "]"; } } print ASFILE ";\n"; print ASFILE " }\n"; }; } #------------------------------------------------------------------------------ # Print End of file information to fapiAttributeIds.H #------------------------------------------------------------------------------ print AIFILE "}\n\n"; print AIFILE "#endif\n"; #------------------------------------------------------------------------------ # Print End of file information to fapiAttributeService.C #-------------------------------------------------------------------------- print ASFILE " else\n"; print ASFILE " {\n"; print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Unrecognized attr: %d\", i_id);\n"; print ASFILE " ReturnCodeFfdc::addEIFfdc(l_rc, static_cast(i_id));"; print ASFILE " l_rc = FAPI_RC_INVALID_ATTR_GET;\n"; print ASFILE " }\n\n"; print ASFILE " if (l_rc)\n"; print ASFILE " {\n"; print ASFILE " FAPI_ERR(\"fapiGetInitFileAttr: Error getting attr\");\n"; print ASFILE " }\n\n"; print ASFILE " return l_rc;\n"; print ASFILE "}\n\n"; print ASFILE "}\n"; #------------------------------------------------------------------------------ # Close output files #------------------------------------------------------------------------------ close(AIFILE); close(ASFILE);