-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.c
72 lines (62 loc) · 1.25 KB
/
util.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
#include "util.h"
// initializes the name generator
void initNameGenerator()
{
nameGenCounter = 1;
}
// generates a variable name sequentially
char* generateVariableName()
{
// this one generates v000, v001, ... , v010, v011, ... , v998, v999
name[0] = 't';
name[1] = 'm';
name[2] = 'p';
sprintf(name + 3, "%.3d", nameGenCounter);
++nameGenCounter;
return name;
}
void initAddressGenerator()
{
mainAddressCounter = 0x110;
tempAddressCounter = 0x120;
// printf("Start From: %x\n", tempAddressCounter);
}
// generates an address for temp(intermediate) variables
char* generateTempAddress()
{
sprintf(tempAddress, "%x", tempAddressCounter);
++tempAddressCounter;
return tempAddress;
}
int reg[7];
int getRegister(){
for(int i=0;i<7;++i){
if(reg[i] == 0 ){
reg[i] = 1;
return i;
}
}
return -1;
}
void freeReg(int i){
reg[i] = 0;
}
// generates an address for variables
char* generateMainAddress()
{
sprintf(mainAddress, "%x", mainAddressCounter);
// printf("%x\n", mainAddressCounter);
++mainAddressCounter;
return mainAddress;
}
// generates sequential numbers
void initNumberGenerator()
{
labelCounter = 0;
}
// returns generated numbers as string
int generateLabelNumber()
{
++labelCounter;
return labelCounter;
}