Subversion Repositories shark

Rev

Rev 1200 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1199 giacomo 1
#include <stdlib.h>
2
#include <string.h>
3
#include <stdio.h>
4
#include "parser.h"
5
 
6
#define PAR_TOTAL_EXEC_TIME 0
7
#define PAR_TIME 2
8
#define PAR_ACT_TYPE 3
9
#define PAR_TASK_NUMBER 4
10
#define PAR_EXEC_TYPE 5
11
#define PAR_TASK_TYPE 6
12
#define PAR_NOTHING 8
13
#define PAR_END 9
14
#define PAR_ERROR 10
15
#define PAR_FOUND 11
16
 
17
#define PAR_EXEC_CONST 12
18
#define PAR_EXEC_MEAN 13
19
#define PAR_EXEC_EXP 14
20
#define PAR_EXEC_EXP_MAX 15
21
 
22
#define PAR_ACT_SINGLE 16
23
#define PAR_ACT_PERIODIC 17
24
#define PAR_ACT_MEAN 18
25
#define PAR_ACT_EXP 19
26
#define PAR_ACT_EXP_MAX 20
27
 
28
#define PAR_TASK_NRT 21
29
#define PAR_TASK_HARD 22
30
#define PAR_TASK_SOFT 23
31
 
32
#define PARSER_DEBUG
33
 
34
static int find_break(char **buf, int find_type, struct timespec *time, int *val)
35
{
36
 
37
  int i;
38
  char str[20];
39
 
40
  i = 0;
41
  while (((char *)(*buf))[i] == ' ' || ((char *)(*buf))[i] == ':') i++;
42
  *buf += i;
43
 
44
  if (((char *)(*buf))[0] == '#') return PAR_NOTHING;
45
 
46
  switch (find_type) {
47
 
48
    case PAR_END:
49
      if (((char *)(*buf))[0] == ';' || ((char *)(*buf))[0] == '\n') return PAR_FOUND;
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, "NRT:",4)) {
87
        *val = PAR_TASK_NRT;
88
        *buf += 4;
89
        return PAR_FOUND;
90
      }
91
      if (!strncmp(*buf, "HARD:",5)) {
92
        *val = PAR_TASK_HARD;
93
        *buf += 5;
94
        return PAR_FOUND;
95
      }
96
      if (!strncmp(*buf, "SOFT:",5)) {
97
        *val = PAR_TASK_SOFT;
98
        *buf += 5;
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
      if (!strncmp(*buf,"ACT_EXP(",8)) {
136
        *buf += 8;
137
        *val = PAR_ACT_EXP;
138
        return PAR_FOUND;;
139
      }
140
      if (!strncmp(*buf,"ACT_EXP_MAX(",12)) {
141
        *buf += 12;
142
        *val = PAR_ACT_EXP_MAX;
143
        return PAR_FOUND;
144
      }
145
      return PAR_ERROR;
146
      break;
147
 
148
   case PAR_EXEC_TYPE:
149
     if (!strncmp(*buf,"EXEC_CONST(",11)) {
150
       *buf += 11;
151
       *val = PAR_EXEC_CONST;
152
       return PAR_FOUND;
153
     }
154
     if (!strncmp(*buf,"EXEC_MEAN(",10)) {
155
       *buf += 10;
156
       *val = PAR_EXEC_MEAN;
157
       return PAR_FOUND;
158
     }
159
     if (!strncmp(*buf,"EXEC_EXP(",9)) {
160
       *buf += 9;
161
       *val = PAR_EXEC_EXP;
162
       return PAR_FOUND;
163
     }
164
     if (!strncmp(*buf,"EXEC_EXP_MAX(",13)) {
165
       *buf += 13;
166
       *val = PAR_EXEC_EXP_MAX;
167
       return PAR_FOUND;
168
     }
169
     return PAR_ERROR;
170
     break;
171
 
172
   }
173
 
174
   return PAR_ERROR;
175
 
176
}
177
 
178
void par_error(int line_num)
179
{
180
 
181
  cprintf("\nParser error: line [%d]\n",line_num);
182
 
183
}
184
 
185
int line_parser(void)
186
{
187
  char buf[1000];
188
  char *pbuf = buf;
189
  struct timespec time,total_exec_time;
190
  struct loader_task ld;
191
  int val, res;
192
 
193
  sprintf(buf,"NRT:[1]:[1]:ACT_PERIODIC([13][123],[45][456]):[0][1000]:EXEC_CONST([0][10]);\n");  
194
 
195
  res = find_break(&pbuf,PAR_TOTAL_EXEC_TIME, &time, &val);
196
  if (res == PAR_FOUND) {
197
    NULL_TIMESPEC(&total_exec_time);
198
    res = find_break(&pbuf, PAR_TIME, &time, &val);
199
    if (res == PAR_FOUND) {
200
      TIMESPEC_ASSIGN(&total_exec_time,&time);
201
      #ifdef PARSER_DEBUG
202
        cprintf("TOTAL EXEC TIME SEC = %ld NSEC = %ld\n",total_exec_time.tv_sec,total_exec_time.tv_nsec);
203
      #endif
204
      return 0;
205
    } else par_error(1);
206
  }
207
 
208
  res = find_break(&pbuf,PAR_TASK_TYPE, &time, &val);
209
  if (res == PAR_FOUND) {
210
    #ifdef PARSER_DEBUG
211
      cprintf("TASK TYPE = %d\n",val);
212
    #endif
213
    ld.task_type = val;
214
  } else par_error(1);
215
 
216
  res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val);
217
  if (res == PAR_FOUND) {
218
    #ifdef PARSER_DEBUG
219
      cprintf("TASK LEVEL = %d\n",val);
220
    #endif
221
    ld.task_level = val;
222
  } else par_error(1);
223
 
224
  res = find_break(&pbuf,PAR_TASK_NUMBER, &time, &val);
225
  if (res == PAR_FOUND) {
226
    #ifdef PARSER_DEBUG
227
      cprintf("TASK NUMBER = %d\n",val);
228
    #endif
229
    ld.number = val;
230
  } else par_error(1);
231
 
232
  res = find_break(&pbuf,PAR_ACT_TYPE, &time, &val);
233
  if (res == PAR_FOUND) {
234
    #ifdef PARSER_DEBUG
235
      cprintf("ACTIVATION TYPE: %d (",val);
236
    #endif
237
    ld.act_type = val;
238
 
239
    res = find_break(&pbuf,PAR_TIME, &time, &val);
240
    if (res == PAR_FOUND) {
241
      #ifdef PARSER_DEBUG
242
        cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
243
      #endif
244
      TIMESPEC_ASSIGN(&ld.act_par_1,&time);
245
    } else par_error(1);
246
 
247
    if (ld.act_type != PAR_ACT_SINGLE) {
248
      res = find_break(&pbuf,PAR_TIME, &time, &val);
249
      if (res == PAR_FOUND) {
250
        #ifdef PARSER_DEBUG
251
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
252
        #endif
253
        TIMESPEC_ASSIGN(&ld.act_par_2,&time);
254
        } else par_error(1);
255
    }
256
 
257
    if (ld.act_type != PAR_ACT_SINGLE && ld.act_type != PAR_ACT_PERIODIC) {
258
      res = find_break(&pbuf,PAR_TIME, &time, &val);
259
      if (res == PAR_FOUND) {
260
        #ifdef PARSER_DEBUG
261
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
262
        #endif
263
        TIMESPEC_ASSIGN(&ld.act_par_3,&time);
264
        } else par_error(1);
265
    }
266
 
267
    if (ld.act_type != PAR_ACT_SINGLE && ld.act_type != PAR_ACT_PERIODIC &&
268
        ld.act_type != PAR_ACT_MEAN && ld.act_type != PAR_ACT_EXP) {
269
      res = find_break(&pbuf,PAR_TIME, &time, &val);
270
      if (res == PAR_FOUND) {
271
        #ifdef PARSER_DEBUG
272
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
273
        #endif
274
        TIMESPEC_ASSIGN(&ld.act_par_4,&time);
275
        } else par_error(1);
276
    }
277
 
278
    #ifdef PARSER_DEBUG
279
      cprintf(")\n");
280
    #endif
281
 
282
  } else par_error(1);
283
 
284
  res = find_break(&pbuf,PAR_TIME, &time, &val);
285
  if (res == PAR_FOUND) {
286
    #ifdef PARSER_DEBUG
287
      cprintf("WCET: [%ld][%ld]\n",time.tv_sec,time.tv_nsec/1000);
288
    #endif
289
    TIMESPEC_ASSIGN(&ld.wcet,&time);
290
  } else par_error(1);
291
 
292
  res = find_break(&pbuf,PAR_EXEC_TYPE, &time, &val);
293
  if (res == PAR_FOUND) {
294
    #ifdef PARSER_DEBUG
295
      cprintf("EXEC TYPE: %d (",val);
296
    #endif
297
    ld.exec_type = val;
298
    res = find_break(&pbuf,PAR_TIME, &time, &val);
299
    if (res == PAR_FOUND) {
300
      #ifdef PARSER_DEBUG
301
        cprintf("[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
302
      #endif
303
      TIMESPEC_ASSIGN(&ld.exec_par_1,&time);
304
    } else par_error(1);
305
 
306
    if (ld.exec_type != PAR_EXEC_CONST) {
307
      res = find_break(&pbuf,PAR_TIME, &time, &val);
308
      if (res == PAR_FOUND) {
309
        #ifdef PARSER_DEBUG
310
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
311
        #endif
312
        TIMESPEC_ASSIGN(&ld.exec_par_2,&time);
313
        } else par_error(1);
314
    }
315
 
316
    if (ld.exec_type != PAR_EXEC_CONST && ld.exec_type != PAR_EXEC_MEAN &&
317
        ld.exec_type != PAR_EXEC_EXP) {
318
      res = find_break(&pbuf,PAR_TIME, &time, &val);
319
      if (res == PAR_FOUND) {
320
        #ifdef PARSER_DEBUG
321
          cprintf(",[%ld][%ld]",time.tv_sec,time.tv_nsec/1000);
322
        #endif
323
        TIMESPEC_ASSIGN(&ld.exec_par_3,&time);
324
        } else par_error(1);
325
    }
326
 
327
    #ifdef PARSER_DEBUG
328
      cprintf(")\n");
329
    #endif
330
 
331
  } else par_error(1);
332
 
333
  return 0;
334
 
335
}