-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.c
3278 lines (3115 loc) · 122 KB
/
gen.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
FILE NAME: gen.c
Copyright (C) 1997-2016 Vladimir Makarov.
Written by Vladimir Makarov <vmakarov@gcc.gnu.org>
This file is part of the tool NONA.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
TITLE: generator of NONA (machine description translator)
DESCRIPTION: This file generates interface and implementation file of
the code selector description.
SPECIAL CONSIDERATION:
The generator is to be called after NONA semantic analyzer only
if any error was not fixed.
Defining macro `NDEBUG' (e.g. by option `-D' in C compiler
command line) during the file compilation disables to fix
some internal errors of the generator.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* #ifdef HAVE_CONFIG_H */
#include <ctype.h>
#include <stdio.h>
#include "position.h"
#include "errors.h"
#include "common.h"
#include "ird.h"
#include "gen.h"
#include <assert.h>
/* This page contains functions which are used to output CS. These
function are used to fix output errors in time. All output of CS is
made only through these function. */
/* The following variable value is number of current line in the
interface file. */
static int current_interface_file_line;
/* The following variable value is number of current line in the
implementation file. */
static int current_implementation_file_line;
/* This function outputs string onto interface or implementation file
and fixes output errors. */
static void
output_string (FILE *f, const char *string)
{
for (; *string != '\0'; string++)
{
if (fputc (*string, f) == EOF)
{
if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else
{
assert (f == output_implementation_file);
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
}
}
if (*string == '\n')
{
if (f == output_interface_file)
current_interface_file_line++;
else
{
assert (f == output_implementation_file);
current_implementation_file_line++;
}
}
}
}
/* This function outputs character onto interface or implementation
file and fixes output errors. */
static void
output_char (int ch, FILE *f)
{
if (fputc (ch, f) == EOF)
{
if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else
{
assert (f == output_implementation_file);
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
}
}
if (ch == '\n')
{
if (f == output_interface_file)
current_interface_file_line++;
else
{
assert (f == output_implementation_file);
current_implementation_file_line++;
}
}
}
/* This function outputs integer number according to format `%d' onto
interface or implementation file and fixes output errors. */
static void
output_decimal_number (FILE *f, int number)
{
if (fprintf (f, "%d", number) == EOF)
{
if (f == output_interface_file)
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_interface_file_name);
else
{
assert (f == output_implementation_file);
system_error (TRUE, no_position, "fatal_error -- %s: ",
output_implementation_file_name);
}
}
}
/* ??? */
static void
initiate_output (void)
{
current_interface_file_line = 1;
current_implementation_file_line = 1;
output_interface_file = fopen (output_interface_file_name, "w");
if (output_interface_file == NULL)
system_error (TRUE, no_position,
"fatal error -- %s: ", output_interface_file_name);
output_implementation_file = fopen (output_implementation_file_name, "w");
if (output_implementation_file == NULL)
system_error (TRUE, no_position,
"fatal error -- %s: ", output_implementation_file_name);
}
/* This page contains functions which are used to output parameterized names
of CS objects. Usually the parameter is prefix given in NONA command
line (see commentaries for variable `prefix'). */
/* Base name of debug macro parameter used to separate debug code in
CS. Full name of the macro parameter is `__CS_DEBUG__' (see function
`output_ifdef_parameter_name'). */
#define DEBUG_PARAMETER_NAME "DEBUG"
/* This function outputs name of debug macro parameter used to
separate debug code in CS. The name is output as
`__<prefix>_<base_name>__' where prefix is value of variable
`prefix' and base name is value of the second parameter. */
static void
output_ifdef_parameter_name (FILE *f, const char *ifdef_parameter_name)
{
output_string (f, "__");
output_string (f, prefix);
output_char ('_', f);
output_string (f, ifdef_parameter_name);
output_string (f, "__");
}
/* ??? */
static void
output_nonterminal_name (FILE *f, const char *nonterminal_name)
{
output_string (f, prefix);
output_string (f, "NT");
output_char ('_', f);
output_string (f, nonterminal_name);
}
/* ??? */
static void
output_decode_nonterminal_rule_vector_name (FILE *f,
const char *nonterminal_name)
{
output_char ('_', f);
output_string (f, prefix);
output_char ('_', f);
output_string (f, nonterminal_name);
output_string (f, "_decode_rule_vector");
}
/* ??? */
static void
output_cs_node_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_NODE");
}
/* ??? */
static void
output_cs_node_type_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_node");
}
/* ??? */
static void
output_cs_operation_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_OPERATION");
}
/* ??? */
static void
output_cs_attribute_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_ATTRIBUTE");
}
/* ??? */
static void
output_cs_type_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_TYPE");
}
/* ??? */
static void
output_cs_error_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_ERROR");
}
/* ??? */
static void
output_cs_start_alloc_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_START_ALLOC");
}
/* ??? */
static void
output_cs_alloc_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_ALLOC");
}
/* ??? */
static void
output_cs_free_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_FREE");
}
/* ??? */
static void
output_cs_finish_alloc_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_FINISH_ALLOC");
}
/* ??? */
static void
output_operand_macro_name (FILE *f, int operand_number, int arity)
{
output_string (f, prefix);
output_string (f, "_OPERAND_");
output_decimal_number (f, operand_number);
output_string (f, "_OF_");
output_decimal_number (f, arity);
}
/* ??? */
static void
output_cs_state_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_STATE");
}
/* ??? */
static void
output_internal_state_macro_name (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_STATE");
}
/* ??? */
static void
output_cs_set_state_macro_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_SET_STATE");
}
/* ??? */
static void
output_cs_cover_type_name (FILE *f)
{
output_string (f, prefix);
output_string (f, "_cover");
}
/* ??? */
static void
output_state_struct_class_name (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_state");
}
/* ??? */
static void
output_cost_type_name (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_cost");
}
/* ??? */
static void
output_name_of_cs_closure_function (FILE *f, const char *nonterm_name)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_closure_");
output_string (f, nonterm_name);
}
/* ??? */
static void
output_name_of_cs_state_function (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_state_");
}
/* ??? */
static void
output_name_of_cs_print_state_function (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_print_node_state");
}
/* ??? */
static void
output_name_of_cs_find_cover_pass_function (FILE *f, int first_pass_flag)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_find_cover_pass_");
if (first_pass_flag)
output_char ('1', f);
else
output_char ('2', f);
}
/* ??? */
static void
output_name_of_cs_find_cover_function (FILE *f)
{
output_string (f, prefix);
output_string (f, "_find_cover");
}
/* ??? */
static void
output_name_of_cs_nonterminal_rule_function (FILE *f)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_nonterminal_rule");
}
/* ??? */
static void
output_name_of_cs_it_is_axiom_function (FILE *f)
{
output_string (f, prefix);
output_string (f, "_it_is_axiom");
}
/* ??? */
static void
output_name_of_cs_pass_of_traverse_cover_function (FILE *f,
int first_pass_flag)
{
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_traverse_cover_");
if (first_pass_flag)
output_char ('1', f);
else
output_char ('2', f);
}
/* ??? */
static void
output_name_of_cs_traverse_cover_function (FILE *f)
{
output_string (f, prefix);
output_string (f, "_traverse_cover");
}
/* ??? */
static void
output_name_of_cs_delete_cover_function (FILE *f, int internal_function_flag)
{
if (internal_function_flag)
output_char ('_', f);
output_string (f, prefix);
output_string (f, "_delete_cover");
}
/* ??? */
static void
output_name_of_cs_start_function (FILE *f)
{
output_string (f, prefix);
output_string (f, "_start");
}
/* ??? */
static void
output_name_of_cs_finish_function (FILE *f)
{
output_string (f, prefix);
output_string (f, "_finish");
}
/* This page contains functions for output of C preprocessors lines
(`#ifdef ...', `#ifndef ', `#endif ... ', and `#line ...'). */
/* This function outputs C preprocessor line `#ifdef ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_ifdef (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#ifdef ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_char ('\n', f);
}
/* This function outputs C preprocessor line `#ifndef ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_ifndef (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#ifndef ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_char ('\n', f);
}
/* This function outputs C preprocessor line `#endif ...' which
contains parameter with given base name (see function
`output_ifdef_parameter_name'). */
static void
output_endif (FILE *f, const char *ifdef_parameter_base_name)
{
output_string (f, "#endif /* ");
output_ifdef_parameter_name (f, ifdef_parameter_base_name);
output_string (f, " */\n");
}
/* This function outputs C preprocessor line `#line ...' which
contains given line number and given file name as C string
constant. */
static void
output_line (FILE *f, int line_number, const char *file_name)
{
output_string (f, "\n#line ");
output_decimal_number (f, line_number);
output_string (f, " \"");
output_string (f, file_name);
output_string (f, "\"\n");
}
/*???*/
static void
output_current_line (FILE *f)
{
output_string (f, "\n#line ");
if (f == output_interface_file)
{
output_decimal_number (f, current_interface_file_line + 1);
output_string (f, " \"");
output_string (f, output_interface_file_name);
}
else
{
assert (f == output_implementation_file);
output_decimal_number (f, current_implementation_file_line + 1);
output_string (f, " \"");
output_string (f, output_implementation_file_name);
}
output_string (f, "\"\n");
}
#define RESULT_ATTRIBUTE_NAME "result"
#define NONTERMINAL_ATTRIBUTE_PREFIX_NAME "nonterm_attr"
/*???*/
static void
output_pattern_access (IR_node_t pattern, const char *node_variable_name)
{
IR_node_t father;
IR_node_t current_pattern;
int operand_number;
father = IR_father (pattern);
if (father == NULL)
output_string (output_implementation_file, node_variable_name);
else
{
for (operand_number = 1, current_pattern = IR_pattern_list (father);
current_pattern != NULL && current_pattern != pattern;
current_pattern = IR_next_pattern (current_pattern))
operand_number++;
assert (current_pattern != NULL);
output_operand_macro_name
(output_implementation_file,
operand_number, IR_arity (IR_single_declaration (father)));
output_string (output_implementation_file, " (");
output_pattern_access (father, node_variable_name);
output_char (')', output_implementation_file);
}
}
/*???*/
static void
output_nonterm_attribute_variable_name (FILE *f, int nonterm_attribute_number)
{
output_string (f, NONTERMINAL_ATTRIBUTE_PREFIX_NAME);
output_char ('_', f);
output_decimal_number (f, nonterm_attribute_number);
}
static IR_node_t
find_pattern (IR_node_t textual_pattern_list, int number)
{
IR_node_t current_textual_pattern;
IR_node_t last_textual_pattern;
last_textual_pattern = textual_pattern_list;
assert (last_textual_pattern != NULL);
current_textual_pattern = last_textual_pattern;
do
{
current_textual_pattern
= IR_next_textual_pattern (current_textual_pattern);
if (number == IR_original_number (current_textual_pattern))
return current_textual_pattern;
}
while (current_textual_pattern != last_textual_pattern);
return NULL;
}
/*???*/
static void
output_attribute (FILE *f, IR_node_t rule, int attribute_number,
const char *node_variable_name)
{
IR_node_t pattern;
IR_node_t single_declaration;
if (attribute_number == 0)
{
single_declaration = IR_single_nonterm_declaration (rule);
output_string (output_implementation_file, RESULT_ATTRIBUTE_NAME);
}
else
{
assert (attribute_number >= 0);
pattern = find_pattern (IR_textual_pattern_list (rule),
attribute_number);
assert (pattern != NULL);
single_declaration = IR_single_declaration (pattern);
if (IR_IS_OF_TYPE (single_declaration, IR_NM_single_term_declaration))
{
output_cs_attribute_macro_name (output_implementation_file);
output_string (output_implementation_file, " (");
output_pattern_access (pattern, node_variable_name);
output_char (')', output_implementation_file);
}
else
{
assert (IR_IS_OF_TYPE (single_declaration,
IR_NM_single_nonterm_declaration));
output_nonterm_attribute_variable_name
(output_implementation_file,
IR_textual_nonterminal_pattern_number (pattern));
}
}
if (IR_type (single_declaration) != NULL)
{
output_char ('.', f);
output_string (output_implementation_file,
IR_identifier_itself (IR_type (single_declaration)));
}
}
/*???*/
static void
output_rule_code (FILE *f, string_t code, IR_node_t rule,
const char *node_variable_name)
{
assert (code != NULL);
/* !! This code is bound to scanner */
for (; *code != '\0'; code++)
switch (*code)
{
case '$':
if (code [1] == '$')
{
code++;
output_attribute (f, rule, 0, node_variable_name);
}
else if (isdigit (code [1]))
{
output_attribute (f, rule, atoi (code + 1), node_variable_name);
while (isdigit (code [1]))
code++;
}
else
output_char (*code, f);
break;
case '/':
output_char (*code, f);
if (code [1] == '*')
{
/* C comment. */
code++;
output_char (*code, f);
for (;;)
{
code++;
if (*code == '*')
{
output_char (*code, f);
code++;
if (*code == '/')
{
output_char (*code, f);
break;
}
else
{
code--;
continue;
}
}
else if (*code == '\0')
{
code--;
break;
}
else
output_char (*code, f);
}
}
break;
case '\'':
output_char (*code, f);
code++;
if (*code == '\0' || *code == '\n')
code--;
else if (*code != '\'')
{
if (*code == '\\')
{
output_char (*code, f);
code++;
if (*code == 'n' || *code == 't' || *code == 'v'
|| *code == 'b' || *code == 'r' || *code == 'f'
|| *code == '\\' || *code == '\'' || *code == '\"')
output_char (*code, f);
else if (*code == '\n')
output_char (*code, f);
else if (isdigit (*code) && *code != '8' && *code != '9')
{
output_char (*code, f);
if (isdigit (code [1]) && code [1] != '8'
&& code [1] != '9')
{
code++;
output_char (*code, f);
if (isdigit (code [1]) && code [1] != '8'
&& code [1] != '9')
{
code++;
output_char (*code, f);
}
}
}
else
code--;
}
else
output_char (*code, f);
}
else
output_char (*code, f);
if (code [1] == '\'')
{
code++;
output_char (*code, f);
}
break;
case '\"':
output_char (*code, f);
for (;;)
{
code++;
if (*code == '\"')
{
output_char (*code, f);
break;
}
else if (*code == '\0' || *code == '\n')
{
code--;
break;
}
else
{
if (*code == '\\')
{
output_char (*code, f);
code++;
if (*code == 'n' || *code == 't' || *code == 'v'
|| *code == 'b' || *code == 'r' || *code == 'f'
|| *code == '\\' || *code == '\'' || *code == '\"')
output_char (*code, f);
else if (*code == '\n')
output_char (*code, f);
else if (isdigit (*code) && *code != '8' && *code != '9')
{
output_char (*code, f);
if (isdigit (code [1]) && code [1] != '8'
&& code [1] != '9')
{
code++;
output_char (*code, f);
if (isdigit (code [1]) && code [1] != '8'
&& code [1] != '9')
{
code++;
output_char (*code, f);
}
}
}
else
code--;
}
else
output_char (*code, f);
}
}
break;
default:
output_char (*code, f);
break;
}
}
/*???*/
static void
output_start_code_insertions (void)
{
IR_node_t current_declaration;
if (IR_declaration_list (description) == NULL)
return;
for (current_declaration = IR_declaration_list (description);
current_declaration != NULL;
current_declaration = IR_next_declaration (current_declaration))
if (IR_IS_OF_TYPE (current_declaration, IR_NM_import_code))
{
output_line (output_interface_file,
IR_position (current_declaration).line_number,
IR_position (current_declaration).file_name);
output_string (output_interface_file,
IR_code_insertion_itself (IR_code_itself
(current_declaration)));
output_char ('\n', output_interface_file);
output_current_line (output_interface_file);
}
else if (IR_IS_OF_TYPE (current_declaration, IR_NM_local_code))
{
output_line (output_implementation_file,
IR_position (current_declaration).line_number,
IR_position (current_declaration).file_name);
output_string (output_implementation_file,
IR_code_insertion_itself (IR_code_itself
(current_declaration)));
output_char ('\n', output_implementation_file);
output_current_line (output_implementation_file);
}
}
/*???*/
static int
output_union (void)
{
IR_node_t current_declaration;
for (current_declaration = IR_declaration_list (description);
current_declaration != NULL;
current_declaration = IR_next_declaration (current_declaration))
if (IR_IS_OF_TYPE (current_declaration, IR_NM_union_code))
{
output_string (output_interface_file, "typedef union\n{");
output_line (output_interface_file,
IR_position (current_declaration).line_number,
IR_position (current_declaration).file_name);
output_string (output_interface_file,
IR_code_insertion_itself (IR_code_itself
(current_declaration)));
output_char ('\n', output_interface_file);
output_string (output_interface_file, "} ");
output_cs_type_macro_name (output_interface_file);
output_string (output_interface_file, ";\n");
output_current_line (output_interface_file);
return TRUE;
}
return FALSE;
}
/*???*/
static void
output_interface_file_macros (void)
{
/* Output definition of macro `CS_NODE'. */
output_string (output_interface_file, "#ifndef ");
output_cs_node_macro_name (output_interface_file);
output_string (output_interface_file, "\n#define ");
output_cs_node_macro_name (output_interface_file);
output_string (output_interface_file,
" struct IR_node_struct *\n#endif\n\n");
if (!output_union ())
{
/* Output definition of macro `CS_TYPE'. */
output_string (output_interface_file, "#ifndef ");
output_cs_type_macro_name (output_interface_file);
output_string (output_interface_file, "\n#define ");
output_cs_type_macro_name (output_interface_file);
output_string (output_interface_file, " ");
output_cs_node_type_name (output_interface_file);
output_string (output_interface_file, "\n#endif\n\n");
}
}
/*???*/
static int
it_is_new_arity_terminal (IR_node_t single_term_declaration)
{
IR_node_t current_single_declaration;
int terminal_arity;
assert (single_term_declaration != NULL);
terminal_arity = IR_arity (single_term_declaration);
for (current_single_declaration
= IR_next_single_declaration (IR_single_declaration_list (description));
single_term_declaration != current_single_declaration;
current_single_declaration
= IR_next_single_declaration (current_single_declaration))
if (IR_IS_OF_TYPE (current_single_declaration,
IR_NM_single_term_declaration)
&& IR_arity (current_single_declaration) == terminal_arity)
return FALSE;
return TRUE;
}
/*???*/
static void
output_cs_operand_macros (void)
{
IR_node_t current_single_declaration;
IR_node_t last_single_declaration;
int operand_number;
int terminal_arity;
last_single_declaration = IR_single_declaration_list (description);
if (last_single_declaration != NULL)
{
current_single_declaration = last_single_declaration;
do
{
current_single_declaration
= IR_next_single_declaration (current_single_declaration);
if (IR_IS_OF_TYPE (current_single_declaration,
IR_NM_single_term_declaration)
&& it_is_new_arity_terminal (current_single_declaration))
{
terminal_arity = IR_arity (current_single_declaration);
for (operand_number = 1;
operand_number <= terminal_arity;
operand_number++)
{
output_string (output_implementation_file, "#ifndef ");
output_operand_macro_name (output_implementation_file,
operand_number, terminal_arity);
output_string (output_implementation_file, "\n#define ");
output_operand_macro_name (output_implementation_file,
operand_number, terminal_arity);
output_string (output_implementation_file,
"(node) IR_operand");
if (terminal_arity > 1)
{
output_char ('_', output_implementation_file);
output_decimal_number (output_implementation_file,
operand_number);
}
output_string (output_implementation_file,
" (node)\n#endif\n\n");
}
}
}
while (current_single_declaration != last_single_declaration);
output_char ('\n', output_implementation_file);
}
}
/*???*/
static void
output_implementation_file_macros (void)
{
/* Output definition of macro `CS_OPERATION'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_operation_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_operation_macro_name (output_implementation_file);
output_string (output_implementation_file,
"(node) IR_NODE_MODE (node)\n#endif\n\n");
/* Output CS_OPERAND... macros. */
output_cs_operand_macros ();
/* Output definition of macro `CS_STATE'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_state_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_state_macro_name (output_implementation_file);
output_string (output_implementation_file,
"(node) IR_state (node)\n#endif\n\n");
/* Output definition of macro `CS_SET_STATE'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_set_state_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_set_state_macro_name (output_implementation_file);
output_string (output_implementation_file,
"(node, state) IR_set_state (node, state)\n#endif\n\n");
/* Output definition of macro `CS_ATTRIBUTE'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_attribute_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_attribute_macro_name (output_implementation_file);
output_string (output_implementation_file, "(node) (node)\n#endif\n\n");
/* Output definition of macro `CS_ERROR'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_error_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_error_macro_name (output_implementation_file);
output_string (output_implementation_file,
"(str) fprintf (stderr, \"%s\\n\", str)\n#endif\n\n");
/* Output definition of macro `CS_START_ALLOC'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_start_alloc_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_start_alloc_macro_name (output_implementation_file);
output_string (output_implementation_file, "()\n#endif\n\n");
/* Output definition of macro `CS_FINISH_ALLOC'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_finish_alloc_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_finish_alloc_macro_name (output_implementation_file);
output_string (output_implementation_file, "()\n#endif\n\n");
/* Output definition of macro `CS_ALLOC'. */
output_string (output_implementation_file, "#ifndef ");
output_cs_alloc_macro_name (output_implementation_file);
output_string (output_implementation_file, "\n#define ");
output_cs_alloc_macro_name (output_implementation_file);
output_string
(output_implementation_file,
"(ptr, size, ptr_type) ((ptr) = (ptr_type) malloc (size))\n#endif\n\n");
/* Output definition of macro `CS_FREE'. */