Mercurial > hg > octave-nkf
annotate liboctave/mk-ops.awk @ 9550:3d6a9aea2aea
refactor binary & bool ops in liboctave
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Wed, 19 Aug 2009 22:55:15 +0200 |
parents | eb63fbe60fab |
children | 7dafdb8b062f |
rev | line source |
---|---|
8920 | 1 # Copyright (C) 2003, 2004, 2006, 2007, 2009 John W. Eaton |
7019 | 2 # |
3 # This file is part of Octave. | |
4 # | |
5 # Octave is free software; you can redistribute it and/or modify it | |
6 # under the terms of the GNU General Public License as published by the | |
7 # Free Software Foundation; either version 3 of the License, or (at | |
8 # your option) any later version. | |
9 # | |
10 # Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 # for more details. | |
14 # | |
15 # You should have received a copy of the GNU General Public License | |
16 # along with Octave; see the file COPYING. If not, see | |
17 # <http://www.gnu.org/licenses/>. | |
18 | |
4544 | 19 BEGIN { |
20 declare_types = 0; | |
21 generate_ops = 0; | |
22 ntypes = 0; | |
4547 | 23 } { |
24 if (NR == 1 && make_inclusive_header) | |
4544 | 25 { |
4547 | 26 print "// DO NOT EDIT -- generated by mk-ops"; |
4544 | 27 tmp = make_inclusive_header; |
4547 | 28 gsub (/[\.-]/, "_", tmp); |
4544 | 29 printf ("#if !defined (octave_%s)\n", tmp); |
30 printf ("#define octave_%s 1\n", tmp); | |
31 } | |
32 } | |
4547 | 33 /^#/ { |
34 if ($2 == "types") | |
35 declare_types = 1; | |
36 else if ($2 == "ops") | |
37 { | |
38 generate_ops = 1; | |
39 declare_types = 0; | |
40 } | |
41 next; | |
42 } { | |
4544 | 43 if (declare_types) |
44 { | |
45 ntypes++; | |
46 | |
6119 | 47 if (NF == 6 || NF == 7) |
4544 | 48 { |
6119 | 49 if (NF == 7) |
50 core_type[ntypes] = $7; | |
51 | |
5030 | 52 scalar_zero_val[ntypes] = $6; |
4544 | 53 fwd_decl_ok[ntypes] = $5 == "YES"; |
54 header[ntypes] = $4 == "NONE" ? "" : $4; | |
55 class[ntypes] = $3; | |
56 type[ntypes] = $2; | |
57 tag[ntypes] = $1; | |
58 rev_tag[$1] = ntypes; | |
59 } | |
60 else | |
61 printf ("skipping line %d: %s\n", NR, $0); | |
62 } | |
63 else if (generate_ops) | |
64 { | |
65 if (NF >= 4) | |
66 { | |
67 result_tag = $1; | |
68 lhs_tag = $2; | |
69 rhs_tag = $3; | |
70 op_type = $4; | |
71 | |
72 bin_ops = index (op_type, "B") != 0; | |
73 cmp_ops = index (op_type, "C") != 0; | |
74 bool_ops = index (op_type, "L") != 0; | |
75 | |
76 n = 4; | |
77 | |
78 lhs_conv = cmp_ops ? $(++n) : ""; | |
79 rhs_conv = cmp_ops ? $(++n) : ""; | |
80 | |
81 if (lhs_conv == "NONE") | |
82 lhs_conv = ""; | |
83 | |
84 if (rhs_conv == "NONE") | |
85 rhs_conv = ""; | |
86 | |
87 k = 0 | |
88 while (NF > n) | |
89 bool_headers[k++] = $(++n); | |
90 | |
91 cc_file = sprintf ("%s-%s-%s.cc", prefix, lhs_tag, rhs_tag); | |
92 h_file = sprintf ("%s-%s-%s.h", prefix, lhs_tag, rhs_tag); | |
93 | |
94 if (list_cc_files) | |
95 { | |
96 print cc_file; | |
97 next; | |
98 } | |
99 | |
100 if (list_h_files) | |
101 { | |
102 print h_file; | |
103 next; | |
104 } | |
105 | |
106 if (make_inclusive_header) | |
4547 | 107 { |
108 printf ("#include \"%s\"\n", h_file); | |
109 next; | |
110 } | |
4544 | 111 |
112 h_guard = sprintf ("octave_%s_%s_%s_h", prefix, lhs_tag, rhs_tag); | |
113 | |
114 result_num = rev_tag[result_tag]; | |
115 lhs_num = rev_tag[lhs_tag]; | |
116 rhs_num = rev_tag[rhs_tag]; | |
117 | |
118 result_type = type[result_num]; | |
119 lhs_type = type[lhs_num]; | |
120 rhs_type = type[rhs_num]; | |
121 | |
6119 | 122 lhs_core_type = core_type[lhs_num]; |
123 rhs_core_type = core_type[rhs_num]; | |
124 | |
5030 | 125 result_scalar_zero_val = scalar_zero_val[result_num]; |
126 lhs_scalar_zero_val = scalar_zero_val[lhs_num]; | |
127 rhs_scalar_zero_val = scalar_zero_val[rhs_num]; | |
128 | |
4544 | 129 result_header = header[result_num]; |
130 lhs_header = header[lhs_num]; | |
131 rhs_header = header[rhs_num]; | |
132 | |
133 lhs_class = class[lhs_num]; | |
134 rhs_class = class[rhs_num]; | |
135 | |
136 print "// DO NOT EDIT -- generated by mk-ops" > h_file; | |
137 | |
138 printf ("#if !defined (%s)\n", h_guard) >> h_file; | |
139 printf ("#define %s 1\n", h_guard) >> h_file; | |
140 | |
141 if (result_header) | |
142 { | |
143 if (result_fwd_decl_ok) | |
144 printf ("class %s\n", result_type) >> h_file; | |
145 else | |
146 printf ("#include \"%s\"\n", result_header) >> h_file; | |
147 } | |
148 | |
149 if (lhs_header && ! (lhs_header == result_header)) | |
150 { | |
151 if (result_fwd_decl_ok) | |
152 printf ("class %s\n", lhs_type) >> h_file; | |
153 else | |
154 printf ("#include \"%s\"\n", lhs_header) >> h_file; | |
155 } | |
156 | |
157 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) | |
158 { | |
159 if (result_fwd_decl_ok) | |
160 printf ("class %s\n", rhs_type) >> h_file; | |
161 else | |
162 printf ("#include \"%s\"\n", rhs_header) >> h_file; | |
163 } | |
164 | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
165 printf ("#include \"mx-op-decl.h\"\n") >> h_file; |
4544 | 166 |
4964 | 167 if (bin_ops) |
6708 | 168 printf ("%s%s_BIN_OP_DECLS (%s, %s, %s, OCTAVE_API)\n", lhs_class, |
4964 | 169 rhs_class, result_type, lhs_type, rhs_type) >> h_file |
170 | |
171 if (cmp_ops) | |
6708 | 172 printf ("%s%s_CMP_OP_DECLS (%s, %s, OCTAVE_API)\n", lhs_class, |
4964 | 173 rhs_class, lhs_type, rhs_type) >> h_file |
174 | |
175 if (bool_ops) | |
6708 | 176 printf ("%s%s_BOOL_OP_DECLS (%s, %s, OCTAVE_API)\n", lhs_class, |
4964 | 177 rhs_class, lhs_type, rhs_type) >> h_file |
178 | |
4544 | 179 |
180 print "#endif" >> h_file; | |
181 | |
182 close (h_file); | |
183 | |
184 | |
185 print "// DO NOT EDIT -- generated by mk-ops" > cc_file; | |
186 | |
187 print "#ifdef HAVE_CONFIG_H" >> cc_file; | |
188 print "#include <config.h>" >> cc_file; | |
189 print "#endif" >> cc_file; | |
190 | |
4669 | 191 print "#include \"Array-util.h\"" >> cc_file; |
192 | |
4544 | 193 printf ("#include \"%s\"\n", h_file) >> cc_file; |
194 | |
8774
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
195 printf ("#include \"mx-op-defs.h\"\n") >> cc_file; |
b756ce0002db
split implementation and interface in mx-op-defs and MArray-defs
Jaroslav Hajek <highegg@gmail.com>
parents:
7019
diff
changeset
|
196 |
4544 | 197 for (i in bool_headers) |
4585 | 198 { |
199 printf ("#include \"%s\"\n", bool_headers[i]) >> cc_file; | |
200 delete bool_headers[i]; | |
201 } | |
4544 | 202 |
203 if (result_header) | |
204 printf ("#include \"%s\"\n", result_header) >> cc_file; | |
205 | |
206 if (lhs_header && ! (lhs_header == result_header)) | |
207 printf ("#include \"%s\"\n", lhs_header) >> cc_file; | |
208 | |
209 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) | |
210 printf ("#include \"%s\"\n", rhs_header) >> cc_file; | |
211 | |
212 if (bin_ops) | |
213 { | |
214 if ((lhs_class == "DM" && rhs_class == "M") || (lhs_class == "M" && rhs_class == "DM")) | |
215 printf ("%s%s_BIN_OPS (%s, %s, %s, %s)\n", | |
216 lhs_class, rhs_class, result_type, | |
5030 | 217 lhs_type, rhs_type, result_scalar_zero_val) >> cc_file |
4544 | 218 else |
219 printf ("%s%s_BIN_OPS (%s, %s, %s)\n", | |
220 lhs_class, rhs_class, result_type, | |
221 lhs_type, rhs_type) >> cc_file | |
222 } | |
223 | |
224 if (cmp_ops) | |
6119 | 225 { |
226 if (lhs_class == "S" || rhs_class == "S") | |
227 { | |
228 if (lhs_core_type) | |
229 { | |
230 if (rhs_core_type) | |
231 printf ("%s%s_CMP_OPS2 (%s, %s, %s, %s, %s, %s)\n", | |
232 lhs_class, rhs_class, lhs_type, lhs_conv, | |
233 rhs_type, rhs_conv, | |
234 lhs_core_type, rhs_core_type) >> cc_file | |
235 else | |
236 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", | |
237 lhs_class, rhs_class, lhs_type, lhs_conv, | |
238 rhs_type, rhs_conv, lhs_core_type) >> cc_file | |
239 } | |
240 else | |
241 { | |
242 if (rhs_core_type) | |
243 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", | |
244 lhs_class, rhs_class, lhs_type, lhs_conv, | |
245 rhs_type, rhs_conv, rhs_core_type) >> cc_file | |
246 else | |
247 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", | |
248 lhs_class, rhs_class, lhs_type, lhs_conv, | |
249 rhs_type, rhs_conv) >> cc_file | |
250 } | |
251 } | |
252 else | |
253 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", | |
254 lhs_class, rhs_class, lhs_type, lhs_conv, | |
255 rhs_type, rhs_conv) >> cc_file | |
256 } | |
4544 | 257 |
258 if (bool_ops) | |
9550
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
259 printf ("%s%s_BOOL_OPS (%s, %s)\n", lhs_class, rhs_class, |
3d6a9aea2aea
refactor binary & bool ops in liboctave
Jaroslav Hajek <highegg@gmail.com>
parents:
8920
diff
changeset
|
260 lhs_type, rhs_type) >> cc_file |
4544 | 261 |
262 | |
263 close (cc_file); | |
264 } | |
265 else | |
266 printf ("skipping line %d: %s\n", NR, $0); | |
267 } | |
268 } | |
269 END { | |
270 if (make_inclusive_header) | |
271 print "#endif"; | |
4547 | 272 } |