comparison liboctave/sparse-mk-ops.awk @ 5164:57077d0ddc8e

[project @ 2005-02-25 19:55:24 by jwe]
author jwe
date Fri, 25 Feb 2005 19:55:28 +0000
parents
children 0ce71beb1cf3
comparison
equal deleted inserted replaced
5163:9f3299378193 5164:57077d0ddc8e
1 BEGIN {
2 declare_types = 0;
3 generate_ops = 0;
4 ntypes = 0;
5 } {
6 if (NR == 1 && make_inclusive_header)
7 {
8 print "// DO NOT EDIT -- generated by sparse-mk-ops";
9 tmp = make_inclusive_header;
10 gsub (/[\.-]/, "_", tmp);
11 printf ("#if !defined (octave_%s)\n", tmp);
12 printf ("#define octave_%s 1\n", tmp);
13 }
14 }
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 } {
25 if (declare_types)
26 {
27 ntypes++;
28
29 if (NF == 6)
30 {
31 scalar_zero_val[ntypes] = $6;
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 >= 5)
45 {
46 result_tag_1 = $1;
47 result_tag_2 = $2;
48 lhs_tag = $3;
49 rhs_tag = $4;
50 op_type = $5;
51
52 bin_ops = index (op_type, "B") != 0;
53 cmp_ops = index (op_type, "C") != 0;
54 eqne_ops = index (op_type, "E") != 0;
55 bool_ops = index (op_type, "L") != 0;
56
57 n = 5;
58
59 lhs_conv = cmp_ops ? $(++n) : "";
60 rhs_conv = cmp_ops ? $(++n) : "";
61
62 if (lhs_conv == "NONE")
63 lhs_conv = "";
64
65 if (rhs_conv == "NONE")
66 rhs_conv = "";
67
68 k = 0
69 while (NF > n)
70 bool_headers[k++] = $(++n);
71
72 cc_file = sprintf ("%s-%s-%s.cc", prefix, lhs_tag, rhs_tag);
73 h_file = sprintf ("%s-%s-%s.h", prefix, lhs_tag, rhs_tag);
74
75 if (list_cc_files)
76 {
77 print cc_file;
78 next;
79 }
80
81 if (list_h_files)
82 {
83 print h_file;
84 next;
85 }
86
87 if (make_inclusive_header)
88 {
89 printf ("#include \"%s\"\n", h_file);
90 next;
91 }
92
93 h_guard = sprintf ("octave_%s_%s_%s_h", prefix, lhs_tag, rhs_tag);
94
95 result_num_1 = rev_tag[result_tag_1];
96 result_num_2 = rev_tag[result_tag_2];
97 lhs_num = rev_tag[lhs_tag];
98 rhs_num = rev_tag[rhs_tag];
99
100 result_type_1 = type[result_num_1];
101 result_type_2 = type[result_num_2];
102 lhs_type = type[lhs_num];
103 rhs_type = type[rhs_num];
104
105 result_scalar_zero_val_1 = scalar_zero_val[result_num_1];
106 result_scalar_zero_val_2 = scalar_zero_val[result_num_2];
107 lhs_scalar_zero_val = scalar_zero_val[lhs_num];
108 rhs_scalar_zero_val = scalar_zero_val[rhs_num];
109
110 result_header_1 = header[result_num_1];
111 result_header_2 = header[result_num_2];
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 sparse-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_1)
124 {
125 if (result_fwd_decl_ok)
126 printf ("class %s\n", result_type_1) >> h_file;
127 else
128 printf ("#include \"%s\"\n", result_header_1) >> h_file;
129 }
130
131 if (result_header_2 && ! (result_header_2 == result_header_1))
132 {
133 if (result_fwd_decl_ok)
134 printf ("class %s\n", result_type_2) >> h_file;
135 else
136 printf ("#include \"%s\"\n", result_header_2) >> h_file;
137 }
138
139 if (lhs_header && ! (lhs_header == result_header_1 || lhs_header == result_header_2))
140 {
141 if (result_fwd_decl_ok)
142 printf ("class %s\n", lhs_type) >> h_file;
143 else
144 printf ("#include \"%s\"\n", lhs_header) >> h_file;
145 }
146
147 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header_1 || rhs_header == result_header_2))
148 {
149 if (result_fwd_decl_ok)
150 printf ("class %s\n", rhs_type) >> h_file;
151 else
152 printf ("#include \"%s\"\n", rhs_header) >> h_file;
153 }
154
155 printf ("#include \"Sparse-op-defs.h\"\n") >> h_file;
156
157 if (bin_ops)
158 printf ("SPARSE_%s%s_BIN_OP_DECLS (%s, %s, %s, %s)\n", lhs_class,
159 rhs_class, result_type_1, result_type_2, lhs_type,
160 rhs_type) >> h_file
161
162 if (cmp_ops)
163 printf ("SPARSE_%s%s_CMP_OP_DECLS (%s, %s)\n", lhs_class,
164 rhs_class, lhs_type, rhs_type) >> h_file
165
166 if (eqne_ops)
167 printf ("SPARSE_%s%s_EQNE_OP_DECLS (%s, %s)\n", lhs_class,
168 rhs_class, lhs_type, rhs_type) >> h_file
169
170 if (bool_ops)
171 printf ("SPARSE_%s%s_BOOL_OP_DECLS (%s, %s)\n", lhs_class,
172 rhs_class, lhs_type, rhs_type) >> h_file
173
174
175 print "#endif" >> h_file;
176
177 close (h_file);
178
179
180 print "// DO NOT EDIT -- generated by sparse-mk-ops" > cc_file;
181
182 ## print "#ifdef HAVE_CONFIG_H" >> cc_file;
183 print "#include <config.h>" >> cc_file;
184 ## print "#endif" >> cc_file;
185
186 print "#include \"Array-util.h\"" >> cc_file;
187 print "#include \"quit.h\"" >> cc_file;
188
189 printf ("#include \"%s\"\n", h_file) >> cc_file;
190
191 for (i in bool_headers)
192 {
193 printf ("#include \"%s\"\n", bool_headers[i]) >> cc_file;
194 delete bool_headers[i];
195 }
196
197 if (result_header_1)
198 printf ("#include \"%s\"\n", result_header_1) >> cc_file;
199
200 if (result_header_2 && ! (result_header_2 == result_header_1))
201 printf ("#include \"%s\"\n", result_header_2) >> cc_file;
202
203 if (lhs_header && ! (lhs_header == result_header_1 || lhs_header == result_header_2))
204 printf ("#include \"%s\"\n", lhs_header) >> cc_file;
205
206 if (rhs_header && ! (rhs_header == lhs_header || rhs_header == result_header_1 || rhs_heaer == result_header_2))
207 printf ("#include \"%s\"\n", rhs_header) >> cc_file;
208
209 if (bin_ops)
210 printf ("SPARSE_%s%s_BIN_OPS (%s, %s, %s, %s)\n", lhs_class,
211 rhs_class, result_type_1, result_type_2, lhs_type,
212 rhs_type) >> cc_file
213
214 if (cmp_ops)
215 printf ("SPARSE_%s%s_CMP_OPS (%s, %s, %s, %s, %s, %s)\n",
216 lhs_class, rhs_class, lhs_type, lhs_scalar_zero_val,
217 lhs_conv, rhs_type, rhs_scalar_zero_val, rhs_conv) >> cc_file
218
219 if (eqne_ops)
220 printf ("SPARSE_%s%s_EQNE_OPS (%s, %s, %s, %s, %s, %s)\n",
221 lhs_class, rhs_class, lhs_type, lhs_scalar_zero_val,
222 lhs_conv, rhs_type, rhs_scalar_zero_val, rhs_conv) >> cc_file
223
224 if (bool_ops)
225 printf ("SPARSE_%s%s_BOOL_OPS2 (%s, %s, %s, %s)\n", lhs_class,
226 rhs_class, lhs_type, rhs_type, lhs_scalar_zero_val,
227 rhs_scalar_zero_val) >> cc_file
228
229
230 close (cc_file);
231 }
232 else
233 printf ("skipping line %d: %s\n", NR, $0);
234 }
235 }
236 END {
237 if (make_inclusive_header)
238 print "#endif";
239 }