Rev 1237 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1237 | giacomo | 1 | #include <stdlib.h> |
2 | #include <string.h> |
||
3 | #include <stdio.h> |
||
1238 | giacomo | 4 | #include "lparser.h" |
1237 | giacomo | 5 | #include "time.h" |
6 | |||
7 | #define PARSER_DEBUG |
||
8 | |||
9 | static int find_break(char **buf, int find_type, struct timespec *time, int *val) |
||
10 | { |
||
11 | |||
12 | int i; |
||
13 | char str[20]; |
||
14 | |||
15 | i = 0; |
||
16 | while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':' || |
||
17 | ((char *)(*buf))[i] == '\n' || ((char *)(*buf))[i] == '\r') i++; |
||
18 | *buf += i; |
||
19 | |||
20 | if (!strncmp(*buf,"END",3) && find_type == PAR_NOTHING) { |
||
21 | *buf += 5; |
||
22 | return PAR_END; |
||
23 | } |
||
24 | |||
25 | i = 0; |
||
26 | if (((char *)(*buf))[0] == '#' && find_type == PAR_NOTHING) { |
||
27 | while (((char *)(*buf))[i] != '\n' && ((char *)(*buf))[i] != '\r') i++; |
||
28 | *buf += i; |
||
29 | return PAR_FOUND; |
||
30 | } |
||
31 | |||
32 | switch (find_type) { |
||
33 | |||
34 | case PAR_NOTHING: |
||
35 | if (((char *)(*buf))[0] == ';' || |
||
36 | ((char *)(*buf))[0] < 32) { |
||
37 | *buf += 1; |
||
38 | return PAR_FOUND; |
||
39 | } |
||
40 | break; |
||
41 | |||
42 | case PAR_TOTAL_EXEC_TIME: |
||
43 | if (!strncmp(*buf, "TOTAL_EXEC_TIME:",16)) { |
||
44 | *buf += 16; |
||
45 | return PAR_FOUND; |
||
46 | } |
||
47 | break; |
||
48 | |||
49 | case PAR_TIME: |
||
50 | if (((char *)(*buf))[0] != '[') return PAR_ERROR; |
||
51 | *buf += 1; |
||
52 | i = 0; |
||
53 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
54 | str[i] = ((char *)(*buf))[i]; |
||
55 | i++; |
||
56 | } |
||
57 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
58 | str[i] = 0; |
||
59 | time->tv_sec = atoi(str); |
||
60 | i += 2; |
||
61 | *buf += i; |
||
62 | i = 0; |
||
63 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
64 | str[i] = ((char *)(*buf))[i]; |
||
65 | i++; |
||
66 | } |
||
67 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
68 | str[i] = 0; |
||
69 | time->tv_nsec = atoi(str) * 1000; |
||
70 | i += 2; |
||
71 | *buf += i; |
||
72 | return PAR_FOUND; |
||
73 | break; |
||
74 | |||
75 | case PAR_TASK_TYPE: |
||
76 | if (!strncmp(*buf, "OS:",3)) { |
||
77 | *val = PAR_TASK_OS; |
||
78 | *buf += 3; |
||
79 | return PAR_FOUND; |
||
80 | } |
||
81 | if (!strncmp(*buf, "CT:",3)) { |
||
82 | *val = PAR_TASK_CT; |
||
83 | *buf += 3; |
||
84 | return PAR_FOUND; |
||
85 | } |
||
86 | if (!strncmp(*buf, "BT:",3)) { |
||
87 | *val = PAR_TASK_BT; |
||
88 | *buf += 3; |
||
89 | return PAR_FOUND; |
||
90 | } |
||
91 | break; |
||
92 | |||
93 | case PAR_TASK_NUMBER: |
||
94 | if (((char *)(*buf))[0] != '[') return PAR_ERROR; |
||
95 | *buf += 1; |
||
96 | i = 0; |
||
97 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
98 | str[i] = ((char *)(*buf))[i]; |
||
99 | i++; |
||
100 | } |
||
101 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
102 | str[i] = 0; |
||
103 | *val = atoi(str); |
||
104 | i += 2; |
||
105 | *buf += i; |
||
106 | return PAR_FOUND; |
||
107 | break; |
||
108 | |||
109 | case PAR_ACT_TYPE: |
||
110 | if (!strncmp(*buf,"ACT_SINGLE(",11)) { |
||
111 | *buf += 11; |
||
112 | *val = PAR_ACT_SINGLE; |
||
113 | return PAR_FOUND; |
||
114 | } |
||
115 | if (!strncmp(*buf,"ACT_PERIODIC(",13)) { |
||
116 | *buf += 13; |
||
117 | *val = PAR_ACT_PERIODIC; |
||
118 | return PAR_FOUND; |
||
119 | } |
||
120 | if (!strncmp(*buf,"ACT_MEAN(",9)) { |
||
121 | *buf += 9; |
||
122 | *val = PAR_ACT_MEAN; |
||
123 | return PAR_FOUND; |
||
124 | } |
||
125 | return PAR_ERROR; |
||
126 | break; |
||
127 | |||
128 | case PAR_LOCAL_SCHEDULER: |
||
129 | if (!strncmp(*buf,"POSIX",5)) { |
||
130 | *buf += 5; |
||
131 | *val = PAR_POSIX; |
||
132 | return PAR_FOUND; |
||
133 | } |
||
134 | if (!strncmp(*buf,"EDF",5)) { |
||
135 | *buf += 5; |
||
136 | *val = PAR_ACT_PERIODIC; |
||
137 | return PAR_FOUND; |
||
138 | } |
||
139 | if (!strncmp(*buf,"RM",2)) { |
||
140 | *buf += 2; |
||
141 | *val = PAR_ACT_MEAN; |
||
142 | return PAR_FOUND; |
||
143 | } |
||
144 | return PAR_ERROR; |
||
145 | break; |
||
146 | |||
147 | case PAR_EXEC_TYPE: |
||
148 | if (!strncmp(*buf,"EXEC_CONST(",11)) { |
||
149 | *buf += 11; |
||
150 | *val = PAR_EXEC_CONST; |
||
151 | return PAR_FOUND; |
||
152 | } |
||
153 | if (!strncmp(*buf,"EXEC_MEAN(",10)) { |
||
154 | *buf += 10; |
||
155 | *val = PAR_EXEC_MEAN; |
||
156 | return PAR_FOUND; |
||
157 | } |
||
158 | return PAR_ERROR; |
||
159 | break; |
||
160 | |||
161 | case PAR_CRIT_SESSION: |
||
162 | if (!strncmp(*buf,"NO_CRIT",7)) { |
||
163 | *buf += 7; |
||
164 | *val = PAR_NO_CRIT; |
||
165 | return PAR_FOUND; |
||
166 | } |
||
167 | if (!strncmp(*buf,"CRIT(",5)) { |
||
168 | *buf += 5; |
||
169 | *val = PAR_CRIT; |
||
170 | return PAR_FOUND; |
||
171 | } |
||
172 | return PAR_ERROR; |
||
173 | break; |
||
174 | |||
175 | } |
||
176 | |||
177 | return PAR_ERROR; |
||
178 | |||
179 | } |
||
180 | |||
181 | void par_error(int line_num) |
||
182 | { |
||
183 | |||
184 | printf("\nParser error: line [%d]\n",line_num); |
||
185 | exit(1); |
||
186 | |||
187 | } |
||
188 | |||
189 | /* result: |
||
190 | * 0 -> nothing |
||
191 | * 1 -> total |
||
192 | * 2 -> new task-loader |
||
193 | * 3 -> end file |
||
194 | */ |
||
195 | int line_parser(char **pbuf, int line_num, struct timespec *total, struct loader_task **last) |
||
196 | { |
||
197 | struct timespec time; |
||
198 | struct loader_task *ld = NULL; |
||
199 | int val, res; |
||
200 | |||
201 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
202 | if (res == PAR_FOUND) return 0; |
||
203 | if (res == PAR_END) return 3; |
||
204 | |||
205 | res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
||
206 | if (res == PAR_FOUND) { |
||
207 | NULL_TIMESPEC(total); |
||
208 | res = find_break(pbuf, PAR_TIME, &time, &val); |
||
209 | if (res == PAR_FOUND) { |
||
210 | TIMESPEC_ASSIGN(total,&time); |
||
211 | #ifdef PARSER_DEBUG |
||
212 | printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec); |
||
213 | #endif |
||
214 | return 1; |
||
215 | } else par_error(line_num); |
||
216 | } |
||
217 | |||
218 | res = find_break(pbuf,PAR_TASK_TYPE, &time, &val); |
||
219 | if (res == PAR_FOUND) { |
||
220 | #ifdef PARSER_DEBUG |
||
221 | printf("TASK TYPE = %d\n",val); |
||
222 | #endif |
||
223 | |||
224 | ld = malloc(sizeof(struct loader_task)); |
||
225 | if (ld == NULL) par_error(line_num); |
||
226 | |||
227 | ld->next = NULL; |
||
228 | *last = ld; |
||
229 | |||
230 | ld->task_type = val; |
||
231 | |||
232 | } else par_error(line_num); |
||
233 | |||
234 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
235 | if (res == PAR_FOUND) { |
||
236 | #ifdef PARSER_DEBUG |
||
237 | printf("TASK SERVER = %d\n",val); |
||
238 | #endif |
||
239 | |||
240 | ld->server = val; |
||
241 | } else par_error(line_num); |
||
242 | |||
243 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
244 | if (res == PAR_FOUND) { |
||
245 | #ifdef PARSER_DEBUG |
||
246 | printf("TASK LOCAL SCHEDULER = %d\n",val); |
||
247 | #endif |
||
248 | |||
249 | ld->local_scheduler = val; |
||
250 | } else par_error(line_num); |
||
251 | |||
252 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
253 | if (res == PAR_FOUND) { |
||
254 | #ifdef PARSER_DEBUG |
||
255 | printf("TASK NUMBER = %d\n",val); |
||
256 | #endif |
||
257 | |||
258 | ld->number = val; |
||
259 | |||
260 | } else par_error(line_num); |
||
261 | |||
262 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
263 | if (res == PAR_FOUND) { |
||
264 | #ifdef PARSER_DEBUG |
||
265 | printf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
266 | #endif |
||
267 | TIMESPEC_ASSIGN(&ld->deadline,&time); |
||
268 | } else par_error(line_num); |
||
269 | |||
270 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
271 | if (res == PAR_FOUND) { |
||
272 | #ifdef PARSER_DEBUG |
||
273 | printf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
274 | #endif |
||
275 | TIMESPEC_ASSIGN(&ld->wcet,&time); |
||
276 | } else par_error(line_num); |
||
277 | |||
278 | res = find_break(pbuf,PAR_ACT_TYPE, &time, &val); |
||
279 | if (res == PAR_FOUND) { |
||
280 | #ifdef PARSER_DEBUG |
||
281 | printf("ACTIVATION TYPE: %d (",val); |
||
282 | #endif |
||
283 | |||
284 | ld->act_type = val; |
||
285 | |||
286 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
287 | if (res == PAR_FOUND) { |
||
288 | #ifdef PARSER_DEBUG |
||
289 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
290 | #endif |
||
291 | TIMESPEC_ASSIGN(&ld->act_par_1,&time); |
||
292 | } else par_error(line_num); |
||
293 | |||
294 | if (ld->act_type != PAR_ACT_SINGLE) { |
||
295 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
296 | if (res == PAR_FOUND) { |
||
297 | #ifdef PARSER_DEBUG |
||
298 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
299 | #endif |
||
300 | TIMESPEC_ASSIGN(&ld->act_par_2,&time); |
||
301 | } else par_error(line_num); |
||
302 | } |
||
303 | |||
304 | #ifdef PARSER_DEBUG |
||
305 | printf(")\n"); |
||
306 | #endif |
||
307 | |||
308 | } else par_error(line_num); |
||
309 | |||
310 | res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val); |
||
311 | if (res == PAR_FOUND) { |
||
312 | #ifdef PARSER_DEBUG |
||
313 | printf("EXEC TYPE: %d (",val); |
||
314 | #endif |
||
315 | ld->exec_type = val; |
||
316 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
317 | if (res == PAR_FOUND) { |
||
318 | #ifdef PARSER_DEBUG |
||
319 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
320 | #endif |
||
321 | TIMESPEC_ASSIGN(&ld->exec_par_1,&time); |
||
322 | } else par_error(line_num); |
||
323 | |||
324 | if (ld->exec_type != PAR_EXEC_CONST) { |
||
325 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
326 | if (res == PAR_FOUND) { |
||
327 | #ifdef PARSER_DEBUG |
||
328 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
329 | #endif |
||
330 | TIMESPEC_ASSIGN(&ld->exec_par_2,&time); |
||
331 | } else par_error(line_num); |
||
332 | } |
||
333 | |||
334 | #ifdef PARSER_DEBUG |
||
335 | printf(")\n"); |
||
336 | #endif |
||
337 | |||
338 | } else par_error(line_num); |
||
339 | |||
340 | res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val); |
||
341 | if (res == PAR_FOUND) { |
||
342 | #ifdef PARSER_DEBUG |
||
343 | printf("CRITITCAL SESSION: %d (",val); |
||
344 | #endif |
||
345 | ld->crit_type = val; |
||
346 | if (ld->crit_type == PAR_CRIT) { |
||
347 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
348 | if (res == PAR_FOUND) { |
||
349 | #ifdef PARSER_DEBUG |
||
350 | printf("[%d]",val); |
||
351 | #endif |
||
352 | ld->resource = val; |
||
353 | } else par_error(line_num); |
||
354 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
355 | if (res == PAR_FOUND) { |
||
356 | #ifdef PARSER_DEBUG |
||
357 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
358 | #endif |
||
359 | TIMESPEC_ASSIGN(&ld->crit_par_1,&time); |
||
360 | } else par_error(line_num); |
||
361 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
362 | if (res == PAR_FOUND) { |
||
363 | #ifdef PARSER_DEBUG |
||
364 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
365 | #endif |
||
366 | TIMESPEC_ASSIGN(&ld->crit_par_2,&time); |
||
367 | } else par_error(line_num); |
||
368 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
369 | if (res == PAR_FOUND) { |
||
370 | #ifdef PARSER_DEBUG |
||
371 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
372 | #endif |
||
373 | TIMESPEC_ASSIGN(&ld->crit_par_3,&time); |
||
374 | } else par_error(line_num); |
||
375 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
376 | if (res == PAR_FOUND) { |
||
377 | #ifdef PARSER_DEBUG |
||
378 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
379 | #endif |
||
380 | TIMESPEC_ASSIGN(&ld->crit_par_4,&time); |
||
381 | } else par_error(line_num); |
||
382 | |||
383 | } |
||
384 | |||
385 | #ifdef PARSER_DEBUG |
||
386 | printf(")\n"); |
||
387 | #endif |
||
388 | |||
389 | } else par_error(line_num); |
||
390 | |||
391 | return 2; |
||
392 | |||
393 | } |
||
394 |