mirror of https://github.com/YosysHQ/yosys.git
Add "read_ilang -[no]overwrite"
Signed-off-by: Clifford Wolf <clifford@clifford.at>
This commit is contained in:
parent
d938ce7ab6
commit
6dad191377
|
@ -44,11 +44,39 @@ struct IlangFrontend : public Frontend {
|
||||||
log("Load modules from an ilang file to the current design. (ilang is a text\n");
|
log("Load modules from an ilang file to the current design. (ilang is a text\n");
|
||||||
log("representation of a design in yosys's internal format.)\n");
|
log("representation of a design in yosys's internal format.)\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -nooverwrite\n");
|
||||||
|
log(" ignore re-definitions of modules. (the default behavior is to\n");
|
||||||
|
log(" create an error message if the existing module is not a blackbox\n");
|
||||||
|
log(" module, and overwrite the existing module if it is a blackbox module.)\n");
|
||||||
|
log("\n");
|
||||||
|
log(" -overwrite\n");
|
||||||
|
log(" overwrite existing modules with the same name\n");
|
||||||
|
log("\n");
|
||||||
}
|
}
|
||||||
void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
void execute(std::istream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
|
||||||
{
|
{
|
||||||
|
ILANG_FRONTEND::flag_nooverwrite = false;
|
||||||
|
ILANG_FRONTEND::flag_overwrite = false;
|
||||||
|
|
||||||
log_header(design, "Executing ILANG frontend.\n");
|
log_header(design, "Executing ILANG frontend.\n");
|
||||||
extra_args(f, filename, args, 1);
|
|
||||||
|
size_t argidx;
|
||||||
|
for (argidx = 1; argidx < args.size(); argidx++) {
|
||||||
|
std::string arg = args[argidx];
|
||||||
|
if (arg == "-nooverwrite") {
|
||||||
|
ILANG_FRONTEND::flag_nooverwrite = true;
|
||||||
|
ILANG_FRONTEND::flag_overwrite = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (arg == "-overwrite") {
|
||||||
|
ILANG_FRONTEND::flag_nooverwrite = false;
|
||||||
|
ILANG_FRONTEND::flag_overwrite = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
extra_args(f, filename, args, argidx);
|
||||||
|
|
||||||
log("Input filename: %s\n", filename.c_str());
|
log("Input filename: %s\n", filename.c_str());
|
||||||
|
|
||||||
ILANG_FRONTEND::lexin = f;
|
ILANG_FRONTEND::lexin = f;
|
||||||
|
|
|
@ -32,6 +32,8 @@ YOSYS_NAMESPACE_BEGIN
|
||||||
namespace ILANG_FRONTEND {
|
namespace ILANG_FRONTEND {
|
||||||
extern std::istream *lexin;
|
extern std::istream *lexin;
|
||||||
extern RTLIL::Design *current_design;
|
extern RTLIL::Design *current_design;
|
||||||
|
extern bool flag_nooverwrite;
|
||||||
|
extern bool flag_overwrite;
|
||||||
}
|
}
|
||||||
|
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
|
|
@ -37,6 +37,8 @@ namespace ILANG_FRONTEND {
|
||||||
std::vector<std::vector<RTLIL::SwitchRule*>*> switch_stack;
|
std::vector<std::vector<RTLIL::SwitchRule*>*> switch_stack;
|
||||||
std::vector<RTLIL::CaseRule*> case_stack;
|
std::vector<RTLIL::CaseRule*> case_stack;
|
||||||
dict<RTLIL::IdString, RTLIL::Const> attrbuf;
|
dict<RTLIL::IdString, RTLIL::Const> attrbuf;
|
||||||
|
bool flag_nooverwrite, flag_overwrite;
|
||||||
|
bool delete_current_module;
|
||||||
}
|
}
|
||||||
using namespace ILANG_FRONTEND;
|
using namespace ILANG_FRONTEND;
|
||||||
YOSYS_NAMESPACE_END
|
YOSYS_NAMESPACE_END
|
||||||
|
@ -93,11 +95,26 @@ design:
|
||||||
|
|
||||||
module:
|
module:
|
||||||
TOK_MODULE TOK_ID EOL {
|
TOK_MODULE TOK_ID EOL {
|
||||||
if (current_design->has($2))
|
delete_current_module = false;
|
||||||
|
if (current_design->has($2)) {
|
||||||
|
RTLIL::Module *existing_mod = current_design->module($2);
|
||||||
|
if (!flag_overwrite && attrbuf.count("\\blackbox") && attrbuf.at("\\blackbox").as_bool()) {
|
||||||
|
log("Ignoring blackbox re-definition of module %s.\n", $2);
|
||||||
|
delete_current_module = true;
|
||||||
|
} else if (!flag_nooverwrite && !flag_overwrite && !existing_mod->get_bool_attribute("\\blackbox")) {
|
||||||
rtlil_frontend_ilang_yyerror(stringf("ilang error: redefinition of module %s.", $2).c_str());
|
rtlil_frontend_ilang_yyerror(stringf("ilang error: redefinition of module %s.", $2).c_str());
|
||||||
|
} else if (flag_nooverwrite) {
|
||||||
|
log("Ignoring re-definition of module %s.\n", $2);
|
||||||
|
delete_current_module = true;
|
||||||
|
} else {
|
||||||
|
log("Replacing existing%s module %s.\n", existing_mod->get_bool_attribute("\\blackbox") ? " blackbox" : "", $2);
|
||||||
|
current_design->remove(existing_mod);
|
||||||
|
}
|
||||||
|
}
|
||||||
current_module = new RTLIL::Module;
|
current_module = new RTLIL::Module;
|
||||||
current_module->name = $2;
|
current_module->name = $2;
|
||||||
current_module->attributes = attrbuf;
|
current_module->attributes = attrbuf;
|
||||||
|
if (!delete_current_module)
|
||||||
current_design->add(current_module);
|
current_design->add(current_module);
|
||||||
attrbuf.clear();
|
attrbuf.clear();
|
||||||
free($2);
|
free($2);
|
||||||
|
@ -105,6 +122,9 @@ module:
|
||||||
if (attrbuf.size() != 0)
|
if (attrbuf.size() != 0)
|
||||||
rtlil_frontend_ilang_yyerror("dangling attribute");
|
rtlil_frontend_ilang_yyerror("dangling attribute");
|
||||||
current_module->fixup_ports();
|
current_module->fixup_ports();
|
||||||
|
if (delete_current_module)
|
||||||
|
delete current_module;
|
||||||
|
current_module = nullptr;
|
||||||
} EOL;
|
} EOL;
|
||||||
|
|
||||||
module_body:
|
module_body:
|
||||||
|
|
Loading…
Reference in New Issue