1414#include < cstddef>
1515#include < cstdint>
1616#include < cstdio>
17+ #include < filesystem>
1718#include < fstream>
1819#include < iterator>
1920#include < memory>
@@ -884,6 +885,24 @@ inline int Snapshot_t::cost_of_snapshot() {
884885 return 5.336 *
885886 (cost_of_stack_copy + cost_of_frame_copy + cost_of_memory_copy);
886887}
888+
889+ struct OverallResult {
890+ int unexplored_count = 0 ;
891+ int finished_count = 0 ;
892+ int failed_count = 0 ;
893+ int not_to_explore_count = 0 ;
894+ int unreachable_count = 0 ;
895+
896+ void print () {
897+ std::cout << " Explore Tree Overall Result:" << std::endl;
898+ std::cout << " Unexplored paths: " << unexplored_count << std::endl;
899+ std::cout << " Finished paths: " << finished_count << std::endl;
900+ std::cout << " Failed paths: " << failed_count << std::endl;
901+ std::cout << " Unreachable paths: " << unreachable_count << std::endl;
902+ std::cout << " NotToExplore paths: " << not_to_explore_count << std::endl;
903+ }
904+ };
905+
887906class ExploreTree_t {
888907public:
889908 explicit ExploreTree_t ()
@@ -1009,6 +1028,16 @@ class ExploreTree_t {
10091028 }
10101029
10111030 std::monostate dump_graphviz (std::string filepath) {
1031+ std::filesystem::path out_path (filepath);
1032+ auto parent = out_path.parent_path ();
1033+ if (!parent.empty ()) {
1034+ std::error_code ec;
1035+ std::filesystem::create_directories (parent, ec);
1036+ if (ec) {
1037+ throw std::runtime_error (" Failed to create output directory: " +
1038+ ec.message ());
1039+ }
1040+ }
10121041 std::ofstream ofs (filepath);
10131042 if (!ofs.is_open ()) {
10141043 throw std::runtime_error (" Failed to open " + filepath + " for writing" );
@@ -1017,45 +1046,35 @@ class ExploreTree_t {
10171046 return std::monostate ();
10181047 }
10191048
1020- std::monostate print_overall_result () {
1021- // Print how many paths have been explored, how many paths are unreachable,
1022- // how many paths are failed, how many paths are finished successfully
1023- int unexplored_count = 0 ;
1024- int finished_count = 0 ;
1025- int failed_count = 0 ;
1026- int not_to_explore_count = 0 ;
1027- int unreachable_count = 0 ;
1049+ OverallResult read_current_overall_result () {
1050+ OverallResult result;
10281051 std::function<void (NodeBox *)> dfs = [&](NodeBox *node) {
10291052 if (auto if_else_node = dynamic_cast <IfElseNode *>(node->node .get ())) {
10301053 dfs (if_else_node->true_branch .get ());
10311054 dfs (if_else_node->false_branch .get ());
10321055 } else if (dynamic_cast <UnExploredNode *>(node->node .get ())) {
1033- unexplored_count += 1 ;
1056+ result. unexplored_count += 1 ;
10341057 } else if (dynamic_cast <Finished *>(node->node .get ())) {
1035- finished_count += 1 ;
1058+ result. finished_count += 1 ;
10361059 } else if (dynamic_cast <Failed *>(node->node .get ())) {
1037- failed_count += 1 ;
1060+ result. failed_count += 1 ;
10381061 } else if (dynamic_cast <Unreachable *>(node->node .get ())) {
1039- unreachable_count += 1 ;
1062+ result. unreachable_count += 1 ;
10401063 } else if (dynamic_cast <SnapshotNode *>(node->node .get ())) {
10411064 // Snapshot node is considered unexplored
1042- unexplored_count += 1 ;
1065+ result. unexplored_count += 1 ;
10431066 } else if (dynamic_cast <NotToExploreNode *>(node->node .get ())) {
1044- not_to_explore_count += 1 ;
1067+ result. not_to_explore_count += 1 ;
10451068 } else {
10461069 throw std::runtime_error (" Unknown node type in explore tree" );
10471070 }
10481071 };
10491072 dfs (root.get ());
1050- std::cout << " Explore Tree Overall Result:" << std::endl;
1051- std::cout << " Unexplored paths: " << unexplored_count << std::endl;
1052- std::cout << " Finished paths: " << finished_count << std::endl;
1053- std::cout << " Failed paths: " << failed_count << std::endl;
1054- std::cout << " Unreachable paths: " << unreachable_count << std::endl;
1055- std::cout << " NotToExplore paths: " << not_to_explore_count << std::endl;
1056- return std::monostate ();
1073+ return result;
10571074 }
10581075
1076+ std::monostate print_overall_result () {}
1077+
10591078 NodeBox *pick_unexplored () {
10601079 // Pick an unexplored node from the tree
10611080 // For now, we just iterate through the tree and return the first unexplored
0 commit comments