1515// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1616// See the License for the specific language governing permissions and
1717// limitations under the License.
18+ #define private public
19+ #include " libparse.h"
20+ #undef private
1821
1922#include < pybind11/pybind11.h>
2023#include < pybind11/stl.h>
2124
22- #include " libparse.h"
2325#include " stdio_filebuf.h"
2426
2527namespace py = pybind11;
2628using namespace Yosys ;
2729
30+ void LibertyParser::error () const
31+ {
32+ std::ostringstream oss;
33+ oss << " Syntax error in liberty file on line " << line << " .\n " ;
34+ throw std::runtime_error (oss.str ());
35+ }
36+
37+ void LibertyParser::error (const std::string &str) const
38+ {
39+ std::stringstream oss;
40+ oss << " Syntax error in liberty file on line " << line << " .\n " ;
41+ oss << " " << str << " \n " ;
42+ throw std::runtime_error (oss.str ());
43+ }
44+
45+
2846struct PyIStream : public std ::istream {
2947 PyIStream (FILE *f) : std::istream(&buffer_), buffer_(f) {}
3048
@@ -35,7 +53,8 @@ struct PyIStream : public std::istream {
3553 }
3654
3755 auto fd_attr = pyfile.attr (" fileno" );
38- auto fd = fd_attr.cast <int >();
56+ auto fd_obj = fd_attr ();
57+ auto fd = fd_obj.cast <int >();
3958 if (fd == -1 ) {
4059 throw std::runtime_error (" Failed to get file descriptor" );
4160 }
@@ -58,6 +77,7 @@ LibertyParser *from_file(const py::object &pyfile)
5877 return new LibertyParser (*cxx_stream);
5978}
6079
80+
6181PYBIND11_MODULE (_libparse, m)
6282{
6383 m.doc () = " libparse from yosys, native component" ;
0 commit comments