comparison g23m/system/busyb/tools/header_gen.pl @ 0:509db1a7b7b8

initial import: leo2moko-r1
author Space Falcon <falcon@ivan.Harhan.ORG>
date Mon, 01 Jun 2015 03:24:05 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:509db1a7b7b8
1 #
2 # combined script: header_gen
3 #
4 # consists of:
5 # header_gen_rv_swe.pl
6 # header_gen_rv_test_inc.pl
7 # header_gen_rv_test_exec_level.pl
8 #
9 # to be invoked with:
10 # header_gen.pl { rv_swe | rv_test_inc | rv_test_exec_level } other-params
11 #
12 # details see below
13 #
14
15 use strict;
16 #use warnings;
17
18 # Define and set global variables.
19 my $selector = shift;
20 print $selector . " ";
21 my $header_file = shift;
22 print $header_file;
23 my $guard_string = "\U__${selector}_H__";
24
25
26 #
27 # Function used to open and write the header to the include file.
28 #
29 sub open_header {
30 # open the file
31 open (HDR,">$header_file")||die "can't open $header_file \n";
32
33 # print guard pattern
34 print HDR "#ifndef $guard_string\n";
35 print HDR "#define $guard_string\n\n";
36 }
37
38 #
39 # Function used to write the footer and close the include file.
40 #
41 sub close_footer {
42 # end guard pattern
43 print HDR "\n#endif /* $guard_string */\n";
44
45 # close the file
46 close HDR;
47 }
48
49
50 if ($selector eq 'rv_swe')
51 {
52
53 open_header();
54
55 foreach (@ARGV) {
56 #look for the following pattern
57 if(/^(SWE_)?(\w+)_STATE=(\d+)/)
58 {
59 if ($3 == 1 || $3 == 2)
60 {
61 #print everything
62 print HDR "#define RVM_${2}_SWE\n";
63 }
64 }
65 }
66
67 close_footer();
68
69 }
70 elsif ($selector eq 'rv_test_inc')
71 {
72
73 #
74 # header_gen_rv_test_inc.pl : tool to generate header files
75 #
76 # Short spec:
77 #
78 # This tool generates one header file using the information from the command
79 # line. The expected fommand line form is:
80 #
81 # header-file-name other-parameters
82 #
83 # where header-file-name is the filename of the include file to be generated
84 # (including path components).
85 # other-parameters parameters define an association of names to values. each
86 # association has the form:
87 #
88 # name=value
89 #
90 # name may have an prefix SWE_, which is then ignored. name must have the
91 # suffix _STATE, otherwise this particular association is ignored.
92 # only the component between SWE_ and _STATE gets considered. value must
93 # be 2, otherwise this particular association is ignored.
94 #
95 # The tool generates from the accepted (not ignored) a list of defines.
96 # the identifiers are the considered part of the other-parameters, but have
97 # the prefix TEST_ and suffix _SWE. The values they define start with 1,
98 # increasing.
99 # the order of the parameters is not important. However, it must be the same
100 # as of the tool header_gen_rv_test_exec_level.pl (see there).
101 # Conveniently both tools should be invoked with the same other-parameters.
102 #
103
104 open_header();
105
106 my $counter = 1;
107
108 foreach (@ARGV) {
109 #look for the following pattern
110 if(/^(SWE_)?(\w+)_STATE=(\d+)/)
111 {
112 if ($3 == 2)
113 {
114 print HDR "#define TEST_${2}_SWE ($counter)\n";
115 $counter++;
116 }
117 }
118 }
119
120 close_footer();
121
122 }
123 elsif ($selector eq 'rv_test_exec_level')
124 {
125
126 #
127 # header_gen_rv_test_exec_level.pl : tool to generate header files
128 #
129 # Short spec:
130 #
131 # This tool generates one header file using the information from the command
132 # line. The expected fommand line form is:
133 #
134 # header-file-name other-parameters
135 #
136 # where header-file-name is the filename of the include file to be generated
137 # (including path components).
138 # other-parameters parameters define an association of names to values. each
139 # association has the form:
140 #
141 # name=value
142 #
143 # name may have an prefix SWE_, which is then ignored. name must have the
144 # suffix _STATE, otherwise this particular association is ignored.
145 # only the component between SWE_ and _STATE gets considered. value must
146 # be 2, otherwise this particular association is ignored.
147 #
148 # the contents of the header file will be of the ANSI C language.
149 # it is a the definition of an array:
150 # static char TEST_LEVEL_LCD [TEST_LEVEL_LCD_LEN][TEST_LEVEL_LCD_STR_LEN] =
151 # having 0-terminated strings as components.
152 # the values of TEST_LEVEL_LCD_LEN and TEST_LEVEL_LCD_STR_LEN and the elements
153 # of the array depend on the parameters:
154 # TEST_LEVEL_LCD_LEN is the number of considered (or not ignored)
155 # other-parameters PLUS 1.
156 # TEST_LEVEL_LCD_STR_LEN is the length of the strings. various rules apply,
157 # e.g. for 0 termination (but at last, it will get the value of 15!).
158 # see below and/or ask a ANSI C guru.
159 # the strings have the form: running index," - ", considered name component
160 # (max 8 chars), filling blanks (up to the final length)
161 # the running index use 3 characters, i.e. no more than 999 considered indexes
162 # are allowed. this is no problem for the time being.
163 # Thus we can compute the max length: 3+3+8+1=15 (running index, delimiter,
164 # name, string delimiter \0).
165 # There is one special initial string. it is always placed at index 0 and has
166 # the contents " TEST LEVEL " plus '\0'.
167 # the 2 spaces at the beginning are legacy, I guess they are just to have a
168 # left alignment with the first 9 indexes (those with 1 figure indexes)
169 #
170
171 if (@ARGV > 999)
172 {
173 die "cannot stand it - too many arguments";
174 }
175
176 open_header();
177
178 my $max_name_len = 8;
179 my @local_args;
180 foreach (@ARGV)
181 {
182 if(/^(SWE_)?(\w+)_STATE=(\d+)/ && $3 == 2)
183 {
184 push @local_args, substr($2, 0, $max_name_len);
185 }
186 }
187
188 print HDR "/* RV TEST TEST_LEVEL PARAMETER */\n";
189 print HDR "#define TEST_LEVEL_LCD_LEN (".(@local_args+1).")\n";
190 print HDR "#define TEST_LEVEL_LCD_STR_LEN (".(3+3+$max_name_len+1).")\n\n";
191 print HDR "static char TEST_LEVEL_LCD [TEST_LEVEL_LCD_LEN][TEST_LEVEL_LCD_STR_LEN] = {\n";
192
193 # the literal constant 1 represents the single char at the beginning ('T')
194 # this is due to the fact that normally the first 3 chars are reserved for the
195 # running index
196 my @print_lines = ("\"" . sprintf(" %-*s", 1+3+$max_name_len, "TEST LEVEL") . "\"");
197
198 my $counter = 1;
199 foreach (@local_args)
200 {
201 push @print_lines, "\"" . sprintf("%3d - %-*s", $counter, $max_name_len, $_) . "\"";
202 $counter++;
203 }
204
205 print HDR " ", join ",\n ", @print_lines;
206
207 print HDR "};\n";
208
209 close_footer();
210
211 }
212 else
213 {
214 die "$selector not recognized";
215 }