From: Eddie Hung Date: Thu, 11 Jul 2019 00:34:51 +0000 (-0700) Subject: Use split_tokens() X-Git-Tag: working-ls180~881^2^2~276 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=a092c48f036b71cc4014ec6f2865297d49589d40;p=yosys.git Use split_tokens() --- diff --git a/backends/aiger/xaiger.cc b/backends/aiger/xaiger.cc index a1085addf..ba0e36ce1 100644 --- a/backends/aiger/xaiger.cc +++ b/backends/aiger/xaiger.cc @@ -276,18 +276,12 @@ struct XAigerWriter if (r.second) { auto it = inst_module->attributes.find("\\abc_flop"); if (it != inst_module->attributes.end()) { - std::string abc_flop = it->second.decode_string(); - size_t start, end; - end = abc_flop.find(','); // Ignore original module - log_assert(end != std::string::npos); - start = end + 1; - end = abc_flop.find(',', start + 1); - 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)); + auto abc_flop = it->second.decode_string(); + auto tokens = split_tokens(abc_flop, ","); + if (tokens.size() != 4) + log_error("'abc_flop' attribute on module '%s' does not contain exactly four comma-separated tokens.\n", log_id(cell->type)); + auto abc_flop_d = RTLIL::escape_id(tokens[1]); + auto abc_flop_q = RTLIL::escape_id(tokens[2]); r.first->second = std::make_pair(abc_flop_d, abc_flop_q); } } @@ -404,15 +398,15 @@ struct XAigerWriter if (it != box_module->attributes.end()) { RTLIL::Wire *carry_in = nullptr, *carry_out = nullptr; auto carry_in_out = it->second.decode_string(); - auto pos = carry_in_out.find(','); - if (pos == std::string::npos) - log_error("'abc_carry' attribute on module '%s' does not contain ','.\n", log_id(cell->type)); - auto carry_in_name = RTLIL::escape_id(carry_in_out.substr(0, pos)); + auto tokens = split_tokens(carry_in_out, ","); + if (tokens.size() != 2) + 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(tokens[0]); carry_in = box_module->wire(carry_in_name); 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()); - 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); 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()); diff --git a/frontends/aiger/aigerparse.cc b/frontends/aiger/aigerparse.cc index 30e35da01..35b7f6a97 100644 --- a/frontends/aiger/aigerparse.cc +++ b/frontends/aiger/aigerparse.cc @@ -754,14 +754,14 @@ void AigerReader::post_process() auto it = box_module->attributes.find("\\abc_flop"); if (it != box_module->attributes.end()) { log_assert(flop_count < flopNum); - std::string abc_flop = it->second.decode_string(); - auto pos = abc_flop.find(','); - log_assert(pos != std::string::npos); - flop_module = design->module(RTLIL::escape_id(abc_flop.substr(0, pos))); - log_assert(flop_module); - pos = abc_flop.rfind(','); - log_assert(pos != std::string::npos); - flop_past_q = RTLIL::escape_id(abc_flop.substr(pos+1)); + auto abc_flop = it->second.decode_string(); + auto tokens = split_tokens(abc_flop, ","); + if (tokens.size() != 4) + log_error("'abc_flop' attribute on module '%s' does not contain exactly four comma-separated tokens.\n", log_id(cell->type)); + flop_module = design->module(RTLIL::escape_id(tokens[0])); + if (!flop_module) + 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(tokens[3]); flop_data[cell->type] = std::make_pair(flop_module, flop_past_q); } it = box_module->attributes.find("\\abc_carry");