-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.cpp
More file actions
151 lines (128 loc) · 4.39 KB
/
cache.cpp
File metadata and controls
151 lines (128 loc) · 4.39 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// Created by Ignacio Mora on 2019-09-11.
//
#include <sstream>
#include <fstream>
#include "cache.h"
int Cache::getTag(int block) {
return cacheBlocks[block].tag;
}
Status Cache::getStatus(int block) {
return cacheBlocks[block].block_status;
}
int Cache::getData(int block) {
return cacheBlocks[block].data;
}
void Cache::setTag(int block, int tag) {
cacheBlocks[block].tag = tag;
std::ofstream outfile;
std::stringstream fmt_filename;
fmt_filename << "info_for_ui/cache" << num_core<< "_content.txt";
outfile.open(fmt_filename.str(), std::ios::out | std::ios::trunc );
std::stringstream fmt_data;
std::stringstream fmt_status;
std::stringstream fmt_tag;
fmt_data << "[";
for (int i = 0; i < 7; ++i) {
fmt_data << cacheBlocks[i].data << ", ";
}
fmt_data << cacheBlocks[7].data << "]";
fmt_status << "[";
for (int i = 0; i < 7; ++i) {
fmt_status << cacheBlocks[i].block_status << ", ";
}
fmt_status << cacheBlocks[7].block_status << "]";
fmt_tag << "[";
for (int i = 0; i < 7; ++i) {
fmt_tag << cacheBlocks[i].tag << ", ";
}
fmt_tag << cacheBlocks[7].tag << "]";
outfile << "[" << fmt_data.str() << ", " << fmt_status.str() << ", " << fmt_tag.str() <<"]"<< std::endl;
outfile.close();
}
void Cache::setStatus(int block, Status status) {
cacheBlocks[block].block_status = status;
std::ofstream outfile;
std::stringstream fmt_filename;
fmt_filename << "info_for_ui/cache" << num_core<< "_content.txt";
outfile.open(fmt_filename.str(), std::ios::out | std::ios::trunc );
std::stringstream fmt_data;
std::stringstream fmt_status;
std::stringstream fmt_tag;
fmt_data << "[";
for (int i = 0; i < 7; ++i) {
fmt_data << cacheBlocks[i].data << ", ";
}
fmt_data << cacheBlocks[7].data << "]";
fmt_status << "[";
for (int i = 0; i < 7; ++i) {
fmt_status << cacheBlocks[i].block_status << ", ";
}
fmt_status << cacheBlocks[7].block_status << "]";
fmt_tag << "[";
for (int i = 0; i < 7; ++i) {
fmt_tag << cacheBlocks[i].tag << ", ";
}
fmt_tag << cacheBlocks[7].tag << "]";
outfile << "[" << fmt_data.str() << ", " << fmt_status.str() << ", " << fmt_tag.str() <<"]"<< std::endl;
outfile.close();
}
void Cache::setData(int block, int data) {
cacheBlocks[block].data = data;
std::ofstream outfile;
std::stringstream fmt_filename;
fmt_filename << "info_for_ui/cache" << num_core<< "_content.txt";
outfile.open(fmt_filename.str(), std::ios::out | std::ios::trunc );
std::stringstream fmt_data;
std::stringstream fmt_status;
std::stringstream fmt_tag;
fmt_data << "[";
for (int i = 0; i < 7; ++i) {
fmt_data << cacheBlocks[i].data << ", ";
}
fmt_data << cacheBlocks[7].data << "]";
fmt_status << "[";
for (int i = 0; i < 7; ++i) {
fmt_status << cacheBlocks[i].block_status << ", ";
}
fmt_status << cacheBlocks[7].block_status << "]";
fmt_tag << "[";
for (int i = 0; i < 7; ++i) {
fmt_tag << cacheBlocks[i].tag << ", ";
}
fmt_tag << cacheBlocks[7].tag << "]";
outfile << "[" << fmt_data.str() << ", " << fmt_status.str() << ", " << fmt_tag.str() <<"]"<< std::endl;
outfile.close();
}
void Cache::setBlock(int block, Status status, int tag, int data) {
std::ofstream outfile;
std::stringstream fmt_filename;
fmt_filename << "info_for_ui/cache" << num_core<< "_content.txt";
outfile.open(fmt_filename.str(), std::ios::out | std::ios::trunc );
std::stringstream fmt_data;
std::stringstream fmt_status;
std::stringstream fmt_tag;
cacheBlocks[block].tag = tag;
cacheBlocks[block].block_status = status;
cacheBlocks[block].data = data;
fmt_data << "[";
for (int i = 0; i < 7; ++i) {
fmt_data << cacheBlocks[i].data << ", ";
}
fmt_data << cacheBlocks[7].data << "]";
fmt_status << "[";
for (int i = 0; i < 7; ++i) {
fmt_status << cacheBlocks[i].block_status << ", ";
}
fmt_status << cacheBlocks[7].block_status << "]";
fmt_tag << "[";
for (int i = 0; i < 7; ++i) {
fmt_tag << cacheBlocks[i].tag << ", ";
}
fmt_tag << cacheBlocks[7].tag << "]";
outfile << "[" << fmt_data.str() << ", " << fmt_status.str() << ", " << fmt_tag.str() <<"]"<< std::endl;
outfile.close();
}
Cache::Cache(int num_core) {
this->num_core = num_core;
}