Use split_tokens()

This commit is contained in:
Eddie Hung 2019-07-10 17:34:51 -07:00
parent 3bb48facb2
commit a092c48f03
2 changed files with 19 additions and 25 deletions

View File

@ -276,18 +276,12 @@ struct XAigerWriter
if (r.second) { if (r.second) {
auto it = inst_module->attributes.find("\\abc_flop"); auto it = inst_module->attributes.find("\\abc_flop");
if (it != inst_module->attributes.end()) { if (it != inst_module->attributes.end()) {
std::string abc_flop = it->second.decode_string(); auto abc_flop = it->second.decode_string();
size_t start, end; auto tokens = split_tokens(abc_flop, ",");
end = abc_flop.find(','); // Ignore original module if (tokens.size() != 4)
log_assert(end != std::string::npos); log_error("'abc_flop' attribute on module '%s' does not contain exactly four comma-separated tokens.\n", log_id(cell->type));
start = end + 1; auto abc_flop_d = RTLIL::escape_id(tokens[1]);
end = abc_flop.find(',', start + 1); auto abc_flop_q = RTLIL::escape_id(tokens[2]);
log_assert(start != std::string::npos && end != std::string::npos);
auto abc_flop_d = RTLIL::escape_id(abc_flop.substr(start, end-start));
start = end + 1;
end = abc_flop.find(',', start + 1);
log_assert(start != std::string::npos && end != std::string::npos);
auto abc_flop_q = RTLIL::escape_id(abc_flop.substr(start, end-start));
r.first->second = std::make_pair(abc_flop_d, abc_flop_q); r.first->second = std::make_pair(abc_flop_d, abc_flop_q);
} }
} }
@ -404,15 +398,15 @@ struct XAigerWriter
if (it != box_module->attributes.end()) { if (it != box_module->attributes.end()) {
RTLIL::Wire *carry_in = nullptr, *carry_out = nullptr; RTLIL::Wire *carry_in = nullptr, *carry_out = nullptr;
auto carry_in_out = it->second.decode_string(); auto carry_in_out = it->second.decode_string();
auto pos = carry_in_out.find(','); auto tokens = split_tokens(carry_in_out, ",");
if (pos == std::string::npos) if (tokens.size() != 2)
log_error("'abc_carry' attribute on module '%s' does not contain ','.\n", log_id(cell->type)); log_error("'abc_carry' attribute on module '%s' does not contain exactly two comma-separated tokens.\n", log_id(cell->type));
auto carry_in_name = RTLIL::escape_id(carry_in_out.substr(0, pos)); auto carry_in_name = RTLIL::escape_id(tokens[0]);
carry_in = box_module->wire(carry_in_name); carry_in = box_module->wire(carry_in_name);
if (!carry_in || !carry_in->port_input) if (!carry_in || !carry_in->port_input)
log_error("'abc_carry' on module '%s' contains '%s' which does not exist or is not an input port.\n", log_id(cell->type), carry_in_name.c_str()); log_error("'abc_carry' on module '%s' contains '%s' which does not exist or is not an input port.\n", log_id(cell->type), carry_in_name.c_str());
auto carry_out_name = RTLIL::escape_id(carry_in_out.substr(pos+1)); auto carry_out_name = RTLIL::escape_id(tokens[1]);
carry_out = box_module->wire(carry_out_name); carry_out = box_module->wire(carry_out_name);
if (!carry_out || !carry_out->port_output) if (!carry_out || !carry_out->port_output)
log_error("'abc_carry' on module '%s' contains '%s' which does not exist or is not an output port.\n", log_id(cell->type), carry_out_name.c_str()); log_error("'abc_carry' on module '%s' contains '%s' which does not exist or is not an output port.\n", log_id(cell->type), carry_out_name.c_str());

View File

@ -754,14 +754,14 @@ void AigerReader::post_process()
auto it = box_module->attributes.find("\\abc_flop"); auto it = box_module->attributes.find("\\abc_flop");
if (it != box_module->attributes.end()) { if (it != box_module->attributes.end()) {
log_assert(flop_count < flopNum); log_assert(flop_count < flopNum);
std::string abc_flop = it->second.decode_string(); auto abc_flop = it->second.decode_string();
auto pos = abc_flop.find(','); auto tokens = split_tokens(abc_flop, ",");
log_assert(pos != std::string::npos); if (tokens.size() != 4)
flop_module = design->module(RTLIL::escape_id(abc_flop.substr(0, pos))); log_error("'abc_flop' attribute on module '%s' does not contain exactly four comma-separated tokens.\n", log_id(cell->type));
log_assert(flop_module); flop_module = design->module(RTLIL::escape_id(tokens[0]));
pos = abc_flop.rfind(','); if (!flop_module)
log_assert(pos != std::string::npos); log_error("First token '%s' in 'abc_flop' attribute on module '%s' is not a valid module.\n", tokens[0].c_str(), log_id(cell->type));
flop_past_q = RTLIL::escape_id(abc_flop.substr(pos+1)); flop_past_q = RTLIL::escape_id(tokens[3]);
flop_data[cell->type] = std::make_pair(flop_module, flop_past_q); flop_data[cell->type] = std::make_pair(flop_module, flop_past_q);
} }
it = box_module->attributes.find("\\abc_carry"); it = box_module->attributes.find("\\abc_carry");