summaryrefslogtreecommitdiff
path: root/io/model.cpp
diff options
context:
space:
mode:
authorJulian Blake Kongslie2022-11-01 10:08:59 -0700
committerJulian Blake Kongslie2022-11-01 10:08:59 -0700
commit62517a8004419591dd031faebb7a9a4827bc002a (patch)
tree14d9b6dae5474fd5d42b78da12b3974a2bcd0584 /io/model.cpp
parentImplemented the remaining instructions required for echo_optimal. (diff)
downloadbiggolf-62517a8004419591dd031faebb7a9a4827bc002a.tar.xz
Support writing a trace at the end of execution.
Diffstat (limited to '')
-rw-r--r--io/model.cpp17
1 files changed, 17 insertions, 0 deletions
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 @@
1#include <array> 1#include <array>
2#include <cassert> 2#include <cassert>
3#include <cstdint> 3#include <cstdint>
4#include <fmt/format.h>
4#include <iostream> 5#include <iostream>
5#include <utility> 6#include <utility>
6 7
@@ -85,3 +86,19 @@ void iomodel::load_evt(std::istream &fh) {
85 } 86 }
86 } 87 }
87} 88}
89
90std::ostream & iomodel::write_evt(std::ostream &fh) {
91 std::uint64_t time = 0;
92 for (const auto &e : log) {
93 if (e.first != time) {
94 fh << fmt::format("+{}\n", e.first - time);
95 time = e.first;
96 }
97 if (e.second.mask == ~(std::uint_fast32_t)0) {
98 fh << fmt::format("{}=0x{:x}\n", ctlreg_names[e.second.reg], e.second.value);
99 } else {
100 fh << fmt::format("{}=0x{:x}/0x{:x}\n", ctlreg_names[e.second.reg], e.second.value, e.second.mask);
101 }
102 }
103 return fh;
104}