#include #include #include std::string thread_to_str(const REGEX_IS024_Thread& thread){ if (!(thread.slot_occupation_status & SLOT_OCCUPIED)) return "{ unoccupied }"; char buf[1024]; snprintf(buf, 1024, "{ IP = %lu }", thread.IP); return buf; } std::string stack_to_str(const REGEX_IS024_Stack& stack){ std::string res = "{ "; for (uint32_t i = 0; i < stack.sz; i++){ if (i != 0) res += ", "; res += std::to_string(stack.slots[i]); } res += " }"; return res; } std::string slots_to_str(const REGEX_IS024_CONTEXT& ctx){ if (!ctx.initialized) return "uninitialized"; std::string READ_slots; for (size_t i = 0; i < ctx.read_slots_number; i++){ uint8_t stat = ctx.READ_halted_slots[i].slot_occupation_status; READ_slots += (stat & SLOT_OCCUPIED) ? ((stat & SLOT_NEW) ? "N" : "O") : "x"; } std::string FORK_slots; for (size_t i = 0; i < ctx.fork_slots_number; i++){ uint8_t stat = ctx.FORK_halted_slots[i].slot_occupation_status; FORK_slots += (stat & SLOT_OCCUPIED) ? "O" : "x"; } char buf[4096]; snprintf(buf, 4096, "READ_slots: %s ; FORK_slots: %s ; READ_stack_new_main: %s ; " "READ_stack_new_second: %s ; READ_stack_old: %s ; FORK_stack: %s", READ_slots.c_str(), FORK_slots.c_str(), stack_to_str(ctx.READ_halted_stack_new_first).c_str(), stack_to_str(ctx.READ_halted_stack_new_second).c_str(), stack_to_str(ctx.READ_halted_stack_old).c_str(), stack_to_str(ctx.FORK_halted_stack).c_str()); return buf; } void debug_print_context(const REGEX_IS024_CONTEXT& ctx, const char* place) { printf("== DEBUG `%s` ==\n", place); printf("Active thread: %s, sifting_with: %s, match: %s\n%s\n", thread_to_str(ctx.active_thread).c_str(), ctx.sifting_with ? thread_to_str(*ctx.sifting_with).c_str() : "NO", thread_to_str(ctx.matched_thread).c_str(), slots_to_str(ctx).c_str()); } void debug_print_thread(const REGEX_IS024_Thread& thr, const char *place) { printf("== DEBUG `%s` ==\n", place); printf("This thread: %s\n", thread_to_str(thr).c_str()); }