mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-13 04:28:18 +00:00
Merge pull request #596 from litghost/extend_blif_parser
#565 Add BLIF parsing support for .conn and .cname
This commit is contained in:
commit
b210e9d293
|
@ -83,7 +83,9 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
RTLIL::Module *module = nullptr;
|
RTLIL::Module *module = nullptr;
|
||||||
RTLIL::Const *lutptr = NULL;
|
RTLIL::Const *lutptr = NULL;
|
||||||
RTLIL::Cell *sopcell = NULL;
|
RTLIL::Cell *sopcell = NULL;
|
||||||
|
RTLIL::Cell *lastcell = nullptr;
|
||||||
RTLIL::State lut_default_state = RTLIL::State::Sx;
|
RTLIL::State lut_default_state = RTLIL::State::Sx;
|
||||||
|
char err_reason[80];
|
||||||
int blif_maxnum = 0, sopmode = -1;
|
int blif_maxnum = 0, sopmode = -1;
|
||||||
|
|
||||||
auto blif_wire = [&](const std::string &wire_name) -> Wire*
|
auto blif_wire = [&](const std::string &wire_name) -> Wire*
|
||||||
|
@ -159,6 +161,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
if (module != nullptr)
|
if (module != nullptr)
|
||||||
goto error;
|
goto error;
|
||||||
module = new RTLIL::Module;
|
module = new RTLIL::Module;
|
||||||
|
lastcell = nullptr;
|
||||||
module->name = RTLIL::escape_id(strtok(NULL, " \t\r\n"));
|
module->name = RTLIL::escape_id(strtok(NULL, " \t\r\n"));
|
||||||
obj_attributes = &module->attributes;
|
obj_attributes = &module->attributes;
|
||||||
obj_parameters = nullptr;
|
obj_parameters = nullptr;
|
||||||
|
@ -232,6 +235,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
}
|
}
|
||||||
|
|
||||||
module = nullptr;
|
module = nullptr;
|
||||||
|
lastcell = nullptr;
|
||||||
obj_attributes = nullptr;
|
obj_attributes = nullptr;
|
||||||
obj_parameters = nullptr;
|
obj_parameters = nullptr;
|
||||||
continue;
|
continue;
|
||||||
|
@ -264,6 +268,22 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!strcmp(cmd, ".cname"))
|
||||||
|
{
|
||||||
|
char *p = strtok(NULL, " \t\r\n");
|
||||||
|
if (p == NULL)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if(lastcell == nullptr || module == nullptr)
|
||||||
|
{
|
||||||
|
snprintf(err_reason, sizeof(err_reason), "No primative object to attach .cname %s.", p);
|
||||||
|
goto error_with_reason;
|
||||||
|
}
|
||||||
|
|
||||||
|
module->rename(lastcell, p);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (!strcmp(cmd, ".attr") || !strcmp(cmd, ".param")) {
|
if (!strcmp(cmd, ".attr") || !strcmp(cmd, ".param")) {
|
||||||
char *n = strtok(NULL, " \t\r\n");
|
char *n = strtok(NULL, " \t\r\n");
|
||||||
char *v = strtok(NULL, "\r\n");
|
char *v = strtok(NULL, "\r\n");
|
||||||
|
@ -281,12 +301,16 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
const_v.bits[i] = v[n-i-1] != '0' ? State::S1 : State::S0;
|
const_v.bits[i] = v[n-i-1] != '0' ? State::S1 : State::S0;
|
||||||
}
|
}
|
||||||
if (!strcmp(cmd, ".attr")) {
|
if (!strcmp(cmd, ".attr")) {
|
||||||
if (obj_attributes == nullptr)
|
if (obj_attributes == nullptr) {
|
||||||
goto error;
|
snprintf(err_reason, sizeof(err_reason), "No object to attach .attr too.");
|
||||||
|
goto error_with_reason;
|
||||||
|
}
|
||||||
(*obj_attributes)[id_n] = const_v;
|
(*obj_attributes)[id_n] = const_v;
|
||||||
} else {
|
} else {
|
||||||
if (obj_parameters == nullptr)
|
if (obj_parameters == nullptr) {
|
||||||
goto error;
|
snprintf(err_reason, sizeof(err_reason), "No object to attach .param too.");
|
||||||
|
goto error_with_reason;
|
||||||
|
}
|
||||||
(*obj_parameters)[id_n] = const_v;
|
(*obj_parameters)[id_n] = const_v;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
@ -331,6 +355,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastcell = cell;
|
||||||
obj_attributes = &cell->attributes;
|
obj_attributes = &cell->attributes;
|
||||||
obj_parameters = &cell->parameters;
|
obj_parameters = &cell->parameters;
|
||||||
continue;
|
continue;
|
||||||
|
@ -383,6 +408,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
cell->setPort(it.first, sig);
|
cell->setPort(it.first, sig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastcell = cell;
|
||||||
obj_attributes = &cell->attributes;
|
obj_attributes = &cell->attributes;
|
||||||
obj_parameters = &cell->parameters;
|
obj_parameters = &cell->parameters;
|
||||||
continue;
|
continue;
|
||||||
|
@ -391,7 +417,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
obj_attributes = nullptr;
|
obj_attributes = nullptr;
|
||||||
obj_parameters = nullptr;
|
obj_parameters = nullptr;
|
||||||
|
|
||||||
if (!strcmp(cmd, ".barbuf"))
|
if (!strcmp(cmd, ".barbuf") || !strcmp(cmd, ".conn"))
|
||||||
{
|
{
|
||||||
char *p = strtok(NULL, " \t\r\n");
|
char *p = strtok(NULL, " \t\r\n");
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
|
@ -459,6 +485,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
sopcell->setPort("\\A", input_sig);
|
sopcell->setPort("\\A", input_sig);
|
||||||
sopcell->setPort("\\Y", output_sig);
|
sopcell->setPort("\\Y", output_sig);
|
||||||
sopmode = -1;
|
sopmode = -1;
|
||||||
|
lastcell = sopcell;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -469,6 +496,7 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
cell->setPort("\\Y", output_sig);
|
cell->setPort("\\Y", output_sig);
|
||||||
lutptr = &cell->parameters.at("\\LUT");
|
lutptr = &cell->parameters.at("\\LUT");
|
||||||
lut_default_state = RTLIL::State::Sx;
|
lut_default_state = RTLIL::State::Sx;
|
||||||
|
lastcell = cell;
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -546,6 +574,8 @@ void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name, bo
|
||||||
|
|
||||||
error:
|
error:
|
||||||
log_error("Syntax error in line %d!\n", line_count);
|
log_error("Syntax error in line %d!\n", line_count);
|
||||||
|
error_with_reason:
|
||||||
|
log_error("Syntax error in line %d: %s\n", line_count, err_reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct BlifFrontend : public Frontend {
|
struct BlifFrontend : public Frontend {
|
||||||
|
|
Loading…
Reference in a new issue