add BSD license
[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 interested_in_range(uint64_t begin, uint64_t end, bool store, bool fetch)
24 {
25 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
26 if ((*it)->interested_in_range(begin, end, store, fetch))
27 return true;
28 return false;
29 }
30 void trace(uint64_t addr, size_t bytes, bool store, bool fetch)
31 {
32 for (std::vector<memtracer_t*>::iterator it = list.begin(); it != list.end(); ++it)
33 (*it)->trace(addr, bytes, store, fetch);
34 }
35 void hook(memtracer_t* h)
36 {
37 list.push_back(h);
38 }
39 private:
40 std::vector<memtracer_t*> list;
41 };
42
43 #endif