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 +++ 2 files changed, 20 insertions(+) (limited to 'io') 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); }; -- cgit v1.2.3