Skip to content

Commit

Permalink
Optional support to parse default attribute tags
Browse files Browse the repository at this point in the history
Change-Id: I0bd282981e79c45a3f915e06f61c329ffadf7aab
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/49607
Tested-by: FSP CI Jenkins <fsp-CI-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins Server <pfd-jenkins+hostboot@us.ibm.com>
Tested-by: HWSV CI <hwsv-ci+hostboot@us.ibm.com>
Tested-by: Hostboot CI <hostboot-ci+hostboot@us.ibm.com>
Reviewed-by: Matt K. Light <mklight@us.ibm.com>
Reviewed-by: Daniel M. Crowell <dcrowell@us.ibm.com>
Dev-Ready: Kahn C. Evans <kahnevan@us.ibm.com>
Reviewed-by: Jennifer A. Stofer <stofer@us.ibm.com>
Reviewed-on: http://ralgit01.raleigh.ibm.com/gerrit1/49611
Reviewed-by: Hostboot Team <hostboot@us.ibm.com>
Tested-by: Jenkins OP Build CI <op-jenkins+hostboot@us.ibm.com>
Tested-by: Jenkins OP HW <op-hw-jenkins+hostboot@us.ibm.com>
Reviewed-by: Christian R. Geddes <crgeddes@us.ibm.com>
  • Loading branch information
kahnevan authored and crgeddes committed Nov 16, 2017
1 parent 47c3bbe commit 0ef7c3c
Showing 1 changed file with 90 additions and 2 deletions.
92 changes: 90 additions & 2 deletions src/import/hwpf/fapi2/tools/parseAttributeInfo.pl
Expand Up @@ -31,17 +31,26 @@
# Print Command Line Help
#------------------------------------------------------------------------------
my $arg_output_dir = undef;
my $parse_defaults = '';

# Get the options from the command line - the rest of @ARGV will
# be filenames
GetOptions( "output-dir=s" => \$arg_output_dir );
GetOptions(
"output-dir=s" => \$arg_output_dir,
"parse_defaults" => \$parse_defaults
);

my $numArgs = $#ARGV + 1;
if ( ( $numArgs < 1 ) || ( $arg_output_dir eq undef ) )
{
print("Usage: parseAttributeInfo.pl --output-dir=<output dir> <attr-xml-file1> [<attr-xml-file2> ...]\n");
print(
"Usage: parseAttributeInfo.pl --output-dir=<output dir> [--parse_defaults] <attr-xml-file1> [<attr-xml-file2> ...]\n"
);
print(" This perl script will parse attribute XML files and create the following files:\n");
print(" - attribute_ids.H. Contains IDs, type, value enums and other information\n");
print(
" When --parse_defaults is specified, default tags are handled and added to this file too.\n"
);
print(" - fapi2_chip_ec_feature.H Contains a function to query chip EC features\n");
print(" - attribute_plat_check.H Contains compile time checks that all attributes are\n");
print(" handled by the platform\n");
Expand Down Expand Up @@ -586,6 +595,85 @@
print AIFILE "};\n";
}

#----------------------------------------------------------------------
# Print if the attribute has a default value
#----------------------------------------------------------------------
if ( $parse_defaults == 1 )
{
if ( exists $attr->{default} )
{
print AIFILE "const bool $attr->{id}_hasDefault = true;\n";

#----------------------------------------------------------------
# Handle default attribute values and printing
#----------------------------------------------------------------

# Need to look for and convert ENUM values.
# Need to add ULL/LL to 64 bit values
# Need to handle array inits
my $defaultVal = $attr->{default};
my @defaultVals = split( ',', $defaultVal );
my @defaultArray = ();

foreach my $defVal (@defaultVals)
{
# Remove leading/trailing whitespace
$defVal =~ s/^\s+//;
$defVal =~ s/\s+$//;

# Determine if this is an enum. If it contains a character, and it doesn't start with "0x"
# then assume it's an enum
my $defaultIsEnum = ( ( $defVal =~ /[[:alpha:]]/ ) && ( substr( $defVal, 0, 2 ) ne "0x" ) );
if ( $defaultIsEnum && ( exists $attr->{enum} ) )
{
$defaultVal = "fapi2::ENUM_$attr->{id}_$defVal";
}
else
{
$defaultVal = $defVal;
if ( $attr->{valueType} eq 'uint64' )
{
$defaultVal = $defaultVal . "ULL";
}
elsif ( $attr->{valueType} eq 'int64' )
{
$defaultVal = $defaultVal . "LL";
}
}
if ( $attr->{array} )
{
push @defaultArray, $defaultVal;
}
}

if ( $attr->{array} )
{
for my $idx ( 0 .. $#defaultArray )
{
if ( $idx == 0 )
{
$defaultVal = "{" . @defaultArray[$idx];
}
else
{
$defaultVal = $defaultVal . "," . @defaultArray[$idx];
}

}
$defaultVal = $defaultVal . "}";

}

print AIFILE "const $attr->{id}_Type $attr->{id}_Default = $defaultVal;\n";

}
else
{
print AIFILE "const bool $attr->{id}_hasDefault = false;\n";
}

}

#----------------------------------------------------------------------
# Print _GETMACRO and _SETMACRO where appropriate to attribute_ids.H
#----------------------------------------------------------------------
Expand Down

0 comments on commit 0ef7c3c

Please sign in to comment.