mirror of
https://github.com/YosysHQ/yosys
synced 2025-08-03 18:00:24 +00:00
raise_error: Add -always
This commit is contained in:
parent
a18acaca82
commit
895dfd963f
2 changed files with 45 additions and 14 deletions
|
@ -20,12 +20,15 @@ struct RaiseErrorPass : public Pass {
|
||||||
log(" -stderr\n");
|
log(" -stderr\n");
|
||||||
log(" Log error messages directly to stderr instead of using 'log_error'.\n");
|
log(" Log error messages directly to stderr instead of using 'log_error'.\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -always\n");
|
||||||
|
log(" Raise an error even if the 'raise_error' attribute is missing.\n");
|
||||||
|
log("\n");
|
||||||
}
|
}
|
||||||
void execute(vector<string> args, RTLIL::Design *design) override
|
void execute(vector<string> args, RTLIL::Design *design) override
|
||||||
{
|
{
|
||||||
log_header(design, "Executing RAISE_ERROR pass.\n");
|
log_header(design, "Executing RAISE_ERROR pass.\n");
|
||||||
|
|
||||||
bool use_stderr = false;
|
bool use_stderr = false, always = false;
|
||||||
|
|
||||||
int argidx;
|
int argidx;
|
||||||
for (argidx = 1; argidx < GetSize(args); argidx++)
|
for (argidx = 1; argidx < GetSize(args); argidx++)
|
||||||
|
@ -34,6 +37,10 @@ struct RaiseErrorPass : public Pass {
|
||||||
use_stderr = true;
|
use_stderr = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (args[argidx] == "-always") {
|
||||||
|
always = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,27 +62,40 @@ struct RaiseErrorPass : public Pass {
|
||||||
if (err_obj != nullptr) break;
|
if (err_obj != nullptr) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (err_obj == nullptr && !always) {
|
||||||
|
log("'raise_error' attribute not found\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int err_no = 1;
|
||||||
|
string err_msg = "";
|
||||||
if (err_obj != nullptr) {
|
if (err_obj != nullptr) {
|
||||||
log("Raising error from '%s'.\n", log_id(err_obj));
|
log("Raising error from '%s'.\n", log_id(err_obj));
|
||||||
auto err_no = err_obj->attributes[ID::raise_error].as_int();
|
err_no = err_obj->attributes[ID::raise_error].as_int();
|
||||||
if (err_no < 256) {
|
if (err_no > 256) {
|
||||||
log_flush();
|
err_msg = err_obj->get_string_attribute(ID::raise_error);
|
||||||
|
err_no = 1;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
auto err_msg = err_obj->get_string_attribute(ID::raise_error);
|
err_msg = "No 'raise_error' attribute found";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (err_msg.size() > 0) {
|
||||||
if (use_stderr) {
|
if (use_stderr) {
|
||||||
std::cerr << err_msg << std::endl;
|
std::cerr << err_msg << std::endl;
|
||||||
err_no = 1;
|
|
||||||
} else {
|
} else {
|
||||||
log_error("%s\n", err_msg.c_str());
|
log_error("%s\n", err_msg.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (err_no < 256) {
|
||||||
|
log_flush();
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
_exit(err_no);
|
_exit(err_no);
|
||||||
#else
|
#else
|
||||||
_Exit(err_no);
|
_Exit(err_no);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
log("'raise_error' attribute not found\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} RaiseErrorPass;
|
} RaiseErrorPass;
|
||||||
|
|
|
@ -14,6 +14,12 @@ EOF
|
||||||
select -assert-mod-count 3 =*
|
select -assert-mod-count 3 =*
|
||||||
design -stash read
|
design -stash read
|
||||||
|
|
||||||
|
# empty design does not raise_error
|
||||||
|
design -reset
|
||||||
|
logger -expect log "'raise_error' attribute not found" 1
|
||||||
|
raise_error
|
||||||
|
logger -check-expected
|
||||||
|
|
||||||
# raise_error with int exits with status
|
# raise_error with int exits with status
|
||||||
design -load read
|
design -load read
|
||||||
bugpoint -suffix error -yosys ../../yosys -command raise_error -expect-return 7
|
bugpoint -suffix error -yosys ../../yosys -command raise_error -expect-return 7
|
||||||
|
@ -41,3 +47,8 @@ rename top abc
|
||||||
bugpoint -suffix error -yosys ../../yosys -command "raise_error -stderr" -err-grep "help me" -expect-return 1
|
bugpoint -suffix error -yosys ../../yosys -command "raise_error -stderr" -err-grep "help me" -expect-return 1
|
||||||
select -assert-mod-count 1 =*
|
select -assert-mod-count 1 =*
|
||||||
select -assert-mod-count 1 other
|
select -assert-mod-count 1 other
|
||||||
|
|
||||||
|
# empty design can raise_error -always
|
||||||
|
design -reset
|
||||||
|
bugpoint -suffix error -yosys ../../yosys -command "raise_error -always" -grep "ERROR: No 'raise_error' attribute found" -expect-return 1
|
||||||
|
bugpoint -suffix error -yosys ../../yosys -command "raise_error -always -stderr" -err-grep "No 'raise_error' attribute found" -expect-return 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue