4544
|
1 BEGIN { |
|
2 declare_types = 0; |
|
3 generate_ops = 0; |
|
4 ntypes = 0; |
4547
|
5 } { |
|
6 if (NR == 1 && make_inclusive_header) |
4544
|
7 { |
4547
|
8 print "// DO NOT EDIT -- generated by mk-ops"; |
4544
|
9 tmp = make_inclusive_header; |
4547
|
10 gsub (/[\.-]/, "_", tmp); |
4544
|
11 printf ("#if !defined (octave_%s)\n", tmp); |
|
12 printf ("#define octave_%s 1\n", tmp); |
|
13 } |
|
14 } |
4547
|
15 /^#/ { |
|
16 if ($2 == "types") |
|
17 declare_types = 1; |
|
18 else if ($2 == "ops") |
|
19 { |
|
20 generate_ops = 1; |
|
21 declare_types = 0; |
|
22 } |
|
23 next; |
|
24 } { |
4544
|
25 if (declare_types) |
|
26 { |
|
27 ntypes++; |
|
28 |
6119
|
29 if (NF == 6 || NF == 7) |
4544
|
30 { |
6119
|
31 if (NF == 7) |
|
32 core_type[ntypes] = $7; |
|
33 |
5030
|
34 scalar_zero_val[ntypes] = $6; |
4544
|
35 fwd_decl_ok[ntypes] = $5 == "YES"; |
|
36 header[ntypes] = $4 == "NONE" ? "" : $4; |
|
37 class[ntypes] = $3; |
|
38 type[ntypes] = $2; |
|
39 tag[ntypes] = $1; |
|
40 rev_tag[$1] = ntypes; |
|
41 } |
|
42 else |
|
43 printf ("skipping line %d: %s\n", NR, $0); |
|
44 } |
|
45 else if (generate_ops) |
|
46 { |
|
47 if (NF >= 4) |
|
48 { |
|
49 result_tag = $1; |
|
50 lhs_tag = $2; |
|
51 rhs_tag = $3; |
|
52 op_type = $4; |
|
53 |
|
54 bin_ops = index (op_type, "B") != 0; |
|
55 cmp_ops = index (op_type, "C") != 0; |
|
56 bool_ops = index (op_type, "L") != 0; |
|
57 |
|
58 n = 4; |
|
59 |
|
60 lhs_conv = cmp_ops ? $(++n) : ""; |
|
61 rhs_conv = cmp_ops ? $(++n) : ""; |
|
62 |
|
63 if (lhs_conv == "NONE") |
|
64 lhs_conv = ""; |
|
65 |
|
66 if (rhs_conv == "NONE") |
|
67 rhs_conv = ""; |
|
68 |
|
69 k = 0 |
|
70 while (NF > n) |
|
71 bool_headers[k++] = $(++n); |
|
72 |
|
73 cc_file = sprintf ("%s-%s-%s.cc", prefix, lhs_tag, rhs_tag); |
|
74 h_file = sprintf ("%s-%s-%s.h", prefix, lhs_tag, rhs_tag); |
|
75 |
|
76 if (list_cc_files) |
|
77 { |
|
78 print cc_file; |
|
79 next; |
|
80 } |
|
81 |
|
82 if (list_h_files) |
|
83 { |
|
84 print h_file; |
|
85 next; |
|
86 } |
|
87 |
|
88 if (make_inclusive_header) |
4547
|
89 { |
|
90 printf ("#include \"%s\"\n", h_file); |
|
91 next; |
|
92 } |
4544
|
93 |
|
94 h_guard = sprintf ("octave_%s_%s_%s_h", prefix, lhs_tag, rhs_tag); |
|
95 |
|
96 result_num = rev_tag[result_tag]; |
|
97 lhs_num = rev_tag[lhs_tag]; |
|
98 rhs_num = rev_tag[rhs_tag]; |
|
99 |
|
100 result_type = type[result_num]; |
|
101 lhs_type = type[lhs_num]; |
|
102 rhs_type = type[rhs_num]; |
|
103 |
6119
|
104 lhs_core_type = core_type[lhs_num]; |
|
105 rhs_core_type = core_type[rhs_num]; |
|
106 |
5030
|
107 result_scalar_zero_val = scalar_zero_val[result_num]; |
|
108 lhs_scalar_zero_val = scalar_zero_val[lhs_num]; |
|
109 rhs_scalar_zero_val = scalar_zero_val[rhs_num]; |
|
110 |
4544
|
111 result_header = header[result_num]; |
|
112 lhs_header = header[lhs_num]; |
|
113 rhs_header = header[rhs_num]; |
|
114 |
|
115 lhs_class = class[lhs_num]; |
|
116 rhs_class = class[rhs_num]; |
|
117 |
|
118 print "// DO NOT EDIT -- generated by mk-ops" > h_file; |
|
119 |
|
120 printf ("#if !defined (%s)\n", h_guard) >> h_file; |
|
121 printf ("#define %s 1\n", h_guard) >> h_file; |
|
122 |
|
123 if (result_header) |
|
124 { |
|
125 if (result_fwd_decl_ok) |
|
126 printf ("class %s\n", result_type) >> h_file; |
|
127 else |
|
128 printf ("#include \"%s\"\n", result_header) >> h_file; |
|
129 } |
|
130 |
|
131 if (lhs_header && ! (lhs_header == result_header)) |
|
132 { |
|
133 if (result_fwd_decl_ok) |
|
134 printf ("class %s\n", lhs_type) >> h_file; |
|
135 else |
|
136 printf ("#include \"%s\"\n", lhs_header) >> h_file; |
|
137 } |
|
138 |
|
139 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) |
|
140 { |
|
141 if (result_fwd_decl_ok) |
|
142 printf ("class %s\n", rhs_type) >> h_file; |
|
143 else |
|
144 printf ("#include \"%s\"\n", rhs_header) >> h_file; |
|
145 } |
|
146 |
|
147 printf ("#include \"mx-op-defs.h\"\n") >> h_file; |
|
148 |
4964
|
149 if (bin_ops) |
|
150 printf ("%s%s_BIN_OP_DECLS (%s, %s, %s)\n", lhs_class, |
|
151 rhs_class, result_type, lhs_type, rhs_type) >> h_file |
|
152 |
|
153 if (cmp_ops) |
|
154 printf ("%s%s_CMP_OP_DECLS (%s, %s)\n", lhs_class, |
|
155 rhs_class, lhs_type, rhs_type) >> h_file |
|
156 |
|
157 if (bool_ops) |
|
158 printf ("%s%s_BOOL_OP_DECLS (%s, %s)\n", lhs_class, |
|
159 rhs_class, lhs_type, rhs_type) >> h_file |
|
160 |
4544
|
161 |
|
162 print "#endif" >> h_file; |
|
163 |
|
164 close (h_file); |
|
165 |
|
166 |
|
167 print "// DO NOT EDIT -- generated by mk-ops" > cc_file; |
|
168 |
|
169 print "#ifdef HAVE_CONFIG_H" >> cc_file; |
|
170 print "#include <config.h>" >> cc_file; |
|
171 print "#endif" >> cc_file; |
|
172 |
4669
|
173 print "#include \"Array-util.h\"" >> cc_file; |
|
174 |
4544
|
175 printf ("#include \"%s\"\n", h_file) >> cc_file; |
|
176 |
|
177 for (i in bool_headers) |
4585
|
178 { |
|
179 printf ("#include \"%s\"\n", bool_headers[i]) >> cc_file; |
|
180 delete bool_headers[i]; |
|
181 } |
4544
|
182 |
|
183 if (result_header) |
|
184 printf ("#include \"%s\"\n", result_header) >> cc_file; |
|
185 |
|
186 if (lhs_header && ! (lhs_header == result_header)) |
|
187 printf ("#include \"%s\"\n", lhs_header) >> cc_file; |
|
188 |
|
189 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header)) |
|
190 printf ("#include \"%s\"\n", rhs_header) >> cc_file; |
|
191 |
|
192 if (bin_ops) |
|
193 { |
|
194 if ((lhs_class == "DM" && rhs_class == "M") || (lhs_class == "M" && rhs_class == "DM")) |
|
195 printf ("%s%s_BIN_OPS (%s, %s, %s, %s)\n", |
|
196 lhs_class, rhs_class, result_type, |
5030
|
197 lhs_type, rhs_type, result_scalar_zero_val) >> cc_file |
4544
|
198 else |
|
199 printf ("%s%s_BIN_OPS (%s, %s, %s)\n", |
|
200 lhs_class, rhs_class, result_type, |
|
201 lhs_type, rhs_type) >> cc_file |
|
202 } |
|
203 |
|
204 if (cmp_ops) |
6119
|
205 { |
|
206 if (lhs_class == "S" || rhs_class == "S") |
|
207 { |
|
208 if (lhs_core_type) |
|
209 { |
|
210 if (rhs_core_type) |
|
211 printf ("%s%s_CMP_OPS2 (%s, %s, %s, %s, %s, %s)\n", |
|
212 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
213 rhs_type, rhs_conv, |
|
214 lhs_core_type, rhs_core_type) >> cc_file |
|
215 else |
|
216 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", |
|
217 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
218 rhs_type, rhs_conv, lhs_core_type) >> cc_file |
|
219 } |
|
220 else |
|
221 { |
|
222 if (rhs_core_type) |
|
223 printf ("%s%s_CMP_OPS1 (%s, %s, %s, %s, %s)\n", |
|
224 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
225 rhs_type, rhs_conv, rhs_core_type) >> cc_file |
|
226 else |
|
227 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", |
|
228 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
229 rhs_type, rhs_conv) >> cc_file |
|
230 } |
|
231 } |
|
232 else |
|
233 printf ("%s%s_CMP_OPS (%s, %s, %s, %s)\n", |
|
234 lhs_class, rhs_class, lhs_type, lhs_conv, |
|
235 rhs_type, rhs_conv) >> cc_file |
|
236 } |
4544
|
237 |
|
238 if (bool_ops) |
5030
|
239 printf ("%s%s_BOOL_OPS2 (%s, %s, %s, %s)\n", lhs_class, rhs_class, |
|
240 lhs_type, rhs_type, lhs_scalar_zero_val, |
|
241 rhs_scalar_zero_val) >> cc_file |
4544
|
242 |
|
243 |
|
244 close (cc_file); |
|
245 } |
|
246 else |
|
247 printf ("skipping line %d: %s\n", NR, $0); |
|
248 } |
|
249 } |
|
250 END { |
|
251 if (make_inclusive_header) |
|
252 print "#endif"; |
4547
|
253 } |