-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmica_utils.cpp
72 lines (61 loc) · 1.64 KB
/
mica_utils.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* This file is part of MICA, a Pin tool to collect
* microarchitecture-independent program characteristics using the Pin
* instrumentation framework.
*
* Please see the README.txt file distributed with the MICA release for more
* information.
*/
/* MICA includes */
#include "mica_utils.h"
/* lookup memNode for key in table
* returns NULL is no such memNode is found
*/
memNode* lookup (nlist** table, ADDRINT key){
nlist* np;
for (np = table[key % MAX_MEM_TABLE_ENTRIES]; np != (nlist*)NULL; np = np->next){
if(np-> id == key)
return np->mem;
}
return (memNode*)NULL;
}
/* install new memNode in table */
memNode* install(nlist** table, ADDRINT key){
nlist* np;
int index, i; // j;
index = key % MAX_MEM_TABLE_ENTRIES;
np = table[index];
if(np == (nlist*)NULL) {
np = (nlist*)malloc(sizeof(nlist));
/*if((np = (nlist*)malloc(sizeof(nlist))) == (nlist*)NULL){
cerr << "Not enough memory (in install)" << endl;
exit(1);
}*/
table[index] = np;
}
else{
while(np->next != (nlist*)NULL){
np = np->next;
}
np->next = (nlist*)malloc(sizeof(nlist));
/*if((np->next = (nlist*)malloc(sizeof(nlist))) == (nlist*)NULL){
cerr << "Not enough memory (in install (2))" << endl;
exit(1);
}*/
np = np->next;
}
np->next = (nlist*)NULL;
np->id = key;
np->mem = (memNode*)malloc (sizeof(memNode));
/*if((np->mem = (memNode*)malloc (sizeof(memNode))) == (memNode*)NULL){
cerr << "Not enough memory (in install (3))" << endl;
exit(1);
}*/
for(i = 0; i < MAX_MEM_ENTRIES; i++){
(np->mem)->timeAvailable[i] = 0;
}
for(i = 0; i < MAX_MEM_BLOCK; i++){
(np->mem)->numReferenced[i] = false;
}
return (np->mem);
}