summaryrefslogtreecommitdiff
path: root/infra/sim.h
blob: b3dd0d3ac716053724c661918e3cfcf03327d2ec (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include <cstdint>
#include <string>
#include <vector>

#include "infra/pipetrace.h"

namespace infra {
    struct sim {
        virtual void clock() {}
        virtual void unclock() {}

        static std::vector<sim *> sims;

        static std::uint64_t now;

        sim() {
            sims.emplace_back(this);
        }

        virtual ~sim() {
            std::erase(sims, this);
        }

        static void advance() {
            for (auto &s : sims)
                s->clock();
            for (auto &s : sims)
                s->unclock();
            ++now;
        }

        void pte(const transaction &t, const char *event) {
            pt::event(t, event, now, "");
        }

        void pte(const transaction &t, const char *event, const std::string &data) {
            pt::event(t, event, now, data);
        }
    };
}