Subversion Repositories shark

Rev

Rev 1254 | 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
366
        TIMESPEC_ASSIGN(&ld->crit_par_1,&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_2,&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_3,&time);
381
      } else par_error(line_num);
382
      res = find_break(pbuf,PAR_TIME, &time, &val);
383
      if (res == PAR_FOUND) {
384
        #ifdef PARSER_DEBUG
385
          printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
386
        #endif
387
        TIMESPEC_ASSIGN(&ld->crit_par_4,&time);
388
      } else par_error(line_num);
389
 
390
    }
391
 
392
    #ifdef PARSER_DEBUG
393
      printf(")\n");
394
    #endif
395
 
396
  } else par_error(line_num);
397
 
398
  return 2;
399
 
400
}
401
 
402
int line_parser_contract(char **pbuf, int line_num, struct timespec *total, struct loader_contract **last)
403
{
404
 
405
  struct timespec time;
406
  struct loader_contract *lc = NULL;
407
  int val, res;
408
 
409
  res = find_break(pbuf, PAR_NOTHING, &time, &val);
410
  if (res == PAR_FOUND) return 0;
411
  if (res == PAR_END) return 3;
412
 
413
  res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val);
414
  if (res == PAR_FOUND) {
415
    NULL_TIMESPEC(total);
416
    res = find_break(pbuf, PAR_TIME, &time, &val);
417
    if (res == PAR_FOUND) {
418
      TIMESPEC_ASSIGN(total,&time);
419
      #ifdef PARSER_DEBUG
420
        printf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec);
421
      #endif
422
      return 1;
423
    } else par_error(line_num);
424
  }
425
 
426
  res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
427
  if (res == PAR_FOUND) {
428
    #ifdef PARSER_DEBUG
429
      printf("CONTRACT [%d]",val);
430
    #endif
431
 
432
    lc = malloc(sizeof(struct loader_contract));
433
    if (lc == NULL) par_error(line_num);
434
 
435
    lc->next = NULL;
436
    *last = lc;
437
 
438
    lc->number = val;
439
  } else par_error(line_num);
440
 
441
  res = find_break(pbuf,PAR_TIME, &time, &val);
442
  if (res == PAR_FOUND) {
443
    #ifdef PARSER_DEBUG
444
      printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
445
    #endif
446
    TIMESPEC_ASSIGN(&lc->cmin,&time);
447
  } else par_error(line_num);
448
 
449
  res = find_break(pbuf,PAR_TIME, &time, &val);
450
  if (res == PAR_FOUND) {
451
    #ifdef PARSER_DEBUG
452
      printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
453
    #endif
454
    TIMESPEC_ASSIGN(&lc->tmax,&time);
455
  } else par_error(line_num);
456
 
457
  res = find_break(pbuf,PAR_TIME, &time, &val);
458
  if (res == PAR_FOUND) {
459
    #ifdef PARSER_DEBUG
460
      printf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
461
    #endif
462
    TIMESPEC_ASSIGN(&lc->cmax,&time);
463
  } else par_error(line_num);
464
 
465
  res = find_break(pbuf,PAR_TIME, &time, &val);
466
  if (res == PAR_FOUND) {
467
    #ifdef PARSER_DEBUG
468
      printf(",[%ld][%ld],",time.tv_sec,time.tv_nsec/1000);
469
    #endif
470
    TIMESPEC_ASSIGN(&lc->tmin,&time);
471
  } else par_error(line_num);
472
 
473
  res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
474
  if (res == PAR_FOUND) {
475
    #ifdef PARSER_DEBUG
476
      printf(",[%d]\n",val);
477
    #endif
478
 
479
    lc->workload = val;
480
  } else par_error(line_num);
481
 
482
  res = find_break(pbuf,PAR_LOCAL_SCHEDULER, &time, &val);
483
  if (res == PAR_FOUND) {
484
    #ifdef PARSER_DEBUG
485
      printf("LOCAL SCHEDULER = %d\n",val);
486
    #endif
487
 
488
    lc->local_scheduler = val;
489
  } else par_error(line_num);
490
 
491
  return 2;
492
 
493
}