summaryrefslogtreecommitdiffstats
path: root/src/usr/hwpf/ifcompiler
diff options
context:
space:
mode:
Diffstat (limited to 'src/usr/hwpf/ifcompiler')
-rwxr-xr-xsrc/usr/hwpf/ifcompiler/initCompiler.lex35
-rwxr-xr-xsrc/usr/hwpf/ifcompiler/initRpn.C40
-rwxr-xr-xsrc/usr/hwpf/ifcompiler/initScom.C29
-rwxr-xr-xsrc/usr/hwpf/ifcompiler/initSymbols.C95
-rwxr-xr-xsrc/usr/hwpf/ifcompiler/initSymbols.H27
5 files changed, 182 insertions, 44 deletions
diff --git a/src/usr/hwpf/ifcompiler/initCompiler.lex b/src/usr/hwpf/ifcompiler/initCompiler.lex
index 66183f776..beed2195a 100755
--- a/src/usr/hwpf/ifcompiler/initCompiler.lex
+++ b/src/usr/hwpf/ifcompiler/initCompiler.lex
@@ -34,6 +34,8 @@
// Ability to specify search paths for include files
// camvanng 04/16/12 Support defines for SCOM address
// Support defines for bits, scom_data and attribute columns
+// camvanng 05/07/12 Support for associated target attributes
+// Save and restore line numbers for each include file
// End Change Log *********************************************************************************/
/**
* @file initCompiler.lex
@@ -79,11 +81,16 @@ std::string g_scomdef_name;
std::map<std::string,std::string> g_defines; //container for all the defines
//i.e. define def_A = (attrA > 1) => key = "DEF_A", value = "(attr_A > 1)"
+std::string g_target; //storage for current target
+
extern int yyline;
extern std::vector<std::string> yyincludepath;
+extern std::map<std::string,std::string> yytarget; //container for all defined targets
+ //i.e. define MBA0 = TGT1 => key = "TGT1", value = "MBA0"
#define MAX_INCLUDE_DEPTH 10
YY_BUFFER_STATE include_stack[MAX_INCLUDE_DEPTH];
+int yyline_stack[MAX_INCLUDE_DEPTH];
int include_stack_num = 0;
%}
@@ -148,6 +155,7 @@ MULTI_DIGIT [0-9]+
yy_delete_buffer(YY_CURRENT_BUFFER);
fclose(yyin);
yy_switch_to_buffer(include_stack[include_stack_num]);
+ yyline = yyline_stack[include_stack_num];
}
}
@@ -177,6 +185,10 @@ include { BEGIN(incl); }
exit( 1 );
}
+ /* Save current line number */
+ yyline_stack[include_stack_num] =
+ yyline;
+
/* Save current input buffer */
include_stack[include_stack_num++] =
YY_CURRENT_BUFFER;
@@ -197,6 +209,7 @@ include { BEGIN(incl); }
exit(1);
}
printf("Include file %s\n", filename.c_str());
+ yyline = 1; //set line number for new buffer
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
BEGIN(INITIAL);
@@ -363,7 +376,19 @@ scom_data { g_coltype = INIT_SCOMD; return INIT_SCOMD;}
END_INITFILE return INIT_ENDINITFILE;
-<*>SYS\. yymore();
+<*>SYS\. yymore(); //System attribute
+
+<*>TGT{MULTI_DIGIT}\. {
+ if (g_target.length())
+ {
+ std::string tgt(yytext);
+ tgt = tgt.substr(0, tgt.length() -1);
+ yytarget[tgt] = g_target;
+ g_target.clear();
+ }
+
+ yymore(); //Associated target attribute
+ }
/* All attribute enums start with "ENUM_ATTR_" */
<*>ENUM_ATTR_{ID} {
@@ -377,6 +402,14 @@ END_INITFILE return INIT_ENDINITFILE;
/* Anything else is a define.
* Removing any requirements that defines has to start with "def_" or "DEF_" */
+<*>{ID}\. { // push back the define value for scanning
+ g_target = yytext;
+ g_target = g_target.substr(0, g_target.length() - 1);
+ //printf("%s\n", g_target.c_str());
+ unput('.');
+ pushBackDefine(g_target.c_str());
+ }
+
<*>{ID} { // push back the define value for scanning
pushBackDefine(yytext);
}
diff --git a/src/usr/hwpf/ifcompiler/initRpn.C b/src/usr/hwpf/ifcompiler/initRpn.C
index 9d8de774a..10b8254e5 100755
--- a/src/usr/hwpf/ifcompiler/initRpn.C
+++ b/src/usr/hwpf/ifcompiler/initRpn.C
@@ -28,6 +28,7 @@
// camvanng 04/16/12 Support defines for SCOM address
// Support defines for bits, scom_data and attribute columns
// Delete obsolete code for defines support
+// camvanng 05/07/12 Support for associated target attributes
// End Change Log *********************************************************************************
/**
@@ -42,6 +43,7 @@
#include <iomanip>
#include <iostream>
#include <stdexcept>
+#include <cstring>
#include <fapiHwpInitFileInclude.H> // Requires file from hwpf
extern void yyerror(const char * s);
@@ -187,6 +189,27 @@ void Rpn::push_id(std::string & i_id, TYPE i_type)
rpn_id = iv_symbols->use_symbol(s);
iv_rpnstack.push_back(rpn_id);
+
+ //If this is an associated target's attribute,
+ //Add the target number as a numerical literal
+ size_t pos = s.find(ASSOC_TGT_ATTR);
+ if (pos != string::npos)
+ {
+ size_t len = ASSOC_TGT_ATTR.length();
+ pos = s.find('.');
+ if ((pos != string::npos) && (pos > len))
+ {
+ uint32_t targetNum = strtoul(s.substr(len, pos-len).c_str(), NULL, 0);
+ //printf("Rpn::push_id: Target# %u\n", targetNum);
+ push_int(targetNum);
+ }
+ else
+ {
+ std::ostringstream oss;
+ oss << "Invalid associated target attribute " << i_id.c_str();
+ yyerror(oss.str().c_str());
+ }
+ }
}
//-------------------------------------------------------------------------------------------------
@@ -591,8 +614,17 @@ void Rpn::bin_read(BINSEQ::const_iterator & bli, Symbols * symbols)
iv_rpnstack.push_back(l_rpn_id);
//Check for attribute of array type
- if ((v & IF_TYPE_MASK) == IF_ATTR_TYPE)
+ if (v & IF_ATTR_TYPE)
{
+ //Check for associated target attribute
+ if ((v & IF_TYPE_MASK) == IF_ASSOC_TGT_ATTR_TYPE)
+ {
+ v = *bli++;
+ v = (v << 8) + (*bli++);
+ iv_rpnstack.push_back(iv_symbols->get_rpn_id(v));
+ //printf("Rpn::bin_read: Assoc target attribute id 0x%x\n", v);
+ }
+
//Get the attribute dimension & shift it to the LS nibble
uint32_t l_type = iv_symbols->get_attr_type(l_rpn_id);
uint8_t l_attrDimension = (static_cast<uint8_t>(l_type) & ATTR_DIMENSION_MASK) >> 4;
@@ -720,9 +752,8 @@ std::string Rpn::listing(const char * i_desc, const std::string & spyname, bool
if(i_final)
{
uint32_t val = iv_symbols->get_tag(*i);
- uint32_t type = val & IF_TYPE_MASK;
- if (type == IF_ATTR_TYPE)
+ if (val & IF_ATTR_TYPE)
{
rpn_byte_size += 2;
oss << "0x" << std::setw(4) << val << "\t\t" << "PUSH " << name << std::endl;
@@ -747,7 +778,8 @@ std::string Rpn::listing(const char * i_desc, const std::string & spyname, bool
}
}
- if((iv_rpnstack.size() == 1) && (iv_rpnstack.front() & SYMBOL)) // skip size and desc
+ //Skip size and desc for empty desc string and SYMBOL literal
+ if(i_desc && (0 == strlen(i_desc)) && (iv_rpnstack.front() & SYMBOL))
{
odesc << oss.str();
}
diff --git a/src/usr/hwpf/ifcompiler/initScom.C b/src/usr/hwpf/ifcompiler/initScom.C
index bfd686832..edd030e56 100755
--- a/src/usr/hwpf/ifcompiler/initScom.C
+++ b/src/usr/hwpf/ifcompiler/initScom.C
@@ -32,6 +32,7 @@
// camvanng 02/14/12 Support binary and hex scom addresses
// Support for array at beginning of scom address
// Fix bug in string size when converting decimal to hex string
+// camvanng 05/07/12 Support for associated target attributes
// End Change Log *********************************************************************************
/**
@@ -53,6 +54,7 @@
extern void yyerror(const char * s);
extern init::ScomList * yyscomlist; // only use this during parsing
+std::map<string,string> yytarget; //generic target name & corresponding real name
namespace init {
extern ostringstream dbg; // debug output
@@ -114,9 +116,7 @@ Scom::Scom(BINSEQ::const_iterator & bli, Symbols * i_symbols):
// Read col heads
for(size_t i = 0; i < numcols; ++i)
{
- uint32_t var_tag = Rpn::extract16(bli);
- Rpn col_name_rpn(iv_symbols);
- col_name_rpn.append(iv_symbols->get_rpn_id(var_tag));
+ Rpn col_name_rpn(bli,iv_symbols);
iv_col_vars.push_back(col_name_rpn);
iv_cols_rpn.push_back(iv_row_rpn); // copy in blank row RPNs for this column
}
@@ -203,12 +203,19 @@ void Scom::add_col(const string & i_colname)
Rpn col_rpn(s,iv_symbols); // = iv_symbols->use_symbol(s);
// add check - Can't add any more cols after EXPR column dg001a
- if(iv_col_vars.size() && s != "EXPR")
+ if(iv_col_vars.size())
{
Rpn exp_rpn("EXPR",iv_symbols);
if(exp_rpn == iv_col_vars.back()) // expr col already added - can't add any more cols
{
- yyerror("EXPR must be the last column");
+ if (s == "EXPR")
+ {
+ yyerror("Multiple EXPR columns specified.");
+ }
+ else
+ {
+ yyerror("EXPR must be the last column");
+ }
}
}
@@ -1216,6 +1223,18 @@ void ScomList::listing(BINSEQ & bin_seq,ostream & olist)
olist << endl;
}
+ if (yytarget.size())
+ {
+ olist << "------------------- TARGET MAPPING ------------------------\n\n"
+ << endl;
+ std::map<string,string>::iterator i;
+ for (i = yytarget.begin(); i != yytarget.end(); i++)
+ {
+ olist << i->first << setfill(' ') << setw(30 - i->first.length())
+ << " = " << i->second << endl;
+ }
+ }
+
olist << iv_symbols->listing() << endl;
olist << "------------------- SCOM TABLES ------------------------\n\n"
<< endl;
diff --git a/src/usr/hwpf/ifcompiler/initSymbols.C b/src/usr/hwpf/ifcompiler/initSymbols.C
index a3003abc5..3a14f0fe0 100755
--- a/src/usr/hwpf/ifcompiler/initSymbols.C
+++ b/src/usr/hwpf/ifcompiler/initSymbols.C
@@ -28,6 +28,7 @@
// camvanng 04/16/12 Support defines for SCOM address
// Support defines for bits, scom_data and attribute columns
// Delete obsolete code for defines support
+// camvanng 05/07/12 Support for associated target attributes
// End Change Log *********************************************************************************
/**
@@ -109,7 +110,6 @@ Symbols::Symbols(FILELIST & i_filenames)
// Store the value
iv_symbols[attr] = MAP_DATA(attrId,NOT_USED);
- iv_symbols[SYS_ATTR + attr] = MAP_DATA(attrId,NOT_USED);
getline(infs,fileline);
}
@@ -219,7 +219,6 @@ Symbols::Symbols(FILELIST & i_filenames)
}
iv_attr_type[attribute_name] = get_attr_type(type,array);
- iv_attr_type[SYS_ATTR + attribute_name] = iv_attr_type[attribute_name];
//printf("Attribute %s Type with array dimension %u for %s is %u\n",attribute_name.c_str(),array,
// type.c_str(),get_attr_type(type,array));
}
@@ -275,6 +274,8 @@ uint32_t Symbols::get_attr_type(const uint32_t i_rpn_id)
uint32_t Symbols::use_symbol(string & i_symbol)
{
uint32_t rpn_id = Rpn::SYMBOL | NOT_FOUND;
+ string l_symbol = i_symbol;
+
if(i_symbol == "ANY") rpn_id = INIT_ANY_LIT | Rpn::SYMBOL;
else if(i_symbol == "EXPR") rpn_id = INIT_EXPR_VAR | Rpn::SYMBOL;
else
@@ -300,7 +301,39 @@ uint32_t Symbols::use_symbol(string & i_symbol)
}
else
{
- rpn_id = add_undefined(i_symbol);
+ //Strip off any prefix (i.e. "SYS." or "TGT<#>.")
+ size_t pos = i_symbol.find('.');
+ if(pos != string::npos)
+ {
+ //Find the attribute without the prefix.
+ //If found, then add this system or assoc target attribute
+ //to our containers.
+ l_symbol = i_symbol.substr(pos+1);
+ SYMBOL_MAP::iterator i = iv_symbols.find(l_symbol);
+ if(i != iv_symbols.end())
+ {
+ //Add the new attribute
+
+ rpn_id = Rpn::SYMBOL | iv_rpn_id++;
+ uint32_t attrId = iv_symbols[l_symbol].first;
+
+ iv_rpn_map[rpn_id] = RPN_DATA(i_symbol,attrId);
+ iv_symbols[i_symbol] = MAP_DATA(attrId, rpn_id);
+ iv_attr_type[i_symbol] = iv_attr_type[l_symbol];
+
+ ++iv_used_var_count;
+
+ //printf ("Symbols::use_symbol: Just added %s symbol, rpn_id:0x%8X\n",i_symbol.c_str(),rpn_id);
+ }
+ else
+ {
+ rpn_id = add_undefined(i_symbol);
+ }
+ }
+ else
+ {
+ rpn_id = add_undefined(i_symbol);
+ }
}
}
@@ -339,8 +372,8 @@ uint16_t Symbols::get_tag(uint32_t i_rpn_id)
iv_used_var.reserve(iv_used_var_count); // makes if faster
iv_used_lit.reserve(iv_used_lit_count);
- //To differentiate between system and target attributes which have the same attribute id,
- //save the attribute name also.
+ //To differentiate between system, target, and associated target attributes
+ //which have the same attribute id, save the attribute name also.
iv_used_var.push_back(RPN_DATA("EXPR",SYM_EXPR)); // EXPR var always first
iv_used_lit.push_back(iv_rpn_map[Rpn::SYMBOL|INIT_ANY_LIT].second); // ANY lit always first
@@ -394,14 +427,20 @@ uint16_t Symbols::get_tag(uint32_t i_rpn_id)
{
if (name == (*i).first)
{
- tag = (uint16_t) (offset | IF_ATTR_TYPE);
-
- if (name.compare(0, 4, SYS_ATTR) == 0)
+ if (name.compare(0, ASSOC_TGT_ATTR.length(), ASSOC_TGT_ATTR) == 0)
{
- tag |= IF_SYS_ATTR_MASK;
- //printf ("get tag: %s tag 0x%x\n", name.c_str(), tag);
+ tag = (uint16_t) (offset | IF_ASSOC_TGT_ATTR_TYPE);
+ }
+ else if (name.compare(0, SYS_ATTR.length(), SYS_ATTR) == 0)
+ {
+ tag = (uint16_t) (offset | IF_SYS_ATTR_TYPE);
+ }
+ else
+ {
+ tag = (uint16_t) (offset | IF_ATTR_TYPE);
}
+ //printf ("get tag: %s tag 0x%x\n", name.c_str(), tag);
break;
}
}
@@ -722,14 +761,21 @@ string Symbols::listing()
for(VAR_SYMBOL_USED::iterator i = iv_used_var.begin() + 1; i != iv_used_var.end(); ++i)
{
++count;
- uint32_t id = count | IF_ATTR_TYPE;
+ uint32_t id = count;
string name = (*i).first;
uint32_t attrId = (*i).second;
- if(name.compare(0, 4, SYS_ATTR) == 0)
+ if(name.compare(0, ASSOC_TGT_ATTR.length(), ASSOC_TGT_ATTR) == 0)
+ {
+ id |= IF_ASSOC_TGT_ATTR_TYPE;
+ }
+ else if(name.compare(0, SYS_ATTR.length(), SYS_ATTR) == 0)
+ {
+ id |= IF_SYS_ATTR_TYPE;
+ }
+ else
{
- id |= IF_SYS_ATTR_MASK;
- attrId = iv_symbols[name.substr(4)].first;
+ id |= IF_ATTR_TYPE;
}
oss << "Type:" << setw(2) << iv_attr_type[name] << " Value:0x" << setw(8) << attrId << '\t' << "ID 0X" << setw(4) << id
@@ -738,8 +784,6 @@ string Symbols::listing()
//printf("ATTRIBUTE: %s Value:0x%02X\n",name,iv_attr_type[name]);
}
- count = 0;
-
oss << "\n--------------- Literal Symbol Table -----------------\n\n";
oss << "\n0x" << setw(4) << iv_lits.size() << '\t' << "Number of numeric literals\n";
@@ -772,9 +816,12 @@ string Symbols::attr_listing()
for(VAR_SYMBOL_USED::iterator i = iv_used_var.begin() + 1; i != iv_used_var.end(); ++i)
{
string name = (*i).first;
- if (name.compare(0, 4, SYS_ATTR) == 0)
+
+ //Strip off any prefix (i.e. "SYS." or "TGT<#>.")
+ size_t pos = name.find('.');
+ if(pos != string::npos)
{
- name = name.substr(4);
+ name = name.substr(pos+1);
}
oss << name << endl;
@@ -871,12 +918,14 @@ uint32_t Symbols::restore_var_bseq(BINSEQ::const_iterator & bli)
string name = find_text(attrId);
string used_var_name = iv_used_var.at(i+1).first;
- // Account for system attributes
+ // Account for system & associated target attributes
if (name != used_var_name)
{
- if (name == used_var_name.substr(4))
+ size_t pos = used_var_name.find(name);
+ if(pos != string::npos)
{
attrId = iv_symbols[used_var_name].first;
+
}
else
{
@@ -976,8 +1025,10 @@ uint32_t Symbols::get_rpn_id(uint32_t bin_tag)
uint32_t offset = bin_tag & ~IF_TYPE_MASK;
switch(type)
{
- case IF_ATTR_TYPE: {
- offset &= ~IF_SYS_ATTR_MASK;
+ case IF_ATTR_TYPE:
+ case IF_SYS_ATTR_TYPE:
+ case IF_ASSOC_TGT_ATTR_TYPE:
+ {
string name = iv_used_var[offset].first;
rpn_id = use_symbol(name);
}
diff --git a/src/usr/hwpf/ifcompiler/initSymbols.H b/src/usr/hwpf/ifcompiler/initSymbols.H
index 67872f1cd..92bd518ee 100755
--- a/src/usr/hwpf/ifcompiler/initSymbols.H
+++ b/src/usr/hwpf/ifcompiler/initSymbols.H
@@ -29,6 +29,7 @@
// camvanng 04/16/12 Support defines for SCOM address
// Support defines for bits, scom_data and attribute columns
// Delete obsolete code for defines support
+// camvanng 05/07/12 Support for associated target attributes
// End Change Log *********************************************************************************
/**
@@ -56,6 +57,7 @@ using namespace std;
namespace init
{
typedef set<string> FILELIST;
+ const string ASSOC_TGT_ATTR = "TGT";
class Symbols
{
@@ -98,11 +100,12 @@ namespace init
* @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
- * tt == 0b01 -> enumerated literal
- * tt == 0b10 -> Variable name
- * tt == 0b11 -> Numeric constant
- * xxxxxx xxxxxxxx assigned tag offset
+ * @note tag bits 0btttxxxxx xxxxxxxx
+ * ttt == 0b010 -> Numeric constant
+ * ttt == 0b100 -> Target attribute
+ * ttt == 0b101 -> System attribute
+ * ttt == 0b110 -> Associated target attribute
+ * xxxxx xxxxxxxx assigned tag offset
*/
uint16_t get_tag(uint32_t i_rpn_id);
@@ -238,21 +241,21 @@ namespace init
typedef pair<uint32_t,uint32_t> MAP_DATA; //cini_id & corresponding rpn_id/NOT_USED
typedef map<string,MAP_DATA > SYMBOL_MAP; //attr name & corresponding cini_id, rpn_id/NOT_USED pair
typedef map<string,uint32_t> SPY_MAP;
- typedef map<string,uint32_t> SYMBOL_ATTR_TYPE;
- typedef map<string,uint64_t> SYMBOL_ATTR_ENUM;
+ typedef map<string,uint32_t> SYMBOL_ATTR_TYPE; //attr name & corresponding type
+ typedef map<string,uint64_t> SYMBOL_ATTR_ENUM; //enum name & corresponding value
typedef pair<string,uint32_t> RPN_DATA; //attribute name & corresponding cini_id
- typedef map<uint32_t,RPN_DATA> RPN_MAP; //attr name & corresponding attr name, cini_id pair
+ typedef map<uint32_t,RPN_DATA> RPN_MAP; //rpn_id & corresponding attr name, cini_id pair
typedef vector<RPN_DATA> VAR_SYMBOL_USED;
typedef vector<uint32_t> SYMBOL_USED;
- typedef pair<uint64_t,uint32_t> LIT_DATA;
- typedef vector<LIT_DATA> LIT_LIST;
+ typedef pair<uint64_t,uint32_t> LIT_DATA; //numeric literal & corresponding size
+ typedef vector<LIT_DATA> LIT_LIST; ///< List of numeric literals and their size
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_ATTR_TYPE iv_attr_type; ///< List of attributes and their type
+ SYMBOL_ATTR_ENUM iv_attr_enum; ///< List of attribute enums and their value
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
VAR_SYMBOL_USED iv_used_var; ///< List of used attributes and their ids ordered by name
OpenPOWER on IntegriCloud