Rev 1258 | Go to most recent revision | 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 | } |
||
154 | return PAR_ERROR; |
||
155 | break; |
||
156 | |||
157 | case PAR_EXEC_TYPE: |
||
158 | if (!strncmp(*buf,"EXEC_CONST(",11)) { |
||
159 | *buf += 11; |
||
160 | *val = PAR_EXEC_CONST; |
||
161 | return PAR_FOUND; |
||
162 | } |
||
163 | if (!strncmp(*buf,"EXEC_MEAN(",10)) { |
||
164 | *buf += 10; |
||
165 | *val = PAR_EXEC_MEAN; |
||
166 | return PAR_FOUND; |
||
167 | } |
||
168 | return PAR_ERROR; |
||
169 | break; |
||
170 | |||
171 | case PAR_CRIT_SESSION: |
||
172 | if (!strncmp(*buf,"NO_CRIT",7)) { |
||
173 | *buf += 7; |
||
174 | *val = PAR_NO_CRIT; |
||
175 | return PAR_FOUND; |
||
176 | } |
||
177 | if (!strncmp(*buf,"CRIT(",5)) { |
||
178 | *buf += 5; |
||
179 | *val = PAR_CRIT; |
||
180 | return PAR_FOUND; |
||
181 | } |
||
182 | return PAR_ERROR; |
||
183 | break; |
||
184 | |||
185 | } |
||
186 | |||
187 | return PAR_ERROR; |
||
188 | |||
189 | } |
||
190 | |||
191 | void par_error(int line_num) |
||
192 | { |
||
193 | |||
194 | printf("\nParser error: line [%d]\n",line_num); |
||
195 | exit(1); |
||
196 | |||
197 | } |
||
198 | |||
199 | /* result: |
||
200 | * 0 -> nothing |
||
201 | * 1 -> total |
||
202 | * 2 -> new task-loader |
||
203 | * 3 -> end file |
||
204 | */ |
||
205 | int line_parser_task(char **pbuf, int line_num, struct loader_task **last) |
||
206 | { |
||
207 | struct timespec time; |
||
208 | struct loader_task *ld = NULL; |
||
209 | int val, res; |
||
210 | |||
211 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
212 | if (res == PAR_FOUND) return 0; |
||
213 | if (res == PAR_END) return 3; |
||
214 | |||
215 | res = find_break(pbuf,PAR_TASK_TYPE, &time, &val); |
||
216 | if (res == PAR_FOUND) { |
||
217 | #ifdef PARSER_DEBUG |
||
218 | printf("TASK TYPE = %d\n",val); |
||
219 | #endif |
||
220 | |||
221 | ld = malloc(sizeof(struct loader_task)); |
||
222 | if (ld == NULL) par_error(line_num); |
||
223 | |||
224 | ld->next = NULL; |
||
225 | *last = ld; |
||
226 | |||
227 | ld->task_type = val; |
||
228 | |||
229 | } else par_error(line_num); |
||
230 | |||
231 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
232 | if (res == PAR_FOUND) { |
||
233 | #ifdef PARSER_DEBUG |
||
234 | printf("TASK SERVER = %d\n",val); |
||
235 | #endif |
||
236 | |||
237 | ld->server = val; |
||
238 | } else par_error(line_num); |
||
239 | |||
240 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
241 | if (res == PAR_FOUND) { |
||
242 | #ifdef PARSER_DEBUG |
||
243 | printf("TASK LOCAL SCHEDULER = %d\n",val); |
||
244 | #endif |
||
245 | |||
246 | ld->local_scheduler = val; |
||
247 | } else par_error(line_num); |
||
248 | |||
249 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
250 | if (res == PAR_FOUND) { |
||
251 | #ifdef PARSER_DEBUG |
||
252 | printf("TASK NUMBER = %d\n",val); |
||
253 | #endif |
||
254 | |||
255 | ld->number = val; |
||
256 | |||
257 | } else par_error(line_num); |
||
258 | |||
259 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
260 | if (res == PAR_FOUND) { |
||
261 | #ifdef PARSER_DEBUG |
||
262 | printf("DEADLINE: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
263 | #endif |
||
264 | TIMESPEC_ASSIGN(&ld->deadline,&time); |
||
265 | } else par_error(line_num); |
||
266 | |||
267 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
268 | if (res == PAR_FOUND) { |
||
269 | #ifdef PARSER_DEBUG |
||
270 | printf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000); |
||
271 | #endif |
||
272 | TIMESPEC_ASSIGN(&ld->wcet,&time); |
||
273 | } else par_error(line_num); |
||
274 | |||
275 | res = find_break(pbuf,PAR_ACT_TYPE, &time, &val); |
||
276 | if (res == PAR_FOUND) { |
||
277 | #ifdef PARSER_DEBUG |
||
278 | printf("ACTIVATION TYPE: %d (",val); |
||
279 | #endif |
||
280 | |||
281 | ld->act_type = val; |
||
282 | |||
283 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
284 | if (res == PAR_FOUND) { |
||
285 | #ifdef PARSER_DEBUG |
||
286 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
287 | #endif |
||
288 | TIMESPEC_ASSIGN(&ld->act_par_1,&time); |
||
289 | } else par_error(line_num); |
||
290 | |||
291 | if (ld->act_type != PAR_ACT_SINGLE) { |
||
292 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
293 | if (res == PAR_FOUND) { |
||
294 | #ifdef PARSER_DEBUG |
||
295 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
296 | #endif |
||
297 | TIMESPEC_ASSIGN(&ld->act_par_2,&time); |
||
298 | } else par_error(line_num); |
||
299 | } |
||
300 | |||
301 | if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) { |
||
302 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
303 | if (res == PAR_FOUND) { |
||
304 | #ifdef PARSER_DEBUG |
||
305 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
306 | #endif |
||
307 | TIMESPEC_ASSIGN(&ld->act_par_3,&time); |
||
308 | } else par_error(line_num); |
||
309 | } |
||
310 | |||
311 | #ifdef PARSER_DEBUG |
||
312 | printf(")\n"); |
||
313 | #endif |
||
314 | |||
315 | } else par_error(line_num); |
||
316 | |||
317 | res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val); |
||
318 | if (res == PAR_FOUND) { |
||
319 | #ifdef PARSER_DEBUG |
||
320 | printf("EXEC TYPE: %d (",val); |
||
321 | #endif |
||
322 | ld->exec_type = val; |
||
323 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
324 | if (res == PAR_FOUND) { |
||
325 | #ifdef PARSER_DEBUG |
||
326 | printf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
327 | #endif |
||
328 | TIMESPEC_ASSIGN(&ld->exec_par_1,&time); |
||
329 | } else par_error(line_num); |
||
330 | |||
331 | if (ld->exec_type != PAR_EXEC_CONST) { |
||
332 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
333 | if (res == PAR_FOUND) { |
||
334 | #ifdef PARSER_DEBUG |
||
335 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
336 | #endif |
||
337 | TIMESPEC_ASSIGN(&ld->exec_par_2,&time); |
||
338 | } else par_error(line_num); |
||
339 | } |
||
340 | |||
341 | #ifdef PARSER_DEBUG |
||
342 | printf(")\n"); |
||
343 | #endif |
||
344 | |||
345 | } else par_error(line_num); |
||
346 | |||
347 | res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val); |
||
348 | if (res == PAR_FOUND) { |
||
349 | #ifdef PARSER_DEBUG |
||
350 | printf("CRITITCAL SESSION: %d (",val); |
||
351 | #endif |
||
352 | ld->crit_type = val; |
||
353 | if (ld->crit_type == PAR_CRIT) { |
||
354 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
355 | if (res == PAR_FOUND) { |
||
356 | #ifdef PARSER_DEBUG |
||
357 | printf("[%d]",val); |
||
358 | #endif |
||
359 | ld->resource = val; |
||
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 |
||
1304 | giacomo | 366 | TIMESPEC_ASSIGN(&ld->crit_par,&time); |
1254 | giacomo | 367 | } else par_error(line_num); |
368 | } |
||
369 | |||
370 | #ifdef PARSER_DEBUG |
||
371 | printf(")\n"); |
||
372 | #endif |
||
373 | |||
374 | } else par_error(line_num); |
||
375 | |||
376 | return 2; |
||
377 | |||
378 | } |
||
379 | |||
380 | int line_parser_contract(char **pbuf, int line_num, struct timespec *total, struct loader_contract **last) |
||
381 | { |
||
382 | |||
383 | struct timespec time; |
||
384 | struct loader_contract *lc = NULL; |
||
385 | int val, res; |
||
386 | |||
387 | res = find_break(pbuf, PAR_NOTHING, &time, &val); |
||
388 | if (res == PAR_FOUND) return 0; |
||
389 | if (res == PAR_END) return 3; |
||
390 | |||
391 | res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val); |
||
392 | if (res == PAR_FOUND) { |
||
393 | NULL_TIMESPEC(total); |
||
394 | res = find_break(pbuf, PAR_TIME, &time, &val); |
||
395 | if (res == PAR_FOUND) { |
||
396 | TIMESPEC_ASSIGN(total,&time); |
||
397 | #ifdef PARSER_DEBUG |
||
398 | printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec); |
||
399 | #endif |
||
400 | return 1; |
||
401 | } else par_error(line_num); |
||
402 | } |
||
403 | |||
404 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
405 | if (res == PAR_FOUND) { |
||
406 | #ifdef PARSER_DEBUG |
||
407 | printf("CONTRACT [%d]",val); |
||
408 | #endif |
||
409 | |||
410 | lc = malloc(sizeof(struct loader_contract)); |
||
411 | if (lc == NULL) par_error(line_num); |
||
412 | |||
413 | lc->next = NULL; |
||
414 | *last = lc; |
||
415 | |||
416 | lc->number = val; |
||
417 | } else par_error(line_num); |
||
418 | |||
419 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
420 | if (res == PAR_FOUND) { |
||
421 | #ifdef PARSER_DEBUG |
||
422 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
423 | #endif |
||
424 | TIMESPEC_ASSIGN(&lc->cmin,&time); |
||
425 | } else par_error(line_num); |
||
426 | |||
427 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
428 | if (res == PAR_FOUND) { |
||
429 | #ifdef PARSER_DEBUG |
||
430 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
431 | #endif |
||
432 | TIMESPEC_ASSIGN(&lc->tmax,&time); |
||
433 | } else par_error(line_num); |
||
434 | |||
435 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
436 | if (res == PAR_FOUND) { |
||
437 | #ifdef PARSER_DEBUG |
||
438 | printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000); |
||
439 | #endif |
||
440 | TIMESPEC_ASSIGN(&lc->cmax,&time); |
||
441 | } else par_error(line_num); |
||
442 | |||
443 | res = find_break(pbuf,PAR_TIME, &time, &val); |
||
444 | if (res == PAR_FOUND) { |
||
445 | #ifdef PARSER_DEBUG |
||
446 | printf(",[%ld][%ld],",time.tv_sec,time.tv_nsec/1000); |
||
447 | #endif |
||
448 | TIMESPEC_ASSIGN(&lc->tmin,&time); |
||
449 | } else par_error(line_num); |
||
450 | |||
451 | res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val); |
||
452 | if (res == PAR_FOUND) { |
||
453 | #ifdef PARSER_DEBUG |
||
454 | printf(",[%d]\n",val); |
||
455 | #endif |
||
456 | |||
457 | lc->workload = val; |
||
458 | } else par_error(line_num); |
||
459 | |||
460 | res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val); |
||
461 | if (res == PAR_FOUND) { |
||
462 | #ifdef PARSER_DEBUG |
||
463 | printf("LOCAL SCHEDULER = %d\n",val); |
||
464 | #endif |
||
465 | |||
466 | lc->local_scheduler = val; |
||
467 | } else par_error(line_num); |
||
468 | |||
469 | return 2; |
||
470 | |||
471 | } |