@@ -86,16 +86,27 @@ void writeResult(
8686{
8787 if (auto output_dir = program.present (" -o" ))
8888 {
89- // Create directory if it doesn't exist yet.
9089 std::filesystem::path output_path{*output_dir};
91- if (!std::filesystem::exists (output_path))
90+ std::string input_dir = program.get <std::string>(" --input-path" );
91+ // If input is a directory, treat output as directory as well.
92+ if (std::filesystem::is_directory (input_dir))
9293 {
93- std::filesystem::create_directories (output_path);
94- }
94+ // Create output directory if it doesn't exist yet.
95+ if (!std::filesystem::exists (output_path))
96+ {
97+ std::filesystem::create_directories (output_path);
98+ }
9599
96- // Write resulting circuit to an output path by original name.
97- std::ofstream file_out (output_path / std::filesystem::path (file_path).filename ());
98- writeBenchFile (simplified_circuit, encoder, file_out);
100+ // Write resulting circuit to an output path by original name.
101+ std::ofstream file_out (output_path / std::filesystem::path (file_path).filename ());
102+ writeBenchFile (simplified_circuit, encoder, file_out);
103+ }
104+ else
105+ {
106+ // Write resulting circuit to an output path by original name.
107+ std::ofstream file_out (output_path);
108+ writeBenchFile (simplified_circuit, encoder, file_out);
109+ }
99110 }
100111 else
101112 {
@@ -312,8 +323,8 @@ int main(int argn, char** argv)
312323
313324 // Set up argument parser.
314325 argparse::ArgumentParser program (" simplifier" , " 0.1" );
315- program.add_argument (" -i" , " --input-path" ).help (" directory with input .BENCH files" );
316- program.add_argument (" -o" , " --output" ).help (" path to resulting directory" );
326+ program.add_argument (" -i" , " --input-path" ).help (" directory with input .BENCH files (or a single .BENCH file) " );
327+ program.add_argument (" -o" , " --output" ).help (" path to resulting directory or to a resulting single .BENCH file " );
317328 program.add_argument (" -s" , " --statistics" ).metavar (" FILE" ).help (" path to file for statistics writing" );
318329 program.add_argument (" -b" , " --basis" ).default_value (std::string (DEFAULT_BASIS)).help (" Choose basis [AIG|BENCH]" );
319330 program.add_argument (" -d" , " --databases" )
@@ -324,9 +335,9 @@ int main(int argn, char** argv)
324335 " The Simplifier tool provides simplification of boolean circuits provided in\n "
325336 " one of two bases: `AIG` or `BENCH`. To run simplification one should provide\n "
326337 " an `--input-path` and `--output` parameters: first is a path to the directory\n "
327- " with boolean circuits, and second is a path where simplified circuits are to \n "
328- " be stored. Both input and output paths should be directories . Program will \n "
329- " take attempt to read all files in input directory as `.bench` circuits. Each\n "
338+ " with boolean circuits (or to a single .bench file) , and second is a path where\n "
339+ " simplified circuits are to be stored (or path to a single .bench file) . Program\n "
340+ " will take attempt to read all files in input directory as `.bench` circuits. Each\n "
330341 " circuit then will be processed by the tool distinctly.\n "
331342 " \n "
332343 " Required basis of input circuits should be specified manually using a `--basis`\n "
@@ -368,18 +379,27 @@ int main(int argn, char** argv)
368379
369380 // Iterate over input directory of circuits.
370381 // Program will perform simplification of each found circuit.
371- std::string input_dir = program.get <std::string>(" --input-path" );
372- for (auto & instance_path : std::filesystem::directory_iterator (input_dir))
382+ std::string input_dir = program.get <std::string>(" --input-path" );
383+ std::string output_dir = program.get <std::string>(" --output" );
384+ if (std::filesystem::is_directory (input_dir))
373385 {
374- // Skip directories and other specific files.
375- if (!instance_path.is_regular_file ())
386+ for (auto & instance_path : std::filesystem::directory_iterator (input_dir))
376387 {
377- continue ;
378- }
388+ // Skip directories and other specific files.
389+ if (!instance_path.is_regular_file ())
390+ {
391+ continue ;
392+ }
379393
380- std::string path = instance_path.path ().string ();
381- logger.info (" Processing benchmark " , path, " ." );
382- simplifier (path, program, logger, statistics_stream);
394+ std::string path = instance_path.path ().string ();
395+ logger.info (" Processing benchmark " , path, " ." );
396+ simplifier (path, program, logger, statistics_stream);
397+ }
398+ }
399+ else
400+ {
401+ logger.info (" Processing benchmark " , input_dir, " ." );
402+ simplifier (input_dir, program, logger, statistics_stream);
383403 }
384404
385405 return 0 ;
0 commit comments