-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvirtualAddress.py
346 lines (301 loc) · 10.1 KB
/
virtualAddress.py
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
# Global address range
intGlobalAddress = 1000
floatGlobalAddress = 2000
charGlobalAddress = 3000
boolGlobalAddress = 4000
# Local address range
intLocalAddress = 5000
floatLocalAddress = 6000
charLocalAddress = 7000
boolLocalAddress = 8000
# Global temporal address range
intTempGlobalAddress = 9000
floatTempGlobalAddress = 10000
charTempGlobalAddress = 11000
boolTempGlobalAddress = 12000
# Local temporal address range
intTempLocalAddress = 13000
floatTempLocalAddress = 14000
charTempLocalAddress = 15000
boolTempLocalAddress = 16000
# Constant address range
intConstAddress = 17000
floatConstAddress = 18000
charConstAddress = 19000
boolConstAddress = 20000
# Pointers
global_pointers = 70000
local_pointers = 71000
# RESET TEMPORALS FOR RE-USE
def resetLocalTemporals():
global intGlobalAddress, floatGlobalAddress, charGlobalAddress, intLocalAddress, floatLocalAddress, charLocalAddress, intTempGlobalAddress, floatTempGlobalAddress, charTempGlobalAddress, intTempLocalAddress, floatTempLocalAddress, charTempLocalAddress, intConstAddress, floatConstAddress, charConstAddress
global boolGlobalAddress, boolLocalAddress, boolTempGlobalAddress, boolTempLocalAddress, boolConstAddress, local_pointers
intLocalAddress = 5000
floatLocalAddress = 6000
charLocalAddress = 7000
boolLocalAddress = 8000
intTempLocalAddress = 13000
floatTempLocalAddress = 14000
charTempLocalAddress = 15000
boolTempLocalAddress = 16000
local_pointers = 71000
def getLocalTempUsed():
ints = intTempLocalAddress - 13000
floats = floatTempLocalAddress - 14000
chars = charTempLocalAddress - 15000
bools = boolTempLocalAddress - 16000
pointers = local_pointers - 71000
return (ints, floats, chars, bools, pointers)
def getLocalUsed():
ints = intLocalAddress - 5000
floats = floatLocalAddress - 6000
chars = charLocalAddress - 7000
bools = boolLocalAddress - 8000
return (ints, floats, chars, bools)
def getGlobalUsed():
ints = intGlobalAddress - 1000
floats = floatGlobalAddress - 2000
chars = charGlobalAddress - 3000
bools = boolGlobalAddress - 4000
return (ints, floats, chars, bools)
def getGlobalTempUsed():
ints = intTempGlobalAddress - 9000
floats = floatTempGlobalAddress - 10000
chars = charTempGlobalAddress - 11000
bools = boolTempGlobalAddress - 12000
pointers = global_pointers - 70000
return (ints, floats, chars, bools, pointers)
def setArrayAddresses(type, scope, size):
global intGlobalAddress, floatGlobalAddress, charGlobalAddress, intLocalAddress, floatLocalAddress, charLocalAddress, intTempGlobalAddress, floatTempGlobalAddress, charTempGlobalAddress, intTempLocalAddress, floatTempLocalAddress, charTempLocalAddress, intConstAddress, floatConstAddress, charConstAddress
global boolGlobalAddress, boolLocalAddress, boolTempGlobalAddress, boolTempLocalAddress, boolConstAddress
size -= 1
# GLOBALS
if(type == "int" and scope == "global"):
if(intGlobalAddress >= 1000 and intGlobalAddress <= 1999):
aux = intGlobalAddress
intGlobalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "global"):
if(floatGlobalAddress >= 2000 and floatGlobalAddress <= 2999):
aux = floatGlobalAddress
floatGlobalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "global"):
if(charGlobalAddress >= 3000 and charGlobalAddress <= 3999):
aux = charGlobalAddress
charGlobalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
# LOCALS
if(type == "int" and scope == "local"):
if(intLocalAddress >= 5000 and intLocalAddress <= 5999):
aux = intLocalAddress
intLocalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "local"):
if(floatLocalAddress >= 6000 and floatLocalAddress <= 6999):
aux = floatLocalAddress
floatLocalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "local"):
if(charLocalAddress >= 7000 and charLocalAddress <= 7999):
aux = charLocalAddress
charLocalAddress += size
return aux
else:
print("Addresing Overflow")
exit()
# Set Address
def setAddress(type, scope):
global intGlobalAddress, floatGlobalAddress, charGlobalAddress, intLocalAddress, floatLocalAddress, charLocalAddress, intTempGlobalAddress, floatTempGlobalAddress, charTempGlobalAddress, intTempLocalAddress, floatTempLocalAddress, charTempLocalAddress, intConstAddress, floatConstAddress, charConstAddress
global boolGlobalAddress, boolLocalAddress, boolTempGlobalAddress, boolTempLocalAddress, boolConstAddress, global_pointers, local_pointers
if(type == "int" and scope == "global"):
if(intGlobalAddress >= 1000 and intGlobalAddress <= 1999):
aux = intGlobalAddress
intGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "global"):
if(floatGlobalAddress >= 2000 and floatGlobalAddress <= 2999):
aux = floatGlobalAddress
floatGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "global"):
if(charGlobalAddress >= 3000 and charGlobalAddress <= 3999):
aux = charGlobalAddress
charGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "bool" and scope == "global"):
if(boolGlobalAddress >= 4000 and boolGlobalAddress <= 4999):
aux = boolGlobalAddress
boolGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "int" and scope == "local"):
if(intLocalAddress >= 5000 and intLocalAddress <= 5999):
aux = intLocalAddress
intLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "local"):
if(floatLocalAddress >= 6000 and floatLocalAddress <= 6999):
aux = floatLocalAddress
floatLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "local"):
if(charLocalAddress >= 7000 and charLocalAddress <= 7999):
aux = charLocalAddress
charLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "bool" and scope == "local"):
if(boolLocalAddress >= 8000 and boolLocalAddress <= 8999):
aux = boolLocalAddress
boolLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "int" and scope == "tempGlobal"):
if(intTempGlobalAddress >= 9000 and intTempGlobalAddress <= 9999):
aux = intTempGlobalAddress
intTempGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "tempGlobal"):
if(floatTempGlobalAddress >= 10000 and floatTempGlobalAddress <= 10999):
aux = floatTempGlobalAddress
floatTempGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "tempGlobal"):
if(charTempGlobalAddress >= 11000 and charTempGlobalAddress <= 11999):
aux = charTempGlobalAddress
charTempGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "bool" and scope == "tempGlobal"):
if(boolTempGlobalAddress >= 12000 and boolTempGlobalAddress <= 12999):
aux = boolTempGlobalAddress
boolTempGlobalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "int" and scope == "tempLocal"):
if(intTempLocalAddress >= 13000 and intTempLocalAddress <= 13999):
aux = intTempLocalAddress
intTempLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "tempLocal"):
if(floatTempLocalAddress >= 14000 and floatTempLocalAddress <= 14999):
aux = floatTempLocalAddress
floatTempLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "tempLocal"):
if(charTempLocalAddress >= 15000 and charTempLocalAddress <= 15999):
aux = charTempLocalAddress
charTempLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "bool" and scope == "tempLocal"):
if(boolTempLocalAddress >= 16000 and boolTempLocalAddress <= 16999):
aux = boolTempLocalAddress
boolTempLocalAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "int" and scope == "constant"):
if(intConstAddress >= 17000 and intConstAddress <= 17999):
aux = intConstAddress
intConstAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "float" and scope == "constant"):
if(floatConstAddress >= 18000 and floatConstAddress <= 18999):
aux = floatConstAddress
floatConstAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "char" and scope == "constant"):
if(charConstAddress >= 19000 and charConstAddress <= 19999):
aux = charConstAddress
charConstAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "bool" and scope == "constant"):
if(boolConstAddress >= 20000 and boolConstAddress <= 20999):
aux = boolConstAddress
boolConstAddress += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "pointer" and scope == "global"):
if(global_pointers >= 70000 and global_pointers <= 70999):
aux = global_pointers
global_pointers += 1
return aux
else:
print("Addresing Overflow")
exit()
if(type == "pointer" and scope == "local"):
if(local_pointers >= 71000 and local_pointers <= 71999 ):
aux = local_pointers
local_pointers += 1
return aux
else:
print("Addresing Overflow")
exit()