]> git.ipfire.org Git - thirdparty/bird.git/blob - filter/decl.m4
Filter: Improved parse-time typechecks
[thirdparty/bird.git] / filter / decl.m4
1 m4_divert(-1)m4_dnl
2 #
3 # BIRD -- Construction of per-instruction structures
4 #
5 # (c) 2018 Maria Matejka <mq@jmq.cz>
6 #
7 # Can be freely distributed and used under the terms of the GNU GPL.
8 #
9 # THIS IS A M4 MACRO FILE GENERATING 3 FILES ALTOGETHER.
10 # KEEP YOUR HANDS OFF UNLESS YOU KNOW WHAT YOU'RE DOING.
11 # EDITING AND DEBUGGING THIS FILE MAY DAMAGE YOUR BRAIN SERIOUSLY.
12 #
13 # But you're welcome to read and edit and debug if you aren't scared.
14 #
15 # Uncomment the following line to get exhaustive debug output.
16 # m4_debugmode(aceflqtx)
17 #
18 # How it works:
19 # 1) Instruction to code conversion (uses diversions 100..199)
20 # 2) Code wrapping (uses diversions 1..99)
21 # 3) Final preparation (uses diversions 200..299)
22 # 4) Shipout
23 #
24 # See below for detailed description.
25 #
26 #
27 # 1) Instruction to code conversion
28 # The code provided in f-inst.c between consecutive INST() calls
29 # is interleaved for many different places. It is here processed
30 # and split into separate instances where split-by-instruction
31 # happens. These parts are stored in temporary diversions listed:
32 #
33 # 101 content of per-inst struct
34 # 102 constructor arguments
35 # 103 constructor body
36 # 104 dump line item content
37 # (there may be nothing in dump-line content and
38 # it must be handled specially in phase 2)
39 # 105 linearize body
40 # 106 comparator body
41 # 107 struct f_line_item content
42 # 108 interpreter body
43 #
44 # Here are macros to allow you to _divert to the right directions.
45 m4_define(FID_STRUCT_IN, `m4_divert(101)')
46 m4_define(FID_NEW_ARGS, `m4_divert(102)')
47 m4_define(FID_NEW_BODY, `m4_divert(103)')
48 m4_define(FID_DUMP_BODY, `m4_divert(104)m4_define([[FID_DUMP_BODY_EXISTS]])')
49 m4_define(FID_LINEARIZE_BODY, `m4_divert(105)')
50 m4_define(FID_SAME_BODY, `m4_divert(106)')
51 m4_define(FID_LINE_IN, `m4_divert(107)')
52 m4_define(FID_INTERPRET_BODY, `m4_divert(108)')
53
54 # Sometimes you want slightly different code versions in different
55 # outputs.
56 # Use FID_HIC(code for inst-gen.h, code for inst-gen.c, code for inst-interpret.c)
57 # and put it into [[ ]] quotes if it shall contain commas.
58 m4_define(FID_HIC, `m4_ifelse(TARGET, [[H]], [[$1]], TARGET, [[I]], [[$2]], TARGET, [[C]], [[$3]])')
59
60 # In interpreter code, this is quite common.
61 m4_define(FID_INTERPRET_EXEC, `FID_HIC(,[[FID_INTERPRET_BODY()]],[[m4_divert(-1)]])')
62 m4_define(FID_INTERPRET_NEW, `FID_HIC(,[[m4_divert(-1)]],[[FID_INTERPRET_BODY()]])')
63
64 # If the instruction is never converted to constant, the interpret
65 # code is not produced at all for constructor
66 m4_define(NEVER_CONSTANT, `m4_define([[INST_NEVER_CONSTANT]])')
67 m4_define(FID_IFCONST, `m4_ifdef([[INST_NEVER_CONSTANT]],[[$2]],[[$1]])')
68
69 # If the instruction has some attributes (here called members),
70 # these are typically carried with the instruction from constructor
71 # to interpreter. This yields a line of code everywhere on the path.
72 # FID_MEMBER is a macro to help with this task.
73 m4_define(FID_MEMBER, `m4_dnl
74 FID_LINE_IN()m4_dnl
75 $1 $2;
76 FID_STRUCT_IN()m4_dnl
77 $1 $2;
78 FID_NEW_ARGS()m4_dnl
79 , $1 $2
80 FID_NEW_BODY()m4_dnl
81 whati->$2 = $2;
82 FID_LINEARIZE_BODY()m4_dnl
83 item->$2 = whati->$2;
84 m4_ifelse($3,,,[[
85 FID_SAME_BODY()m4_dnl
86 if ($3) return 0;
87 ]])
88 m4_ifelse($4,,,[[
89 FID_DUMP_BODY()m4_dnl
90 debug("%s" $4 "\n", INDENT, $5);
91 ]])
92 FID_INTERPRET_EXEC()m4_dnl
93 const $1 $2 = whati->$2
94 FID_INTERPRET_BODY')
95
96 # Instruction arguments are needed only until linearization is done.
97 # This puts the arguments into the filter line to be executed before
98 # the instruction itself.
99 #
100 # To achieve this, ARG_ANY must be called before anything writes into
101 # the instruction line as it moves the instruction pointer forward.
102 m4_define(ARG_ANY, `
103 FID_STRUCT_IN()m4_dnl
104 struct f_inst * f$1;
105 FID_NEW_ARGS()m4_dnl
106 , struct f_inst * f$1
107 FID_NEW_BODY
108 whati->f$1 = f$1;
109 for (const struct f_inst *child = f$1; child; child = child->next) {
110 what->size += child->size;
111 FID_IFCONST([[
112 if (child->fi_code != FI_CONSTANT)
113 constargs = 0;
114 ]])
115 }
116 FID_LINEARIZE_BODY
117 pos = linearize(dest, whati->f$1, pos);
118 FID_INTERPRET_BODY()')
119
120 # Some instructions accept variable number of arguments.
121 m4_define(VARARG, `
122 FID_NEW_ARGS()m4_dnl
123 , struct f_inst * fvar
124 FID_STRUCT_IN()m4_dnl
125 struct f_inst * fvar;
126 uint varcount;
127 FID_LINE_IN()m4_dnl
128 uint varcount;
129 FID_NEW_BODY()m4_dnl
130 whati->varcount = 0;
131 whati->fvar = fvar;
132 for (const struct f_inst *child = fvar; child; child = child->next, whati->varcount++) {
133 what->size += child->size;
134 FID_IFCONST([[
135 if (child->fi_code != FI_CONSTANT)
136 constargs = 0;
137 ]])
138 }
139 FID_IFCONST([[
140 const struct f_inst **items = NULL;
141 if (constargs) {
142 items = alloca(whati->varcount * sizeof(struct f_inst *));
143 const struct f_inst *child = fvar;
144 for (uint i=0; child; i++)
145 child = (items[i] = child)->next;
146 }
147 ]])
148 FID_LINEARIZE_BODY()m4_dnl
149 pos = linearize(dest, whati->fvar, pos);
150 item->varcount = whati->varcount;
151 FID_DUMP_BODY()m4_dnl
152 debug("%snumber of varargs %u\n", INDENT, item->varcount);
153 FID_SAME_BODY()m4_dnl
154 if (f1->varcount != f2->varcount) return 0;
155 FID_INTERPRET_BODY()
156 FID_HIC(,[[
157 if (fstk->vcnt < whati->varcount) runtime("Stack underflow");
158 fstk->vcnt -= whati->varcount;
159 ]],)
160 ')
161
162 # Some arguments need to check their type. After that, ARG_ANY is called.
163 m4_define(ARG, `ARG_ANY($1) ARG_TYPE($1,$2)')
164 m4_define(ARG_TYPE, `
165 FID_NEW_BODY()m4_dnl
166 if (f$1->type && (f$1->type != ($2)))
167 cf_error("Argument $1 of instruction %s must be of type $2, got 0x%02x", f_instruction_name(what->fi_code), f$1->type);
168 FID_INTERPRET_EXEC()m4_dnl
169 if (v$1.type != ($2))
170 runtime("Argument $1 of instruction %s must be of type $2, got 0x%02x", f_instruction_name(what->fi_code), v$1.type)m4_dnl
171 FID_INTERPRET_BODY()')
172
173 # Executing another filter line. This replaces the recursion
174 # that was needed in the former implementation.
175 m4_define(LINEX, `FID_INTERPRET_EXEC()LINEX_($1)FID_INTERPRET_NEW()return $1 FID_INTERPRET_BODY()')
176 m4_define(LINEX_, `do {
177 fstk->estk[fstk->ecnt].pos = 0;
178 fstk->estk[fstk->ecnt].line = $1;
179 fstk->estk[fstk->ecnt].ventry = fstk->vcnt;
180 fstk->estk[fstk->ecnt].vbase = fstk->estk[fstk->ecnt-1].vbase;
181 fstk->estk[fstk->ecnt].emask = 0;
182 fstk->ecnt++;
183 } while (0)')
184
185 m4_define(LINE, `
186 FID_LINE_IN()m4_dnl
187 const struct f_line * fl$1;
188 FID_STRUCT_IN()m4_dnl
189 struct f_inst * f$1;
190 FID_NEW_ARGS()m4_dnl
191 , struct f_inst * f$1
192 FID_NEW_BODY()m4_dnl
193 whati->f$1 = f$1;
194 FID_DUMP_BODY()m4_dnl
195 f_dump_line(item->fl$1, indent + 1);
196 FID_LINEARIZE_BODY()m4_dnl
197 item->fl$1 = f_linearize(whati->f$1);
198 FID_SAME_BODY()m4_dnl
199 if (!f_same(f1->fl$1, f2->fl$1)) return 0;
200 FID_INTERPRET_EXEC()m4_dnl
201 do { if (whati->fl$1) {
202 LINEX_(whati->fl$1);
203 } } while(0)
204 FID_INTERPRET_NEW()m4_dnl
205 return whati->f$1
206 FID_INTERPRET_BODY()')
207
208 # Some of the instructions have a result. These constructions
209 # state the result and put it to the right place.
210 m4_define(RESULT, `RESULT_TYPE([[$1]]) RESULT_([[$1]],[[$2]],[[$3]])')
211 m4_define(RESULT_, `RESULT_VAL([[ (struct f_val) { .type = $1, .val.$2 = $3 } ]])')
212 m4_define(RESULT_VAL, `FID_HIC(, [[do { res = $1; fstk->vcnt++; } while (0)]],
213 [[return fi_constant(what, $1)]])')
214 m4_define(RESULT_VOID, `RESULT_VAL([[ (struct f_val) { .type = T_VOID } ]])')
215
216 m4_define(ERROR,
217 `m4_errprint(m4___file__:m4___line__: $*
218 )m4_m4exit(1)')
219
220 m4_define(RESULT_TYPE,
221 `m4_ifdef([[INST_RESULT_TYPE]],
222 [[m4_ifelse(INST_RESULT_TYPE,$1,,[[ERROR([[Multiple type definitons]])]])]],
223 [[m4_define(INST_RESULT_TYPE,$1) FID_NEW_BODY() what->type = $1;FID_INTERPRET_BODY()]])')
224
225 # Some common filter instruction members
226 m4_define(SYMBOL, `FID_MEMBER(struct symbol *, sym, [[strcmp(f1->sym->name, f2->sym->name) || (f1->sym->class != f2->sym->class)]], "symbol %s", item->sym->name)')
227 m4_define(RTC, `FID_MEMBER(struct rtable_config *, rtc, [[strcmp(f1->rtc->name, f2->rtc->name)]], "route table %s", item->rtc->name)')
228 m4_define(STATIC_ATTR, `FID_MEMBER(struct f_static_attr, sa, f1->sa.sa_code != f2->sa.sa_code,,)')
229 m4_define(DYNAMIC_ATTR, `FID_MEMBER(struct f_dynamic_attr, da, f1->da.ea_code != f2->da.ea_code,,)')
230 m4_define(ACCESS_RTE, `FID_HIC(,[[do { if (!fs->rte) runtime("No route to access"); } while (0)]],NEVER_CONSTANT())')
231
232 # 2) Code wrapping
233 # The code produced in 1xx temporary diversions is a raw code without
234 # any auxiliary commands and syntactical structures around. When the
235 # instruction is done, INST_FLUSH is called. More precisely, it is called
236 # at the beginning of INST() call and at the end of file.
237 #
238 # INST_FLUSH picks all the temporary diversions, wraps their content
239 # into appropriate headers and structures and saves them into global
240 # diversions listed:
241 #
242 # 4 enum fi_code
243 # 5 enum fi_code to string
244 # 6 dump line item
245 # 7 dump line item callers
246 # 8 linearize
247 # 9 same (filter comparator)
248 # 1 union in struct f_inst
249 # 3 constructors + interpreter
250 #
251 # These global diversions contain blocks of code that can be directly
252 # put into the final file, yet it still can't be written out now as
253 # every instruction writes to all of these diversions.
254
255 # Code wrapping diversion names. Here we want an explicit newline
256 # after the C comment.
257 m4_define(FID_ZONE, `m4_divert($1) /* $2 for INST_NAME() */
258 ')
259 m4_define(FID_INST, `FID_ZONE(1, Instruction structure for config)')
260 m4_define(FID_LINE, `FID_ZONE(2, Instruction structure for interpreter)')
261 m4_define(FID_NEW, `FID_ZONE(3, Constructor)')
262 m4_define(FID_ENUM, `FID_ZONE(4, Code enum)')
263 m4_define(FID_ENUM_STR, `FID_ZONE(5, Code enum to string)')
264 m4_define(FID_DUMP, `FID_ZONE(6, Dump line)')
265 m4_define(FID_DUMP_CALLER, `FID_ZONE(7, Dump line caller)')
266 m4_define(FID_LINEARIZE, `FID_ZONE(8, Linearize)')
267 m4_define(FID_SAME, `FID_ZONE(9, Comparison)')
268
269 # This macro does all the code wrapping. See inline comments.
270 m4_define(INST_FLUSH, `m4_ifdef([[INST_NAME]], [[
271 FID_ENUM()m4_dnl Contents of enum fi_code { ... }
272 INST_NAME(),
273 FID_ENUM_STR()m4_dnl Contents of const char * indexed by enum fi_code
274 [INST_NAME()] = "INST_NAME()",
275 FID_INST()m4_dnl Anonymous structure inside struct f_inst
276 struct {
277 m4_undivert(101)m4_dnl
278 } i_[[]]INST_NAME();
279 FID_LINE()m4_dnl Anonymous structure inside struct f_line_item
280 struct {
281 m4_undivert(107)m4_dnl
282 } i_[[]]INST_NAME();
283 FID_NEW()m4_dnl Constructor and interpreter code together
284 FID_HIC(
285 [[m4_dnl Public declaration of constructor in H file
286 struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
287 m4_undivert(102)m4_dnl
288 );]],
289 [[m4_dnl The one case in The Big Switch inside interpreter
290 case INST_NAME():
291 #define whati (&(what->i_]]INST_NAME()[[))
292 m4_ifelse(m4_eval(INST_INVAL() > 0), 1, [[if (fstk->vcnt < INST_INVAL()) runtime("Stack underflow"); fstk->vcnt -= INST_INVAL(); ]])
293 m4_undivert(108)m4_dnl
294 #undef whati
295 break;
296 ]],
297 [[m4_dnl Constructor itself
298 struct f_inst *f_new_inst_]]INST_NAME()[[(enum f_instruction_code fi_code
299 m4_undivert(102)m4_dnl
300 )
301 {
302 /* Allocate the structure */
303 struct f_inst *what = fi_new(fi_code);
304 FID_IFCONST([[uint constargs = 1;]])
305
306 /* Initialize all the members */
307 #define whati (&(what->i_]]INST_NAME()[[))
308 m4_undivert(103)m4_dnl
309
310 /* If not constant, return the instruction itself */
311 FID_IFCONST([[if (!constargs)]])
312 return what;
313
314 /* Try to pre-calculate the result */
315 FID_IFCONST([[m4_undivert(108)]])m4_dnl
316 #undef whati
317 }
318 ]])
319
320 FID_DUMP_CALLER()m4_dnl Case in another big switch used in instruction dumping (debug)
321 case INST_NAME(): f_dump_line_item_]]INST_NAME()[[(item, indent + 1); break;
322
323 FID_DUMP()m4_dnl The dumper itself
324 m4_ifdef([[FID_DUMP_BODY_EXISTS]],
325 [[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item_, const int indent)]],
326 [[static inline void f_dump_line_item_]]INST_NAME()[[(const struct f_line_item *item UNUSED, const int indent UNUSED)]])
327 m4_undefine([[FID_DUMP_BODY_EXISTS]])
328 {
329 #define item (&(item_->i_]]INST_NAME()[[))
330 m4_undivert(104)m4_dnl
331 #undef item
332 }
333
334 FID_LINEARIZE()m4_dnl The linearizer
335 case INST_NAME(): {
336 #define whati (&(what->i_]]INST_NAME()[[))
337 #define item (&(dest->items[pos].i_]]INST_NAME()[[))
338 m4_undivert(105)m4_dnl
339 #undef whati
340 #undef item
341 dest->items[pos].fi_code = what->fi_code;
342 dest->items[pos].lineno = what->lineno;
343 break;
344 }
345
346 FID_SAME()m4_dnl This code compares two f_line"s while reconfiguring
347 case INST_NAME():
348 #define f1 (&(f1_->i_]]INST_NAME()[[))
349 #define f2 (&(f2_->i_]]INST_NAME()[[))
350 m4_undivert(106)m4_dnl
351 #undef f1
352 #undef f2
353 break;
354
355 m4_divert(-1)FID_FLUSH(101,200)m4_dnl And finally this flushes all the unused diversions
356 ]])')
357
358 m4_define(INST, `m4_dnl This macro is called on beginning of each instruction.
359 INST_FLUSH()m4_dnl First, old data is flushed
360 m4_define([[INST_NAME]], [[$1]])m4_dnl Then we store instruction name,
361 m4_define([[INST_INVAL]], [[$2]])m4_dnl instruction input value count,
362 m4_undefine([[INST_NEVER_CONSTANT]])m4_dnl reset NEVER_CONSTANT trigger,
363 m4_undefine([[INST_RESULT_TYPE]])m4_dnl and reset RESULT_TYPE value.
364 FID_INTERPRET_BODY()m4_dnl By default, every code is interpreter code.
365 ')
366
367 # 3) Final preparation
368 #
369 # Now we prepare all the code around the global diversions.
370 # It must be here, not in m4wrap, as we want M4 to mark the code
371 # by #line directives correctly, not to claim that every single line
372 # is at the beginning of the m4wrap directive.
373 #
374 # This part is split by the final file.
375 # H for inst-gen.h
376 # I for inst-interpret.c
377 # C for inst-gen.c
378 #
379 # So we in cycle:
380 # A. open a diversion
381 # B. send there some code
382 # C. close that diversion
383 # D. flush a global diversion
384 # E. open another diversion and goto B.
385 #
386 # Final diversions
387 # 200+ completed text before it is flushed to output
388
389 # This is a list of output diversions
390 m4_define(FID_WR_PUT_LIST)
391
392 # This macro does the steps C to E, see before.
393 m4_define(FID_WR_PUT_ALSO, `m4_define([[FID_WR_PUT_LIST]],FID_WR_PUT_LIST()[[FID_WR_DPUT(]]FID_WR_DIDX[[)FID_WR_DPUT(]]$1[[)]])m4_define([[FID_WR_DIDX]],m4_eval(FID_WR_DIDX+1))m4_divert(FID_WR_DIDX)')
394
395 # These macros do the splitting between H/I/C
396 m4_define(FID_WR_DIRECT, `m4_ifelse(TARGET,[[$1]],[[FID_WR_INIT()]],[[FID_WR_STOP()]])')
397 m4_define(FID_WR_INIT, `m4_define([[FID_WR_DIDX]],200)m4_define([[FID_WR_PUT]],[[FID_WR_PUT_ALSO($]][[@)]])m4_divert(200)')
398 m4_define(FID_WR_STOP, `m4_define([[FID_WR_PUT]])m4_divert(-1)')
399
400 # Here is the direct code to be put into the output files
401 # together with the undiversions, being hidden under FID_WR_PUT()
402
403 m4_changequote([[,]])
404 FID_WR_DIRECT(I)
405 FID_WR_PUT(3)
406 FID_WR_DIRECT(C)
407
408 #if defined(__GNUC__) && __GNUC__ >= 6
409 #pragma GCC diagnostic push
410 #pragma GCC diagnostic ignored "-Wmisleading-indentation"
411 #endif
412
413 #include "nest/bird.h"
414 #include "filter/filter.h"
415 #include "filter/f-inst.h"
416
417 /* Instruction codes to string */
418 static const char * const f_instruction_name_str[] = {
419 FID_WR_PUT(5)
420 };
421
422 const char *
423 f_instruction_name(enum f_instruction_code fi)
424 {
425 if (fi < (sizeof(f_instruction_name_str) / sizeof(f_instruction_name_str[0])))
426 return f_instruction_name_str[fi];
427 else
428 bug("Got unknown instruction code: %d", fi);
429 }
430
431 static inline struct f_inst *
432 fi_new(enum f_instruction_code fi_code)
433 {
434 struct f_inst *what = cfg_allocz(sizeof(struct f_inst));
435 what->lineno = ifs->lino;
436 what->size = 1;
437 what->fi_code = fi_code;
438 return what;
439 }
440
441 static inline struct f_inst *
442 fi_constant(struct f_inst *what, struct f_val val)
443 {
444 what->fi_code = FI_CONSTANT;
445 what->i_FI_CONSTANT.val = val;
446 return what;
447 }
448
449 #define v1 whati->f1->i_FI_CONSTANT.val
450 #define v2 whati->f2->i_FI_CONSTANT.val
451 #define v3 whati->f3->i_FI_CONSTANT.val
452 #define vv(i) items[i]->i_FI_CONSTANT.val
453 #define runtime(fmt, ...) cf_error("filter preevaluation, line %d: " fmt, ifs->lino, ##__VA_ARGS__)
454 #define fpool cfg_mem
455 #define falloc(size) cfg_alloc(size)
456 /* Instruction constructors */
457 FID_WR_PUT(3)
458 #undef v1
459 #undef v2
460 #undef v3
461 #undef vv
462
463 /* Line dumpers */
464 #define INDENT (((const char *) f_dump_line_indent_str) + sizeof(f_dump_line_indent_str) - (indent) - 1)
465 static const char f_dump_line_indent_str[] = " ";
466
467 FID_WR_PUT(6)
468
469 void f_dump_line(const struct f_line *dest, uint indent)
470 {
471 if (!dest) {
472 debug("%sNo filter line (NULL)\n", INDENT);
473 return;
474 }
475 debug("%sFilter line %p (len=%u)\n", INDENT, dest, dest->len);
476 for (uint i=0; i<dest->len; i++) {
477 const struct f_line_item *item = &dest->items[i];
478 debug("%sInstruction %s at line %u\n", INDENT, f_instruction_name(item->fi_code), item->lineno);
479 switch (item->fi_code) {
480 FID_WR_PUT(7)
481 default: bug("Unknown instruction %x in f_dump_line", item->fi_code);
482 }
483 }
484 debug("%sFilter line %p dump done\n", INDENT, dest);
485 }
486
487 /* Linearize */
488 static uint
489 linearize(struct f_line *dest, const struct f_inst *what, uint pos)
490 {
491 for ( ; what; what = what->next) {
492 switch (what->fi_code) {
493 FID_WR_PUT(8)
494 }
495 pos++;
496 }
497 return pos;
498 }
499
500 struct f_line *
501 f_linearize_concat(const struct f_inst * const inst[], uint count)
502 {
503 uint len = 0;
504 for (uint i=0; i<count; i++)
505 for (const struct f_inst *what = inst[i]; what; what = what->next)
506 len += what->size;
507
508 struct f_line *out = cfg_allocz(sizeof(struct f_line) + sizeof(struct f_line_item)*len);
509
510 for (uint i=0; i<count; i++)
511 out->len = linearize(out, inst[i], out->len);
512
513 #if DEBUGGING
514 f_dump_line(out, 0);
515 #endif
516 return out;
517 }
518
519 /* Filter line comparison */
520 int
521 f_same(const struct f_line *fl1, const struct f_line *fl2)
522 {
523 if ((!fl1) && (!fl2))
524 return 1;
525 if ((!fl1) || (!fl2))
526 return 0;
527 if (fl1->len != fl2->len)
528 return 0;
529 for (uint i=0; i<fl1->len; i++) {
530 #define f1_ (&(fl1->items[i]))
531 #define f2_ (&(fl2->items[i]))
532 if (f1_->fi_code != f2_->fi_code)
533 return 0;
534 if (f1_->flags != f2_->flags)
535 return 0;
536
537 switch(f1_->fi_code) {
538 FID_WR_PUT(9)
539 }
540 }
541 #undef f1_
542 #undef f2_
543 return 1;
544 }
545
546 #if defined(__GNUC__) && __GNUC__ >= 6
547 #pragma GCC diagnostic pop
548 #endif
549
550 FID_WR_DIRECT(H)
551 /* Filter instruction codes */
552 enum f_instruction_code {
553 FID_WR_PUT(4)m4_dnl
554 } PACKED;
555
556 /* Filter instruction structure for config */
557 struct f_inst {
558 struct f_inst *next; /* Next instruction */
559 enum f_instruction_code fi_code; /* Instruction code */
560 enum f_type type; /* Type of returned value, if known */
561 int size; /* How many instructions are underneath */
562 int lineno; /* Line number */
563 union {
564 FID_WR_PUT(1)m4_dnl
565 };
566 };
567
568 /* Filter line item */
569 struct f_line_item {
570 enum f_instruction_code fi_code; /* What to do */
571 enum f_instruction_flags flags; /* Flags, instruction-specific */
572 uint lineno; /* Where */
573 union {
574 FID_WR_PUT(2)m4_dnl
575 };
576 };
577
578 /* Instruction constructors */
579 FID_WR_PUT(3)
580 m4_divert(-1)
581
582 # 4) Shipout
583 #
584 # Everything is prepared in FID_WR_PUT_LIST now. Let's go!
585
586 m4_changequote(`,')
587
588 # Flusher auxiliary macro
589 m4_define(FID_FLUSH, `m4_ifelse($1,$2,,[[m4_undivert($1)FID_FLUSH(m4_eval($1+1),$2)]])')
590
591 # Defining the macro used in FID_WR_PUT_LIST
592 m4_define(FID_WR_DPUT, `m4_undivert($1)')
593
594 # After the code is read and parsed, we:
595 m4_m4wrap(`INST_FLUSH()m4_divert(0)FID_WR_PUT_LIST()m4_divert(-1)FID_FLUSH(1,200)')
596
597 m4_changequote([[,]])
598 # And now M4 is going to parse f-inst.c, fill the diversions
599 # and after the file is done, the content of m4_m4wrap (see before)
600 # is executed.