Skip to content

Commit

Permalink
pyosys: catch boost::python::error_already_set
Browse files Browse the repository at this point in the history
* This catches exceptions from internal passes, printing them in a
  readable manner where the user would otherwise see an unspecified
  boost exception
  • Loading branch information
georgerennie committed Nov 4, 2024
1 parent b2d7858 commit f7c2b42
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions kernel/driver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
# include <unistd.h>
#endif

#ifdef WITH_PYTHON
# include <boost/python.hpp>
#endif

USING_YOSYS_NAMESPACE

#ifdef EMSCRIPTEN
Expand Down Expand Up @@ -525,6 +529,11 @@ int main(int argc, char **argv)
run_shell = false;
}

#ifdef WITH_PYTHON
// For boost::python::error_already_set
try {
#endif

if (!topmodule.empty())
run_pass("hierarchy -top " + topmodule);
if (!scriptfile.empty()) {
Expand Down Expand Up @@ -596,6 +605,13 @@ int main(int argc, char **argv)
run_backend(output_filename, backend_command);
}

#ifdef WITH_PYTHON
} catch (boost::python::error_already_set &) {
PyErr_Print();
log_error("Python interpreter encountered an exception.\n");
}
#endif

yosys_design->check();
for (auto it : saved_designs)
it.second->check();
Expand Down

0 comments on commit f7c2b42

Please sign in to comment.