diff options
| author | Julian Blake Kongslie | 2022-10-02 15:32:49 -0700 |
|---|---|---|
| committer | Julian Blake Kongslie | 2022-10-02 15:32:49 -0700 |
| commit | 82cc71261d3d32012d33d3bebe56ca5e3b0bcdbd (patch) | |
| tree | f1358a38d244e27d9740e914c54328d753cb0b4f /infra/sim.h | |
| download | biggolf-82cc71261d3d32012d33d3bebe56ca5e3b0bcdbd.tar.xz | |
Initial commit.
Diffstat (limited to 'infra/sim.h')
| -rw-r--r-- | infra/sim.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/infra/sim.h b/infra/sim.h new file mode 100644 index 0000000..185916a --- /dev/null +++ b/infra/sim.h | |||
| @@ -0,0 +1,38 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <cstdint> | ||
| 4 | #include <string> | ||
| 5 | #include <vector> | ||
| 6 | |||
| 7 | #include "infra/pipetrace.h" | ||
| 8 | |||
| 9 | namespace infra { | ||
| 10 | struct sim { | ||
| 11 | virtual void clock() {} | ||
| 12 | virtual void unclock() {} | ||
| 13 | |||
| 14 | static std::vector<sim *> sims; | ||
| 15 | |||
| 16 | static std::uint64_t now; | ||
| 17 | |||
| 18 | sim() { | ||
| 19 | sims.emplace_back(this); | ||
| 20 | } | ||
| 21 | |||
| 22 | virtual ~sim() { | ||
| 23 | std::erase(sims, this); | ||
| 24 | } | ||
| 25 | |||
| 26 | static void advance() { | ||
| 27 | for (auto &s : sims) | ||
| 28 | s->clock(); | ||
| 29 | for (auto &s : sims) | ||
| 30 | s->unclock(); | ||
| 31 | ++now; | ||
| 32 | } | ||
| 33 | |||
| 34 | void pte(const transaction &t, const char *event, const std::string &data) { | ||
| 35 | pt::event(t, event, now, data); | ||
| 36 | } | ||
| 37 | }; | ||
| 38 | } | ||
