Rev 1442 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1254 | giacomo | 1 | #include <stdlib.h> |
2 | #include <string.h> |
||
3 | #include <stdio.h> |
||
4 | #include "lparser.h" |
||
5 | #include "common/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 += 3; |
||
22 | return PAR_END; |
||
23 | } |
||
24 | |||
25 | if (!strncmp(*buf,"CONTRACT SECTION",16) && find_type == PAR_NOTHING) { |
||
26 | *buf += 16; |
||
27 | return PAR_CONTRACT_SECTION; |
||
28 | } |
||
29 | |||
30 | if (!strncmp(*buf,"TASK SECTION",12) && find_type == PAR_NOTHING) { |
||
31 | *buf += 12; |
||
32 | return PAR_TASK_SECTION; |
||
33 | } |
||
34 | |||
35 | i = 0; |
||
36 | if (((char *)(*buf))[0] == '#' && find_type == PAR_NOTHING) { |
||
37 | while (((char *)(*buf))[i] != '\n' && ((char *)(*buf))[i] != '\r') i++; |
||
38 | *buf += i; |
||
39 | return PAR_FOUND; |
||
40 | } |
||
41 | |||
42 | switch (find_type) { |
||
43 | |||
44 | case PAR_NOTHING: |
||
45 | if (((char *)(*buf))[0] == ';' || |
||
46 | ((char *)(*buf))[0] < 32) { |
||
47 | *buf += 1; |
||
48 | return PAR_FOUND; |
||
49 | } |
||
50 | break; |
||
51 | |||
52 | case PAR_TOTAL_EXEC_TIME: |
||
53 | if (!strncmp(*buf, "TOTAL_EXEC_TIME:",16)) { |
||
54 | *buf += 16; |
||
55 | return PAR_FOUND; |
||
56 | } |
||
57 | break; |
||
58 | |||
59 | case PAR_TIME: |
||
60 | if (((char *)(*buf))[0] != '[') return PAR_ERROR; |
||
61 | *buf += 1; |
||
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_sec = atoi(str); |
||
70 | i += 2; |
||
71 | *buf += i; |
||
72 | i = 0; |
||
73 | while (((char *)(*buf))[i] >= '0' && ((char *)(*buf))[i] <= '9') { |
||
74 | str[i] = ((char *)(*buf))[i]; |
||
75 | i++; |
||
76 | } |
||
77 | if (((char *)(*buf))[i] != ']') return PAR_ERROR; |
||
78 | str[i] = 0; |
||
79 | time->tv_nsec = atoi(str) * 1000; |
||
80 | i += 2; |
||
81 | *buf += i; |
||
82 | return PAR_FOUND; |
||
83 | break; |
||
84 | |||
85 | case PAR_TASK_TYPE: |
||
86 | if (!strncmp(*buf, "OS:",3)) { |
||
87 | *val = PAR_TASK_OS; |
||
88 | *buf += 3; |
||
89 | return PAR_FOUND; |
||
90 | } |
||
91 | if (!strncmp(*buf, "CT:",3)) { |
||
92 | *val = PAR_TASK_CT; |
||
93 | *buf += 3; |
||
94 | return PAR_FOUND; |
||
95 | } |
||
96 | if (!strncmp(*buf, "BT:",3)) { |
||
97 | *val = PAR_TASK_BT; |
||
98 | *buf += 3; |
||
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_ACT_TYPE: |
||
120 | if (!strncmp(*buf,"ACT_SINGLE(",11)) { |
||
121 | *buf += 11; |
||
122 | *val = PAR_ACT_SINGLE; |
||
123 | return PAR_FOUND; |
||
124 | } |
||
125 | if (!strncmp(*buf,"ACT_PERIODIC(",13)) { |
||
126 | *buf += 13; |
||
127 | *val = PAR_ACT_PERIODIC; |
||
128 | return PAR_FOUND; |
||
129 | } |
||
130 | if (!strncmp(*buf,"ACT_MEAN(",9)) { |
||
131 | *buf += 9; |
||
132 | *val = PAR_ACT_MEAN; |
||
133 | return PAR_FOUND; |
||
134 | } |
||
135 | return PAR_ERROR; |
||
136 | break; |
||
137 | |||
138 | case PAR_LOCAL_SCHEDULER: |
||
139 | if (!strncmp(*buf,"POSIX",5)) { |
||
140 | *buf += 5; |
||
141 | *val = PAR_POSIX; |
||
142 | return PAR_FOUND; |
||
143 | } |
||
144 | if (!strncmp(*buf,"EDF",3)) { |
||
145 | *buf += 3; |
||
146 | *val = PAR_EDF; |
||
147 | return PAR_FOUND; |
||
148 | } |
||
149 | if (!strncmp(*buf,"RM",2)) { |
||
150 | *buf += 2; |
||
151 | *val = PAR_RM; |
||
152 | return PAR_FOUND; |
||
153 | } |
||
1540 | trimarchi | 154 | |
155 | if (!strncmp(*buf,"NONE",2)) { |
||
156 | *buf += 4; |
||
157 | *val = PAR_NONE; |
||
158 | return PAR_FOUND; |
||
159 | } |
||
160 | |||
1254 | giacomo | 161 | return PAR_ERROR; |
162 | break; |
||
163 | |||
164 | case PAR_EXEC_TYPE: |
||
165 | if (!strncmp(*buf,"EXEC_CONST(",11)) { |
||
166 | *buf += 11; |
||
167 | *val = PAR_EXEC_CONST; |
||
168 | return PAR_FOUND; |
||
169 | } |
||
170 | if (!strncmp(*buf,"EXEC_MEAN(",10)) { |
||
171 | *buf += 10; |
||
172 | *val = PAR_EXEC_MEAN; |
||
173 | return PAR_FOUND; |
||
174 | } |
||
175 | return PAR_ERROR; |
||
176 | break; |
||
177 | |||
178 | case PAR_CRIT_SESSION: |
||
179 | if (!strncmp(*buf,"NO_CRIT",7)) { |
||
180 | *buf += 7; |
||
181 | *val = PAR_NO_CRIT; |
||
182 | return PAR_FOUND; |
||
183 | } |
||
184 | if (!strncmp(*buf,"CRIT(",5)) { |
||
185 | *buf += 5; |
||
186 | *val = PAR_CRIT; |
||
187 | return PAR_FOUND; |
||
188 | } |
||
189 | return PAR_ERROR; |
||
190 | break; |
||
191 | |||
192 | } |
||
193 | |||
194 | return PAR_ERROR; |
||
195 | |||
196 | } |
||
197 | |||
198 | void par_error(int line_num) |
||
199 | { |
||
200 | |||
201 | printf("\nParser error: line [%d]\n",line_num); |
||
202 | exit(1); |
||
203 | |||
204 | } |
||
205 | |||
206 | /* result: |
||
207 | * 0 -> nothing |
||
208 | * 1 -> total |
||
209 | * 2 -> new task-loader |
||
210 | * 3 -> end file |
||
211 | */ |
||
212 | int line_parser_task(char **pbuf, int line_num, struct loader_task **last) |
||
213 | { |
||
214 | struct timespec time; |
||
215 | struct loader_task *ld = NULL; |
||
216 | int val, res; |
||
217 | |||
218 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
219 | if (res == PAR_FOUND) return 0; |
||
220 | if (res == PAR_END) return 3; |
||
221 | |||
222 | res = find_break(pbuf,PAR_TASK_TYPE, &time, &val); |
||
223 | if (res == PAR_FOUND) { |
||
224 | #ifdef PARSER_DEBUG |
||
225 | printf("TASK TYPE = %d\n",val); |
||
226 | #endif |
||
227 | |||
228 | ld = malloc(sizeof(struct loader_task)); |
||
229 | if (ld == NULL) par_error(line_num); |
||
230 | |||
231 | ld->next = NULL; |
||
232 | *last = ld; |
||
233 | |||
234 | ld->task_type = val; |
||
235 | |||
236 | } else par_error(line_num); |
||
237 | |||
238 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
239 | if (res == PAR_FOUND) { |
||
240 | #ifdef PARSER_DEBUG |
||
241 | printf("TASK SERVER = %d\n",val); |
||
242 | #endif |
||
243 | |||
244 | ld->server = val; |
||
245 | } else par_error(line_num); |
||
246 | |||
247 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
248 | if (res == PAR_FOUND) { |
||
249 | #ifdef PARSER_DEBUG |
||
250 | printf("TASK LOCAL SCHEDULER = %d\n",val); |
||
251 | #endif |
||
252 | |||
253 | ld->local_scheduler = val; |
||
254 | } else par_error(line_num); |
||
255 | |||
256 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
257 | if (res == PAR_FOUND) { |
||
258 | #ifdef PARSER_DEBUG |
||
259 | printf("TASK NUMBER = %d\n",val); |
||
260 | #endif |
||
261 | |||
262 | ld->number = val; |
||
263 | |||
264 | } else par_error(line_num); |
||
265 | |||
266 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
267 | if (res == PAR_FOUND) { |
||
268 | #ifdef PARSER_DEBUG |
||
269 | printf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
270 | #endif |
||
271 | TIMESPEC_ASSIGN(&ld->deadline,&time); |
||
272 | } else par_error(line_num); |
||
273 | |||
274 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
275 | if (res == PAR_FOUND) { |
||
276 | #ifdef PARSER_DEBUG |
||
277 | printf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
278 | #endif |
||
279 | TIMESPEC_ASSIGN(&ld->wcet,&time); |
||
280 | } else par_error(line_num); |
||
281 | |||
282 | res = find_break(pbuf,PAR_ACT_TYPE, &time, &val); |
||
283 | if (res == PAR_FOUND) { |
||
284 | #ifdef PARSER_DEBUG |
||
285 | printf("ACTIVATION TYPE: %d (",val); |
||
286 | #endif |
||
287 | |||
288 | ld->act_type = val; |
||
289 | |||
290 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
291 | if (res == PAR_FOUND) { |
||
292 | #ifdef PARSER_DEBUG |
||
293 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
294 | #endif |
||
295 | TIMESPEC_ASSIGN(&ld->act_par_1,&time); |
||
296 | } else par_error(line_num); |
||
297 | |||
298 | if (ld->act_type != PAR_ACT_SINGLE) { |
||
299 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
300 | if (res == PAR_FOUND) { |
||
301 | #ifdef PARSER_DEBUG |
||
302 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
303 | #endif |
||
304 | TIMESPEC_ASSIGN(&ld->act_par_2,&time); |
||
305 | } else par_error(line_num); |
||
306 | } |
||
307 | |||
308 | if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) { |
||
309 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
310 | if (res == PAR_FOUND) { |
||
311 | #ifdef PARSER_DEBUG |
||
312 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
313 | #endif |
||
314 | TIMESPEC_ASSIGN(&ld->act_par_3,&time); |
||
315 | } else par_error(line_num); |
||
316 | } |
||
317 | |||
318 | #ifdef PARSER_DEBUG |
||
319 | printf(")\n"); |
||
320 | #endif |
||
321 | |||
322 | } else par_error(line_num); |
||
323 | |||
324 | res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val); |
||
325 | if (res == PAR_FOUND) { |
||
326 | #ifdef PARSER_DEBUG |
||
327 | printf("EXEC TYPE: %d (",val); |
||
328 | #endif |
||
329 | ld->exec_type = val; |
||
330 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
331 | if (res == PAR_FOUND) { |
||
332 | #ifdef PARSER_DEBUG |
||
333 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
334 | #endif |
||
335 | TIMESPEC_ASSIGN(&ld->exec_par_1,&time); |
||
336 | } else par_error(line_num); |
||
337 | |||
338 | if (ld->exec_type != PAR_EXEC_CONST) { |
||
339 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
340 | if (res == PAR_FOUND) { |
||
341 | #ifdef PARSER_DEBUG |
||
342 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
343 | #endif |
||
344 | TIMESPEC_ASSIGN(&ld->exec_par_2,&time); |
||
345 | } else par_error(line_num); |
||
346 | } |
||
347 | |||
348 | #ifdef PARSER_DEBUG |
||
349 | printf(")\n"); |
||
350 | #endif |
||
351 | |||
352 | } else par_error(line_num); |
||
353 | |||
354 | res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val); |
||
355 | if (res == PAR_FOUND) { |
||
356 | #ifdef PARSER_DEBUG |
||
357 | printf("CRITITCAL SESSION: %d (",val); |
||
358 | #endif |
||
359 | ld->crit_type = val; |
||
360 | if (ld->crit_type == PAR_CRIT) { |
||
361 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
362 | if (res == PAR_FOUND) { |
||
363 | #ifdef PARSER_DEBUG |
||
364 | printf("[%d]",val); |
||
365 | #endif |
||
366 | ld->resource = val; |
||
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 |
||
1304 | giacomo | 373 | TIMESPEC_ASSIGN(&ld->crit_par,&time); |
1254 | giacomo | 374 | } else par_error(line_num); |
375 | } |
||
376 | |||
377 | #ifdef PARSER_DEBUG |
||
378 | printf(")\n"); |
||
379 | #endif |
||
380 | |||
381 | } else par_error(line_num); |
||
382 | |||
383 | return 2; |
||
384 | |||
385 | } |
||
386 | |||
387 | int line_parser_contract(char **pbuf, int line_num, struct timespec *total, struct loader_contract **last) |
||
388 | { |
||
389 | |||
390 | struct timespec time; |
||
391 | struct loader_contract *lc = NULL; |
||
392 | int val, res; |
||
393 | |||
394 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
395 | if (res == PAR_FOUND) return 0; |
||
396 | if (res == PAR_END) return 3; |
||
397 | |||
398 | res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
||
399 | if (res == PAR_FOUND) { |
||
400 | NULL_TIMESPEC(total); |
||
401 | res = find_break(pbuf, PAR_TIME, &time, &val); |
||
402 | if (res == PAR_FOUND) { |
||
403 | TIMESPEC_ASSIGN(total,&time); |
||
404 | #ifdef PARSER_DEBUG |
||
405 | printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec); |
||
406 | #endif |
||
407 | return 1; |
||
408 | } else par_error(line_num); |
||
409 | } |
||
410 | |||
411 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
412 | if (res == PAR_FOUND) { |
||
413 | #ifdef PARSER_DEBUG |
||
414 | printf("CONTRACT [%d]",val); |
||
415 | #endif |
||
416 | |||
417 | lc = malloc(sizeof(struct loader_contract)); |
||
418 | if (lc == NULL) par_error(line_num); |
||
419 | |||
420 | lc->next = NULL; |
||
421 | *last = lc; |
||
422 | |||
423 | lc->number = val; |
||
424 | } else par_error(line_num); |
||
425 | |||
426 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
427 | if (res == PAR_FOUND) { |
||
428 | #ifdef PARSER_DEBUG |
||
429 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
430 | #endif |
||
431 | TIMESPEC_ASSIGN(&lc->cmin,&time); |
||
432 | } else par_error(line_num); |
||
433 | |||
434 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
435 | if (res == PAR_FOUND) { |
||
436 | #ifdef PARSER_DEBUG |
||
437 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
438 | #endif |
||
439 | TIMESPEC_ASSIGN(&lc->tmax,&time); |
||
440 | } else par_error(line_num); |
||
441 | |||
442 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
443 | if (res == PAR_FOUND) { |
||
444 | #ifdef PARSER_DEBUG |
||
445 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
446 | #endif |
||
447 | TIMESPEC_ASSIGN(&lc->cmax,&time); |
||
448 | } else par_error(line_num); |
||
449 | |||
450 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
451 | if (res == PAR_FOUND) { |
||
452 | #ifdef PARSER_DEBUG |
||
453 | printf(",[%ld][%ld],",time.tv_sec,time.tv_nsec/1000); |
||
454 | #endif |
||
455 | TIMESPEC_ASSIGN(&lc->tmin,&time); |
||
456 | } else par_error(line_num); |
||
457 | |||
458 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
459 | if (res == PAR_FOUND) { |
||
460 | #ifdef PARSER_DEBUG |
||
461 | printf(",[%d]\n",val); |
||
462 | #endif |
||
463 | |||
464 | lc->workload = val; |
||
465 | } else par_error(line_num); |
||
1442 | giacomo | 466 | |
467 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
468 | if (res == PAR_FOUND) { |
||
469 | #ifdef PARSER_DEBUG |
||
470 | printf(",[%ld][%ld],",time.tv_sec,time.tv_nsec/1000); |
||
471 | #endif |
||
472 | TIMESPEC_ASSIGN(&lc->deadline,&time); |
||
473 | } else par_error(line_num); |
||
1254 | giacomo | 474 | |
475 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
476 | if (res == PAR_FOUND) { |
||
477 | #ifdef PARSER_DEBUG |
||
478 | printf("LOCAL SCHEDULER = %d\n",val); |
||
479 | #endif |
||
480 | |||
481 | lc->local_scheduler = val; |
||
482 | } else par_error(line_num); |
||
483 | |||
484 | return 2; |
||
485 | |||
486 | } |