Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1255 | giacomo | 1 | #include <kernel/kern.h> |
2 | #include <stdlib.h> |
||
3 | #include <string.h> |
||
4 | #include <stdio.h> |
||
5 | #include "parser.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, "NRT:",4)) { |
||
77 | *val = PAR_TASK_NRT; |
||
78 | *buf += 4; |
||
79 | return PAR_FOUND; |
||
80 | } |
||
81 | if (!strncmp(*buf, "HARD:",5)) { |
||
82 | *val = PAR_TASK_HARD; |
||
83 | *buf += 5; |
||
84 | return PAR_FOUND; |
||
85 | } |
||
86 | if (!strncmp(*buf, "SOFT:",5)) { |
||
87 | *val = PAR_TASK_SOFT; |
||
88 | *buf += 5; |
||
89 | return PAR_FOUND; |
||
90 | } |
||
91 | if (!strncmp(*buf, "BACK:",5)) { |
||
92 | *val = PAR_TASK_BACK; |
||
93 | *buf += 5; |
||
94 | return PAR_FOUND; |
||
95 | } |
||
96 | if (!strncmp(*buf, "FSF:",4)) { |
||
97 | *val = PAR_TASK_FSF; |
||
98 | *buf += 4; |
||
99 | return PAR_FOUND; |
||
100 | } |
||
101 | break; |
||
102 | |||
103 | case PAR_TASK_NUMBER: |
||
104 | if (((char *)(*buf))[0] != '[') return PAR_ERROR; |
||
105 | *buf += 1; |
||
106 | i = 0; |
||
107 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
108 | str[i] = ((char *)(*buf))[i]; |
||
109 | i++; |
||
110 | } |
||
111 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
112 | str[i] = 0; |
||
113 | *val = atoi(str); |
||
114 | i += 2; |
||
115 | *buf += i; |
||
116 | return PAR_FOUND; |
||
117 | break; |
||
118 | |||
119 | case PAR_LOCAL_SCHEDULER: |
||
120 | if (!strncmp(*buf,"POSIX",5)) { |
||
121 | *buf += 5; |
||
122 | *val = PAR_POSIX; |
||
123 | return PAR_FOUND; |
||
124 | } |
||
125 | if (!strncmp(*buf,"EDF",3)) { |
||
126 | *buf += 3; |
||
127 | *val = PAR_EDF; |
||
128 | return PAR_FOUND; |
||
129 | } |
||
130 | if (!strncmp(*buf,"RM",2)) { |
||
131 | *buf += 2; |
||
132 | *val = PAR_RM; |
||
133 | return PAR_FOUND; |
||
134 | } |
||
135 | break; |
||
136 | |||
137 | case PAR_ACT_TYPE: |
||
138 | if (!strncmp(*buf,"ACT_SINGLE(",11)) { |
||
139 | *buf += 11; |
||
140 | *val = PAR_ACT_SINGLE; |
||
141 | return PAR_FOUND; |
||
142 | } |
||
143 | if (!strncmp(*buf,"ACT_PERIODIC(",13)) { |
||
144 | *buf += 13; |
||
145 | *val = PAR_ACT_PERIODIC; |
||
146 | return PAR_FOUND; |
||
147 | } |
||
148 | if (!strncmp(*buf,"ACT_MEAN(",9)) { |
||
149 | *buf += 9; |
||
150 | *val = PAR_ACT_MEAN; |
||
151 | return PAR_FOUND; |
||
152 | } |
||
153 | if (!strncmp(*buf,"ACT_GAUSS(",10)) { |
||
154 | *buf += 10; |
||
155 | *val = PAR_ACT_GAUSS; |
||
156 | return PAR_FOUND;; |
||
157 | } |
||
158 | if (!strncmp(*buf,"ACT_GAUSS_MAX(",14)) { |
||
159 | *buf += 14; |
||
160 | *val = PAR_ACT_GAUSS_MAX; |
||
161 | return PAR_FOUND; |
||
162 | } |
||
163 | return PAR_ERROR; |
||
164 | break; |
||
165 | |||
166 | case PAR_EXEC_TYPE: |
||
167 | if (!strncmp(*buf,"EXEC_CONST(",11)) { |
||
168 | *buf += 11; |
||
169 | *val = PAR_EXEC_CONST; |
||
170 | return PAR_FOUND; |
||
171 | } |
||
172 | if (!strncmp(*buf,"EXEC_MEAN(",10)) { |
||
173 | *buf += 10; |
||
174 | *val = PAR_EXEC_MEAN; |
||
175 | return PAR_FOUND; |
||
176 | } |
||
177 | if (!strncmp(*buf,"EXEC_GAUSS(",11)) { |
||
178 | *buf += 11; |
||
179 | *val = PAR_EXEC_GAUSS; |
||
180 | return PAR_FOUND; |
||
181 | } |
||
182 | if (!strncmp(*buf,"EXEC_GAUSS_MAX(",15)) { |
||
183 | *buf += 15; |
||
184 | *val = PAR_EXEC_GAUSS_MAX; |
||
185 | return PAR_FOUND; |
||
186 | } |
||
187 | return PAR_ERROR; |
||
188 | break; |
||
189 | |||
190 | case PAR_CRIT_SESSION: |
||
191 | if (!strncmp(*buf,"NO_CRIT",7)) { |
||
192 | *buf += 7; |
||
193 | *val = PAR_NO_CRIT; |
||
194 | return PAR_FOUND; |
||
195 | } |
||
196 | if (!strncmp(*buf,"CRIT(",5)) { |
||
197 | *buf += 5; |
||
198 | *val = PAR_CRIT; |
||
199 | return PAR_FOUND; |
||
200 | } |
||
201 | return PAR_ERROR; |
||
202 | break; |
||
203 | |||
204 | case PAR_FSF_SERVER: |
||
205 | if (!strncmp(*buf,"[S",2)) { |
||
206 | *buf += 2; |
||
207 | i = 0; |
||
208 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
209 | str[i] = ((char *)(*buf))[i]; |
||
210 | i++; |
||
211 | } |
||
212 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
213 | str[i] = 0; |
||
214 | *val = atoi(str); |
||
215 | i += 2; |
||
216 | *buf += i; |
||
217 | return PAR_FOUND; |
||
218 | } else return PAR_ERROR; |
||
219 | break; |
||
220 | |||
221 | } |
||
222 | |||
223 | return PAR_ERROR; |
||
224 | |||
225 | } |
||
226 | |||
227 | void par_error(int line_num) |
||
228 | { |
||
229 | |||
230 | cprintf("\nParser error: line [%d]\n",line_num); |
||
231 | sys_end(); |
||
232 | |||
233 | } |
||
234 | |||
235 | /* result: |
||
236 | * 0 -> nothing |
||
237 | * 1 -> total |
||
238 | * 2 -> new task-loader |
||
239 | * 3 -> end file |
||
240 | */ |
||
241 | int line_parser(char **pbuf, int line_num, struct timespec *total, struct loader_task **last) |
||
242 | { |
||
243 | struct timespec time; |
||
244 | struct loader_task *ld = NULL; |
||
245 | int val, res; |
||
246 | |||
247 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
248 | if (res == PAR_FOUND) return 0; |
||
249 | if (res == PAR_END) return 3; |
||
250 | |||
251 | res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
||
252 | if (res == PAR_FOUND) { |
||
253 | NULL_TIMESPEC(total); |
||
254 | res = find_break(pbuf, PAR_TIME, &time, &val); |
||
255 | if (res == PAR_FOUND) { |
||
256 | TIMESPEC_ASSIGN(total,&time); |
||
257 | #ifdef PARSER_DEBUG |
||
258 | cprintf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec); |
||
259 | #endif |
||
260 | return 1; |
||
261 | } else par_error(line_num); |
||
262 | } |
||
263 | |||
264 | res = find_break(pbuf,PAR_TASK_TYPE, &time, &val); |
||
265 | if (res == PAR_FOUND) { |
||
266 | #ifdef PARSER_DEBUG |
||
267 | cprintf("TASK TYPE = %d\n",val); |
||
268 | #endif |
||
269 | |||
270 | ld = malloc(sizeof(struct loader_task)); |
||
271 | if (ld == NULL) par_error(line_num); |
||
272 | |||
273 | ld->next = NULL; |
||
274 | *last = ld; |
||
275 | |||
276 | ld->task_type = val; |
||
277 | |||
278 | } else par_error(line_num); |
||
279 | |||
280 | if (ld->task_type == PAR_TASK_FSF) { |
||
281 | res = find_break(pbuf,PAR_FSF_SERVER, &time, &val); |
||
282 | if (res == PAR_FOUND) { |
||
283 | #ifdef PARSER_DEBUG |
||
284 | cprintf("TASK SERVER = %d\n",val); |
||
285 | #endif |
||
286 | |||
287 | ld->server = val; |
||
288 | } else par_error(line_num); |
||
289 | |||
290 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
291 | if (res == PAR_FOUND) { |
||
292 | #ifdef PARSER_DEBUG |
||
293 | cprintf("TASK LOCAL SCHEDULER = %d\n",val); |
||
294 | #endif |
||
295 | |||
296 | ld->local_scheduler = val; |
||
297 | } else par_error(line_num); |
||
298 | |||
299 | } else { |
||
300 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
301 | if (res == PAR_FOUND) { |
||
302 | #ifdef PARSER_DEBUG |
||
303 | cprintf("TASK LEVEL = %d\n",val); |
||
304 | #endif |
||
305 | |||
306 | ld->task_level = val; |
||
307 | |||
308 | } else par_error(line_num); |
||
309 | } |
||
310 | |||
311 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
312 | if (res == PAR_FOUND) { |
||
313 | #ifdef PARSER_DEBUG |
||
314 | cprintf("TASK NUMBER = %d\n",val); |
||
315 | #endif |
||
316 | |||
317 | ld->number = val; |
||
318 | |||
319 | } else par_error(line_num); |
||
320 | |||
321 | res = find_break(pbuf,PAR_ACT_TYPE, &time, &val); |
||
322 | if (res == PAR_FOUND) { |
||
323 | #ifdef PARSER_DEBUG |
||
324 | cprintf("ACTIVATION TYPE: %d (",val); |
||
325 | #endif |
||
326 | |||
327 | ld->act_type = val; |
||
328 | |||
329 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
330 | if (res == PAR_FOUND) { |
||
331 | #ifdef PARSER_DEBUG |
||
332 | cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
333 | #endif |
||
334 | TIMESPEC_ASSIGN(&ld->act_par_1,&time); |
||
335 | } else par_error(line_num); |
||
336 | |||
337 | if (ld->act_type != PAR_ACT_SINGLE) { |
||
338 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
339 | if (res == PAR_FOUND) { |
||
340 | #ifdef PARSER_DEBUG |
||
341 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
342 | #endif |
||
343 | TIMESPEC_ASSIGN(&ld->act_par_2,&time); |
||
344 | } else par_error(line_num); |
||
345 | } |
||
346 | |||
347 | if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) { |
||
348 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
349 | if (res == PAR_FOUND) { |
||
350 | #ifdef PARSER_DEBUG |
||
351 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
352 | #endif |
||
353 | TIMESPEC_ASSIGN(&ld->act_par_3,&time); |
||
354 | } else par_error(line_num); |
||
355 | } |
||
356 | |||
357 | if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC && |
||
358 | ld->act_type != PAR_ACT_MEAN && ld->act_type != PAR_ACT_GAUSS) { |
||
359 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
360 | if (res == PAR_FOUND) { |
||
361 | #ifdef PARSER_DEBUG |
||
362 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
363 | #endif |
||
364 | TIMESPEC_ASSIGN(&ld->act_par_4,&time); |
||
365 | } else par_error(line_num); |
||
366 | } |
||
367 | |||
368 | #ifdef PARSER_DEBUG |
||
369 | cprintf(")\n"); |
||
370 | #endif |
||
371 | |||
372 | } else par_error(line_num); |
||
373 | |||
374 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
375 | if (res == PAR_FOUND) { |
||
376 | #ifdef PARSER_DEBUG |
||
377 | cprintf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
378 | #endif |
||
379 | TIMESPEC_ASSIGN(&ld->deadline,&time); |
||
380 | } else par_error(line_num); |
||
381 | |||
382 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
383 | if (res == PAR_FOUND) { |
||
384 | #ifdef PARSER_DEBUG |
||
385 | cprintf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
386 | #endif |
||
387 | TIMESPEC_ASSIGN(&ld->wcet,&time); |
||
388 | } else par_error(line_num); |
||
389 | |||
390 | res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val); |
||
391 | if (res == PAR_FOUND) { |
||
392 | #ifdef PARSER_DEBUG |
||
393 | cprintf("EXEC TYPE: %d (",val); |
||
394 | #endif |
||
395 | ld->exec_type = val; |
||
396 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
397 | if (res == PAR_FOUND) { |
||
398 | #ifdef PARSER_DEBUG |
||
399 | cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
400 | #endif |
||
401 | TIMESPEC_ASSIGN(&ld->exec_par_1,&time); |
||
402 | } else par_error(line_num); |
||
403 | |||
404 | if (ld->exec_type != PAR_EXEC_CONST) { |
||
405 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
406 | if (res == PAR_FOUND) { |
||
407 | #ifdef PARSER_DEBUG |
||
408 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
409 | #endif |
||
410 | TIMESPEC_ASSIGN(&ld->exec_par_2,&time); |
||
411 | } else par_error(line_num); |
||
412 | } |
||
413 | |||
414 | if (ld->exec_type != PAR_EXEC_CONST && ld->exec_type != PAR_EXEC_MEAN && |
||
415 | ld->exec_type != PAR_EXEC_GAUSS) { |
||
416 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
417 | if (res == PAR_FOUND) { |
||
418 | #ifdef PARSER_DEBUG |
||
419 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
420 | #endif |
||
421 | TIMESPEC_ASSIGN(&ld->exec_par_3,&time); |
||
422 | } else par_error(line_num); |
||
423 | } |
||
424 | |||
425 | #ifdef PARSER_DEBUG |
||
426 | cprintf(")\n"); |
||
427 | #endif |
||
428 | |||
429 | } else par_error(line_num); |
||
430 | |||
431 | res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val); |
||
432 | if (res == PAR_FOUND) { |
||
433 | #ifdef PARSER_DEBUG |
||
434 | cprintf("CRITITCAL SESSION: %d (",val); |
||
435 | #endif |
||
436 | ld->crit_type = val; |
||
437 | if (ld->crit_type == PAR_CRIT) { |
||
438 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
439 | if (res == PAR_FOUND) { |
||
440 | #ifdef PARSER_DEBUG |
||
441 | cprintf("[%d]",val); |
||
442 | #endif |
||
443 | ld->resource = val; |
||
444 | } else par_error(line_num); |
||
445 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
446 | if (res == PAR_FOUND) { |
||
447 | #ifdef PARSER_DEBUG |
||
448 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
449 | #endif |
||
450 | TIMESPEC_ASSIGN(&ld->crit_par_1,&time); |
||
451 | } else par_error(line_num); |
||
452 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
453 | if (res == PAR_FOUND) { |
||
454 | #ifdef PARSER_DEBUG |
||
455 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
456 | #endif |
||
457 | TIMESPEC_ASSIGN(&ld->crit_par_2,&time); |
||
458 | } else par_error(line_num); |
||
459 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
460 | if (res == PAR_FOUND) { |
||
461 | #ifdef PARSER_DEBUG |
||
462 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
463 | #endif |
||
464 | TIMESPEC_ASSIGN(&ld->crit_par_3,&time); |
||
465 | } else par_error(line_num); |
||
466 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
467 | if (res == PAR_FOUND) { |
||
468 | #ifdef PARSER_DEBUG |
||
469 | cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
470 | #endif |
||
471 | TIMESPEC_ASSIGN(&ld->crit_par_4,&time); |
||
472 | } else par_error(line_num); |
||
473 | |||
474 | } |
||
475 | |||
476 | #ifdef PARSER_DEBUG |
||
477 | cprintf(")\n"); |
||
478 | #endif |
||
479 | |||
480 | } else par_error(line_num); |
||
481 | |||
482 | return 2; |
||
483 | |||
484 | } |
||
485 |