Skip to content

Commit

Permalink
lorina update. (lsils#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
hriener authored Feb 13, 2021
1 parent ad8a841 commit 0589b42
Show file tree
Hide file tree
Showing 8 changed files with 376 additions and 45 deletions.
46 changes: 37 additions & 9 deletions lib/lorina/lorina/aiger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

#pragma once

#include <lorina/common.hpp>
#include <lorina/diagnostics.hpp>
#include <lorina/detail/utils.hpp>
#include "common.hpp"
#include "diagnostics.hpp"
#include "detail/utils.hpp"
#include <fstream>
#include <iostream>
#include <regex>
Expand Down Expand Up @@ -444,7 +444,7 @@ static std::regex fairness( R"(^f(\d+) (.*)$)" );
* \param in Input stream
* \param reader An AIGER reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_ascii_aiger( std::istream& in, const aiger_reader& reader, diagnostic_engine* diag = nullptr )
{
Expand Down Expand Up @@ -666,12 +666,26 @@ inline return_code read_ascii_aiger( std::istream& in, const aiger_reader& reade
* \param filename Name of the file
* \param reader An AIGER reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_ascii_aiger( const std::string& filename, const aiger_reader& reader, diagnostic_engine* diag = nullptr )
{
std::ifstream in( detail::word_exp_filename( filename ), std::ifstream::in );
return read_ascii_aiger( in, reader, diag );
if ( !in.is_open() )
{
if ( diag )
{
diag->report( diagnostic_level::fatal,
fmt::format( "could not open file `{0}`", filename ) );
}
return return_code::parse_error;
}
else
{
auto const ret = read_ascii_aiger( in, reader, diag );
in.close();
return ret;
}
}

/*! \brief Reader function for binary AIGER format.
Expand All @@ -682,7 +696,7 @@ inline return_code read_ascii_aiger( const std::string& filename, const aiger_re
* \param in Input stream
* \param reader An AIGER reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_aiger( std::istream& in, const aiger_reader& reader, diagnostic_engine* diag = nullptr )
{
Expand Down Expand Up @@ -887,12 +901,26 @@ inline return_code read_aiger( std::istream& in, const aiger_reader& reader, dia
* \param filename Name of the file
* \param reader An AIGER reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_aiger( const std::string& filename, const aiger_reader& reader, diagnostic_engine* diag = nullptr )
{
std::ifstream in( detail::word_exp_filename( filename ), std::ifstream::binary );
return read_aiger( in, reader, diag );
if ( !in.is_open() )
{
if ( diag )
{
diag->report( diagnostic_level::fatal,
fmt::format( "could not open file `{0}`", filename ) );
}
return return_code::parse_error;
}
else
{
auto const ret = read_aiger( in, reader, diag );
in.close();
return ret;
}
}

} // namespace lorina
26 changes: 20 additions & 6 deletions lib/lorina/lorina/bench.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

#pragma once

#include <lorina/common.hpp>
#include <lorina/diagnostics.hpp>
#include <lorina/detail/utils.hpp>
#include "common.hpp"
#include "diagnostics.hpp"
#include "detail/utils.hpp"
#include <fstream>
#include <regex>
#include <iostream>
Expand Down Expand Up @@ -170,7 +170,7 @@ static std::regex gate_asgn( R"((.*)\s+=\s+(.*))" );
* \param in Input stream
* \param reader A BENCH reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_bench( std::istream& in, const bench_reader& reader, diagnostic_engine* diag = nullptr )
{
Expand Down Expand Up @@ -294,12 +294,26 @@ inline return_code read_bench( std::istream& in, const bench_reader& reader, dia
* \param filename Name of the file
* \param reader A BENCH reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_bench( const std::string& filename, const bench_reader& reader, diagnostic_engine* diag = nullptr )
{
std::ifstream in( detail::word_exp_filename( filename ), std::ifstream::in );
return read_bench( in, reader, diag );
if ( !in.is_open() )
{
if ( diag )
{
diag->report( diagnostic_level::fatal,
fmt::format( "could not open file `{0}`", filename ) );
}
return return_code::parse_error;
}
else
{
auto const ret = read_bench( in, reader, diag );
in.close();
return ret;
}
}

} // namespace lorina
26 changes: 20 additions & 6 deletions lib/lorina/lorina/blif.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

#pragma once

#include <lorina/common.hpp>
#include <lorina/diagnostics.hpp>
#include <lorina/detail/utils.hpp>
#include "common.hpp"
#include "diagnostics.hpp"
#include "detail/utils.hpp"
#include <regex>
#include <iostream>
#include <optional>
Expand Down Expand Up @@ -271,7 +271,7 @@ static std::regex end( R"(.end)" );
* \param in Input stream
* \param reader A BLIF reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_blif( std::istream& in, const blif_reader& reader, diagnostic_engine* diag = nullptr )
{
Expand Down Expand Up @@ -457,12 +457,26 @@ inline return_code read_blif( std::istream& in, const blif_reader& reader, diagn
* \param filename Name of the file
* \param reader A BLIF reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing have been successful, or parse error if parsing have failed
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_blif( const std::string& filename, const blif_reader& reader, diagnostic_engine* diag = nullptr )
{
std::ifstream in( detail::word_exp_filename( filename ), std::ifstream::in );
return read_blif( in, reader, diag );
if ( !in.is_open() )
{
if ( diag )
{
diag->report( diagnostic_level::fatal,
fmt::format( "could not open file `{0}`", filename ) );
}
return return_code::parse_error;
}
else
{
auto const ret = read_blif( in, reader, diag );
in.close();
return ret;
}
}

} // namespace lorina
33 changes: 29 additions & 4 deletions lib/lorina/lorina/bristol.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#pragma once

#include "common.hpp"
#include "diagnostics.hpp"
#include "detail/utils.hpp"

#include <algorithm>
Expand Down Expand Up @@ -168,8 +169,13 @@ class bristol_parser
*
* A callback method of the reader visitor is invoked for each
* primitive object matched in the specification.
*
* \param in Input stream
* \param reader A BRISTOL reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_bristol( std::istream& is, bristol_reader const& reader )
inline return_code read_bristol( std::istream& is, bristol_reader const& reader, diagnostic_engine* diag = nullptr )
{
return bristol_parser( is, reader ).run();
}
Expand All @@ -178,11 +184,30 @@ inline return_code read_bristol( std::istream& is, bristol_reader const& reader
*
* A callback method of the reader visitor is invoked for each
* primitive object matched in the specification.
*
* \param filename Name of the file
* \param reader A BRISTOL reader with callback methods invoked for parsed primitives
* \param diag An optional diagnostic engine with callback methods for parse errors
* \return Success if parsing has been successful, or parse error if parsing has failed
*/
inline return_code read_bristol( std::string const& filename, bristol_reader const& reader )
inline return_code read_bristol( std::string const& filename, bristol_reader const& reader, diagnostic_engine* diag = nullptr )
{
std::ifstream is( filename, std::ifstream::in );
return read_bristol( is, reader );
std::ifstream in( filename, std::ifstream::in );
if ( !in.is_open() )
{
if ( diag )
{
diag->report( diagnostic_level::fatal,
fmt::format( "could not open file `{0}`", filename ) );
}
return return_code::parse_error;
}
else
{
auto const ret = read_bristol( in, reader );
in.close();
return ret;
}
}

} // namespace lorina
Loading

0 comments on commit 0589b42

Please sign in to comment.