-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm.c
48 lines (36 loc) · 786 Bytes
/
mm.c
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
43
44
45
46
47
#include "mm.h"
#define MM_NODE_BLOCK_LENGTH (1llu<<32llu)
static MNode mm_node_block[MM_NODE_BLOCK_LENGTH];
static M32 mm_node_head;
static void mm_init(void) {
mm_node_head = 1;
}
static M32 mm_next_id(void) {
return mm_node_head++;
}
static inline MNode* mm_get(M32 mid) {
return &mm_node_block[mid];
}
static M32 mm_make_load(M32 prev, V32 addr, V32 size) {
M32 mid = mm_next_id();
MNode* mnode = mm_get(mid);
*mnode = (MNode){
.kind = MM_LOAD,
.addr = addr,
.size = size,
.prev = prev,
};
return mid;
}
static M32 mm_make_store(M32 prev, V32 addr, V32 value, V32 size) {
M32 mid = mm_next_id();
MNode* mnode = mm_get(mid);
*mnode = (MNode){
.kind = MM_STORE,
.addr = addr,
.size = size,
.value = value,
.prev = prev,
};
return mid;
}