The following code snippet parses the bench file "network.bench"
and calls the methods on_input
and on_gate
for each input and gate declaration in the file, respectively.
#include <lorina/lorina.hpp>
class reader : public bench_reader
{
public:
void on_input( const std::string& name ) const override
{
/* ... */
}
void on_gate( const std::vector<std::string>& inputs, const std::string& output,
const std::string& type ) const override
{
/* ... */
}
}; /* reader */
auto const result = read_bench( "network.bench", reader() );
assert( result == return_code::success );
Besides parsing, the reader supports a mechanism to react on parse errors.
#include <lorina/diagnostics.hpp>
class diagnostics : public diagnostic_consumer
{
public:
void handle_diagnostic( diagnostic_level level, std::string const& message ) const override
{
/* ... */
}
}; /* diagnostics */
diagnostics consumer;
diagnostic_engine diag( &consumer );
auto const result = read_bench( "network.bench", reader(), &diag );
assert( result == return_code::success );
lorina is part of the EPFL logic synthesis libraries. The other libraries and several examples on how to use and integrate the libraries can be found in the logic synthesis tool showcase.