-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconverTrace.cpp
More file actions
179 lines (152 loc) · 4.54 KB
/
Copy pathconverTrace.cpp
File metadata and controls
179 lines (152 loc) · 4.54 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#include "memorySimulator.h"
ConverTrace::ConverTrace() {
ifstream traces;
ofstream AddressAndTypeFile;
string outname;
outname = string("C:\\Users\\AA\\source\\repos\\MemoryHirarchyPerformanceSimulator\\MemoryHirarchyPerformanceSimulator\\AddressAndTypeFile.txt");
traces.open("C:\\Users\\AA\\source\\repos\\MemoryHirarchyPerformanceSimulator\\MemoryHirarchyPerformanceSimulator\\trace.txt");
AddressAndTypeFile.open(outname.c_str());
string line;
string x, registerName1, oldData, y, newDate;
string z, t, commandType, assemblyCommand;
// Initialize array
string registerName[32]{ "zero" , "ra" , "sp" , "gp" , "tp"
, "t0" , "t1" , "t2"
, "s0" , "s1"
, "a0", "a1" ,"a2" , "a3" , "a4" , "a5" , "a6" , "a7"
, "s2" , "a3" , "a4" , "a5" , "s6" , "s7" , "s8" , "a9" , "a10" , "a11"
, "t3" , "t4" , "t5" , "t6" };
string registerData[32];
registerData[0] = "00000000";
int iTemp = 0;
int iTemp1 = 0;
int count = 0;
if (traces.is_open() && AddressAndTypeFile.is_open()) {
while (getline(traces, line)) { // read mem access file and access Cache
int lineSize = line.length();
istringstream iss(line);
if (lineSize > 70) {
if (!(iss >> x >> y >> z >> y >> commandType >> assemblyCommand)) { break; }
string r1, r2, num;
string command = commandType.substr(0, 1);
string type;
if (command == "s") type = { "W" };
if (command == "l")type = { "R" };
if (commandType == "ld" || commandType == "lw"
|| commandType == "lb" || commandType == "lh"
|| commandType == "sd" || commandType == "sw"
|| commandType == "sb" || commandType == "sh") {
if (assemblyCommand.length() == 8) {
string size;
string data;
string r1 = assemblyCommand.substr(0, 2);
string sheftRegister = assemblyCommand.substr(3, 1);
string r2 = assemblyCommand.substr(5, 2);
if (commandType == "sb") size = "b";
if (commandType == "sw") size = "w";
if (commandType == "sh") size = "hw";
for (int i = 0; i < 32; i++) {
if (r1 == registerName[i])
{
if (registerData[i] == "")
{
data = "00000";
}
else
{
data = registerData[i];
}
break;
}
}
for (int i = 0; i < 32; i++) {
if (r2 == registerName[i])
{
// << " " << size << " " << data
AddressAndTypeFile << type << " " << intToHex(registerData[i], sheftRegister) << endl;
break;
}
}
}
if (assemblyCommand.length() == 9) {
string size, data;
string r1 = assemblyCommand.substr(0, 2);
string sheftRegister = assemblyCommand.substr(3, 2);
string r2 = assemblyCommand.substr(6, 2);
if (commandType == "sb") size = "b";
if (commandType == "sw") size = "w";
if (commandType == "sh") size = "hw";
for (int i = 0; i < 32; i++) {
if (r1 == registerName[i])
{
data = intToHex(registerData[i], sheftRegister);
break;
}
}
for (int i = 0; i < 32; i++) {
if (r2 == registerName[i])
{
// size << data <<
AddressAndTypeFile << type << " " << intToHex(registerData[i], sheftRegister) << endl;
break;
}
}
}
}
}
if (lineSize < 60) {
if (!(iss >> x >> registerName1 >> oldData >> y >> newDate)) { break; }
string Date;
if (newDate.length() == 16)
{
Date = newDate;
}
else
{
Date = "00000000" + newDate;
}
for (int i = 0; i < 32; i++) {
if (registerName1 == registerName[i])
{
registerData[i] = Date;
break;
}
}
}
}
}
}
string ConverTrace::intToHex(string registerData, string sheftRegister) {
string updateRegister;
int sheftRegisterInt;
updateRegister = registerData;
std::stringstream str;
str << updateRegister;
int value;
str >> std::hex >> value;
sheftRegisterInt = stoi(sheftRegister);
value = value + sheftRegisterInt;
std::stringstream stream;
stream << std::hex << value;
std::string result(stream.str());
if (result.length() == 4) {
result = "0x0000" + result;
}
if (result.length() == 5) {
result = "0x000" + result;
}
if (result.length() == 6) {
result = "0x00" + result;
}
if (result.length() == 7) {
result = "0x0" + result;
}
if (result.length() == 8) {
result = "0x" + result;
}
if (result.length() == 16)
{
result = "0x" + result;
}
return result;
}