Subversion Repositories shark

Rev

Details | 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
    if (ld->exec_type != PAR_EXEC_CONST) {
342
      res = find_break(pbuf,PAR_TIME, &time, &val);
343
      if (res == PAR_FOUND) {
344
        #ifdef PARSER_DEBUG
345
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
346
        #endif
347
        TIMESPEC_ASSIGN(&ld->exec_par_3,&time);
348
        } else par_error(line_num);
349
    }
350
 
351
    #ifdef PARSER_DEBUG
352
      printf(")\n");
353
    #endif
354
 
355
  } else par_error(line_num);
356
 
357
  res = find_break(pbuf,PAR_CRIT_SESSION, &time, &val);
358
  if (res == PAR_FOUND) {
359
    #ifdef PARSER_DEBUG
360
      printf("CRITITCAL SESSION: %d (",val);
361
    #endif
362
    ld->crit_type = val;
363
    if (ld->crit_type == PAR_CRIT) {
364
      res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
365
      if (res == PAR_FOUND) {
366
        #ifdef PARSER_DEBUG
367
          printf("[%d]",val);
368
        #endif
369
        ld->resource = val;
370
      } else par_error(line_num);
371
      res = find_break(pbuf,PAR_TIME, &time, &val);
372
      if (res == PAR_FOUND) {
373
        #ifdef PARSER_DEBUG
374
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
375
        #endif
376
        TIMESPEC_ASSIGN(&ld->crit_par_1,&time);
377
      } else par_error(line_num);
378
      res = find_break(pbuf,PAR_TIME, &time, &val);
379
      if (res == PAR_FOUND) {
380
        #ifdef PARSER_DEBUG
381
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
382
        #endif
383
        TIMESPEC_ASSIGN(&ld->crit_par_2,&time);
384
      } else par_error(line_num);
385
      res = find_break(pbuf,PAR_TIME, &time, &val);
386
      if (res == PAR_FOUND) {
387
        #ifdef PARSER_DEBUG
388
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
389
        #endif
390
        TIMESPEC_ASSIGN(&ld->crit_par_3,&time);
391
      } else par_error(line_num);
392
      res = find_break(pbuf,PAR_TIME, &time, &val);
393
      if (res == PAR_FOUND) {
394
        #ifdef PARSER_DEBUG
395
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
396
        #endif
397
        TIMESPEC_ASSIGN(&ld->crit_par_4,&time);
398
      } else par_error(line_num);
399
 
400
    }
401
 
402
    #ifdef PARSER_DEBUG
403
      printf(")\n");
404
    #endif
405
 
406
  } else par_error(line_num);
407
 
408
  return 2;
409
 
410
}
411
 
412
int line_parser_contract(char **pbuf, int line_num, struct timespec *total, struct loader_contract **last)
413
{
414
 
415
  struct timespec time;
416
  struct loader_contract *lc = NULL;
417
  int val, res;
418
 
419
  res = find_break(pbuf, PAR_NOTHING, &time, &val);
420
  if (res == PAR_FOUND) return 0;
421
  if (res == PAR_END) return 3;
422
 
423
  res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val);
424
  if (res == PAR_FOUND) {
425
    NULL_TIMESPEC(total);
426
    res = find_break(pbuf, PAR_TIME, &time, &val);
427
    if (res == PAR_FOUND) {
428
      TIMESPEC_ASSIGN(total,&time);
429
      #ifdef PARSER_DEBUG
430
        printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec);
431
      #endif
432
      return 1;
433
    } else par_error(line_num);
434
  }
435
 
436
  res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
437
  if (res == PAR_FOUND) {
438
    #ifdef PARSER_DEBUG
439
      printf("CONTRACT [%d]",val);
440
    #endif
441
 
442
    lc = malloc(sizeof(struct loader_contract));
443
    if (lc == NULL) par_error(line_num);
444
 
445
    lc->next = NULL;
446
    *last = lc;
447
 
448
    lc->number = val;
449
  } else par_error(line_num);
450
 
451
  res = find_break(pbuf,PAR_TIME, &time, &val);
452
  if (res == PAR_FOUND) {
453
    #ifdef PARSER_DEBUG
454
      printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
455
    #endif
456
    TIMESPEC_ASSIGN(&lc->cmin,&time);
457
  } else par_error(line_num);
458
 
459
  res = find_break(pbuf,PAR_TIME, &time, &val);
460
  if (res == PAR_FOUND) {
461
    #ifdef PARSER_DEBUG
462
      printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
463
    #endif
464
    TIMESPEC_ASSIGN(&lc->tmax,&time);
465
  } else par_error(line_num);
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->cmax,&time);
473
  } else par_error(line_num);
474
 
475
  res = find_break(pbuf,PAR_TIME, &time, &val);
476
  if (res == PAR_FOUND) {
477
    #ifdef PARSER_DEBUG
478
      printf(",[%ld][%ld],",time.tv_sec,time.tv_nsec/1000);
479
    #endif
480
    TIMESPEC_ASSIGN(&lc->tmin,&time);
481
  } else par_error(line_num);
482
 
483
  res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
484
  if (res == PAR_FOUND) {
485
    #ifdef PARSER_DEBUG
486
      printf(",[%d]\n",val);
487
    #endif
488
 
489
    lc->workload = val;
490
  } else par_error(line_num);
491
 
492
  res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val);
493
  if (res == PAR_FOUND) {
494
    #ifdef PARSER_DEBUG
495
      printf("LOCAL SCHEDULER = %d\n",val);
496
    #endif
497
 
498
    lc->local_scheduler = val;
499
  } else par_error(line_num);
500
 
501
  return 2;
502
 
503
}