-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtree.cpp
242 lines (222 loc) · 4.55 KB
/
tree.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
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
/*
thrice -> hold up a light
*/
#include <stdio.h>
#include <iostream>
#include "tree.hpp"
#include "compiler/registers/register_manager.hpp"
#include <algorithm>
using namespace std;
int orp = 15; //offset register params
void randomString(int size, char *output) // pass the destination size and the destination itself
{
srand(time(NULL)); // seed with time
char src[size];
size = rand() % size; // this randomises the size (optional)
src[size] = '\0'; // start with the end of the string...
// ...and work your way backwards
while (--size > -1)
src[size] = (rand() % 94) + 32; // generate a string ranging from the space character to ~ (tilde)
strcpy(output, src); // store the random string
};
string *_to_reg_(int r, int offset)
{
//return new string("R"+to_string(r));
switch (r + offset)
{
case 1:
{
return new string("rax");
}
case 2:
{
return new string("rbx");
}
case 3:
{
return new string("rcx");
}
case 4:
{
return new string("rdx");
}
case 5:
{
return new string("rdi");
}
case 6:
{
return new string("rsi");
}
case 7:
{
return new string("r8");
}
case 8:
{
return new string("r9");
}
case 9:
{
return new string("r10");
}
case 10:
{
return new string("r11");
}
case 11:
{
return new string("r12");
}
case 12:
{
return new string("r13");
}
case 13:
{
return new string("r14");
}
case 14:
{
return new string("r15");
}
case 15:
{ //parametros
return new string("rdi");
}
case 16:
{
return new string("rsi");
}
case 17:
{
return new string("rdx");
}
case 18:
{
return new string("rcx");
}
case 19:
{
return new string("r8");
}
case 20:
{
return new string("r9");
}
}
}
string *_to_reg_(int r)
{
return _to_reg_(r, 0);
}
bool sreq(Struct *o1, Struct *o2)
{
if (o1->elemType != NULL && o2->elemType != NULL)
{
if (o1->kind == o2->kind)
{
sreq(o1->elemType, o2->elemType);
}
else
{
return false;
}
}
else
{
if (o1->elemType == NULL && o2->elemType != NULL)
{
return false;
}
else if (o2->elemType == NULL && o1->elemType != NULL)
{
return false;
}
return o1->kind == o2->kind;
}
}
EffectivePart::EffectivePart()
{
this->mode = Add;
this->type = Reg;
};
EffectivePart::EffectivePart(int load)
: EffectivePart()
{
this->load = load;
};
EffectivePart::EffectivePart(int load, EffectiveType type)
: EffectivePart(load)
{
this->mode = Add;
this->type = type;
};
EffectivePart::EffectivePart(int load, EffectivePartLoadMode mod)
: EffectivePart(load)
{
this->mode = mod;
};
EffectivePart::EffectivePart(int load, EffectiveType type, EffectivePartLoadMode mod)
: EffectivePart(load, type)
{
this->mode = mod;
};
/////////////////////////
const char *modoToString(EffectivePartLoadMode mode)
{
switch (mode)
{
case Add:
return "+";
break;
case Sub:
return "-";
break;
case Div:
return "/";
break;
case Mul:
return "*";
break;
default:
break;
}
};
bool compareEfectivePart(EffectivePart *p1, EffectivePart *p2)
{
return (p1->mode < p2->mode);
}
char *EffectiveAddr::toString()
{
RegisterProvider *rp = RegisterManager::getInstance()->getProviderBy(64);
string *addr = new string();
/**
* TODO: delete
* TODO: colocar el registro dependiendo de la arquitectura
*/
if (withBp)
{
// RegisterProvider *rp = RegisterManager::getInstance()->getProviderBy(64);
addr->append(rp->get_by_name("rbp")->getName());
addr->append("+");
}
if (!this->parts.empty())
{
//std::sort(regis.begin(), regis.end(), compareEfectivePart);
for (int i = 0; i < parts.size(); i++)
{
if (i != 0)
addr->append(modoToString(parts[i]->mode));
if (parts[i]->type == Reg)
{
addr->append(rp->get(parts[i]->load)->getName());
}
else if (parts[i]->type == Num)
{
addr->append(to_string(parts[i]->load));
}
}
}
return (char *)addr->c_str();
}