Skip to content

Commit

Permalink
pofParser: removed getMemSection. Simplify getData/getLength logic. I…
Browse files Browse the repository at this point in the history
…mproved displayHeader format
  • Loading branch information
trabucayre committed Jan 26, 2025
1 parent 48da801 commit bb0591e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
34 changes: 12 additions & 22 deletions src/pofParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,45 +28,35 @@ POFParser::POFParser(const std::string &filename, bool verbose):
POFParser::~POFParser()
{}

int POFParser::getMemSection(const std::string &name)
{
int i = 0;
for (auto it = mem_section.begin(); it != mem_section.end(); it++, i++) {
if ((*it).first == name)
return i;
}
return -1;
}

uint8_t *POFParser::getData(const std::string &section_name)
{
if (section_name == "")
return (uint8_t*)_bit_data.data();
int idx = getMemSection(section_name);
if (idx != -1)
return mem_section[section_name].data;
else
auto section = mem_section.find(section_name);
if (section == mem_section.end())
return NULL;
return (*section).second.data;
}

int POFParser::getLength(const std::string &section_name)
{
if (section_name == "")
return _bit_length;
int idx = getMemSection(section_name);
if (idx != -1)
return mem_section[section_name].len;
else
auto section = mem_section.find(section_name);
if (section == mem_section.end())
return -1;
return (*section).second.len;
}

void POFParser::displayHeader()
{
ConfigBitstreamParser::displayHeader();
char mess[1024];
snprintf(mess, 1024, "Flag section offset len end");
printInfo(mess);
for (auto it = mem_section.begin(); it != mem_section.end(); it++) {
memory_section_t v = (*it).second;
char mess[1024];
snprintf(mess, 1024, "%02x %4s: ", v.flag, v.section.c_str());
snprintf(mess, 1024, "%02x %4s: ", v.flag, v.section.c_str());
printInfo(mess, false);
// start address + len (in bits) + end addr
snprintf(mess, 1024, " %08x %08x %08x", v.offset, v.len, v.offset + ((v.len/8)-1));
Expand Down Expand Up @@ -111,9 +101,9 @@ int POFParser::parse()
/* update pointers to memory area */
ptr = (uint8_t *)_bit_data.data();
mem_section["CFM0"].data = &ptr[mem_section["CFM0"].offset + 0x0C];
if (getMemSection("CFM1") != -1)
if (mem_section.find("CFM1") != mem_section.end())
mem_section["CFM1"].data = &ptr[mem_section["CFM1"].offset + 0x0C];
if (getMemSection("CFM2") != -1)
if (mem_section.find("CFM2") != mem_section.end())
mem_section["CFM2"].data = &ptr[mem_section["CFM2"].offset + 0x0C];
mem_section["UFM"].data = &ptr[mem_section["UFM"].offset + 0x0C];
mem_section["ICB"].data = &ptr[mem_section["ICB"].offset + 0x0C];
Expand Down
5 changes: 0 additions & 5 deletions src/pofParser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ class POFParser: public ConfigBitstreamParser {


private:
/* \brief return index for a section called name
* \return -1 when section not present, index otherwise
*/
int getMemSection(const std::string &name);

/* packet 0x1A content */
typedef struct {
uint8_t flag; // 1 Byte before section name
Expand Down

0 comments on commit bb0591e

Please sign in to comment.