-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimulator.cpp
executable file
·100 lines (79 loc) · 2.71 KB
/
simulator.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
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
#include "simulator.hpp"
orcs_engine_t orcs_engine;
// =============================================================================
static void display_use() {
ORCS_PRINTF("**** OrCS - Ordinary Computer Simulator ****\n\n");
ORCS_PRINTF("Please provide -t <trace_file_basename>\n");
ORCS_PRINTF("Please provide -c <cache_file_config>\n");
};
// =============================================================================
static void process_argv(int argc, char **argv) {
// Name, {no_argument, required_argument and optional_argument}, flag, value
static struct option long_options[] = {
{"help", no_argument, 0, 'h'},
{"trace", required_argument, 0, 't'},
{NULL, 0, NULL, 0}
};
// Count number of traces
int opt;
int option_index = 0;
while ((opt = getopt_long_only(argc, argv, "h:t:",
long_options, &option_index)) != -1) {
switch (opt) {
case 0:
printf ("Option %s", long_options[option_index].name);
if (optarg)
printf (" with arg %s", optarg);
printf ("\n");
break;
case 'h':
display_use();
break;
case 't':
orcs_engine.arg_trace_file_name = optarg;
break;
case '?':
break;
default:
ORCS_PRINTF(">> getopt returned character code 0%o ??\n", opt);
}
}
if (optind < argc) {
ORCS_PRINTF("Non-option ARGV-elements: ");
while (optind < argc)
ORCS_PRINTF("%s ", argv[optind++]);
ORCS_PRINTF("\n");
}
if (orcs_engine.arg_trace_file_name == NULL) {
ORCS_PRINTF("Trace file not defined.\n");
display_use();
}
};
// =============================================================================
int main(int argc, char **argv) {
process_argv(argc, argv);
/// Call all the allocate's
orcs_engine.allocate();
orcs_engine.trace_reader->allocate(orcs_engine.arg_trace_file_name);
orcs_engine.processor->allocate();
//plbp
orcs_engine.plbp->allocate();
// aloca config cache
orcs_engine.cache = new cache_t[CACHE_LEVELS];
for(size_t i = 0; i<CACHE_LEVELS;i++){
orcs_engine.cache[i].allocate((uint32_t)i);
}
orcs_engine.simulator_alive = true;
/// Start CLOCK for all the components
while (orcs_engine.simulator_alive) {
orcs_engine.processor->clock();
orcs_engine.global_cycle++;
}
ORCS_PRINTF("End of Simulation\n")
orcs_engine.trace_reader->statistics();
orcs_engine.processor->statistics();
for(size_t i = 0; i<CACHE_LEVELS;i++){
orcs_engine.cache[i].statistics();
}
return(EXIT_SUCCESS);
};