Speed things up quite a bit
[riscv-isa-sim.git] / riscv / memtracer.h
1 // See LICENSE for license details.
2
3 #ifndef _MEMTRACER_H
4 #define _MEMTRACER_H
5
6 #include <stdint.h>
7 #include <string.h>
8 #include <vector>
9
10 class memtracer_t
11 {
12 public:
13 memtracer_t() {}
14 virtual ~memtracer_t() {}
15
16 virtual bool interested_in_range(uint64_t begin, uint64_t end, bool store, bool fetch) = 0;
17 virtual void trace(uint64_t addr, size_t bytes, bool store, bool fetch) = 0;
18 };
19
20 class memtracer_list_t : public memtracer_t
21 {
22 public:
23 bool empty() { return list.empty(); }
24 bool interested_in_range(uint64_t begin, uint64_t end, bool store, bool fetch)
25 {
26 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
27 if ((*it)->interested_in_range(begin, end, store, fetch))
28 return true;
29 return false;
30 }
31 void trace(uint64_t addr, size_t bytes, bool store, bool fetch)
32 {
33 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
34 (*it)->trace(addr, bytes, store, fetch);
35 }
36 void hook(memtracer_t* h)
37 {
38 list.push_back(h);
39 }
40 private:
41 std::vector<memtracer_t*> list;
42 };
43
44 #endif