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