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
|
#include <stdio.h>
int main (void)
{
FILE *f,*o;
int c,offset;
f=fopen ("areals.s","r");
o=fopen ("areals_offsets.s","w");
for (;;){
c=getc (f);
if (c!='\t')
goto next_line_1;
c=getc (f);
if (c!='#')
goto next_line_1;
c=getc (f);
if (c!='o')
goto next_line_1;
c=getc (f);
if (c!='f')
goto next_line_1;
c=getc (f);
if (c!='f')
goto next_line_1;
c=getc (f);
if (c!='s')
goto next_line_1;
c=getc (f);
if (c!='e')
goto next_line_1;
c=getc (f);
if (c!='t')
goto next_line_1;
c=getc (f);
if (c!='s')
goto next_line_1;
c=getc (f);
while (c!='\n')
c=getc (f);
break;
next_line_1:
while (c!='\n')
c=getc (f);
}
printf ("found #offsets\n");
offset=0;
for (;;){
if (c=='\n' || c=='\r'){
c=getc (f);
continue;
}
if (c=='#')
goto next_line;
if ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_'){
do {
fprintf (o,"%c",c);
c=getc (f);
} while ((c>='a' && c<='z') || (c>='A' && c<='Z') || (c>='0' && c<='9') || c=='_');
fprintf (o,"_offset = %d\n",offset);
if (c==':')
goto next_line;
printf (": expected, not %c\n",c);
return 0;
}
if (c==EOF)
break;
if (!(c==' ' || c=='\t')){
printf ("line should start with a tab, space or #, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='.'){
printf (". expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c=='d'){
c=getc (f);
if (c!='o'){
printf ("o. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='u'){
printf ("u. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='b'){
printf ("b. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='l'){
printf ("l. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='e'){
printf ("e. expected, not %c\n",c);
return 0;
}
if (offset & 7){
printf (".double not 8 byte aligned\n");
return 0;
}
offset+=8;
c=getc (f);
goto next_line;
}
if (c=='q'){
c=getc (f);
if (c!='u'){
printf ("u. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='a'){
printf ("a. expected, not %c\n",c);
return 0;
}
c=getc (f);
if (c!='d'){
printf ("d. expected, not %c\n",c);
return 0;
}
offset+=4;
c=getc (f);
goto next_line;
}
printf (".double or .quad expected, not .%c\n",c);
return 0;
next_line:
while (c!='\n' && c!='\r' && c!=EOF)
c=getc (f);
if (c==EOF)
break;
}
fclose (o);
fclose (f);
printf ("all offsets written\n");
return 1;
}
|