Skip to content

Commit e9aa8df

Browse files
committed
input file parsser implemented
1 parent e0dc77c commit e9aa8df

File tree

5 files changed

+100
-12
lines changed

5 files changed

+100
-12
lines changed

MSI.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class MSI {
2+
3+
4+
5+
}

Main.cpp

+31-10
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
11
#include <iostream>
2-
#include "cache.h"
2+
#include "processor.h"
3+
#include "parser.h"
34
#include <stdlib.h> /* atoi */
45
int main (int argc, char* argv[]) {
56
int lineSize = 1024;
67
int linesNumber = 4;
7-
if (argc < 3) {
8+
int procNumber = 1;
9+
10+
if (argc < 4) {
811
std::cout << "Not enough arguments\n";
912
exit(1);
1013
}
11-
14+
1215
lineSize = atoi(argv[1]);
1316
linesNumber = atoi(argv[2]);
17+
procNumber = atoi(argv[3]);
18+
19+
Processor **procTable = new Processor*[procNumber];
20+
for (int i = 0; i < procNumber; i++) {
21+
Cache cache(lineSize, linesNumber);
22+
procTable[i] = new Processor(i, &cache);
23+
std::cout << "Cache line size: " << cache.retLineSize() << std::endl;
24+
std::cout << "Cache lines number: " << cache.retLinesNumber() << std::endl;
25+
std::cout << "cache Line of 17: " << cache.findCacheLine(17) << std::endl;
26+
std::cout << "cache tag of 17: " << cache.findTag(17) << std::endl;
27+
cache.cacheWord(cache.findCacheLine(17), cache.findTag(17), 17);
28+
std::cout << "address: " << cache.retWord(cache.findCacheLine(17), cache.findTag(17)) << std::endl;
29+
}
1430

15-
Cache cache(lineSize, linesNumber);
16-
std::cout << "Cache line size: " << cache.retLineSize() << std::endl;
17-
std::cout << "Cache lines number: " << cache.retLinesNumber() << std::endl;
18-
std::cout << "cache Line of 17: " << cache.findCacheLine(17) << std::endl;
19-
std::cout << "cache tag of 17: " << cache.findTag(17) << std::endl;
20-
cache.cacheWord(cache.findCacheLine(17), cache.findTag(17), 17);
21-
std::cout << "address: " << cache.retWord(cache.findCacheLine(17), cache.findTag(17));
31+
Parser p;
32+
int ret;
33+
ret = p.parse();
34+
int pId;
35+
int adr;
36+
while (ret) {
37+
// here cache coherence should be implemented
38+
pId = p.getProcessor();
39+
adr = p.getAddress();
40+
std::cout << pId << " " << adr << std::endl;
41+
ret = p.parse();
42+
}
2243
}

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
target:
2-
g++ Main.cpp cache.cpp processor.cpp MSI.cpp -o CC
2+
g++ Main.cpp cache.cpp processor.cpp MSI.cpp -o CC -std=c++11
33
# g++ Main.cpp cache.cpp
44

55
clean:

parser.h

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include <fstream>
2+
#include <sstream>
3+
4+
class Parser{
5+
private:
6+
std::ifstream infile;
7+
int id;
8+
std::string operation;
9+
int address;
10+
11+
public:
12+
Parser () {
13+
infile.open("trace1.txt");
14+
}
15+
16+
int parse() {
17+
std::string line;
18+
19+
if (std::getline(infile, line)) {
20+
// std::cout << line << std::endl;
21+
processLine(line);
22+
return 1;
23+
}
24+
return 0;
25+
}
26+
27+
void processLine(std::string line) {
28+
std::string str;
29+
std::string ss;
30+
std::stringstream sstream;
31+
std::stringstream linestream(line);
32+
int i = 0;
33+
while (std::getline(linestream, str, ' ')) {
34+
// std::cout<<str;
35+
switch(i) {
36+
case 0:
37+
sstream.str(str);
38+
while (std::getline(sstream, ss, 'P')) {}
39+
id = std::stoi(ss);
40+
break;
41+
case 1:
42+
operation = str;
43+
break;
44+
case 2:
45+
address = std::stoi(str);
46+
break;
47+
}
48+
i++;
49+
}
50+
}
51+
52+
int getProcessor() {
53+
return id;
54+
}
55+
56+
int getAddress() {
57+
return address;
58+
}
59+
60+
std::string getOper() {
61+
return operation;
62+
}
63+
};

processor.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include "processor.h"
2-
// #include "cache.h"
32

43
Processor::Processor(int processorId, Cache *privateCache) {
54
id = processorId;

0 commit comments

Comments
 (0)