1 | #! /usr/bin/perl
|
---|
2 | #
|
---|
3 | # TOPPERS Software
|
---|
4 | # Toyohashi Open Platform for Embedded Real-Time Systems
|
---|
5 | #
|
---|
6 | # Copyright (C) 2007-2014 by Embedded and Real-Time Systems Laboratory
|
---|
7 | # Graduate School of Information Science, Nagoya Univ., JAPAN
|
---|
8 | #
|
---|
9 | # ä¸è¨èä½æ¨©è
|
---|
10 | ã¯ï¼ä»¥ä¸ã®(1)ï½(4)ã®æ¡ä»¶ãæºããå ´åã«éãï¼æ¬ã½ããã¦ã§
|
---|
11 | # ã¢ï¼æ¬ã½ããã¦ã§ã¢ãæ¹å¤ãããã®ãå«ãï¼ä»¥ä¸åãï¼ã使ç¨ã»è¤è£½ã»æ¹
|
---|
12 | # å¤ã»åé
|
---|
13 | å¸ï¼ä»¥ä¸ï¼å©ç¨ã¨å¼ã¶ï¼ãããã¨ãç¡åã§è¨±è«¾ããï¼
|
---|
14 | # (1) æ¬ã½ããã¦ã§ã¢ãã½ã¼ã¹ã³ã¼ãã®å½¢ã§å©ç¨ããå ´åã«ã¯ï¼ä¸è¨ã®èä½
|
---|
15 | # 権表示ï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãï¼ãã®ã¾ã¾ã®å½¢ã§ã½ã¼
|
---|
16 | # ã¹ã³ã¼ãä¸ã«å«ã¾ãã¦ãããã¨ï¼
|
---|
17 | # (2) æ¬ã½ããã¦ã§ã¢ãï¼ã©ã¤ãã©ãªå½¢å¼ãªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
18 | # ç¨ã§ããå½¢ã§åé
|
---|
19 | å¸ããå ´åã«ã¯ï¼åé
|
---|
20 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨
|
---|
21 | # è
|
---|
22 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®èä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨
|
---|
23 | # ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
24 | # (3) æ¬ã½ããã¦ã§ã¢ãï¼æ©å¨ã«çµã¿è¾¼ããªã©ï¼ä»ã®ã½ããã¦ã§ã¢éçºã«ä½¿
|
---|
25 | # ç¨ã§ããªãå½¢ã§åé
|
---|
26 | å¸ããå ´åã«ã¯ï¼æ¬¡ã®ããããã®æ¡ä»¶ãæºããã
|
---|
27 | # ã¨ï¼
|
---|
28 | # (a) åé
|
---|
29 | å¸ã«ä¼´ãããã¥ã¡ã³ãï¼å©ç¨è
|
---|
30 | ããã¥ã¢ã«ãªã©ï¼ã«ï¼ä¸è¨ã®è
|
---|
31 | # ä½æ¨©è¡¨ç¤ºï¼ãã®å©ç¨æ¡ä»¶ããã³ä¸è¨ã®ç¡ä¿è¨¼è¦å®ãæ²è¼ãããã¨ï¼
|
---|
32 | # (b) åé
|
---|
33 | å¸ã®å½¢æ
|
---|
34 | ãï¼å¥ã«å®ããæ¹æ³ã«ãã£ã¦ï¼TOPPERSããã¸ã§ã¯ãã«
|
---|
35 | # å ±åãããã¨ï¼
|
---|
36 | # (4) æ¬ã½ããã¦ã§ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ
|
---|
37 | # 害ãããï¼ä¸è¨èä½æ¨©è
|
---|
38 | ããã³TOPPERSããã¸ã§ã¯ããå
|
---|
39 | 責ãããã¨ï¼
|
---|
40 | # ã¾ãï¼æ¬ã½ããã¦ã§ã¢ã®ã¦ã¼ã¶ã¾ãã¯ã¨ã³ãã¦ã¼ã¶ããã®ãããªãç
|
---|
41 | # ç±ã«åºã¥ãè«æ±ãããï¼ä¸è¨èä½æ¨©è
|
---|
42 | ããã³TOPPERSããã¸ã§ã¯ãã
|
---|
43 | # å
|
---|
44 | 責ãããã¨ï¼
|
---|
45 | #
|
---|
46 | # æ¬ã½ããã¦ã§ã¢ã¯ï¼ç¡ä¿è¨¼ã§æä¾ããã¦ãããã®ã§ããï¼ä¸è¨èä½æ¨©è
|
---|
47 | ã
|
---|
48 | # ãã³TOPPERSããã¸ã§ã¯ãã¯ï¼æ¬ã½ããã¦ã§ã¢ã«é¢ãã¦ï¼ç¹å®ã®ä½¿ç¨ç®ç
|
---|
49 | # ã«å¯¾ããé©åæ§ãå«ãã¦ï¼ãããªãä¿è¨¼ãè¡ããªãï¼ã¾ãï¼æ¬ã½ããã¦ã§
|
---|
50 | # ã¢ã®å©ç¨ã«ããç´æ¥çã¾ãã¯éæ¥çã«çãããããªãæ害ã«é¢ãã¦ãï¼ã
|
---|
51 | # ã®è²¬ä»»ãè² ããªãï¼
|
---|
52 | #
|
---|
53 | # $Id: gentest 2588 2014-01-02 05:07:24Z ertl-hiro $
|
---|
54 | #
|
---|
55 |
|
---|
56 | #
|
---|
57 | # ãã¹ãããã°ã©ã çæãã¼ã«
|
---|
58 | #
|
---|
59 |
|
---|
60 | use open ":encoding(euc-jp)";
|
---|
61 | use encoding "euc-jp";
|
---|
62 |
|
---|
63 | $infile = $ARGV[0];
|
---|
64 |
|
---|
65 | %parampos = (
|
---|
66 | "get_pri" => 2,
|
---|
67 | "get_inf" => 1,
|
---|
68 | "ref_tsk" => 2,
|
---|
69 | "ref_tex" => 2,
|
---|
70 | "ref_sem" => 2,
|
---|
71 | "ref_flg" => 2,
|
---|
72 | "ref_dtq" => 2,
|
---|
73 | "ref_pdq" => 2,
|
---|
74 | "ref_mbx" => 2,
|
---|
75 | "ref_mtx" => 2,
|
---|
76 | "ref_mbf" => 2,
|
---|
77 | "ref_mpf" => 2,
|
---|
78 | "get_tim" => 1,
|
---|
79 | "get_utm" => 1,
|
---|
80 | "ref_cyc" => 2,
|
---|
81 | "ref_alm" => 2,
|
---|
82 | "get_tid" => 1,
|
---|
83 | "iget_tid" => 1,
|
---|
84 | "get_ipm" => 1,
|
---|
85 | );
|
---|
86 |
|
---|
87 | %paramtype = (
|
---|
88 | "get_pri" => "PRI",
|
---|
89 | "get_inf" => "intptr_t",
|
---|
90 | "ref_tsk" => "T_RTSK",
|
---|
91 | "ref_tex" => "T_RTEX",
|
---|
92 | "ref_sem" => "T_RSEM",
|
---|
93 | "ref_flg" => "T_RFLG",
|
---|
94 | "ref_dtq" => "T_RDTQ",
|
---|
95 | "ref_pdq" => "T_RPDQ",
|
---|
96 | "ref_mbx" => "T_RMBX",
|
---|
97 | "ref_mtx" => "T_RMTX",
|
---|
98 | "ref_mbf" => "T_RMBF",
|
---|
99 | "ref_mpf" => "T_RMPF",
|
---|
100 | "get_tim" => "SYSTIM",
|
---|
101 | "get_utm" => "SYSUTM",
|
---|
102 | "ref_cyc" => "T_RCYC",
|
---|
103 | "ref_alm" => "T_RALM",
|
---|
104 | "get_tid" => "ID",
|
---|
105 | "iget_tid" => "ID",
|
---|
106 | "get_ipm" => "PRI",
|
---|
107 | );
|
---|
108 |
|
---|
109 | $last_check_point = 0;
|
---|
110 |
|
---|
111 | sub gen_var_def {
|
---|
112 | local($svc_call) = @_;
|
---|
113 | local($svcname, @params);
|
---|
114 | local($typename, $varname);
|
---|
115 |
|
---|
116 | if ($svc_call =~ /^([a-z_]+)\((.*)\)$/) {
|
---|
117 | $svcname = $1;
|
---|
118 | @params = split(/\s*,\s*/, $2);
|
---|
119 |
|
---|
120 | if ($parampos{$svcname}) {
|
---|
121 | $varname = $params[@parampos{$svcname} - 1];
|
---|
122 | $varname =~ s/^\&//;
|
---|
123 | $typename = $paramtype{$svcname};
|
---|
124 | ${$TASKVAR{$tskid}}{$typename} = ${varname};
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | sub gen_svc_call {
|
---|
130 | local($svc_call, $error_code_string) = @_;
|
---|
131 | local($error_code);
|
---|
132 |
|
---|
133 | ${$TASKVAR{$tskid}}{"ER_UINT"} = "ercd";
|
---|
134 |
|
---|
135 | push(@{$TASKCODE{$tskid}{$tskcnt}}, sprintf("\tercd = %s;", $svc_call));
|
---|
136 | gen_var_def($svc_call);
|
---|
137 |
|
---|
138 | if ($error_code_string eq "") {
|
---|
139 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
140 | sprintf("\tcheck_ercd(ercd, E_OK);"), "");
|
---|
141 | }
|
---|
142 | elsif ($error_code_string =~ /^\-\>\s*noreturn$/) {
|
---|
143 | push(@{$TASKCODE{$tskid}{$tskcnt}}, "");
|
---|
144 | }
|
---|
145 | else {
|
---|
146 | $error_code = $error_code_string;
|
---|
147 | $error_code =~ s/^\-\>\s*([A-Za-z0-9_]*)$/$1/;
|
---|
148 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
149 | sprintf("\tcheck_ercd(ercd, %s);", $error_code), "");
|
---|
150 | }
|
---|
151 | }
|
---|
152 |
|
---|
153 | sub parse_line {
|
---|
154 | local($line) = @_;
|
---|
155 |
|
---|
156 | while ($line =~ s/\\$//) {
|
---|
157 | $line1 = <INFILE>;
|
---|
158 | $output_line .= $line1;
|
---|
159 | chomp $line1;
|
---|
160 | $line1 =~ s/^\s*\*\s*//;
|
---|
161 | $line1 =~ s/\s*\/\/.*$//;
|
---|
162 | $line1 =~ s/\s*\.\.\..*$//;
|
---|
163 | $line .= $line1;
|
---|
164 | }
|
---|
165 |
|
---|
166 | if ($line =~ /^\.\./) {
|
---|
167 | # do nothing.
|
---|
168 | }
|
---|
169 | elsif ($line =~ /^==\s*((TASK|ALM|CPUEXC|EXTSVC)[0-9]*)(.*)$/) {
|
---|
170 | $procflag = 1;
|
---|
171 | $tskid = $1;
|
---|
172 | $line2 = $3;
|
---|
173 | if ($line2 =~ /^\-TEX(.*)$/) {
|
---|
174 | $tskid = $tskid."-TEX";
|
---|
175 | $line2 = $1;
|
---|
176 | }
|
---|
177 | if ($line2 =~ /^\-([0-9]+)(.*)$/) {
|
---|
178 | $tskcnt = $1;
|
---|
179 | if (!$TASKCOUNTVAR{$tskid}) {
|
---|
180 | if ($tskid =~ /^TASK([0-9]*)$/) {
|
---|
181 | $countvar = "task$1_count";
|
---|
182 | }
|
---|
183 | elsif ($tskid =~ /^TASK([0-9]*)-TEX$/) {
|
---|
184 | $countvar = "tex_task$1_count";
|
---|
185 | }
|
---|
186 | elsif ($tskid =~ /^ALM([0-9]*)$/) {
|
---|
187 | $countvar = "alarm$1_count";
|
---|
188 | }
|
---|
189 | elsif ($tskid =~ /^CPUEXC([0-9]*)$/) {
|
---|
190 | $countvar = "cpuexc$1_count";
|
---|
191 | }
|
---|
192 | elsif ($tskid =~ /^EXTSVC([0-9]*)$/) {
|
---|
193 | $countvar = "extsvc$1_count";
|
---|
194 | }
|
---|
195 | $TASKCOUNTVAR{$tskid} = $countvar;
|
---|
196 | }
|
---|
197 | }
|
---|
198 | else {
|
---|
199 | $tskcnt = "";
|
---|
200 | }
|
---|
201 | if ($startflag) {
|
---|
202 | push(@{$TASKCODE{$tskid}{$tskcnt}}, "\ttest_start(__FILE__);");
|
---|
203 | push(@{$TASKCODE{$tskid}{$tskcnt}}, "");
|
---|
204 | $startflag = 0;
|
---|
205 | }
|
---|
206 | }
|
---|
207 | elsif (!$procflag) {
|
---|
208 | # do nothing.
|
---|
209 | }
|
---|
210 | elsif ($line =~ /^([0-9]+\:)\s*END$/) {
|
---|
211 | $check_str = $1;
|
---|
212 | $check_no = ++$last_check_point;
|
---|
213 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
214 | sprintf("\tcheck_finish(%d);", $check_no));
|
---|
215 | $procflag = 0;
|
---|
216 | $output_line =~ s/$check_str/$check_no:/;
|
---|
217 | }
|
---|
218 | else {
|
---|
219 | if ($line =~ /^([0-9]+\:)\s*(.*)/) {
|
---|
220 | $check_str = $1;
|
---|
221 | $line = $2;
|
---|
222 | $check_no = ++$last_check_point;
|
---|
223 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
224 | sprintf("\tcheck_point(%d);", $check_no));
|
---|
225 | $output_line =~ s/$check_str/$check_no:/;
|
---|
226 | }
|
---|
227 | if ($line =~ /^(assert\(.*\))$/) {
|
---|
228 | $assert_string = $1;
|
---|
229 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
230 | sprintf("\tcheck_%s;", $assert_string), "");
|
---|
231 | }
|
---|
232 | elsif ($line =~ /^(state(_i)?\(.*\))$/) {
|
---|
233 | $state_string = $1;
|
---|
234 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
235 | sprintf("\tcheck_%s;", $state_string), "");
|
---|
236 | }
|
---|
237 | elsif ($line =~ /^call\((.*)\)$/ || $line =~ /^DO\((.*)\)$/) {
|
---|
238 | $call_string = $1;
|
---|
239 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
240 | sprintf("\t%s;", $call_string), "");
|
---|
241 | }
|
---|
242 | elsif ($line =~ /^MISSING$/) {
|
---|
243 | push(@{$TASKCODE{$tskid}{$tskcnt}}, "");
|
---|
244 | }
|
---|
245 | elsif ($line =~ /^RETURN((\(.*\))?)$/) {
|
---|
246 | $return_string = $1;
|
---|
247 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
248 | "\treturn".$return_string.";", "");
|
---|
249 | }
|
---|
250 | elsif ($line =~ /^GOTO\((.*)\)$/) {
|
---|
251 | $goto_string = $1;
|
---|
252 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
253 | sprintf("\tgoto %s;", $goto_string), "");
|
---|
254 | }
|
---|
255 | elsif ($line =~ /^LABEL\((.*)\)$/) {
|
---|
256 | $label_string = $1;
|
---|
257 | $indent_string = $indentstr;
|
---|
258 | $indent_string =~ s/\t$//;
|
---|
259 | push(@{$TASKCODE{$tskid}{$tskcnt}},
|
---|
260 | sprintf("%s:", $label_string));
|
---|
261 | }
|
---|
262 | elsif ($line =~ /^([a-z_]+\(.*\))\s*(\-\>\s*[A-Za-z0-9_]*)?\s*$/) {
|
---|
263 | $svc_call = $1;
|
---|
264 | $error_code_string = $2;
|
---|
265 | gen_svc_call($svc_call, $error_code_string);
|
---|
266 | }
|
---|
267 | else {
|
---|
268 | print STDERR "Error: ",$line,"\n";
|
---|
269 | }
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | #
|
---|
274 | # ã¹ã¯ãªãããã¡ã¤ã«èªè¾¼ã¿å¦ç
|
---|
275 | #
|
---|
276 | $procflag = 0;
|
---|
277 | $startflag = 1;
|
---|
278 | $outflag = 1;
|
---|
279 | open(INFILE, $infile) || die "Cannot open $infile";
|
---|
280 | while (($line = <INFILE>) && $outflag) {
|
---|
281 | $output_line = $line;
|
---|
282 | chomp $line;
|
---|
283 | $line =~ s/^\s*\*\s*//;
|
---|
284 | $line =~ s/\s*\/\/.*$//;
|
---|
285 | $line =~ s/\s*\.\.\..*$//;
|
---|
286 | if ($line) {
|
---|
287 | parse_line($line);
|
---|
288 | }
|
---|
289 | print $output_line;
|
---|
290 | if ($output_line =~ /DO NOT DELETE THIS LINE/) {
|
---|
291 | $outflag = 0;
|
---|
292 | }
|
---|
293 | }
|
---|
294 | close(INFILE);
|
---|
295 |
|
---|
296 | #
|
---|
297 | # ã¿ã¹ã¯ã®å¤æ°å®ç¾©ã®ã³ã¼ãåºå
|
---|
298 | #
|
---|
299 | sub output_task_vardef {
|
---|
300 | my($tskid) = @_;
|
---|
301 |
|
---|
302 | foreach my $typename (keys(%{$TASKVAR{$tskid}})) {
|
---|
303 | print "\t",$typename, (length($typename) < 4 ? "\t\t" : "\t"),
|
---|
304 | ${$TASKVAR{$tskid}}{$typename},";\n";
|
---|
305 | }
|
---|
306 | }
|
---|
307 |
|
---|
308 | #
|
---|
309 | # ã¿ã¹ã¯æ¬ä½ã®ã³ã¼ãåºå
|
---|
310 | #
|
---|
311 | sub output_task_body {
|
---|
312 | my($tskid) = @_;
|
---|
313 |
|
---|
314 | foreach my $tskcnt (sort {$a <=> $b} (keys(%{$TASKCODE{$tskid}}))) {
|
---|
315 | printf "\tcase %d:\n", $tskcnt;
|
---|
316 | foreach my $line (@{$TASKCODE{$tskid}{$tskcnt}}) {
|
---|
317 | print "\t",$line if ($line);
|
---|
318 | print "\n";
|
---|
319 | }
|
---|
320 | printf "\t\tcheck_point(0);\n\n";
|
---|
321 | }
|
---|
322 | }
|
---|
323 |
|
---|
324 | #
|
---|
325 | # ã¿ã¹ã¯ã³ã¼ãã®åºå
|
---|
326 | #
|
---|
327 | sub output_task {
|
---|
328 | if ($TASKCOUNTVAR{$tskid}) {
|
---|
329 | printf "\nstatic uint_t\t%s = 0;\n", $TASKCOUNTVAR{$tskid};
|
---|
330 | }
|
---|
331 | if ($tskid =~ /^TASK([0-9]*)$/) {
|
---|
332 | print "\nvoid\n";
|
---|
333 | print "task$1(intptr_t exinf)\n";
|
---|
334 | }
|
---|
335 | elsif ($tskid =~ /^TASK([0-9]*)-TEX$/) {
|
---|
336 | print "\nvoid\n";
|
---|
337 | print "tex_task$1(TEXPTN texptn, intptr_t exinf)\n";
|
---|
338 | }
|
---|
339 | elsif ($tskid =~ /^ALM([0-9]*)$/) {
|
---|
340 | print "\nvoid\n";
|
---|
341 | print "alarm$1_handler(intptr_t exinf)\n";
|
---|
342 | }
|
---|
343 | elsif ($tskid =~ /^CPUEXC([0-9]*)$/) {
|
---|
344 | print "\nvoid\n";
|
---|
345 | print "cpuexc$1_handler(void *p_excinf)\n";
|
---|
346 | }
|
---|
347 | elsif ($tskid =~ /^EXTSVC([0-9]*)$/) {
|
---|
348 | print "\nER_UINT\n";
|
---|
349 | print "extsvc$1_routine(intptr_t par1, intptr_t par2, intptr_t par3,\n";
|
---|
350 | print "\t\t\t\t\t\t\t\tintptr_t par4, intptr_t par5, ID cdmid)\n";
|
---|
351 | }
|
---|
352 | print "{\n";
|
---|
353 | output_task_vardef($tskid);
|
---|
354 | print "\n";
|
---|
355 | if ($TASKCOUNTVAR{$tskid}) {
|
---|
356 | printf "\tswitch (++%s) {\n", $TASKCOUNTVAR{$tskid};
|
---|
357 | output_task_body($tskid);
|
---|
358 | printf "\tdefault:\n";
|
---|
359 | printf "\t\tcheck_point(0);\n";
|
---|
360 | printf "\t}\n";
|
---|
361 | }
|
---|
362 | else {
|
---|
363 | foreach my $line (@{$TASKCODE{$tskid}{""}}) {
|
---|
364 | print $line,"\n";
|
---|
365 | }
|
---|
366 | }
|
---|
367 | print "\tcheck_point(0);\n";
|
---|
368 | if ($tskid =~ /^EXTSVC([0-9]*)$/) {
|
---|
369 | print "\treturn(E_SYS);\n";
|
---|
370 | }
|
---|
371 | print "}\n";
|
---|
372 | }
|
---|
373 |
|
---|
374 | #
|
---|
375 | # ãã¹ãããã°ã©ã åºåå¦ç
|
---|
376 | #
|
---|
377 | foreach $tskid (sort(keys(%TASKCODE))) {
|
---|
378 | output_task();
|
---|
379 | }
|
---|