7019
|
1 # Copyright (C) 2003, 2004, 2006, 2007 John W. Eaton |
|
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 |
|
165 printf ("#include \"mx-op-defs.h\"\n") >> h_file; |
|
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 |
|
195 for (i in bool_headers) |
4585
|
196 { |
|
197 printf ("#include \"%s\"\n", bool_headers[i]) >> cc_file; |
|
198 delete bool_headers[i]; |
|
199 } |
4544
|
200 |
|
201 if (result_header) |
|
202 printf ("#include \"%s\"\n", result_header) >> cc_file; |
|
203 |
|
204 if (lhs_header && ! (lhs_header == result_header)) |
|
205 printf ("#include \"%s\"\n", lhs_header) >> cc_file; |
|
206 |
|
207 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) |
|
208 printf ("#include \"%s\"\n", rhs_header) >> cc_file; |
|
209 |
|
210 if (bin_ops) |
|
211 { |
|
212 if ((lhs_class == "DM" && rhs_class == "M") || (lhs_class == "M" && rhs_class == "DM")) |
|
213 printf ("%s%s_BIN_OPS (%s, %s, %s, %s)\n", |
|
214 lhs_class, rhs_class, result_type, |
5030
|
215 lhs_type, rhs_type, result_scalar_zero_val) >> cc_file |
4544
|
216 else |
|
217 printf ("%s%s_BIN_OPS (%s, %s, %s)\n", |
|
218 lhs_class, rhs_class, result_type, |
|
219 lhs_type, rhs_type) >> cc_file |
|
220 } |
|
221 |
|
222 if (cmp_ops) |
6119
|
223 { |
|
224 if (lhs_class == "S" || rhs_class == "S") |
|
225 { |
|
226 if (lhs_core_type) |
|
227 { |
|
228 if (rhs_core_type) |
|
229 printf ("%s%s_CMP_OPS2 (%s, %s, %s, %s, %s, %s)\n", |
|
230 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
231 rhs_type, rhs_conv, |
|
232 lhs_core_type, rhs_core_type) >> cc_file |
|
233 else |
|
234 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", |
|
235 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
236 rhs_type, rhs_conv, lhs_core_type) >> cc_file |
|
237 } |
|
238 else |
|
239 { |
|
240 if (rhs_core_type) |
|
241 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", |
|
242 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
243 rhs_type, rhs_conv, rhs_core_type) >> cc_file |
|
244 else |
|
245 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", |
|
246 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
247 rhs_type, rhs_conv) >> cc_file |
|
248 } |
|
249 } |
|
250 else |
|
251 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", |
|
252 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
253 rhs_type, rhs_conv) >> cc_file |
|
254 } |
4544
|
255 |
|
256 if (bool_ops) |
5030
|
257 printf ("%s%s_BOOL_OPS2 (%s, %s, %s, %s)\n", lhs_class, rhs_class, |
|
258 lhs_type, rhs_type, lhs_scalar_zero_val, |
|
259 rhs_scalar_zero_val) >> cc_file |
4544
|
260 |
|
261 |
|
262 close (cc_file); |
|
263 } |
|
264 else |
|
265 printf ("skipping line %d: %s\n", NR, $0); |
|
266 } |
|
267 } |
|
268 END { |
|
269 if (make_inclusive_header) |
|
270 print "#endif"; |
4547
|
271 } |