Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions include/mockturtle/io/write_aiger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,9 @@ inline void write_aiger( Ntk const& aig, std::ostream& os )
template<typename Ntk>
inline void write_aiger( Ntk const& aig, std::string const& filename )
{
std::ofstream os( filename.c_str(), std::ofstream::out );
std::ofstream os( filename.c_str(), std::ofstream::out | std::ofstream::binary );
write_aiger( aig, os );
os.close();
}

} /* namespace mockturtle */
} /* namespace mockturtle */
39 changes: 39 additions & 0 deletions test/io/write_aiger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@

#include <lorina/aiger.hpp>

#include <cstdio>
#include <fstream>
#include <iterator>
#include <sstream>
#include <string>
#include <vector>

template<
typename T,
Expand Down Expand Up @@ -70,6 +74,41 @@ TEST_CASE( "write single-gate AIG into AIGER file", "[write_aiger]" )
} );
}

TEST_CASE( "write binary AIGER into a file", "[write_aiger]" )
{
aig_network aig;

std::vector<aig_network::signal> pis;
for ( auto i = 0u; i < 6u; ++i )
{
pis.push_back( aig.create_pi() );
}

aig.create_po( aig.create_and( pis[0], pis[1] ) );

std::string const filename = "write_aiger_binary.aig";
write_aiger( aig, filename );

std::ifstream in( filename, std::ifstream::in | std::ifstream::binary );
REQUIRE( in.is_open() );
std::vector<char> const data{ std::istreambuf_iterator<char>{ in }, std::istreambuf_iterator<char>{} };
in.close();
CHECK( std::remove( filename.c_str() ) == 0 );

CHECK( data ==
std::vector<char>{
0x61, 0x69, 0x67, 0x20, // aig
0x37, 0x20, // M=7 (I+L+A)
0x36, 0x20, // I=6
0x30, 0x20, // L=0
0x31, 0x20, // O=1
0x31, 0x0a, // A=1
0x31, 0x34, 0x0a, // 1 PO
0x0a, 0x02, // 1 AND gate
0x63 // comment
} );
}

TEST_CASE( "write AIG for XOR into AIGERfile", "[write_aiger]" )
{
aig_network aig;
Expand Down
Loading