Subversion Repositories shark

Rev

Rev 1208 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1200 giacomo 1
#include <kernel/kern.h>
1199 giacomo 2
#include <stdlib.h>
3
#include <string.h>
4
#include <stdio.h>
5
#include "parser.h"
6
 
1207 giacomo 7
//#define PARSER_DEBUG
1199 giacomo 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;
1206 giacomo 16
  while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':' ||
17
         ((char *)(*buf))[i] == '\n' || ((char *)(*buf))[i] == '\r') i++;
1199 giacomo 18
  *buf += i;
1206 giacomo 19
 
20
  if (!strncmp(*buf,"END",3) && find_type == PAR_NOTHING) {
21
    *buf += 5;
22
    return PAR_END;
23
  }
1199 giacomo 24
 
1206 giacomo 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
 
1199 giacomo 32
  switch (find_type) {
1200 giacomo 33
 
34
    case PAR_NOTHING:
1206 giacomo 35
      if (((char *)(*buf))[0] == ';' ||
36
          ((char *)(*buf))[0] < 32) {
37
            *buf += 1;
38
            return PAR_FOUND;
39
          }
40
      break;
1199 giacomo 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
      }
1208 giacomo 91
      if (!strncmp(*buf, "BACK:",5)) {
92
        *val = PAR_TASK_BACK;
93
        *buf += 5;
94
        return PAR_FOUND;
95
      }
1209 giacomo 96
      if (!strncmp(*buf, "FSF:",4)) {
97
        *val = PAR_TASK_FSF;
98
        *buf += 4;
99
        return PAR_FOUND;
100
      }
1199 giacomo 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;
1209 giacomo 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;
1199 giacomo 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
      }
1203 giacomo 153
      if (!strncmp(*buf,"ACT_GAUSS(",10)) {
154
        *buf += 10;
155
        *val = PAR_ACT_GAUSS;
1199 giacomo 156
        return PAR_FOUND;;
157
      }
1203 giacomo 158
      if (!strncmp(*buf,"ACT_GAUSS_MAX(",14)) {
159
        *buf += 14;
160
        *val = PAR_ACT_GAUSS_MAX;
1199 giacomo 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
     }
1203 giacomo 177
     if (!strncmp(*buf,"EXEC_GAUSS(",11)) {
178
       *buf += 11;
179
       *val = PAR_EXEC_GAUSS;
1199 giacomo 180
       return PAR_FOUND;
181
     }
1203 giacomo 182
     if (!strncmp(*buf,"EXEC_GAUSS_MAX(",15)) {
183
       *buf += 15;
184
       *val = PAR_EXEC_GAUSS_MAX;
1199 giacomo 185
       return PAR_FOUND;
186
     }
187
     return PAR_ERROR;
188
     break;
189
 
1206 giacomo 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
 
1209 giacomo 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
 
1199 giacomo 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);
1200 giacomo 231
  sys_end();
1199 giacomo 232
 
233
}
234
 
1200 giacomo 235
/* result:
236
 * 0 -> nothing
237
 * 1 -> total
238
 * 2 -> new task-loader
1206 giacomo 239
 * 3 -> end file
1200 giacomo 240
 */
1206 giacomo 241
int line_parser(char **pbuf, int line_num, struct timespec *total, struct loader_task **last)
1199 giacomo 242
{
1200 giacomo 243
  struct timespec time;
244
  struct loader_task *ld = NULL;
1199 giacomo 245
  int val, res;
246
 
1206 giacomo 247
  res = find_break(pbuf, PAR_NOTHING, &time, &val);
1200 giacomo 248
  if (res == PAR_FOUND) return 0;
1206 giacomo 249
  if (res == PAR_END) return 3;
1200 giacomo 250
 
1206 giacomo 251
  res = find_break(pbuf,PAR_TOTAL_EXEC_TIME, &time, &val);
1199 giacomo 252
  if (res == PAR_FOUND) {
1200 giacomo 253
    NULL_TIMESPEC(total);
1206 giacomo 254
    res = find_break(pbuf, PAR_TIME, &time, &val);
1199 giacomo 255
    if (res == PAR_FOUND) {
1200 giacomo 256
      TIMESPEC_ASSIGN(total,&time);
1199 giacomo 257
      #ifdef PARSER_DEBUG
1200 giacomo 258
        cprintf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total->tv_sec,total->tv_nsec);
1199 giacomo 259
      #endif
1200 giacomo 260
      return 1;
261
    } else par_error(line_num);
1199 giacomo 262
  }
263
 
1206 giacomo 264
  res = find_break(pbuf,PAR_TASK_TYPE, &time, &val);
1199 giacomo 265
  if (res == PAR_FOUND) {
266
    #ifdef PARSER_DEBUG
267
      cprintf("TASK TYPE = %d\n",val);
268
    #endif
269
 
1200 giacomo 270
    ld = malloc(sizeof(struct loader_task));
271
    if (ld == NULL) par_error(line_num);
272
 
273
    ld->next = NULL;
1201 giacomo 274
    *last = ld;
1200 giacomo 275
 
276
    ld->task_type = val;
277
 
278
  } else par_error(line_num);
279
 
1209 giacomo 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);
1199 giacomo 289
 
1209 giacomo 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
1200 giacomo 305
 
1209 giacomo 306
      ld->task_level = val;
1200 giacomo 307
 
1209 giacomo 308
    } else par_error(line_num);
309
  }
310
 
1206 giacomo 311
  res = find_break(pbuf,PAR_TASK_NUMBER, &time, &val);
1199 giacomo 312
  if (res == PAR_FOUND) {
313
    #ifdef PARSER_DEBUG
314
      cprintf("TASK NUMBER = %d\n",val);
315
    #endif
316
 
1200 giacomo 317
    ld->number = val;
318
 
319
  } else par_error(line_num);
320
 
1206 giacomo 321
  res = find_break(pbuf,PAR_ACT_TYPE, &time, &val);
1199 giacomo 322
  if (res == PAR_FOUND) {
323
    #ifdef PARSER_DEBUG
324
      cprintf("ACTIVATION TYPE: %d (",val);
325
    #endif
1200 giacomo 326
 
327
    ld->act_type = val;
1199 giacomo 328
 
1206 giacomo 329
    res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 330
    if (res == PAR_FOUND) {
331
      #ifdef PARSER_DEBUG
332
        cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
333
      #endif
1200 giacomo 334
      TIMESPEC_ASSIGN(&ld->act_par_1,&time);
335
    } else par_error(line_num);
1199 giacomo 336
 
1200 giacomo 337
    if (ld->act_type != PAR_ACT_SINGLE) {
1206 giacomo 338
      res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 339
      if (res == PAR_FOUND) {
340
        #ifdef PARSER_DEBUG
341
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
342
        #endif
1200 giacomo 343
        TIMESPEC_ASSIGN(&ld->act_par_2,&time);
344
        } else par_error(line_num);
1199 giacomo 345
    }
346
 
1200 giacomo 347
    if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC) {
1206 giacomo 348
      res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 349
      if (res == PAR_FOUND) {
350
        #ifdef PARSER_DEBUG
351
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
352
        #endif
1200 giacomo 353
        TIMESPEC_ASSIGN(&ld->act_par_3,&time);
354
        } else par_error(line_num);
1199 giacomo 355
    }
356
 
1200 giacomo 357
    if (ld->act_type != PAR_ACT_SINGLE && ld->act_type != PAR_ACT_PERIODIC &&
1203 giacomo 358
        ld->act_type != PAR_ACT_MEAN && ld->act_type != PAR_ACT_GAUSS) {
1206 giacomo 359
      res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 360
      if (res == PAR_FOUND) {
361
        #ifdef PARSER_DEBUG
362
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
363
        #endif
1200 giacomo 364
        TIMESPEC_ASSIGN(&ld->act_par_4,&time);
365
        } else par_error(line_num);
1199 giacomo 366
    }
367
 
368
    #ifdef PARSER_DEBUG
369
      cprintf(")\n");
370
    #endif
371
 
1200 giacomo 372
  } else par_error(line_num);
1199 giacomo 373
 
1206 giacomo 374
  res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 375
  if (res == PAR_FOUND) {
376
    #ifdef PARSER_DEBUG
1203 giacomo 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
 
1206 giacomo 382
  res = find_break(pbuf,PAR_TIME, &time, &val);
1203 giacomo 383
  if (res == PAR_FOUND) {
384
    #ifdef PARSER_DEBUG
1199 giacomo 385
      cprintf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
386
    #endif
1200 giacomo 387
    TIMESPEC_ASSIGN(&ld->wcet,&time);
388
  } else par_error(line_num);
1199 giacomo 389
 
1206 giacomo 390
  res = find_break(pbuf,PAR_EXEC_TYPE, &time, &val);
1199 giacomo 391
  if (res == PAR_FOUND) {
392
    #ifdef PARSER_DEBUG
393
      cprintf("EXEC TYPE: %d (",val);
394
    #endif
1200 giacomo 395
    ld->exec_type = val;
1206 giacomo 396
    res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 397
    if (res == PAR_FOUND) {
398
      #ifdef PARSER_DEBUG
399
        cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
400
      #endif
1200 giacomo 401
      TIMESPEC_ASSIGN(&ld->exec_par_1,&time);
402
    } else par_error(line_num);
1199 giacomo 403
 
1200 giacomo 404
    if (ld->exec_type != PAR_EXEC_CONST) {
1206 giacomo 405
      res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 406
      if (res == PAR_FOUND) {
407
        #ifdef PARSER_DEBUG
408
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
409
        #endif
1200 giacomo 410
        TIMESPEC_ASSIGN(&ld->exec_par_2,&time);
411
        } else par_error(line_num);
1199 giacomo 412
    }
413
 
1200 giacomo 414
    if (ld->exec_type != PAR_EXEC_CONST && ld->exec_type != PAR_EXEC_MEAN &&
1203 giacomo 415
        ld->exec_type != PAR_EXEC_GAUSS) {
1206 giacomo 416
      res = find_break(pbuf,PAR_TIME, &time, &val);
1199 giacomo 417
      if (res == PAR_FOUND) {
418
        #ifdef PARSER_DEBUG
419
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
420
        #endif
1200 giacomo 421
        TIMESPEC_ASSIGN(&ld->exec_par_3,&time);
422
        } else par_error(line_num);
1199 giacomo 423
    }
424
 
425
    #ifdef PARSER_DEBUG
426
      cprintf(")\n");
427
    #endif
428
 
1200 giacomo 429
  } else par_error(line_num);
1199 giacomo 430
 
1206 giacomo 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
 
1200 giacomo 482
  return 2;
1199 giacomo 483
 
484
}
1200 giacomo 485