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