From 4d9344f1025ee77e24e88249dd3e32f3d4c9a3ba Mon Sep 17 00:00:00 2001 From: CamVan Nguyen Date: Thu, 10 Nov 2011 13:22:16 -0600 Subject: Added initfile compiler support for attribute enums Change-Id: I78a2a85831b545e7213e08a272fec482bd69cdf1 Reviewed-on: http://gfw160.austin.ibm.com:8080/gerrit/493 Tested-by: Jenkins Server Reviewed-by: MIKE J. JONES Reviewed-by: Andrew J. Geissler Reviewed-by: A. Patrick Williams III --- src/build/ifcompiler/initCompiler.lex | 8 ++- src/build/ifcompiler/initCompiler.y | 5 ++ src/build/ifcompiler/initRpn.C | 12 +++++ src/build/ifcompiler/initRpn.H | 10 ++++ src/build/ifcompiler/initSymbols.C | 77 ++++++++++++++++++++++++++++- src/build/ifcompiler/initSymbols.H | 12 ++++- src/usr/hwpf/fapi/fapiParseAttributeInfo.pl | 4 +- src/usr/hwpf/hwp/fapiTestHwpAttr.C | 5 +- 8 files changed, 125 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/build/ifcompiler/initCompiler.lex b/src/build/ifcompiler/initCompiler.lex index 2361272f2..9abdaded3 100755 --- a/src/build/ifcompiler/initCompiler.lex +++ b/src/build/ifcompiler/initCompiler.lex @@ -23,6 +23,7 @@ // dg01 D766229 dgilbert 08/03/10 add check for hex/bin data > 64 bits // dg02 SW058986 dgilbert 02/28/11 More noticeable fail for missing col headers // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log *********************************************************************************/ /** * @file initCompiler.lex @@ -202,16 +203,19 @@ bits { g_coltype = INIT_BITS; return INIT_BITS;} expr { g_coltype = INIT_EXPR; return INIT_EXPR;} scom_data { g_coltype = INIT_SCOMD; return INIT_SCOMD;} - /*HEX and Binary nubers in the scombody can be up to 64bit, + /*HEX and Binary numbers in the scombody can be up to 64bit, * decimal numbers will always fit in 32bit int */ {BINARY} { yylval.uint64 = bits2int(yytext); return INIT_INT64; } - <*>; { g_coltype = 0; return ';'; } END_INITFILE return INIT_ENDINITFILE; +<*>ENUM_{ID} { + yylval.str_ptr = new std::string(yytext); return ATTRIBUTE_ENUM; + } + <*>{ID} { yylval.str_ptr = new std::string(yytext); return INIT_ID; } diff --git a/src/build/ifcompiler/initCompiler.y b/src/build/ifcompiler/initCompiler.y index 672a2039e..4c86575d0 100755 --- a/src/build/ifcompiler/initCompiler.y +++ b/src/build/ifcompiler/initCompiler.y @@ -22,6 +22,7 @@ // D754106 dgilbert 06/14/10 Create // D774126 dgilbert 09/30/10 Add ERROR: to yyerror message // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log ********************************************************************************* /** * @file initCompiler.y @@ -76,6 +77,7 @@ int scom; %token INIT_ID %token INIT_VERSIONS %token ATTRIBUTE_INDEX +%token ATTRIBUTE_ENUM /* Define terminal symbols that don't have any associated data */ @@ -233,6 +235,7 @@ idrows: id_col { init::dbg << $1->listing(NULL); current_scom->add_row_ id_col: INIT_ID { $$ = new init::Rpn(*($1),yyscomlist->get_symbols()); $$->push_op(init::Rpn::EQ); delete $1; } | INIT_INTEGER { $$ = new init::Rpn($1,yyscomlist->get_symbols()); $$->push_op(init::Rpn::EQ); } | '{' num_list '}' { $$ = $2; $2->push_op(init::Rpn::LIST); $2->push_op(init::Rpn::EQ); } + | ATTRIBUTE_ENUM { $$ = new init::Rpn((yyscomlist->get_symbols())->get_attr_enum_val(*($1)),yyscomlist->get_symbols()); $$->push_op(init::Rpn::EQ); delete $1; } ; @@ -241,6 +244,7 @@ num_list: INIT_INTEGER { $$ = new init::Rpn($1,yyscomlist->get_symbols()); | INIT_ID { $$ = new init::Rpn(*($1),yyscomlist->get_symbols()); } | num_list ',' INIT_INTEGER { $$ = $1; $1->merge(new init::Rpn($3,yyscomlist->get_symbols())); } | num_list ',' INIT_ID { $$ = $1; $1->merge(new init::Rpn(*($3),yyscomlist->get_symbols())); } + | ATTRIBUTE_ENUM { $$ = new init::Rpn((yyscomlist->get_symbols())->get_attr_enum_val(*($1)),yyscomlist->get_symbols()); } ; @@ -255,6 +259,7 @@ define: INIT_DEFINE INIT_ID '=' expr ';' /* expr should return an RPN string of some kind */ expr: INIT_INTEGER { $$= new init::Rpn($1,yyscomlist->get_symbols()); } | INIT_ID { $$= new init::Rpn(*($1),yyscomlist->get_symbols()); delete $1; } + | ATTRIBUTE_ENUM { $$= new init::Rpn((yyscomlist->get_symbols())->get_attr_enum_val(*($1)),yyscomlist->get_symbols()); delete $1; } | INIT_INT64 { $$=new init::Rpn($1,yyscomlist->get_symbols()); } | expr ATTRIBUTE_INDEX { $1->push_array_index(*($2)); } | expr INIT_LOGIC_OR expr { $$ = $1->push_merge($3,init::Rpn::OR); } diff --git a/src/build/ifcompiler/initRpn.C b/src/build/ifcompiler/initRpn.C index bb0fcca1a..bd1b8b1a1 100755 --- a/src/build/ifcompiler/initRpn.C +++ b/src/build/ifcompiler/initRpn.C @@ -21,6 +21,7 @@ // dg003 SW047506 dgilbert 12/09/10 SERIES filtering // andrewg 05/24/11 Port over for VPL/PgP // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log ********************************************************************************* /** @@ -210,6 +211,17 @@ void Rpn::push_array_index(std::string &i_array_idx) } +//------------------------------------------------------------------------------------------------- +void Rpn::push_attr_enum(std::string &i_attr_enum) +{ + uint64_t l_attr_enum_val = iv_symbols->get_attr_enum_val(i_attr_enum); + + uint32_t rpn_id = iv_symbols->find_numeric_lit(l_attr_enum_val,8); + iv_rpnstack.push_back(rpn_id); + + //printf("Attribute Enum name: %s Value:%u rpn_id:0x%8X\n",i_attr_enum.c_str(),l_attr_enum_val,rpn_id); +} + //------------------------------------------------------------------------------------------------- bool Rpn::isTrue() const //dg003a diff --git a/src/build/ifcompiler/initRpn.H b/src/build/ifcompiler/initRpn.H index 5bd98a3fa..33a503842 100755 --- a/src/build/ifcompiler/initRpn.H +++ b/src/build/ifcompiler/initRpn.H @@ -24,6 +24,7 @@ // dg002 SW039868 dgilbert 10/15/10 Add support to filter unneeded inits by EC // dg003 SW047506 dgilbert 12/09/10 SERIES filtering // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log ********************************************************************************* /** @@ -135,6 +136,15 @@ namespace init */ void push_array_index(std::string &i_array_idx); + /** + * @brief Add an attribute enum + * + * @param[in] i_attr_enum attribute enum name + * + * @return Void + */ + void push_attr_enum(std::string &i_attr_enum); + Rpn * push_op(RPN_OP op); //<<< Add an operation to the Rpn sequence /** diff --git a/src/build/ifcompiler/initSymbols.C b/src/build/ifcompiler/initSymbols.C index a09421be8..018e82f0d 100755 --- a/src/build/ifcompiler/initSymbols.C +++ b/src/build/ifcompiler/initSymbols.C @@ -19,6 +19,7 @@ // D754106 dgilbert 06/14/10 Create // dgilbert 10/22/10 Add spies_are_in() // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log ********************************************************************************* /** @@ -75,7 +76,7 @@ Symbols::Symbols(FILELIST & i_filenames) if(def == "AttributeId") { // We've now found the beginning of the attribute enum definition - // Read and skip the { on the next line + // Read and skip the '{' on the next line getline(infs,fileline); getline(infs,fileline); @@ -105,6 +106,72 @@ Symbols::Symbols(FILELIST & i_filenames) getline(infs,fileline); } } + else + { + // Make sure it's an attribute enum + + string attribute_enum_name; + string find_enum = "_Enum"; + + // Check for _Enum in the name + size_t pos = def.find(find_enum); + if(pos != string::npos) + { + // We've now found the beginning of the attribute enum definition + // Read and skip the '{' on the next line + getline(infs,fileline); + getline(infs,fileline); + + // We're just parsing the enum in order so values start + // at 0 and increment by 1 after that unless they are + // explicitly assigned. + uint64_t value = 0; + + while(fileline[0] != '}') + { + istringstream attr_enum_stream(fileline); + string attr_enum; + string tmp; + + // Get the attribute enum name + attr_enum_stream >> attr_enum; + + // Strip off the "," at the end. + pos = attr_enum.find(','); + if(pos != string::npos) + { + attr_enum = attr_enum.substr(0,attr_enum.length()-1); + } + else + { + // Is a value for the enum specified? + attr_enum_stream >> tmp; + + if (!attr_enum_stream.eof()) + { + //Make sure it's an '=' + if ("=" != tmp) + { + printf ("ERROR: Unknown attribute enum! %s\n",attr_enum.c_str()); + exit(1); + } + else + { + attr_enum_stream >> tmp; + value = strtoll(tmp.c_str(), NULL, 0); + } + } + } + + //printf("Attribute Enum String:%s Value %u\n",attr_enum.c_str(), value); + + // Get a value for the string + iv_attr_enum[attr_enum] = value; + value++; + getline(infs,fileline); + } + } + } } else if(def == "typedef") { @@ -516,6 +583,12 @@ uint64_t Symbols::get_numeric_data(uint32_t i_rpn_id, uint32_t & o_size) return data; } +// ------------------------------------------------------------------------------------------------ +uint64_t Symbols::get_attr_enum_val(string & i_attr_enum) +{ + return iv_attr_enum[i_attr_enum]; +} + // ------------------------------------------------------------------------------------------------ string Symbols::find_text(uint32_t i_cini_id) @@ -729,7 +802,7 @@ string Symbols::not_found_listing() ostringstream oss; if(iv_not_found.size()) { - oss << "\n------------- Symbols reqested that were NOT FOUND ---------------\n\n"; + oss << "\n------------- Symbols requested that were NOT FOUND ---------------\n\n"; for(SYMBOL_MAP::iterator i = iv_not_found.begin(); i != iv_not_found.end(); ++i) { //if(i->first == "SPY_NOTFOUND" || (i->first).compare(0,13,"ENUM_NOTFOUND") == 0) continue; diff --git a/src/build/ifcompiler/initSymbols.H b/src/build/ifcompiler/initSymbols.H index 68ba70718..93613e059 100755 --- a/src/build/ifcompiler/initSymbols.H +++ b/src/build/ifcompiler/initSymbols.H @@ -21,6 +21,7 @@ // ---- -------- -------- -------- ------------------------------------------------------------- // D754106 dgilbert 06/14/10 Create // andrewg 09/19/11 Updates based on review +// camvanng 11/08/11 Added support for attribute enums // End Change Log ********************************************************************************* /** @@ -98,7 +99,7 @@ namespace init /** * Lookup the tag id from the rpn_id provided by use_symbol() * @returns tag id - * @param prn_id + * @param rpn_id * @pre all the symbols have been marked used (no new symbols) * @post tag table built if not already built. * @note tag bits 0bttxxxxxx xxxxxxxx @@ -158,6 +159,13 @@ namespace init */ uint64_t get_numeric_data(uint32_t i_rpn_id, uint32_t & o_size); + /** + * Get the attribute enum value for the attr enum + * @param string attribute enum name + * @returns uint64_t value + */ + uint64_t get_attr_enum_val(string & i_attr_enum); + /** * Store enum name & return rpn_id @@ -231,6 +239,7 @@ namespace init typedef map SYMBOL_MAP; typedef map SPY_MAP; typedef map SYMBOL_ATTR_TYPE; + typedef map SYMBOL_ATTR_ENUM; typedef pair DEF_DATA; typedef map DEF_MAP; @@ -245,6 +254,7 @@ namespace init SYMBOL_MAP iv_symbols; ///< From ciniIfSymbols.H all vars and enumerated lits SYMBOL_ATTR_TYPE iv_attr_type; + SYMBOL_ATTR_ENUM iv_attr_enum; SYMBOL_MAP iv_not_found; ///< List of symbols not found RPN_MAP iv_rpn_map; ///< Map rpn_id to symbol name/cini_id of used Symbols SYMBOL_USED iv_used_var; ///< List of cini_ids of used vars ordered by name diff --git a/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl index 2d7051b5e..333e68440 100755 --- a/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl +++ b/src/usr/hwpf/fapi/fapiParseAttributeInfo.pl @@ -45,6 +45,8 @@ # mjjones 10/18/11 Support multiple attr files and # multi-line descriptions # camvanng 10/20/11 Changed i_pTarget to "const" ptr +# camvanng 11/09/11 Prepend "ENUM_" to attribute +# enums # # End Change Log ****************************************************** @@ -266,7 +268,7 @@ foreach my $argnum (1 .. $#ARGV) { # Remove leading spaces $val =~ s/^\s+//; - print AIFILE " $attr->{id}_${val},\n"; + print AIFILE " ENUM_$attr->{id}_${val},\n"; } print AIFILE "};\n"; diff --git a/src/usr/hwpf/hwp/fapiTestHwpAttr.C b/src/usr/hwpf/hwp/fapiTestHwpAttr.C index 1fae73b75..df13107dc 100755 --- a/src/usr/hwpf/hwp/fapiTestHwpAttr.C +++ b/src/usr/hwpf/hwp/fapiTestHwpAttr.C @@ -39,6 +39,7 @@ * mjjones 10/17/2011 Update scratch test * camvanng 10/26/2011 Update scratch test * mjjones 10/28/2011 Fix error generation + * camvanng 11/09/2011 Update attr enum test */ #include @@ -765,7 +766,7 @@ fapi::ReturnCode hwpTestAttributes() // Test setting and getting an enum value from a scratch attribute //---------------------------------------------------------------------- { - uint64_t l_uint64 = fapi::ATTR_SCRATCH_UINT64_2_VAL_C; + uint64_t l_uint64 = fapi::ENUM_ATTR_SCRATCH_UINT64_2_VAL_C; // Test set l_rc = FAPI_ATTR_SET(ATTR_SCRATCH_UINT64_2, NULL, l_uint64); @@ -785,7 +786,7 @@ fapi::ReturnCode hwpTestAttributes() } // Check value - if (l_uint64 != fapi::ATTR_SCRATCH_UINT64_2_VAL_C) + if (l_uint64 != fapi::ENUM_ATTR_SCRATCH_UINT64_2_VAL_C) { FAPI_SET_HWP_ERROR(l_rc, RC_HWP_ATTR_UNIT_TEST_FAIL); FAPI_ERR("hwpTestAttributes: ATTR_SCRATCH_UINT64_2. GET returned %d (enum)", -- cgit v1.2.1