Skip to content
Open
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
38 changes: 19 additions & 19 deletions src/ext/sim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,12 @@ struct randomSim : public Pass {
}
ofs << " cxxrtl_design::p_" + module_name + " top;\n";
ofs << "long long base_cycle = 0;\n";
// Checkpoint file for the next -continue run: must be written after every run that
// advances simulation (including -reset/-reset_n), not only when -continue is set.
ofs << "const char* state_file = \".sim_state.txt\";\n";
ofs << "cxxrtl::debug_items state_items;\n";
ofs << "top.debug_info(state_items);\n";
if (continue_set) {
ofs << "const char* state_file = \".sim_state.txt\";\n";
ofs << "cxxrtl::debug_items state_items;\n";
ofs << "top.debug_info(state_items);\n";
ofs << "std::unordered_map<std::string, cxxrtl::debug_item*> state_map;\n";
ofs << "for (auto &entry : state_items.table) {\n";
ofs << " for (size_t part = 0; part < entry.second.size(); ++part) {\n";
Expand Down Expand Up @@ -420,22 +422,20 @@ struct randomSim : public Pass {
}

ofs << "}\n";
if (continue_set) {
ofs << "std::ofstream state_ofs(state_file);\n";
ofs << "state_ofs << \"__cycle__ \" << (base_cycle + " << sim_cycle << ") << \"\\n\";\n";
ofs << "for (auto &entry : state_items.table) {\n";
ofs << " for (size_t part = 0; part < entry.second.size(); ++part) {\n";
ofs << " auto &item = entry.second[part];\n";
ofs << " if (item.depth != 1 || item.curr == nullptr || item.next == nullptr) continue;\n";
ofs << " size_t chunks = (item.width + 31) / 32;\n";
ofs << " state_ofs << entry.first << \"#\" << part << \" \" << item.width << \" \" << chunks;\n";
ofs << " for (size_t c = 0; c < chunks; ++c)\n";
ofs << " state_ofs << \" \" << std::hex << item.curr[c] << std::dec;\n";
ofs << " state_ofs << \"\\n\";\n";
ofs << " }\n";
ofs << "}\n";
ofs << "state_ofs.close();\n";
}
ofs << "std::ofstream state_ofs(state_file);\n";
ofs << "state_ofs << \"__cycle__ \" << (base_cycle + " << sim_cycle << ") << \"\\n\";\n";
ofs << "for (auto &entry : state_items.table) {\n";
ofs << " for (size_t part = 0; part < entry.second.size(); ++part) {\n";
ofs << " auto &item = entry.second[part];\n";
ofs << " if (item.depth != 1 || item.curr == nullptr || item.next == nullptr) continue;\n";
ofs << " size_t chunks = (item.width + 31) / 32;\n";
ofs << " state_ofs << entry.first << \"#\" << part << \" \" << item.width << \" \" << chunks;\n";
ofs << " for (size_t c = 0; c < chunks; ++c)\n";
ofs << " state_ofs << \" \" << std::hex << item.curr[c] << std::dec;\n";
ofs << " state_ofs << \"\\n\";\n";
ofs << " }\n";
ofs << "}\n";
ofs << "state_ofs.close();\n";
if (output_file_set) ofs << "ofs.close();\n";
ofs << "}\n";
ofs << "\n";
Expand Down
Loading