mirror of
https://github.com/YosysHQ/yosys
synced 2025-04-12 20:18:20 +00:00
Generalized blifparse API
This commit is contained in:
parent
7dad017c9c
commit
e5116eeb77
|
@ -21,7 +21,7 @@
|
||||||
|
|
||||||
YOSYS_NAMESPACE_BEGIN
|
YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
static bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count, FILE *f)
|
static bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count, std::istream &f)
|
||||||
{
|
{
|
||||||
int buffer_len = 0;
|
int buffer_len = 0;
|
||||||
buffer[0] = 0;
|
buffer[0] = 0;
|
||||||
|
@ -42,32 +42,31 @@ static bool read_next_line(char *&buffer, size_t &buffer_size, int &line_count,
|
||||||
if (buffer_len > 0 && buffer[buffer_len-1] == '\\')
|
if (buffer_len > 0 && buffer[buffer_len-1] == '\\')
|
||||||
buffer[--buffer_len] = 0;
|
buffer[--buffer_len] = 0;
|
||||||
line_count++;
|
line_count++;
|
||||||
if (fgets(buffer+buffer_len, buffer_size-buffer_len, f) == NULL)
|
if (!f.getline(buffer+buffer_len, buffer_size-buffer_len))
|
||||||
return false;
|
return false;
|
||||||
} else
|
} else
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name)
|
void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name)
|
||||||
{
|
{
|
||||||
RTLIL::Design *design = new RTLIL::Design;
|
RTLIL::Module *module = nullptr;
|
||||||
RTLIL::Module *module = new RTLIL::Module;
|
|
||||||
|
|
||||||
RTLIL::Const *lutptr = NULL;
|
RTLIL::Const *lutptr = NULL;
|
||||||
RTLIL::State lut_default_state = RTLIL::State::Sx;
|
RTLIL::State lut_default_state = RTLIL::State::Sx;
|
||||||
|
|
||||||
module->name = "\\netlist";
|
|
||||||
design->add(module);
|
|
||||||
|
|
||||||
size_t buffer_size = 4096;
|
size_t buffer_size = 4096;
|
||||||
char *buffer = (char*)malloc(buffer_size);
|
char *buffer = (char*)malloc(buffer_size);
|
||||||
int line_count = 0;
|
int line_count = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (!read_next_line(buffer, buffer_size, line_count, f))
|
if (!read_next_line(buffer, buffer_size, line_count, f)) {
|
||||||
goto error;
|
if (module != nullptr)
|
||||||
|
goto error;
|
||||||
|
free(buffer);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
continue_without_read:
|
continue_without_read:
|
||||||
if (buffer[0] == '#')
|
if (buffer[0] == '#')
|
||||||
|
@ -85,13 +84,24 @@ RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name)
|
||||||
|
|
||||||
char *cmd = strtok(buffer, " \t\r\n");
|
char *cmd = strtok(buffer, " \t\r\n");
|
||||||
|
|
||||||
if (!strcmp(cmd, ".model"))
|
if (!strcmp(cmd, ".model")) {
|
||||||
|
if (module != nullptr)
|
||||||
|
goto error;
|
||||||
|
module = new RTLIL::Module;
|
||||||
|
module->name = RTLIL::escape_id(strtok(NULL, " \t\r\n"));
|
||||||
|
if (design->module(module->name))
|
||||||
|
log_error("Duplicate definition of module %s in line %d!\n", log_id(module->name), line_count);
|
||||||
|
design->add(module);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (module == nullptr)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (!strcmp(cmd, ".end")) {
|
if (!strcmp(cmd, ".end")) {
|
||||||
module->fixup_ports();
|
module->fixup_ports();
|
||||||
free(buffer);
|
module = nullptr;
|
||||||
return design;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcmp(cmd, ".inputs") || !strcmp(cmd, ".outputs")) {
|
if (!strcmp(cmd, ".inputs") || !strcmp(cmd, ".outputs")) {
|
||||||
|
@ -256,8 +266,6 @@ RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name)
|
||||||
|
|
||||||
error:
|
error:
|
||||||
log_error("Syntax error in line %d!\n", line_count);
|
log_error("Syntax error in line %d!\n", line_count);
|
||||||
// delete design;
|
|
||||||
// return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
YOSYS_NAMESPACE_BEGIN
|
YOSYS_NAMESPACE_BEGIN
|
||||||
|
|
||||||
extern RTLIL::Design *abc_parse_blif(FILE *f, std::string dff_name);
|
extern void parse_blif(RTLIL::Design *design, std::istream &f, std::string dff_name);
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
||||||
|
|
|
@ -877,14 +877,16 @@ void abc_module(RTLIL::Design *design, RTLIL::Module *current_module, std::strin
|
||||||
log_error("ABC: execution of command \"%s\" failed: return code %d.\n", buffer.c_str(), ret);
|
log_error("ABC: execution of command \"%s\" failed: return code %d.\n", buffer.c_str(), ret);
|
||||||
|
|
||||||
buffer = stringf("%s/%s", tempdir_name.c_str(), "output.blif");
|
buffer = stringf("%s/%s", tempdir_name.c_str(), "output.blif");
|
||||||
f = fopen(buffer.c_str(), "rt");
|
std::ifstream ifs;
|
||||||
if (f == NULL)
|
ifs.open(buffer);
|
||||||
|
if (ifs.fail())
|
||||||
log_error("Can't open ABC output file `%s'.\n", buffer.c_str());
|
log_error("Can't open ABC output file `%s'.\n", buffer.c_str());
|
||||||
|
|
||||||
bool builtin_lib = liberty_file.empty() && script_file.empty() && !lut_mode;
|
bool builtin_lib = liberty_file.empty() && script_file.empty() && !lut_mode;
|
||||||
RTLIL::Design *mapped_design = abc_parse_blif(f, builtin_lib ? "\\DFF" : "\\_dff_");
|
RTLIL::Design *mapped_design = new RTLIL::Design;
|
||||||
|
parse_blif(mapped_design, ifs, builtin_lib ? "\\DFF" : "\\_dff_");
|
||||||
|
|
||||||
fclose(f);
|
ifs.close();
|
||||||
|
|
||||||
log_header("Re-integrating ABC results.\n");
|
log_header("Re-integrating ABC results.\n");
|
||||||
RTLIL::Module *mapped_mod = mapped_design->modules_["\\netlist"];
|
RTLIL::Module *mapped_mod = mapped_design->modules_["\\netlist"];
|
||||||
|
|
Loading…
Reference in a new issue