From 62517a8004419591dd031faebb7a9a4827bc002a Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Tue, 1 Nov 2022 10:08:59 -0700 Subject: Support writing a trace at the end of execution. --- io/model.cpp | 17 +++++++++++++++++ io/model.h | 3 +++ main.cpp | 3 +++ 3 files changed, 23 insertions(+) diff --git a/io/model.cpp b/io/model.cpp index 79bc511..81cf318 100644 --- a/io/model.cpp +++ b/io/model.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -85,3 +86,19 @@ void iomodel::load_evt(std::istream &fh) { } } } + +std::ostream & iomodel::write_evt(std::ostream &fh) { + std::uint64_t time = 0; + for (const auto &e : log) { + if (e.first != time) { + fh << fmt::format("+{}\n", e.first - time); + time = e.first; + } + if (e.second.mask == ~(std::uint_fast32_t)0) { + fh << fmt::format("{}=0x{:x}\n", ctlreg_names[e.second.reg], e.second.value); + } else { + fh << fmt::format("{}=0x{:x}/0x{:x}\n", ctlreg_names[e.second.reg], e.second.value, e.second.mask); + } + } + return fh; +} diff --git a/io/model.h b/io/model.h index 2826170..f8a852b 100644 --- a/io/model.h +++ b/io/model.h @@ -3,6 +3,7 @@ #include #include #include +#include #include "io/event.h" #include "isa/isa.h" @@ -19,4 +20,6 @@ struct iomodel { std::uint64_t load_time = 0; void load_evt(std::istream &fh); + + std::ostream & write_evt(std::ostream &fh); }; diff --git a/main.cpp b/main.cpp index 62926a5..1f1b6de 100644 --- a/main.cpp +++ b/main.cpp @@ -76,5 +76,8 @@ int main(int argc, const char *argv[]) { checker.execute(); } + std::ofstream fh("trace.evt"); + system.write_evt(fh); + return 0; } -- cgit v1.2.3