-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.c
176 lines (125 loc) · 4.02 KB
/
printer.c
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
#include "definitions.h"
#include "info_list.h"
// 8 9 10 11 12 13 14 15
// entoli cmd dst src1 src2 | ......... I E E E S S S W
/*
leave space for a command
printf(" |");
for(i=0; i<curreny_cycle
printf("%5d|", i)
//foreach elem in infoprint
printf %5sgetEnumStrcmd)
for(i=0; i<cycle_issued; i++)
printf(" |");
printf" I "
*/
/** Using terminal "color codes" (control sequences) to set foreground and background colors.
Not very portable, but pretty.
Tested with the terminal emulator "rxvt-unicode", properly configured.
To see the output correctly formatted, use the command "less -RS -~ -6 /full/path/to/file"
**/
/*
Black 0;30 Dark Gray 1;30
Blue 0;34 Light Blue 1;34
Green 0;32 Light Green 1;32
Cyan 0;36 Light Cyan 1;36
Red 0;31 Light Red 1;31
Purple 0;35 Light Purple 1;35
Brown 0;33 Yellow 1;33
Light Gray 0;37 White 1;37
*/
static FILE* fp; // to make setting colors easier
static inline
void setRed(void){
fprintf(fp, "%c[%dm", 0x1B, 31);
}
static inline
void setLBLue(void){
fprintf(fp, "%c[%dm", 0x1B, 34);
}
static inline
void setBlue(void){
fprintf(fp, "%c[%dm", 0x1B, 34);
}
static inline
void setLPurple(void){
fprintf(fp, "%c[%dm", 0x1B, 35);
}
static inline
void setCyan(void){
fprintf(fp, "%c[%dm", 0x1B, 36);
}
static inline
void setLCyan(void){
fprintf(fp, "%c[%dm", 0x1B, 36);
}
static inline
void setWhite(void){
fprintf(fp, "%c[%dm", 0x1B, 37);
}
static inline
void setGreen(void){
fprintf(fp, "%c[%dm", 0x1B, 32);
}
//static inline fprint_spaces(FILE *f)
//{
//
//}
void print_info_node(FILE *f, printinfo *p)
{
fp = f;
setGreen();
fprintf(f, "%5s |", getCmdStr(p->cmd->instr.r.cmd));
/*
for(int i = 0; i < p.cycle_issued; ++i)
// fprintf(f, "%s", " "[MAX_PRINTABLE_DIGITS]); //up to 10 printable spaces ;)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " ");
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "I ");
for(int i = 0; i < p.stalls_ex; ++i)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " ");
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "S ");
for(int i = 0; i < p.stalls_ex; ++i)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " ");
for(int i = 0; i < get_instr_ex_cycles(p.cmd); ++i)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "E ");
if (p.cmd.type != BEQZ){
for(int i = 0; i < p.stalls_wb; ++i)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " ");
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "S ");
for(int i = 0; i < p.stalls_wb; ++i)
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", " ");
fprintf(f, "%"MAX_PRINTABLE_DIGITS"s", "WB ");
}
*/
setBlue();
for(int i = 1; i < p->cycle_issued; ++i)
fprintf(f, " ");
fprintf(f, "%5s", " I ");
setRed();
for(int i = 0; i < p->stalls_ex; ++i)
fprintf(f, "%5s", " S ");
setLPurple();
for(int i = 0; i < get_instr_ex_cycles(&p->cmd); ++i)
fprintf(f, "%5s", " E ");
setRed();
if (p->cmd->type != BEQZ){
for(int i = 0; i < p->stalls_wb; ++i)
fprintf(f, "%5s", " S ");
setLCyan();
fprintf(f, "%5s", " WB ");
}
fprintf(f, "\n");
}
/* Function print_all() uses the address of func. print_info_node() as a callback for the
* func. print_info_list(), which traverses the list recursively. */
void print_all(FILE *f, info_list *IL, int current_cycle)
{
//assert(current_cycle <= MAX_PRINTABLE_CYCLES); // else our layout breaks!
/* print header */
fprintf(f, " Cmd |"); //print 5 spaces
for(int i = 1; i < current_cycle; ++i)
fprintf(f, "%4d|", i);
fprintf(f, "\n");
/* print all info foreach instruction before a breakpoint or a terminated execution */
print_info_list(f, IL, print_info_node);
}