1 /* Output Go language descriptions of types.
2 Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3 Written by Ian Lance Taylor <iant@google.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 /* This file is used during the build process to emit Go language
22 descriptions of declarations from C header files. It uses the
23 debug info hooks to emit the descriptions. The Go language
24 descriptions then become part of the Go runtime support
27 All global names are output with a leading underscore, so that they
28 are all hidden in Go. */
32 #include "coretypes.h"
33 #include "diagnostic-core.h"
36 #include "pointer-set.h"
40 /* We dump this information from the debug hooks. This gives us a
41 stable and maintainable API to hook into. In order to work
42 correctly when -g is used, we build our own hooks structure which
43 wraps the hooks we need to change. */
45 /* Our debug hooks. This is initialized by dump_go_spec_init. */
47 static struct gcc_debug_hooks go_debug_hooks
;
49 /* The real debug hooks. */
51 static const struct gcc_debug_hooks
*real_debug_hooks
;
53 /* The file where we should write information. */
55 static FILE *go_dump_file
;
57 /* A queue of decls to output. */
59 static GTY(()) VEC(tree
,gc
) *queue
;
61 /* A hash table of macros we have seen. */
63 static htab_t macro_hash
;
65 /* For the hash tables. */
68 string_hash_eq (const void *y1
, const void *y2
)
70 return strcmp ((const char *) y1
, (const char *) y2
) == 0;
73 /* A macro definition. */
76 go_define (unsigned int lineno
, const char *buffer
)
88 real_debug_hooks
->define (lineno
, buffer
);
90 /* Skip macro functions. */
91 for (p
= buffer
; *p
!= '\0' && *p
!= ' '; ++p
)
104 copy
= XNEWVEC (char, name_end
- buffer
+ 1);
105 memcpy (copy
, buffer
, name_end
- buffer
);
106 copy
[name_end
- buffer
] = '\0';
108 hashval
= htab_hash_string (copy
);
109 slot
= htab_find_slot_with_hash (macro_hash
, copy
, hashval
, NO_INSERT
);
116 /* For simplicity, we force all names to be hidden by adding an
117 initial underscore, and let the user undo this as needed. */
118 out_buffer
= XNEWVEC (char, strlen (p
) * 2 + 1);
121 need_operand
= false;
126 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
127 case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
128 case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
129 case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
131 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
132 case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
133 case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
134 case 's': case 't': case 'u': case 'v': case 'w': case 'x':
138 /* The start of an identifier. Technically we should also
139 worry about UTF-8 identifiers, but they are not a
140 problem for practical uses of -fdump-go-spec so we
141 don't worry about them. */
149 while (ISALNUM (*p
) || *p
== '_')
151 n
= XALLOCAVEC (char, p
- start
+ 1);
152 memcpy (n
, start
, p
- start
);
154 slot
= htab_find_slot (macro_hash
, n
, NO_INSERT
);
155 if (slot
== NULL
|| *slot
== NULL
)
157 /* This is a reference to a name which was not defined
163 memcpy (q
, start
, p
- start
);
167 need_operand
= false;
175 case '0': case '1': case '2': case '3': case '4':
176 case '5': case '6': case '7': case '8': case '9':
183 if (*p
== '0' && (p
[1] == 'x' || p
[1] == 'X'))
188 while (ISDIGIT (*p
) || *p
== '.' || *p
== 'e' || *p
== 'E'
190 && ((*p
>= 'a' && *p
<= 'f')
191 || (*p
>= 'A' && *p
<= 'F'))))
193 memcpy (q
, start
, p
- start
);
195 while (*p
== 'u' || *p
== 'U' || *p
== 'l' || *p
== 'L'
196 || *p
== 'f' || *p
== 'F'
197 || *p
== 'd' || *p
== 'D')
199 /* Go doesn't use any of these trailing type
204 /* We'll pick up the exponent, if any, as an
208 need_operand
= false;
217 /* Always OK, not part of an operand, presumed to start an
221 need_operand
= false;
225 /* OK if we don't need an operand, and presumed to indicate
234 /* Always OK, but not part of an operand. */
239 case '*': case '/': case '%': case '|': case '&': case '^':
240 /* Must be a binary operator. */
252 /* Must be a binary operator. */
264 /* Must be a binary operator. */
273 /* Must be a unary operator. */
281 /* Must be a binary operand, may be << or >> or <= or >=. */
285 if (*p
== *(p
- 1) || *p
== '=')
292 /* Must be a unary operand, must be translated for Go. */
325 case '0': case '1': case '2': case '3':
326 case '4': case '5': case '6': case '7':
328 while (*p
>= '0' && *p
<= '7')
333 /* Go octal characters are always 3
342 while (ISXDIGIT (*p
))
347 /* Go hex characters are always 2 digits. */
352 case 'a': case 'b': case 'f': case 'n': case 'r':
353 case 't': case 'v': case '\\': case '\'': case '"':
375 slot
= htab_find_slot_with_hash (macro_hash
, copy
, hashval
, INSERT
);
378 fprintf (go_dump_file
, "const _%s = %s\n", copy
, out_buffer
);
380 XDELETEVEC (out_buffer
);
384 fprintf (go_dump_file
, "// unknowndefine %s\n", buffer
);
385 XDELETEVEC (out_buffer
);
392 go_undef (unsigned int lineno
, const char *buffer
)
396 real_debug_hooks
->undef (lineno
, buffer
);
398 slot
= htab_find_slot (macro_hash
, buffer
, NO_INSERT
);
401 fprintf (go_dump_file
, "// undef _%s\n", buffer
);
402 /* We don't delete the slot from the hash table because that will
403 cause a duplicate const definition. */
406 /* A function or variable decl. */
411 if (!TREE_PUBLIC (decl
)
412 || DECL_IS_BUILTIN (decl
)
413 || DECL_NAME (decl
) == NULL_TREE
)
415 VEC_safe_push (tree
, gc
, queue
, decl
);
418 /* A function decl. */
421 go_function_decl (tree decl
)
423 real_debug_hooks
->function_decl (decl
);
427 /* A global variable decl. */
430 go_global_decl (tree decl
)
432 real_debug_hooks
->global_decl (decl
);
436 /* A type declaration. */
439 go_type_decl (tree decl
, int local
)
441 real_debug_hooks
->type_decl (decl
, local
);
443 if (local
|| DECL_IS_BUILTIN (decl
))
445 if (DECL_NAME (decl
) == NULL_TREE
446 && (TYPE_NAME (TREE_TYPE (decl
)) == NULL_TREE
447 || TREE_CODE (TYPE_NAME (TREE_TYPE (decl
))) != IDENTIFIER_NODE
)
448 && TREE_CODE (TREE_TYPE (decl
)) != ENUMERAL_TYPE
)
450 VEC_safe_push (tree
, gc
, queue
, decl
);
453 /* A container for the data we pass around when generating information
454 at the end of the compilation. */
456 struct godump_container
458 /* DECLs that we have already seen. */
459 struct pointer_set_t
*decls_seen
;
461 /* Types which may potentially have to be defined as dummy
463 struct pointer_set_t
*pot_dummy_types
;
468 /* Global type definitions. */
474 /* Obstack used to write out a type definition. */
475 struct obstack type_obstack
;
478 /* Append an IDENTIFIER_NODE to OB. */
481 go_append_string (struct obstack
*ob
, tree id
)
483 obstack_grow (ob
, IDENTIFIER_POINTER (id
), IDENTIFIER_LENGTH (id
));
486 /* Write the Go version of TYPE to CONTAINER->TYPE_OBSTACK.
487 USE_TYPE_NAME is true if we can simply use a type name here without
488 needing to define it. IS_FUNC_OK is true if we can output a func
489 type here; the "func" keyword will already have been added. Return
490 true if the type can be represented in Go, false otherwise. */
493 go_format_type (struct godump_container
*container
, tree type
,
494 bool use_type_name
, bool is_func_ok
)
500 ob
= &container
->type_obstack
;
502 if (TYPE_NAME (type
) != NULL_TREE
503 && (pointer_set_contains (container
->decls_seen
, type
)
504 || pointer_set_contains (container
->decls_seen
, TYPE_NAME (type
)))
505 && (AGGREGATE_TYPE_P (type
)
506 || POINTER_TYPE_P (type
)
507 || TREE_CODE (type
) == FUNCTION_TYPE
))
512 name
= TYPE_NAME (type
);
513 if (TREE_CODE (name
) == TYPE_DECL
)
514 name
= DECL_NAME (name
);
516 slot
= htab_find_slot (container
->invalid_hash
, IDENTIFIER_POINTER (name
),
521 obstack_1grow (ob
, '_');
522 go_append_string (ob
, name
);
526 pointer_set_insert (container
->decls_seen
, type
);
528 switch (TREE_CODE (type
))
531 obstack_grow (ob
, "int", 3);
538 slot
= htab_find_slot (container
->invalid_hash
,
539 IDENTIFIER_POINTER (DECL_NAME (type
)),
544 obstack_1grow (ob
, '_');
545 go_append_string (ob
, DECL_NAME (type
));
554 switch (TYPE_PRECISION (type
))
557 s
= TYPE_UNSIGNED (type
) ? "uint8" : "int8";
560 s
= TYPE_UNSIGNED (type
) ? "uint16" : "int16";
563 s
= TYPE_UNSIGNED (type
) ? "uint32" : "int32";
566 s
= TYPE_UNSIGNED (type
) ? "uint64" : "int64";
569 snprintf (buf
, sizeof buf
, "INVALID-int-%u%s",
570 TYPE_PRECISION (type
),
571 TYPE_UNSIGNED (type
) ? "u" : "");
576 obstack_grow (ob
, s
, strlen (s
));
585 switch (TYPE_PRECISION (type
))
594 snprintf (buf
, sizeof buf
, "INVALID-float-%u",
595 TYPE_PRECISION (type
));
600 obstack_grow (ob
, s
, strlen (s
));
605 obstack_grow (ob
, "bool", 4);
610 && TYPE_NAME (TREE_TYPE (type
)) != NULL_TREE
611 && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
))
612 || (POINTER_TYPE_P (TREE_TYPE (type
))
613 && (TREE_CODE (TREE_TYPE (TREE_TYPE (type
)))
619 name
= TYPE_NAME (TREE_TYPE (type
));
620 if (TREE_CODE (name
) == TYPE_DECL
)
621 name
= DECL_NAME (name
);
623 slot
= htab_find_slot (container
->invalid_hash
,
624 IDENTIFIER_POINTER (name
), NO_INSERT
);
628 obstack_grow (ob
, "*_", 2);
629 go_append_string (ob
, name
);
631 /* The pointer here can be used without the struct or union
632 definition. So this struct or union is a potential dummy
634 if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (type
)))
635 pointer_set_insert (container
->pot_dummy_types
,
636 IDENTIFIER_POINTER (name
));
640 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
641 obstack_grow (ob
, "func", 4);
643 obstack_1grow (ob
, '*');
644 if (VOID_TYPE_P (TREE_TYPE (type
)))
645 obstack_grow (ob
, "byte", 4);
648 if (!go_format_type (container
, TREE_TYPE (type
), use_type_name
,
655 obstack_1grow (ob
, '[');
656 if (TYPE_DOMAIN (type
) != NULL_TREE
657 && TREE_CODE (TYPE_DOMAIN (type
)) == INTEGER_TYPE
658 && TYPE_MIN_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
659 && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))) == INTEGER_CST
660 && tree_int_cst_sgn (TYPE_MIN_VALUE (TYPE_DOMAIN (type
))) == 0
661 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != NULL_TREE
662 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) == INTEGER_CST
663 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0))
667 snprintf (buf
, sizeof buf
, HOST_WIDE_INT_PRINT_DEC
"+1",
668 tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0));
669 obstack_grow (ob
, buf
, strlen (buf
));
671 obstack_1grow (ob
, ']');
672 if (!go_format_type (container
, TREE_TYPE (type
), use_type_name
, false))
682 obstack_grow (ob
, "struct { ", 9);
684 for (field
= TYPE_FIELDS (type
);
686 field
= TREE_CHAIN (field
))
688 struct obstack hold_type_obstack
;
691 if (TREE_CODE (type
) == UNION_TYPE
)
693 hold_type_obstack
= container
->type_obstack
;
694 obstack_init (&container
->type_obstack
);
699 if (DECL_NAME (field
) == NULL
)
703 obstack_grow (ob
, "Godump_", 2);
704 snprintf (buf
, sizeof buf
, "%d", i
);
705 obstack_grow (ob
, buf
, strlen (buf
));
710 const char *var_name
;
713 /* Start variable name with an underscore if a keyword. */
714 var_name
= IDENTIFIER_POINTER (DECL_NAME (field
));
715 slot
= htab_find_slot (container
->keyword_hash
, var_name
,
718 obstack_1grow (ob
, '_');
719 go_append_string (ob
, DECL_NAME (field
));
721 obstack_1grow (ob
, ' ');
722 if (DECL_BIT_FIELD (field
))
724 obstack_grow (ob
, "INVALID-bit-field", 17);
729 /* Do not expand type if a record or union type or a
731 if (TYPE_NAME (TREE_TYPE (field
)) != NULL_TREE
732 && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field
))
733 || (POINTER_TYPE_P (TREE_TYPE (field
))
734 && (TREE_CODE (TREE_TYPE (TREE_TYPE (field
)))
740 name
= TYPE_NAME (TREE_TYPE (field
));
741 if (TREE_CODE (name
) == TYPE_DECL
)
742 name
= DECL_NAME (name
);
744 slot
= htab_find_slot (container
->invalid_hash
,
745 IDENTIFIER_POINTER (name
),
750 obstack_1grow (ob
, '_');
751 go_append_string (ob
, name
);
755 if (!go_format_type (container
, TREE_TYPE (field
), true,
760 obstack_grow (ob
, "; ", 2);
762 /* Only output the first successful field of a union, and
763 hope for the best. */
764 if (TREE_CODE (type
) == UNION_TYPE
)
766 if (!field_ok
&& TREE_CHAIN (field
) == NULL_TREE
)
775 sz
= obstack_object_size (&container
->type_obstack
);
776 obstack_grow (&hold_type_obstack
,
777 obstack_base (&container
->type_obstack
),
780 obstack_free (&container
->type_obstack
, NULL
);
781 container
->type_obstack
= hold_type_obstack
;
791 obstack_1grow (ob
, '}');
800 function_args_iterator iter
;
803 /* Go has no way to write a type which is a function but not a
804 pointer to a function. */
807 obstack_grow (ob
, "func*", 5);
811 obstack_1grow (ob
, '(');
812 is_varargs
= stdarg_p (type
);
814 FOREACH_FUNCTION_ARGS (type
, arg_type
, iter
)
816 if (VOID_TYPE_P (arg_type
))
819 obstack_grow (ob
, ", ", 2);
820 if (!go_format_type (container
, arg_type
, true, false))
826 if (prototype_p (type
))
827 obstack_grow (ob
, ", ", 2);
828 obstack_grow (ob
, "...interface{}", 14);
830 obstack_1grow (ob
, ')');
832 result
= TREE_TYPE (type
);
833 if (!VOID_TYPE_P (result
))
835 obstack_1grow (ob
, ' ');
836 if (!go_format_type (container
, result
, use_type_name
, false))
843 obstack_grow (ob
, "INVALID-type", 12);
851 /* Output the type which was built on the type obstack, and then free
855 go_output_type (struct godump_container
*container
)
859 ob
= &container
->type_obstack
;
860 obstack_1grow (ob
, '\0');
861 fputs (obstack_base (ob
), go_dump_file
);
862 obstack_free (ob
, obstack_base (ob
));
865 /* Output a function declaration. */
868 go_output_fndecl (struct godump_container
*container
, tree decl
)
870 if (!go_format_type (container
, TREE_TYPE (decl
), false, true))
871 fprintf (go_dump_file
, "// ");
872 fprintf (go_dump_file
, "func _%s ",
873 IDENTIFIER_POINTER (DECL_NAME (decl
)));
874 go_output_type (container
);
875 fprintf (go_dump_file
, " __asm__(\"%s\")\n",
876 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
879 /* Output a typedef or something like a struct definition. */
882 go_output_typedef (struct godump_container
*container
, tree decl
)
884 /* If we have an enum type, output the enum constants
886 if (TREE_CODE (TREE_TYPE (decl
)) == ENUMERAL_TYPE
887 && TYPE_SIZE (TREE_TYPE (decl
)) != 0
888 && !pointer_set_contains (container
->decls_seen
, TREE_TYPE (decl
))
889 && (TYPE_CANONICAL (TREE_TYPE (decl
)) == NULL_TREE
890 || !pointer_set_contains (container
->decls_seen
,
891 TYPE_CANONICAL (TREE_TYPE (decl
)))))
895 for (element
= TYPE_VALUES (TREE_TYPE (decl
));
896 element
!= NULL_TREE
;
897 element
= TREE_CHAIN (element
))
902 name
= IDENTIFIER_POINTER (TREE_PURPOSE (element
));
904 /* Sometimes a name will be defined as both an enum constant
905 and a macro. Avoid duplicate definition errors by
906 treating enum constants as macros. */
907 slot
= htab_find_slot (macro_hash
, name
, INSERT
);
910 *slot
= CONST_CAST (char *, name
);
911 fprintf (go_dump_file
,
912 "const _%s = " HOST_WIDE_INT_PRINT_DEC
"\n",
913 name
, tree_low_cst (TREE_VALUE (element
), 0));
916 pointer_set_insert (container
->decls_seen
, TREE_TYPE (decl
));
917 if (TYPE_CANONICAL (TREE_TYPE (decl
)) != NULL_TREE
)
918 pointer_set_insert (container
->decls_seen
,
919 TYPE_CANONICAL (TREE_TYPE (decl
)));
922 if (DECL_NAME (decl
) != NULL_TREE
)
927 type
= IDENTIFIER_POINTER (DECL_NAME (decl
));
928 /* If type defined already, skip. */
929 slot
= htab_find_slot (container
->type_hash
, type
, INSERT
);
932 *slot
= CONST_CAST (void *, (const void *) type
);
934 if (!go_format_type (container
, TREE_TYPE (decl
), false, false))
936 fprintf (go_dump_file
, "// ");
937 slot
= htab_find_slot (container
->invalid_hash
, type
, INSERT
);
938 *slot
= CONST_CAST (void *, (const void *) type
);
940 fprintf (go_dump_file
, "type _%s ",
941 IDENTIFIER_POINTER (DECL_NAME (decl
)));
942 go_output_type (container
);
943 pointer_set_insert (container
->decls_seen
, decl
);
945 else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
)))
950 type
= IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE ((decl
))));
951 /* If type defined already, skip. */
952 slot
= htab_find_slot (container
->type_hash
, type
, INSERT
);
955 *slot
= CONST_CAST (void *, (const void *) type
);
957 if (!go_format_type (container
, TREE_TYPE (decl
), false, false))
959 fprintf (go_dump_file
, "// ");
960 slot
= htab_find_slot (container
->invalid_hash
, type
, INSERT
);
961 *slot
= CONST_CAST (void *, (const void *) type
);
963 fprintf (go_dump_file
, "type _%s ",
964 IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl
))));
965 go_output_type (container
);
970 fprintf (go_dump_file
, "\n");
973 /* Output a variable. */
976 go_output_var (struct godump_container
*container
, tree decl
)
980 if (pointer_set_contains (container
->decls_seen
, decl
)
981 || pointer_set_contains (container
->decls_seen
, DECL_NAME (decl
)))
983 pointer_set_insert (container
->decls_seen
, decl
);
984 pointer_set_insert (container
->decls_seen
, DECL_NAME (decl
));
986 is_valid
= go_format_type (container
, TREE_TYPE (decl
), true, false);
988 && htab_find_slot (container
->type_hash
,
989 IDENTIFIER_POINTER (DECL_NAME (decl
)),
992 /* There is already a type with this name, probably from a
993 struct tag. Prefer the type to the variable. */
997 fprintf (go_dump_file
, "// ");
999 fprintf (go_dump_file
, "var _%s ",
1000 IDENTIFIER_POINTER (DECL_NAME (decl
)));
1001 go_output_type (container
);
1002 fprintf (go_dump_file
, "\n");
1004 /* Sometimes an extern variable is declared with an unknown struct
1006 if (TYPE_NAME (TREE_TYPE (decl
)) != NULL_TREE
1007 && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl
)))
1009 tree type_name
= TYPE_NAME (TREE_TYPE (decl
));
1010 if (TREE_CODE (type_name
) == IDENTIFIER_NODE
)
1011 pointer_set_insert (container
->pot_dummy_types
,
1012 IDENTIFIER_POINTER (type_name
));
1013 else if (TREE_CODE (type_name
) == TYPE_DECL
)
1014 pointer_set_insert (container
->pot_dummy_types
,
1015 IDENTIFIER_POINTER (DECL_NAME (type_name
)));
1019 /* Build a hash table with the Go keywords. */
1021 static const char * const keywords
[] = {
1022 "__asm__", "break", "case", "chan", "const", "continue", "default",
1023 "defer", "else", "fallthrough", "for", "func", "go", "goto", "if",
1024 "import", "interface", "map", "package", "range", "return", "select",
1025 "struct", "switch", "type", "var"
1029 keyword_hash_init (struct godump_container
*container
)
1032 size_t count
= sizeof (keywords
) / sizeof (keywords
[0]);
1035 for (i
= 0; i
< count
; i
++)
1037 slot
= htab_find_slot (container
->keyword_hash
, keywords
[i
], INSERT
);
1038 *slot
= CONST_CAST (void *, (const void *) keywords
[i
]);
1042 /* Traversing the pot_dummy_types and seeing which types are present
1043 in the global types hash table and creating dummy definitions if
1044 not found. This function is invoked by pointer_set_traverse. */
1047 find_dummy_types (const void *ptr
, void *adata
)
1049 struct godump_container
*data
= (struct godump_container
*) adata
;
1050 const char *type
= (const char *) ptr
;
1053 slot
= htab_find_slot (data
->type_hash
, type
, NO_INSERT
);
1055 fprintf (go_dump_file
, "type _%s struct {}\n", type
);
1059 /* Output symbols. */
1062 go_finish (const char *filename
)
1064 struct godump_container container
;
1068 real_debug_hooks
->finish (filename
);
1070 container
.decls_seen
= pointer_set_create ();
1071 container
.pot_dummy_types
= pointer_set_create ();
1072 container
.type_hash
= htab_create (100, htab_hash_string
,
1073 string_hash_eq
, NULL
);
1074 container
.invalid_hash
= htab_create (10, htab_hash_string
,
1075 string_hash_eq
, NULL
);
1076 container
.keyword_hash
= htab_create (50, htab_hash_string
,
1077 string_hash_eq
, NULL
);
1078 obstack_init (&container
.type_obstack
);
1080 keyword_hash_init (&container
);
1082 FOR_EACH_VEC_ELT (tree
, queue
, ix
, decl
)
1084 switch (TREE_CODE (decl
))
1087 go_output_fndecl (&container
, decl
);
1091 go_output_typedef (&container
, decl
);
1095 go_output_var (&container
, decl
);
1103 /* To emit dummy definitions. */
1104 pointer_set_traverse (container
.pot_dummy_types
, find_dummy_types
,
1105 (void *) &container
);
1107 pointer_set_destroy (container
.decls_seen
);
1108 pointer_set_destroy (container
.pot_dummy_types
);
1109 htab_delete (container
.type_hash
);
1110 htab_delete (container
.invalid_hash
);
1111 htab_delete (container
.keyword_hash
);
1112 obstack_free (&container
.type_obstack
, NULL
);
1116 if (fclose (go_dump_file
) != 0)
1117 error ("could not close Go dump file: %m");
1118 go_dump_file
= NULL
;
1121 /* Set up our hooks. */
1123 const struct gcc_debug_hooks
*
1124 dump_go_spec_init (const char *filename
, const struct gcc_debug_hooks
*hooks
)
1126 go_dump_file
= fopen (filename
, "w");
1127 if (go_dump_file
== NULL
)
1129 error ("could not open Go dump file %qs: %m", filename
);
1133 go_debug_hooks
= *hooks
;
1134 real_debug_hooks
= hooks
;
1136 go_debug_hooks
.finish
= go_finish
;
1137 go_debug_hooks
.define
= go_define
;
1138 go_debug_hooks
.undef
= go_undef
;
1139 go_debug_hooks
.function_decl
= go_function_decl
;
1140 go_debug_hooks
.global_decl
= go_global_decl
;
1141 go_debug_hooks
.type_decl
= go_type_decl
;
1143 macro_hash
= htab_create (100, htab_hash_string
, string_hash_eq
, NULL
);
1145 return &go_debug_hooks
;
1148 #include "gt-godump.h"