LCOV - code coverage report
Current view: top level - gcc - godump.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 89.7 % 774 694
Test Date: 2024-04-20 14:03:02 Functions: 96.2 % 26 25
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Output Go language descriptions of types.
       2                 :             :    Copyright (C) 2008-2024 Free Software Foundation, Inc.
       3                 :             :    Written by Ian Lance Taylor <iant@google.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       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
      10                 :             : version.
      11                 :             : 
      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
      15                 :             : for more details.
      16                 :             : 
      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/>.  */
      20                 :             : 
      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
      25                 :             :    library.
      26                 :             : 
      27                 :             :    All global names are output with a leading underscore, so that they
      28                 :             :    are all hidden in Go.  */
      29                 :             : 
      30                 :             : #include "config.h"
      31                 :             : #include "system.h"
      32                 :             : #include "coretypes.h"
      33                 :             : #include "tree.h"
      34                 :             : #include "diagnostic-core.h"
      35                 :             : #include "debug.h"
      36                 :             : #include "stor-layout.h"
      37                 :             : 
      38                 :             : /* We dump this information from the debug hooks.  This gives us a
      39                 :             :    stable and maintainable API to hook into.  In order to work
      40                 :             :    correctly when -g is used, we build our own hooks structure which
      41                 :             :    wraps the hooks we need to change.  */
      42                 :             : 
      43                 :             : /* Our debug hooks.  This is initialized by dump_go_spec_init.  */
      44                 :             : 
      45                 :             : static struct gcc_debug_hooks go_debug_hooks;
      46                 :             : 
      47                 :             : /* The real debug hooks.  */
      48                 :             : 
      49                 :             : static const struct gcc_debug_hooks *real_debug_hooks;
      50                 :             : 
      51                 :             : /* The file where we should write information.  */
      52                 :             : 
      53                 :             : static FILE *go_dump_file;
      54                 :             : 
      55                 :             : /* A queue of decls to output.  */
      56                 :             : 
      57                 :             : static GTY(()) vec<tree, va_gc> *queue;
      58                 :             : 
      59                 :             : struct godump_str_hash : string_hash, ggc_remove <const char *> {};
      60                 :             : 
      61                 :             : /* A hash table of macros we have seen.  */
      62                 :             : 
      63                 :             : static htab_t macro_hash;
      64                 :             : 
      65                 :             : /* The type of a value in macro_hash.  */
      66                 :             : 
      67                 :             : struct macro_hash_value
      68                 :             : {
      69                 :             :   /* The name stored in the hash table.  */
      70                 :             :   char *name;
      71                 :             :   /* The value of the macro.  */
      72                 :             :   char *value;
      73                 :             : };
      74                 :             : 
      75                 :             : /* Returns the number of units necessary to represent an integer with the given
      76                 :             :    PRECISION (in bits).  */
      77                 :             : 
      78                 :             : static inline unsigned int
      79                 :        2757 : precision_to_units (unsigned int precision)
      80                 :             : {
      81                 :        2757 :   return (precision + BITS_PER_UNIT - 1) / BITS_PER_UNIT;
      82                 :             : }
      83                 :             : 
      84                 :             : /* Calculate the hash value for an entry in the macro hash table.  */
      85                 :             : 
      86                 :             : static hashval_t
      87                 :       27844 : macro_hash_hashval (const void *val)
      88                 :             : {
      89                 :       27844 :   const struct macro_hash_value *mhval = (const struct macro_hash_value *) val;
      90                 :       27844 :   return htab_hash_string (mhval->name);
      91                 :             : }
      92                 :             : 
      93                 :             : /* Compare values in the macro hash table for equality.  */
      94                 :             : 
      95                 :             : static int
      96                 :       42214 : macro_hash_eq (const void *v1, const void *v2)
      97                 :             : {
      98                 :       42214 :   const struct macro_hash_value *mhv1 = (const struct macro_hash_value *) v1;
      99                 :       42214 :   const struct macro_hash_value *mhv2 = (const struct macro_hash_value *) v2;
     100                 :       42214 :   return strcmp (mhv1->name, mhv2->name) == 0;
     101                 :             : }
     102                 :             : 
     103                 :             : /* Free values deleted from the macro hash table.  */
     104                 :             : 
     105                 :             : static void
     106                 :         549 : macro_hash_del (void *v)
     107                 :             : {
     108                 :         549 :   struct macro_hash_value *mhv = (struct macro_hash_value *) v;
     109                 :         549 :   XDELETEVEC (mhv->name);
     110                 :         549 :   XDELETEVEC (mhv->value);
     111                 :         549 :   XDELETE (mhv);
     112                 :         549 : }
     113                 :             : 
     114                 :             : /* A macro definition.  */
     115                 :             : 
     116                 :             : static void
     117                 :       14584 : go_define (unsigned int lineno, const char *buffer)
     118                 :             : {
     119                 :       14584 :   const char *p;
     120                 :       14584 :   const char *name_end;
     121                 :       14584 :   size_t out_len;
     122                 :       14584 :   char *out_buffer;
     123                 :       14584 :   char *q;
     124                 :       14584 :   bool saw_operand;
     125                 :       14584 :   bool need_operand;
     126                 :       14584 :   struct macro_hash_value *mhval;
     127                 :       14584 :   char *copy;
     128                 :       14584 :   hashval_t hashval;
     129                 :       14584 :   void **slot;
     130                 :             : 
     131                 :       14584 :   real_debug_hooks->define (lineno, buffer);
     132                 :             : 
     133                 :             :   /* Skip macro functions.  */
     134                 :      229525 :   for (p = buffer; *p != '\0' && *p != ' '; ++p)
     135                 :      201137 :     if (*p == '(')
     136                 :             :       return;
     137                 :             : 
     138                 :       13804 :   if (*p == '\0')
     139                 :             :     return;
     140                 :             : 
     141                 :       13804 :   name_end = p;
     142                 :             : 
     143                 :       13804 :   ++p;
     144                 :       13804 :   if (*p == '\0')
     145                 :             :     return;
     146                 :             : 
     147                 :       13375 :   copy = XNEWVEC (char, name_end - buffer + 1);
     148                 :       13375 :   memcpy (copy, buffer, name_end - buffer);
     149                 :       13375 :   copy[name_end - buffer] = '\0';
     150                 :             : 
     151                 :       13375 :   mhval = XNEW (struct macro_hash_value);
     152                 :       13375 :   mhval->name = copy;
     153                 :       13375 :   mhval->value = NULL;
     154                 :             : 
     155                 :       13375 :   hashval = htab_hash_string (copy);
     156                 :       13375 :   slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, NO_INSERT);
     157                 :             : 
     158                 :             :   /* For simplicity, we force all names to be hidden by adding an
     159                 :             :      initial underscore, and let the user undo this as needed.  */
     160                 :       13375 :   out_len = strlen (p) * 2 + 1;
     161                 :       13375 :   out_buffer = XNEWVEC (char, out_len);
     162                 :       13375 :   q = out_buffer;
     163                 :       13375 :   saw_operand = false;
     164                 :       13375 :   need_operand = false;
     165                 :       41603 :   while (*p != '\0')
     166                 :             :     {
     167                 :       17922 :       switch (*p)
     168                 :             :         {
     169                 :        4733 :         case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
     170                 :        4733 :         case 'G': case 'H': case 'I': case 'J': case 'K': case 'L':
     171                 :        4733 :         case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R':
     172                 :        4733 :         case 'S': case 'T': case 'U': case 'V': case 'W': case 'X':
     173                 :        4733 :         case 'Y': case 'Z':
     174                 :        4733 :         case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
     175                 :        4733 :         case 'g': case 'h': case 'i': case 'j': case 'k': case 'l':
     176                 :        4733 :         case 'm': case 'n': case 'o': case 'p': case 'q': case 'r':
     177                 :        4733 :         case 's': case 't': case 'u': case 'v': case 'w': case 'x':
     178                 :        4733 :         case 'y': case 'z':
     179                 :        4733 :         case '_':
     180                 :        4733 :           {
     181                 :             :             /* The start of an identifier.  Technically we should also
     182                 :             :                worry about UTF-8 identifiers, but they are not a
     183                 :             :                problem for practical uses of -fdump-go-spec so we
     184                 :             :                don't worry about them.  */
     185                 :        4733 :             const char *start;
     186                 :        4733 :             char *n;
     187                 :        4733 :             struct macro_hash_value idval;
     188                 :             : 
     189                 :        4733 :             if (saw_operand)
     190                 :        2894 :               goto unknown;
     191                 :             : 
     192                 :             :             start = p;
     193                 :       62990 :             while (ISALNUM (*p) || *p == '_')
     194                 :       58317 :               ++p;
     195                 :        4673 :             n = XALLOCAVEC (char, p - start + 1);
     196                 :        4673 :             memcpy (n, start, p - start);
     197                 :        4673 :             n[p - start] = '\0';
     198                 :        4673 :             idval.name = n;
     199                 :        4673 :             idval.value = NULL;
     200                 :        4673 :             if (htab_find (macro_hash, &idval) == NULL)
     201                 :             :               {
     202                 :             :                 /* This is a reference to a name which was not defined
     203                 :             :                    as a macro.  */
     204                 :        2834 :                 goto unknown;
     205                 :             :               }
     206                 :             : 
     207                 :        1839 :             *q++ = '_';
     208                 :        1839 :             memcpy (q, start, p - start);
     209                 :        1839 :             q += p - start;
     210                 :             : 
     211                 :        1839 :             saw_operand = true;
     212                 :        1839 :             need_operand = false;
     213                 :             :           }
     214                 :        1839 :           break;
     215                 :             : 
     216                 :           0 :         case '.':
     217                 :           0 :           if (!ISDIGIT (p[1]))
     218                 :           0 :             goto unknown;
     219                 :             :           /* Fall through.  */
     220                 :        9272 :         case '0': case '1': case '2': case '3': case '4':
     221                 :        9272 :         case '5': case '6': case '7': case '8': case '9':
     222                 :        9272 :           {
     223                 :        9272 :             const char *start;
     224                 :        9272 :             bool is_hex;
     225                 :             : 
     226                 :        9272 :             start = p;
     227                 :        9272 :             is_hex = false;
     228                 :        9272 :             if (*p == '0' && (p[1] == 'x' || p[1] == 'X'))
     229                 :             :               {
     230                 :        1833 :                 p += 2;
     231                 :        1833 :                 is_hex = true;
     232                 :             :               }
     233                 :       41413 :             while (ISDIGIT (*p) || *p == '.' || *p == 'e' || *p == 'E'
     234                 :       52665 :                    || (is_hex
     235                 :        3813 :                        && ((*p >= 'a' && *p <= 'f')
     236                 :        2057 :                            || (*p >= 'A' && *p <= 'F'))))
     237                 :       32141 :               ++p;
     238                 :        9272 :             memcpy (q, start, p - start);
     239                 :        9272 :             q += p - start;
     240                 :        9272 :             while (*p == 'u' || *p == 'U' || *p == 'l' || *p == 'L'
     241                 :             :                    || *p == 'f' || *p == 'F'
     242                 :       10038 :                    || *p == 'd' || *p == 'D')
     243                 :             :               {
     244                 :             :                 /* Go doesn't use any of these trailing type
     245                 :             :                    modifiers.  */
     246                 :         766 :                 ++p;
     247                 :             :               }
     248                 :             : 
     249                 :             :             /* We'll pick up the exponent, if any, as an
     250                 :             :                expression.  */
     251                 :             : 
     252                 :             :             saw_operand = true;
     253                 :             :             need_operand = false;
     254                 :             :           }
     255                 :             :           break;
     256                 :             : 
     257                 :         900 :         case ' ': case '\t':
     258                 :         900 :           *q++ = *p++;
     259                 :         900 :           break;
     260                 :             : 
     261                 :        1030 :         case '(':
     262                 :             :           /* Always OK, not part of an operand, presumed to start an
     263                 :             :              operand.  */
     264                 :        1030 :           *q++ = *p++;
     265                 :        1030 :           saw_operand = false;
     266                 :        1030 :           need_operand = false;
     267                 :        1030 :           break;
     268                 :             : 
     269                 :         585 :         case ')':
     270                 :             :           /* OK if we don't need an operand, and presumed to indicate
     271                 :             :              an operand.  */
     272                 :         585 :           if (need_operand)
     273                 :           0 :             goto unknown;
     274                 :         585 :           *q++ = *p++;
     275                 :         585 :           saw_operand = true;
     276                 :         585 :           break;
     277                 :             : 
     278                 :         538 :         case '+': case '-':
     279                 :             :           /* Always OK, but not part of an operand.  */
     280                 :         538 :           *q++ = *p++;
     281                 :         538 :           saw_operand = false;
     282                 :         538 :           break;
     283                 :             : 
     284                 :         174 :         case '*': case '/': case '%': case '|': case '&': case '^':
     285                 :             :           /* Must be a binary operator.  */
     286                 :         174 :           if (!saw_operand)
     287                 :           6 :             goto unknown;
     288                 :         168 :           *q++ = *p++;
     289                 :         168 :           saw_operand = false;
     290                 :         168 :           need_operand = true;
     291                 :         168 :           break;
     292                 :             : 
     293                 :           0 :         case '=':
     294                 :           0 :           *q++ = *p++;
     295                 :           0 :           if (*p != '=')
     296                 :           0 :             goto unknown;
     297                 :             :           /* Must be a binary operator.  */
     298                 :           0 :           if (!saw_operand)
     299                 :           0 :             goto unknown;
     300                 :           0 :           *q++ = *p++;
     301                 :           0 :           saw_operand = false;
     302                 :           0 :           need_operand = true;
     303                 :           0 :           break;
     304                 :             : 
     305                 :           0 :         case '!':
     306                 :           0 :           *q++ = *p++;
     307                 :           0 :           if (*p == '=')
     308                 :             :             {
     309                 :             :               /* Must be a binary operator.  */
     310                 :           0 :               if (!saw_operand)
     311                 :           0 :                 goto unknown;
     312                 :           0 :               *q++ = *p++;
     313                 :           0 :               saw_operand = false;
     314                 :           0 :               need_operand = true;
     315                 :             :             }
     316                 :             :           else
     317                 :             :             {
     318                 :             :               /* Must be a unary operator.  */
     319                 :           0 :               if (saw_operand)
     320                 :           0 :                 goto unknown;
     321                 :             :               need_operand = true;
     322                 :             :             }
     323                 :             :           break;
     324                 :             : 
     325                 :         256 :         case '<': case '>':
     326                 :             :           /* Must be a binary operand, may be << or >> or <= or >=.  */
     327                 :         256 :           if (!saw_operand)
     328                 :           0 :             goto unknown;
     329                 :         256 :           *q++ = *p++;
     330                 :         256 :           if (*p == *(p - 1) || *p == '=')
     331                 :         256 :             *q++ = *p++;
     332                 :             :           saw_operand = false;
     333                 :             :           need_operand = true;
     334                 :             :           break;
     335                 :             : 
     336                 :          10 :         case '~':
     337                 :             :           /* Must be a unary operand, must be translated for Go.  */
     338                 :          10 :           if (saw_operand)
     339                 :           0 :             goto unknown;
     340                 :          10 :           *q++ = '^';
     341                 :          10 :           p++;
     342                 :          10 :           need_operand = true;
     343                 :          10 :           break;
     344                 :             : 
     345                 :         411 :         case '"':
     346                 :         411 :         case '\'':
     347                 :         411 :           {
     348                 :         411 :             char quote;
     349                 :         411 :             int count;
     350                 :             : 
     351                 :         411 :             if (saw_operand)
     352                 :         154 :               goto unknown;
     353                 :         257 :             quote = *p;
     354                 :         257 :             *q++ = *p++;
     355                 :         257 :             count = 0;
     356                 :        1177 :             while (*p != quote)
     357                 :             :               {
     358                 :         922 :                 int c;
     359                 :             : 
     360                 :         922 :                 if (*p == '\0')
     361                 :           0 :                   goto unknown;
     362                 :             : 
     363                 :         922 :                 ++count;
     364                 :             : 
     365                 :         922 :                 if (*p != '\\')
     366                 :             :                   {
     367                 :         920 :                     *q++ = *p++;
     368                 :         920 :                     continue;
     369                 :             :                   }
     370                 :             : 
     371                 :           2 :                 *q++ = *p++;
     372                 :           2 :                 switch (*p)
     373                 :             :                   {
     374                 :             :                   case '0': case '1': case '2': case '3':
     375                 :             :                   case '4': case '5': case '6': case '7':
     376                 :             :                     c = 0;
     377                 :           4 :                     while (*p >= '0' && *p <= '7')
     378                 :             :                       {
     379                 :           2 :                         *q++ = *p++;
     380                 :           2 :                         ++c;
     381                 :             :                       }
     382                 :             :                     /* Go octal characters are always 3
     383                 :             :                        digits.  */
     384                 :           2 :                     if (c != 3)
     385                 :           2 :                       goto unknown;
     386                 :             :                     break;
     387                 :             : 
     388                 :           0 :                   case 'x':
     389                 :           0 :                     *q++ = *p++;
     390                 :           0 :                     c = 0;
     391                 :           0 :                     while (ISXDIGIT (*p))
     392                 :             :                       {
     393                 :           0 :                         *q++ = *p++;
     394                 :           0 :                         ++c;
     395                 :             :                       }
     396                 :             :                     /* Go hex characters are always 2 digits.  */
     397                 :           0 :                     if (c != 2)
     398                 :           0 :                       goto unknown;
     399                 :             :                     break;
     400                 :             : 
     401                 :           0 :                   case 'a': case 'b': case 'f': case 'n': case 'r':
     402                 :           0 :                   case 't': case 'v': case '\\': case '\'': case '"':
     403                 :           0 :                     *q++ = *p++;
     404                 :           0 :                     break;
     405                 :             : 
     406                 :           0 :                   default:
     407                 :           0 :                     goto unknown;
     408                 :             :                   }
     409                 :             :               }
     410                 :             : 
     411                 :         255 :             *q++ = *p++;
     412                 :             : 
     413                 :         255 :             if (quote == '\'' && count != 1)
     414                 :           0 :               goto unknown;
     415                 :             : 
     416                 :             :             saw_operand = true;
     417                 :             :             need_operand = false;
     418                 :             : 
     419                 :             :             break;
     420                 :             :           }
     421                 :             : 
     422                 :          13 :         default:
     423                 :          13 :           goto unknown;
     424                 :             :         }
     425                 :             :     }
     426                 :             : 
     427                 :       10306 :   if (need_operand)
     428                 :           0 :     goto unknown;
     429                 :             : 
     430                 :       10306 :   gcc_assert ((size_t) (q - out_buffer) < out_len);
     431                 :       10306 :   *q = '\0';
     432                 :             : 
     433                 :       10306 :   mhval->value = out_buffer;
     434                 :             : 
     435                 :       10306 :   if (slot == NULL)
     436                 :             :     {
     437                 :       10038 :       slot = htab_find_slot_with_hash (macro_hash, mhval, hashval, INSERT);
     438                 :       10038 :       gcc_assert (slot != NULL && *slot == NULL);
     439                 :             :     }
     440                 :             :   else
     441                 :             :     {
     442                 :         268 :       if (*slot != NULL)
     443                 :         268 :         macro_hash_del (*slot);
     444                 :             :     }
     445                 :             : 
     446                 :       10306 :   *slot = mhval;
     447                 :             : 
     448                 :       10306 :   return;
     449                 :             : 
     450                 :        3069 :  unknown:
     451                 :        3069 :   fprintf (go_dump_file, "// unknowndefine %s\n", buffer);
     452                 :        3069 :   if (slot != NULL)
     453                 :           0 :     htab_clear_slot (macro_hash, slot);
     454                 :        3069 :   XDELETEVEC (out_buffer);
     455                 :        3069 :   XDELETEVEC (copy);
     456                 :             : }
     457                 :             : 
     458                 :             : /* A macro undef.  */
     459                 :             : 
     460                 :             : static void
     461                 :         674 : go_undef (unsigned int lineno, const char *buffer)
     462                 :             : {
     463                 :         674 :   struct macro_hash_value mhval;
     464                 :         674 :   void **slot;
     465                 :             : 
     466                 :         674 :   real_debug_hooks->undef (lineno, buffer);
     467                 :             : 
     468                 :         674 :   mhval.name = CONST_CAST (char *, buffer);
     469                 :         674 :   mhval.value = NULL;
     470                 :         674 :   slot = htab_find_slot (macro_hash, &mhval, NO_INSERT);
     471                 :         674 :   if (slot != NULL)
     472                 :         150 :     htab_clear_slot (macro_hash, slot);
     473                 :         674 : }
     474                 :             : 
     475                 :             : /* A function or variable decl.  */
     476                 :             : 
     477                 :             : static void
     478                 :        2988 : go_decl (tree decl)
     479                 :             : {
     480                 :        2988 :   if (!TREE_PUBLIC (decl)
     481                 :        2215 :       || DECL_IS_UNDECLARED_BUILTIN (decl)
     482                 :        5203 :       || DECL_NAME (decl) == NULL_TREE)
     483                 :             :     return;
     484                 :        2215 :   vec_safe_push (queue, decl);
     485                 :             : }
     486                 :             : 
     487                 :             : /* A function decl.  */
     488                 :             : 
     489                 :             : static void
     490                 :           0 : go_function_decl (tree decl)
     491                 :             : {
     492                 :           0 :   real_debug_hooks->function_decl (decl);
     493                 :           0 :   go_decl (decl);
     494                 :           0 : }
     495                 :             : 
     496                 :             : static void
     497                 :        2988 : go_early_global_decl (tree decl)
     498                 :             : {
     499                 :        2988 :   go_decl (decl);
     500                 :        2988 :   if (TREE_CODE (decl) != FUNCTION_DECL || DECL_STRUCT_FUNCTION (decl) != NULL)
     501                 :        1112 :     real_debug_hooks->early_global_decl (decl);
     502                 :        2988 : }
     503                 :             : 
     504                 :             : /* A global variable decl.  */
     505                 :             : 
     506                 :             : static void
     507                 :         133 : go_late_global_decl (tree decl)
     508                 :             : {
     509                 :         133 :   real_debug_hooks->late_global_decl (decl);
     510                 :         133 : }
     511                 :             : 
     512                 :             : /* A type declaration.  */
     513                 :             : 
     514                 :             : static void
     515                 :        1921 : go_type_decl (tree decl, int local)
     516                 :             : {
     517                 :        1921 :   real_debug_hooks->type_decl (decl, local);
     518                 :             : 
     519                 :        1921 :   if (local || DECL_IS_UNDECLARED_BUILTIN (decl))
     520                 :             :     return;
     521                 :        1805 :   if (DECL_NAME (decl) == NULL_TREE
     522                 :        1032 :       && (TYPE_NAME (TREE_TYPE (decl)) == NULL_TREE
     523                 :         521 :           || TREE_CODE (TYPE_NAME (TREE_TYPE (decl))) != IDENTIFIER_NODE)
     524                 :        2316 :       && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE)
     525                 :             :     return;
     526                 :        1501 :   vec_safe_push (queue, decl);
     527                 :             : }
     528                 :             : 
     529                 :             : /* A container for the data we pass around when generating information
     530                 :             :    at the end of the compilation.  */
     531                 :             : 
     532                 :           4 : class godump_container
     533                 :             : {
     534                 :             : public:
     535                 :             :   /* DECLs that we have already seen.  */
     536                 :             :   hash_set<tree> decls_seen;
     537                 :             : 
     538                 :             :   /* Types which may potentially have to be defined as dummy
     539                 :             :      types.  */
     540                 :             :   hash_set<const char *, false, godump_str_hash> pot_dummy_types;
     541                 :             : 
     542                 :             :   /* Go keywords.  */
     543                 :             :   htab_t keyword_hash;
     544                 :             : 
     545                 :             :   /* Global type definitions.  */
     546                 :             :   htab_t type_hash;
     547                 :             : 
     548                 :             :   /* Invalid types.  */
     549                 :             :   htab_t invalid_hash;
     550                 :             : 
     551                 :             :   /* Obstack used to write out a type definition.  */
     552                 :             :   struct obstack type_obstack;
     553                 :             : };
     554                 :             : 
     555                 :             : /* Append an IDENTIFIER_NODE to OB.  */
     556                 :             : 
     557                 :             : static void
     558                 :        4181 : go_append_string (struct obstack *ob, tree id)
     559                 :             : {
     560                 :        4181 :   obstack_grow (ob, IDENTIFIER_POINTER (id), IDENTIFIER_LENGTH (id));
     561                 :        4181 : }
     562                 :             : 
     563                 :             : /* Given an integer PRECISION in bits, returns a constant string that is the
     564                 :             :    matching go int or uint type (depending on the IS_UNSIGNED flag).  Returns a
     565                 :             :    NULL pointer if there is no matching go type.  */
     566                 :             : 
     567                 :             : static const char *
     568                 :        7704 : go_get_uinttype_for_precision (unsigned int precision, bool is_unsigned)
     569                 :             : {
     570                 :        7704 :   switch (precision)
     571                 :             :     {
     572                 :        1808 :     case 8:
     573                 :        1808 :       return is_unsigned ? "uint8" : "int8";
     574                 :         431 :     case 16:
     575                 :         431 :       return is_unsigned ? "uint16" : "int16";
     576                 :        4239 :     case 32:
     577                 :        4239 :       return is_unsigned ? "uint32" : "int32";
     578                 :        1223 :     case 64:
     579                 :        1223 :       return is_unsigned ? "uint64" : "int64";
     580                 :             :     default:
     581                 :             :       return NULL;
     582                 :             :     }
     583                 :             : }
     584                 :             : 
     585                 :             : /* Append an artificial variable name with the suffix _INDEX to OB.  Returns
     586                 :             :    INDEX + 1.  */
     587                 :             : 
     588                 :             : static unsigned int
     589                 :         150 : go_append_artificial_name (struct obstack *ob, unsigned int index)
     590                 :             : {
     591                 :         150 :   char buf[100];
     592                 :             : 
     593                 :             :   /* FIXME: identifier may not be unique.  */
     594                 :         150 :   obstack_grow (ob, "Godump_", 7);
     595                 :         150 :   snprintf (buf, sizeof buf, "%u", index);
     596                 :         150 :   obstack_grow (ob, buf, strlen (buf));
     597                 :             : 
     598                 :         150 :   return index + 1;
     599                 :             : }
     600                 :             : 
     601                 :             : /* Append the variable name from DECL to OB.  If the name is in the
     602                 :             :    KEYWORD_HASH, prepend an '_'.  */
     603                 :             : 
     604                 :             : static void
     605                 :        2665 : go_append_decl_name (struct obstack *ob, tree decl, htab_t keyword_hash)
     606                 :             : {
     607                 :        2665 :   const char *var_name;
     608                 :        2665 :   void **slot;
     609                 :             : 
     610                 :             :   /* Start variable name with an underscore if a keyword.  */
     611                 :        2665 :   var_name = IDENTIFIER_POINTER (DECL_NAME (decl));
     612                 :        2665 :   slot = htab_find_slot (keyword_hash, var_name, NO_INSERT);
     613                 :        2665 :   if (slot != NULL)
     614                 :           4 :     obstack_1grow (ob, '_');
     615                 :        2665 :   go_append_string (ob, DECL_NAME (decl));
     616                 :        2665 : }
     617                 :             : 
     618                 :             : /* Appends a byte array with the necessary number of elements and the name
     619                 :             :    "Godump_INDEX_pad" to pad from FROM_OFFSET to TO_OFFSET to OB assuming that
     620                 :             :    the next field is automatically aligned to ALIGN_UNITS.  Returns INDEX + 1,
     621                 :             :    or INDEX if no padding had to be appended.  The resulting offset where the
     622                 :             :    next field is allocated is returned through RET_OFFSET.  */
     623                 :             : 
     624                 :             : static unsigned int
     625                 :        3476 : go_append_padding (struct obstack *ob, unsigned int from_offset,
     626                 :             :                    unsigned int to_offset, unsigned int align_units,
     627                 :             :                    unsigned int index, unsigned int *ret_offset)
     628                 :             : {
     629                 :        3476 :   if (from_offset % align_units > 0)
     630                 :          54 :     from_offset += align_units - (from_offset % align_units);
     631                 :        3476 :   gcc_assert (to_offset >= from_offset);
     632                 :        3476 :   if (to_offset > from_offset)
     633                 :             :     {
     634                 :         124 :       char buf[100];
     635                 :             : 
     636                 :         124 :       index = go_append_artificial_name (ob, index);
     637                 :         124 :       snprintf (buf, sizeof buf, "_pad [%u]byte; ", to_offset - from_offset);
     638                 :         124 :       obstack_grow (ob, buf, strlen (buf));
     639                 :             :     }
     640                 :        3476 :   *ret_offset = to_offset;
     641                 :             : 
     642                 :        3476 :   return index;
     643                 :             : }
     644                 :             : 
     645                 :             : /* Appends an array of type TYPE_STRING with zero elements and the name
     646                 :             :    "_" to OB.  If TYPE_STRING is a null pointer, ERROR_STRING is appended
     647                 :             :    instead of the type.  Returns INDEX + 1.  */
     648                 :             : 
     649                 :             : static unsigned int
     650                 :          59 : go_force_record_alignment (struct obstack *ob, const char *type_string,
     651                 :             :                            unsigned int index, const char *error_string)
     652                 :             : {
     653                 :          59 :   obstack_grow (ob, "_ ", 2);
     654                 :          59 :   if (type_string == NULL)
     655                 :           0 :     obstack_grow (ob, error_string, strlen (error_string));
     656                 :             :   else
     657                 :             :     {
     658                 :          59 :       obstack_grow (ob, "[0]", 3);
     659                 :          59 :       obstack_grow (ob, type_string, strlen (type_string));
     660                 :             :     }
     661                 :          59 :   obstack_grow (ob, "; ", 2);
     662                 :             : 
     663                 :          59 :   return index;
     664                 :             : }
     665                 :             : 
     666                 :             : /* Write the Go version of TYPE to CONTAINER->TYPE_OBSTACK.
     667                 :             :    USE_TYPE_NAME is true if we can simply use a type name here without
     668                 :             :    needing to define it.  IS_FUNC_OK is true if we can output a func
     669                 :             :    type here; the "func" keyword will already have been added.
     670                 :             :    Return true if the type can be represented in Go, false otherwise.
     671                 :             :    P_ART_I is used for indexing artificial elements in nested structures and
     672                 :             :    should always be a NULL pointer when called, except by certain recursive
     673                 :             :    calls from go_format_type() itself.  */
     674                 :             : 
     675                 :             : static bool
     676                 :       15342 : go_format_type (class godump_container *container, tree type,
     677                 :             :                 bool use_type_name, bool is_func_ok, unsigned int *p_art_i,
     678                 :             :                 bool is_anon_record_or_union)
     679                 :             : {
     680                 :       15342 :   bool ret;
     681                 :       15342 :   struct obstack *ob;
     682                 :       15342 :   unsigned int art_i_dummy;
     683                 :       15342 :   bool is_union = false;
     684                 :             : 
     685                 :       15342 :   if (p_art_i == NULL)
     686                 :             :     {
     687                 :       12782 :       art_i_dummy = 0;
     688                 :       12782 :       p_art_i = &art_i_dummy;
     689                 :             :     }
     690                 :       15342 :   ret = true;
     691                 :       15342 :   ob = &container->type_obstack;
     692                 :             : 
     693                 :       15342 :   if (use_type_name
     694                 :       14821 :       && TYPE_NAME (type) != NULL_TREE
     695                 :       24254 :       && (AGGREGATE_TYPE_P (type)
     696                 :             :           || POINTER_TYPE_P (type)
     697                 :             :           || TREE_CODE (type) == FUNCTION_TYPE))
     698                 :             :     {
     699                 :        1240 :       tree name;
     700                 :        1240 :       void **slot;
     701                 :             : 
     702                 :             :       /* References to complex builtin types cannot be translated to
     703                 :             :         Go.  */
     704                 :        1240 :       if (DECL_P (TYPE_NAME (type))
     705                 :        1240 :           && DECL_IS_UNDECLARED_BUILTIN (TYPE_NAME (type)))
     706                 :             :         ret = false;
     707                 :             : 
     708                 :        1240 :       name = TYPE_IDENTIFIER (type);
     709                 :             : 
     710                 :        1240 :       slot = htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (name),
     711                 :             :                              NO_INSERT);
     712                 :        1240 :       if (slot != NULL)
     713                 :          17 :         ret = false;
     714                 :             : 
     715                 :             :       /* References to incomplete structs are permitted in many
     716                 :             :          contexts, like behind a pointer or inside of a typedef. So
     717                 :             :          consider any referenced struct a potential dummy type.  */
     718                 :        1240 :       if (RECORD_OR_UNION_TYPE_P (type))
     719                 :        1127 :        container->pot_dummy_types.add (IDENTIFIER_POINTER (name));
     720                 :             : 
     721                 :        1240 :       obstack_1grow (ob, '_');
     722                 :        1240 :       go_append_string (ob, name);
     723                 :        1240 :       return ret;
     724                 :             :     }
     725                 :             : 
     726                 :       14102 :   switch (TREE_CODE (type))
     727                 :             :     {
     728                 :           0 :     case TYPE_DECL:
     729                 :           0 :       {
     730                 :           0 :         void **slot;
     731                 :             : 
     732                 :           0 :         slot = htab_find_slot (container->invalid_hash,
     733                 :           0 :                                IDENTIFIER_POINTER (DECL_NAME (type)),
     734                 :             :                                NO_INSERT);
     735                 :           0 :         if (slot != NULL)
     736                 :           0 :           ret = false;
     737                 :             : 
     738                 :           0 :         obstack_1grow (ob, '_');
     739                 :           0 :         go_append_string (ob, DECL_NAME (type));
     740                 :             :       }
     741                 :           0 :       break;
     742                 :             : 
     743                 :        7641 :     case ENUMERAL_TYPE:
     744                 :        7641 :     case INTEGER_TYPE:
     745                 :        7641 :       {
     746                 :        7641 :         const char *s;
     747                 :        7641 :         char buf[100];
     748                 :             : 
     749                 :        7641 :         s = go_get_uinttype_for_precision (TYPE_PRECISION (type),
     750                 :        7641 :                                            TYPE_UNSIGNED (type));
     751                 :        7641 :         if (s == NULL)
     752                 :             :           {
     753                 :           6 :             snprintf (buf, sizeof buf, "INVALID-int-%u%s",
     754                 :           2 :                       TYPE_PRECISION (type),
     755                 :           2 :                       TYPE_UNSIGNED (type) ? "u" : "");
     756                 :           2 :             s = buf;
     757                 :           2 :             ret = false;
     758                 :             :           }
     759                 :        7641 :         obstack_grow (ob, s, strlen (s));
     760                 :             :       }
     761                 :        7641 :       break;
     762                 :             : 
     763                 :           4 :     case BITINT_TYPE:
     764                 :           4 :       {
     765                 :           4 :         const char *s;
     766                 :           4 :         char buf[100];
     767                 :             : 
     768                 :           4 :         s = go_get_uinttype_for_precision (TYPE_PRECISION (type),
     769                 :           4 :                                            TYPE_UNSIGNED (type));
     770                 :           4 :         if (s == NULL)
     771                 :             :           {
     772                 :           3 :             snprintf (buf, sizeof buf, "INVALID-bitint-%u%s",
     773                 :           1 :                       TYPE_PRECISION (type),
     774                 :           1 :                       TYPE_UNSIGNED (type) ? "u" : "");
     775                 :           1 :             s = buf;
     776                 :           1 :             ret = false;
     777                 :             :           }
     778                 :           4 :         obstack_grow (ob, s, strlen(s));
     779                 :             :       }
     780                 :           4 :       break;
     781                 :             : 
     782                 :          97 :     case REAL_TYPE:
     783                 :          97 :       {
     784                 :          97 :         const char *s;
     785                 :          97 :         char buf[100];
     786                 :             : 
     787                 :          97 :         switch (TYPE_PRECISION (type))
     788                 :             :           {
     789                 :             :           case 32:
     790                 :             :             s = "float32";
     791                 :             :             break;
     792                 :          48 :           case 64:
     793                 :          48 :             s = "float64";
     794                 :          48 :             break;
     795                 :          31 :           default:
     796                 :          62 :             snprintf (buf, sizeof buf, "INVALID-float-%u",
     797                 :          31 :                       TYPE_PRECISION (type));
     798                 :          31 :             s = buf;
     799                 :          31 :             ret = false;
     800                 :          31 :             break;
     801                 :             :           }
     802                 :          97 :         obstack_grow (ob, s, strlen (s));
     803                 :             :       }
     804                 :          97 :       break;
     805                 :             : 
     806                 :          12 :     case COMPLEX_TYPE:
     807                 :          12 :       {
     808                 :          12 :         const char *s;
     809                 :          12 :         char buf[100];
     810                 :          12 :         tree real_type;
     811                 :             : 
     812                 :          12 :         real_type = TREE_TYPE (type);
     813                 :          12 :         if (TREE_CODE (real_type) == REAL_TYPE)
     814                 :             :           {
     815                 :           9 :             switch (TYPE_PRECISION (real_type))
     816                 :             :               {
     817                 :             :               case 32:
     818                 :             :                 s = "complex64";
     819                 :             :                 break;
     820                 :           4 :               case 64:
     821                 :           4 :                 s = "complex128";
     822                 :           4 :                 break;
     823                 :           3 :               default:
     824                 :           6 :                 snprintf (buf, sizeof buf, "INVALID-complex-%u",
     825                 :           3 :                           2 * TYPE_PRECISION (real_type));
     826                 :           3 :                 s = buf;
     827                 :           3 :                 ret = false;
     828                 :           3 :                 break;
     829                 :             :               }
     830                 :             :           }
     831                 :             :         else
     832                 :             :           {
     833                 :             :             s = "INVALID-complex-non-real";
     834                 :             :             ret = false;
     835                 :             :           }
     836                 :          12 :         obstack_grow (ob, s, strlen (s));
     837                 :             :       }
     838                 :          12 :       break;
     839                 :             : 
     840                 :           0 :     case BOOLEAN_TYPE:
     841                 :           0 :       obstack_grow (ob, "bool", 4);
     842                 :           0 :       break;
     843                 :             : 
     844                 :        3415 :     case POINTER_TYPE:
     845                 :        3415 :       if (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
     846                 :          76 :         obstack_grow (ob, "func", 4);
     847                 :             :       else
     848                 :        3339 :         obstack_1grow (ob, '*');
     849                 :        3415 :       if (VOID_TYPE_P (TREE_TYPE (type)))
     850                 :         416 :         obstack_grow (ob, "byte", 4);
     851                 :             :       else
     852                 :             :         {
     853                 :        2999 :           if (!go_format_type (container, TREE_TYPE (type), use_type_name,
     854                 :             :                                true, NULL, false))
     855                 :          23 :             ret = false;
     856                 :             :         }
     857                 :             :       break;
     858                 :             : 
     859                 :         260 :     case ARRAY_TYPE:
     860                 :         260 :       obstack_1grow (ob, '[');
     861                 :         260 :       if (TYPE_DOMAIN (type) != NULL_TREE
     862                 :         259 :           && TREE_CODE (TYPE_DOMAIN (type)) == INTEGER_TYPE
     863                 :         259 :           && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
     864                 :         259 :           && TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
     865                 :         259 :           && tree_int_cst_sgn (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) == 0
     866                 :         259 :           && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != NULL_TREE
     867                 :         246 :           && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) == INTEGER_CST
     868                 :         506 :           && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type))))
     869                 :             :         {
     870                 :         246 :           char buf[100];
     871                 :             : 
     872                 :         492 :           snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC "+1",
     873                 :         246 :                     tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type))));
     874                 :         246 :           obstack_grow (ob, buf, strlen (buf));
     875                 :             :         }
     876                 :             :       else
     877                 :          14 :         obstack_1grow (ob, '0');
     878                 :         260 :       obstack_1grow (ob, ']');
     879                 :         260 :       if (!go_format_type (container, TREE_TYPE (type), use_type_name, false,
     880                 :             :                            NULL, false))
     881                 :          23 :         ret = false;
     882                 :             :       break;
     883                 :             : 
     884                 :         130 :     case UNION_TYPE:
     885                 :         130 :       is_union = true;
     886                 :             :       /* Fall through to RECORD_TYPE case.  */
     887                 :         719 :       gcc_fallthrough ();
     888                 :         719 :     case RECORD_TYPE:
     889                 :         719 :       {
     890                 :         719 :         unsigned int prev_field_end;
     891                 :         719 :         unsigned int known_alignment;
     892                 :         719 :         tree field;
     893                 :         719 :         bool emitted_a_field;
     894                 :             : 
     895                 :             :         /* FIXME: Why is this necessary?  Without it we can get a core
     896                 :             :            dump on the s390x headers, or from a file containing simply
     897                 :             :            "typedef struct S T;".  */
     898                 :         719 :         layout_type (type);
     899                 :             : 
     900                 :         719 :         prev_field_end = 0;
     901                 :         719 :         known_alignment = 1;
     902                 :             :         /* Anonymous records and unions are flattened, i.e. they are not put
     903                 :             :            into "struct { ... }".  */
     904                 :         719 :         if (!is_anon_record_or_union)
     905                 :         653 :           obstack_grow (ob, "struct { ", 9);
     906                 :         719 :         for (field = TYPE_FIELDS (type), emitted_a_field = false;
     907                 :        3808 :              field != NULL_TREE;
     908                 :        3089 :              field = TREE_CHAIN (field))
     909                 :             :           {
     910                 :        3089 :             if (TREE_CODE (field) != FIELD_DECL)
     911                 :           0 :               continue;
     912                 :        3089 :             if (DECL_BIT_FIELD (field))
     913                 :             :               /* Bit fields are replaced by padding.  */
     914                 :         122 :               continue;
     915                 :             :             /* Only the first non-bitfield field is emitted for unions.  */
     916                 :        2967 :             if (!is_union || !emitted_a_field)
     917                 :             :               {
     918                 :             :                 /* Emit the field.  */
     919                 :        2757 :                 bool field_ok;
     920                 :        2757 :                 bool is_anon_substructure;
     921                 :        2757 :                 unsigned int decl_align_unit;
     922                 :        2757 :                 unsigned int decl_offset;
     923                 :             : 
     924                 :        2757 :                 field_ok = true;
     925                 :        2757 :                 emitted_a_field = true;
     926                 :        5514 :                 is_anon_substructure =
     927                 :        2757 :                   (DECL_NAME (field) == NULL
     928                 :        2757 :                    && (TREE_CODE (TREE_TYPE (field)) == RECORD_TYPE
     929                 :          78 :                        || TREE_CODE (TREE_TYPE (field)) == UNION_TYPE));
     930                 :             :                 /* Keep track of the alignment of named substructures, either
     931                 :             :                    of the whole record, or the alignment of the emitted field
     932                 :             :                    (for unions).  */
     933                 :        2757 :                 decl_align_unit = DECL_ALIGN_UNIT (field);
     934                 :        2757 :                 if (!is_anon_substructure && decl_align_unit > known_alignment)
     935                 :         681 :                   known_alignment = decl_align_unit;
     936                 :             :                 /* Pad to start of field.  */
     937                 :        5514 :                 decl_offset =
     938                 :        2757 :                   TREE_INT_CST_LOW (DECL_FIELD_OFFSET (field))
     939                 :        2757 :                   + precision_to_units
     940                 :        2757 :                   (TREE_INT_CST_LOW (DECL_FIELD_BIT_OFFSET (field)));
     941                 :        2757 :                 {
     942                 :        2757 :                   unsigned int align_unit;
     943                 :             : 
     944                 :             :                   /* For anonymous records and unions there is no automatic
     945                 :             :                      structure alignment, so use 1 as the alignment.  */
     946                 :        2757 :                   align_unit = (is_anon_substructure) ? 1 : decl_align_unit;
     947                 :        5514 :                   *p_art_i = go_append_padding
     948                 :        2757 :                     (ob, prev_field_end, decl_offset, align_unit, *p_art_i,
     949                 :             :                      &prev_field_end);
     950                 :             :                 }
     951                 :        2757 :                 if (DECL_SIZE_UNIT (field))
     952                 :        5494 :                   prev_field_end +=
     953                 :        2747 :                     TREE_INT_CST_LOW (DECL_SIZE_UNIT (field));
     954                 :             :                 /* Emit the field name, but not for anonymous records and
     955                 :             :                    unions.  */
     956                 :        2757 :                 if (!is_anon_substructure)
     957                 :             :                   {
     958                 :        2691 :                     if (DECL_NAME (field) == NULL)
     959                 :          26 :                       *p_art_i = go_append_artificial_name (ob, *p_art_i);
     960                 :             :                     else
     961                 :        2665 :                       go_append_decl_name
     962                 :        2665 :                         (ob, field, container->keyword_hash);
     963                 :        2691 :                     obstack_1grow (ob, ' ');
     964                 :             :                   }
     965                 :             :                 /* Do not expand type if a record or union type or a function
     966                 :             :                    pointer.  */
     967                 :        2757 :                 if (TYPE_NAME (TREE_TYPE (field)) != NULL_TREE
     968                 :        2757 :                     && (RECORD_OR_UNION_TYPE_P (TREE_TYPE (field))
     969                 :        2013 :                         || (POINTER_TYPE_P (TREE_TYPE (field))
     970                 :           6 :                             && (TREE_CODE (TREE_TYPE (TREE_TYPE (field)))
     971                 :             :                                 == FUNCTION_TYPE))))
     972                 :             :                   {
     973                 :         197 :                     tree name;
     974                 :         197 :                     void **slot;
     975                 :             : 
     976                 :         197 :                     name = TYPE_IDENTIFIER (TREE_TYPE (field));
     977                 :             : 
     978                 :         197 :                     slot = htab_find_slot (container->invalid_hash,
     979                 :         197 :                                            IDENTIFIER_POINTER (name),
     980                 :             :                                            NO_INSERT);
     981                 :         197 :                     if (slot != NULL)
     982                 :           0 :                       field_ok = false;
     983                 :             : 
     984                 :         197 :                     obstack_1grow (ob, '_');
     985                 :         197 :                     go_append_string (ob, name);
     986                 :             :                   }
     987                 :             :                 else
     988                 :             :                   {
     989                 :        2560 :                     if (!go_format_type (container, TREE_TYPE (field), true,
     990                 :             :                                          false, p_art_i, is_anon_substructure))
     991                 :             :                       field_ok = false;
     992                 :             :                   }
     993                 :        2757 :                 if (!is_anon_substructure)
     994                 :        2691 :                   obstack_grow (ob, "; ", 2);
     995                 :        2757 :                 if (!field_ok)
     996                 :           8 :                   ret = false;
     997                 :             :               }
     998                 :             :           }
     999                 :             :         /* Padding.  */
    1000                 :        2157 :         *p_art_i = go_append_padding (ob, prev_field_end,
    1001                 :         719 :                                       TREE_INT_CST_LOW (TYPE_SIZE_UNIT (type)),
    1002                 :             :                                       1, *p_art_i, &prev_field_end);
    1003                 :             :         /* Alignment.  */
    1004                 :         719 :         if (!is_anon_record_or_union
    1005                 :         719 :             && known_alignment < TYPE_ALIGN_UNIT (type))
    1006                 :             :           {
    1007                 :          59 :             const char *s;
    1008                 :          59 :             char buf[100];
    1009                 :             : 
    1010                 :             :             /* Enforce proper record alignment.  */
    1011                 :          59 :             s = go_get_uinttype_for_precision
    1012                 :          59 :               (TYPE_ALIGN (type), TYPE_UNSIGNED (type));
    1013                 :          59 :             if (s == NULL)
    1014                 :             :               {
    1015                 :           0 :                 snprintf (buf, sizeof buf, "INVALID-int-%u%s",
    1016                 :           0 :                           TYPE_ALIGN (type), TYPE_UNSIGNED (type) ? "u" : "");
    1017                 :           0 :                 s = buf;
    1018                 :           0 :                 ret = false;
    1019                 :             :               }
    1020                 :          59 :             *p_art_i = go_force_record_alignment (ob, s, *p_art_i, buf);
    1021                 :             :           }
    1022                 :         719 :         if (!is_anon_record_or_union)
    1023                 :         653 :           obstack_1grow (ob, '}');
    1024                 :             :       }
    1025                 :         719 :     break;
    1026                 :             : 
    1027                 :        1952 :     case FUNCTION_TYPE:
    1028                 :        1952 :       {
    1029                 :        1952 :         tree arg_type;
    1030                 :        1952 :         bool is_varargs;
    1031                 :        1952 :         tree result;
    1032                 :        1952 :         function_args_iterator iter;
    1033                 :        1952 :         bool seen_arg;
    1034                 :             : 
    1035                 :             :         /* Go has no way to write a type which is a function but not a
    1036                 :             :            pointer to a function.  */
    1037                 :        1952 :         if (!is_func_ok)
    1038                 :             :           {
    1039                 :           8 :             obstack_grow (ob, "func*", 5);
    1040                 :           8 :             ret = false;
    1041                 :             :           }
    1042                 :             : 
    1043                 :        1952 :         obstack_1grow (ob, '(');
    1044                 :        1952 :         is_varargs = stdarg_p (type);
    1045                 :        1952 :         seen_arg = false;
    1046                 :        6411 :         FOREACH_FUNCTION_ARGS (type, arg_type, iter)
    1047                 :             :           {
    1048                 :        6349 :             if (VOID_TYPE_P (arg_type))
    1049                 :             :               break;
    1050                 :        4459 :             if (seen_arg)
    1051                 :        2670 :               obstack_grow (ob, ", ", 2);
    1052                 :        4459 :             if (!go_format_type (container, arg_type, true, false, NULL, false))
    1053                 :          34 :               ret = false;
    1054                 :        4459 :             seen_arg = true;
    1055                 :             :           }
    1056                 :        1952 :         if (is_varargs)
    1057                 :             :           {
    1058                 :          62 :             if (prototype_p (type))
    1059                 :          62 :               obstack_grow (ob, ", ", 2);
    1060                 :          62 :             obstack_grow (ob, "...interface{}", 14);
    1061                 :             :           }
    1062                 :        1952 :         obstack_1grow (ob, ')');
    1063                 :             : 
    1064                 :        1952 :         result = TREE_TYPE (type);
    1065                 :        1952 :         if (!VOID_TYPE_P (result))
    1066                 :             :           {
    1067                 :        1780 :             obstack_1grow (ob, ' ');
    1068                 :        1780 :             if (!go_format_type (container, result, use_type_name, false, NULL,
    1069                 :             :                                  false))
    1070                 :        1952 :               ret = false;
    1071                 :             :           }
    1072                 :             :       }
    1073                 :        1952 :       break;
    1074                 :             : 
    1075                 :           2 :     default:
    1076                 :           2 :       obstack_grow (ob, "INVALID-type", 12);
    1077                 :           2 :       ret = false;
    1078                 :           2 :       break;
    1079                 :             :     }
    1080                 :             : 
    1081                 :             :   return ret;
    1082                 :             : }
    1083                 :             : 
    1084                 :             : /* Output the type which was built on the type obstack, and then free
    1085                 :             :    it.  */
    1086                 :             : 
    1087                 :             : static void
    1088                 :        3363 : go_output_type (class godump_container *container)
    1089                 :             : {
    1090                 :        3363 :   struct obstack *ob;
    1091                 :             : 
    1092                 :        3363 :   ob = &container->type_obstack;
    1093                 :        3363 :   obstack_1grow (ob, '\0');
    1094                 :        3363 :   fputs ((char *) obstack_base (ob), go_dump_file);
    1095                 :        3363 :   obstack_free (ob, obstack_base (ob));
    1096                 :        3363 : }
    1097                 :             : 
    1098                 :             : /* Output a function declaration.  */
    1099                 :             : 
    1100                 :             : static void
    1101                 :        1876 : go_output_fndecl (class godump_container *container, tree decl)
    1102                 :             : {
    1103                 :        1876 :   if (!go_format_type (container, TREE_TYPE (decl), true, true, NULL, false))
    1104                 :          46 :     fprintf (go_dump_file, "// ");
    1105                 :        3752 :   fprintf (go_dump_file, "func _%s ",
    1106                 :        1876 :            IDENTIFIER_POINTER (DECL_NAME (decl)));
    1107                 :        1876 :   go_output_type (container);
    1108                 :        3752 :   fprintf (go_dump_file, " __asm__(\"%s\")\n",
    1109                 :        1876 :            IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
    1110                 :        1876 : }
    1111                 :             : 
    1112                 :             : /* Output a typedef or something like a struct definition.  */
    1113                 :             : 
    1114                 :             : static void
    1115                 :        1501 : go_output_typedef (class godump_container *container, tree decl)
    1116                 :             : {
    1117                 :             :   /* If we have an enum type, output the enum constants
    1118                 :             :      separately.  */
    1119                 :        1501 :   if (TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE
    1120                 :         296 :       && TYPE_SIZE (TREE_TYPE (decl)) != 0
    1121                 :         296 :       && !container->decls_seen.contains (TREE_TYPE (decl))
    1122                 :        1796 :       && (TYPE_CANONICAL (TREE_TYPE (decl)) == NULL_TREE
    1123                 :         295 :           || !container->decls_seen.contains
    1124                 :         295 :                                     (TYPE_CANONICAL (TREE_TYPE (decl)))))
    1125                 :             :     {
    1126                 :         279 :       tree element;
    1127                 :             : 
    1128                 :         279 :       for (element = TYPE_VALUES (TREE_TYPE (decl));
    1129                 :        3641 :            element != NULL_TREE;
    1130                 :        3362 :            element = TREE_CHAIN (element))
    1131                 :             :         {
    1132                 :        3362 :           const char *name;
    1133                 :        3362 :           struct macro_hash_value *mhval;
    1134                 :        3362 :           void **slot;
    1135                 :        3362 :           char buf[WIDE_INT_PRINT_BUFFER_SIZE];
    1136                 :        3362 :           tree value = DECL_INITIAL (TREE_VALUE (element));
    1137                 :             : 
    1138                 :        3362 :           name = IDENTIFIER_POINTER (TREE_PURPOSE (element));
    1139                 :             : 
    1140                 :             :           /* Sometimes a name will be defined as both an enum constant
    1141                 :             :              and a macro.  Avoid duplicate definition errors by
    1142                 :             :              treating enum constants as macros.  */
    1143                 :        3362 :           mhval = XNEW (struct macro_hash_value);
    1144                 :        3362 :           mhval->name = xstrdup (name);
    1145                 :        3362 :           mhval->value = NULL;
    1146                 :        3362 :           slot = htab_find_slot (macro_hash, mhval, INSERT);
    1147                 :        3362 :           if (*slot != NULL)
    1148                 :         131 :             macro_hash_del (*slot);
    1149                 :             : 
    1150                 :        3362 :           if (tree_fits_shwi_p (value))
    1151                 :        3362 :             snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_DEC,
    1152                 :             :                      tree_to_shwi (value));
    1153                 :           0 :           else if (tree_fits_uhwi_p (value))
    1154                 :           0 :             snprintf (buf, sizeof buf, HOST_WIDE_INT_PRINT_UNSIGNED,
    1155                 :             :                       tree_to_uhwi (value));
    1156                 :             :           else
    1157                 :             :             {
    1158                 :           0 :               wide_int w = wi::to_wide (element);
    1159                 :           0 :               gcc_assert (w.get_len () <= WIDE_INT_MAX_INL_ELTS);
    1160                 :           0 :               print_hex (w, buf);
    1161                 :           0 :             }
    1162                 :             : 
    1163                 :        3362 :           mhval->value = xstrdup (buf);
    1164                 :        3362 :           *slot = mhval;
    1165                 :             :         }
    1166                 :         279 :       container->decls_seen.add (TREE_TYPE (decl));
    1167                 :         279 :       if (TYPE_CANONICAL (TREE_TYPE (decl)) != NULL_TREE)
    1168                 :         279 :         container->decls_seen.add (TYPE_CANONICAL (TREE_TYPE (decl)));
    1169                 :             :     }
    1170                 :             : 
    1171                 :        1501 :   if (DECL_NAME (decl) != NULL_TREE)
    1172                 :             :     {
    1173                 :         773 :       void **slot;
    1174                 :         773 :       const char *type;
    1175                 :         773 :       tree original_type;
    1176                 :             : 
    1177                 :         773 :       type = IDENTIFIER_POINTER (DECL_NAME (decl));
    1178                 :         773 :       original_type = DECL_ORIGINAL_TYPE (decl);
    1179                 :         773 :       if (original_type == NULL_TREE)
    1180                 :           0 :         original_type = TREE_TYPE (decl);
    1181                 :             : 
    1182                 :             :       /* Suppress typedefs where the type name matches the underlying
    1183                 :             :          struct/union/enum tag. This way we'll emit the struct definition
    1184                 :             :          instead of an invalid recursive type.  */
    1185                 :         773 :       if (TYPE_IDENTIFIER (original_type) != NULL
    1186                 :        1389 :           && IDENTIFIER_POINTER (TYPE_IDENTIFIER (original_type)) == type)
    1187                 :             :         return;
    1188                 :             : 
    1189                 :             :       /* If type defined already, skip.  */
    1190                 :         761 :       slot = htab_find_slot (container->type_hash, type, INSERT);
    1191                 :         761 :       if (*slot != NULL)
    1192                 :             :         return;
    1193                 :         761 :       *slot = CONST_CAST (void *, (const void *) type);
    1194                 :             : 
    1195                 :         761 :       if (!go_format_type (container, original_type, true, false,
    1196                 :             :                            NULL, false))
    1197                 :             :         {
    1198                 :          21 :           fprintf (go_dump_file, "// ");
    1199                 :          21 :           slot = htab_find_slot (container->invalid_hash, type, INSERT);
    1200                 :          21 :           *slot = CONST_CAST (void *, (const void *) type);
    1201                 :             :         }
    1202                 :        1522 :       fprintf (go_dump_file, "type _%s ",
    1203                 :         761 :                IDENTIFIER_POINTER (DECL_NAME (decl)));
    1204                 :         761 :       go_output_type (container);
    1205                 :             : 
    1206                 :         761 :       if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
    1207                 :             :         {
    1208                 :         154 :           HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (decl));
    1209                 :             : 
    1210                 :         154 :           if (size > 0)
    1211                 :         296 :             fprintf (go_dump_file,
    1212                 :             :                      "\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC,
    1213                 :         148 :                      IDENTIFIER_POINTER (DECL_NAME (decl)),
    1214                 :             :                      size);
    1215                 :             :         }
    1216                 :             : 
    1217                 :         761 :       container->decls_seen.add (decl);
    1218                 :             :     }
    1219                 :        1015 :   else if ((RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl))
    1220                 :         279 :             || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
    1221                 :        1015 :            && TYPE_NAME (TREE_TYPE (decl)) != NULL)
    1222                 :             :     {
    1223                 :         521 :        void **slot;
    1224                 :         521 :        const char *type;
    1225                 :         521 :        HOST_WIDE_INT size;
    1226                 :             : 
    1227                 :         521 :        type = IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE ((decl))));
    1228                 :             :        /* If type defined already, skip.  */
    1229                 :         521 :        slot = htab_find_slot (container->type_hash, type, INSERT);
    1230                 :         521 :        if (*slot != NULL)
    1231                 :             :          return;
    1232                 :         521 :        *slot = CONST_CAST (void *, (const void *) type);
    1233                 :             : 
    1234                 :         521 :        if (!go_format_type (container, TREE_TYPE (decl), false, false, NULL,
    1235                 :             :                             false))
    1236                 :             :          {
    1237                 :           2 :            fprintf (go_dump_file, "// ");
    1238                 :           2 :            slot = htab_find_slot (container->invalid_hash, type, INSERT);
    1239                 :           2 :            *slot = CONST_CAST (void *, (const void *) type);
    1240                 :             :          }
    1241                 :        1042 :        fprintf (go_dump_file, "type _%s ",
    1242                 :         521 :                IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))));
    1243                 :         521 :        go_output_type (container);
    1244                 :             : 
    1245                 :         521 :        size = int_size_in_bytes (TREE_TYPE (decl));
    1246                 :         521 :        if (size > 0)
    1247                 :        1032 :          fprintf (go_dump_file,
    1248                 :             :                   "\nconst _sizeof_%s = " HOST_WIDE_INT_PRINT_DEC,
    1249                 :         516 :                   IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))),
    1250                 :             :                   size);
    1251                 :             :     }
    1252                 :             :   else
    1253                 :             :     return;
    1254                 :             : 
    1255                 :        1282 :   fprintf (go_dump_file, "\n");
    1256                 :             : }
    1257                 :             : 
    1258                 :             : /* Output a variable.  */
    1259                 :             : 
    1260                 :             : static void
    1261                 :         339 : go_output_var (class godump_container *container, tree decl)
    1262                 :             : {
    1263                 :         339 :   bool is_valid;
    1264                 :         339 :   tree type_name;
    1265                 :         339 :   tree id;
    1266                 :             : 
    1267                 :         339 :   if (container->decls_seen.contains (decl)
    1268                 :         339 :       || container->decls_seen.contains (DECL_NAME (decl)))
    1269                 :         134 :     return;
    1270                 :         205 :   container->decls_seen.add (decl);
    1271                 :         205 :   container->decls_seen.add (DECL_NAME (decl));
    1272                 :             : 
    1273                 :         205 :   type_name = TYPE_NAME (TREE_TYPE (decl));
    1274                 :         205 :   id = NULL_TREE;
    1275                 :         205 :   if (type_name != NULL_TREE && TREE_CODE (type_name) == IDENTIFIER_NODE)
    1276                 :             :     id = type_name;
    1277                 :         118 :   else if (type_name != NULL_TREE && TREE_CODE (type_name) == TYPE_DECL
    1278                 :         118 :            && DECL_SOURCE_LOCATION (type_name) != BUILTINS_LOCATION
    1279                 :         118 :            && DECL_NAME (type_name))
    1280                 :         118 :     id = DECL_NAME (type_name);
    1281                 :         118 :   if (id != NULL_TREE
    1282                 :         241 :       && (!htab_find_slot (container->type_hash, IDENTIFIER_POINTER (id),
    1283                 :             :                            NO_INSERT)
    1284                 :          82 :           || htab_find_slot (container->invalid_hash, IDENTIFIER_POINTER (id),
    1285                 :             :                              NO_INSERT)))
    1286                 :             :     id = NULL_TREE;
    1287                 :         161 :   if (id != NULL_TREE)
    1288                 :             :     {
    1289                 :          79 :       struct obstack *ob;
    1290                 :             : 
    1291                 :          79 :       ob = &container->type_obstack;
    1292                 :          79 :       obstack_1grow (ob, '_');
    1293                 :          79 :       go_append_string (ob, id);
    1294                 :          79 :       is_valid = htab_find_slot (container->type_hash, IDENTIFIER_POINTER (id),
    1295                 :             :                                  NO_INSERT) != NULL;
    1296                 :             :     }
    1297                 :             :   else
    1298                 :         126 :     is_valid = go_format_type (container, TREE_TYPE (decl), true, false, NULL,
    1299                 :             :                                false);
    1300                 :         205 :   if (is_valid
    1301                 :         403 :       && htab_find_slot (container->type_hash,
    1302                 :         198 :                          IDENTIFIER_POINTER (DECL_NAME (decl)),
    1303                 :             :                          NO_INSERT) != NULL)
    1304                 :             :     {
    1305                 :             :       /* There is already a type with this name, probably from a
    1306                 :             :          struct tag.  Prefer the type to the variable.  */
    1307                 :             :       is_valid = false;
    1308                 :             :     }
    1309                 :         203 :   if (!is_valid)
    1310                 :           9 :     fprintf (go_dump_file, "// ");
    1311                 :             : 
    1312                 :         410 :   fprintf (go_dump_file, "var _%s ",
    1313                 :         205 :            IDENTIFIER_POINTER (DECL_NAME (decl)));
    1314                 :         205 :   go_output_type (container);
    1315                 :         205 :   fprintf (go_dump_file, "\n");
    1316                 :             : 
    1317                 :             :   /* Sometimes an extern variable is declared with an unknown struct
    1318                 :             :      type.  */
    1319                 :         205 :   if (type_name != NULL_TREE && RECORD_OR_UNION_TYPE_P (TREE_TYPE (decl)))
    1320                 :             :     {
    1321                 :          37 :       if (TREE_CODE (type_name) == IDENTIFIER_NODE)
    1322                 :           5 :         container->pot_dummy_types.add (IDENTIFIER_POINTER (type_name));
    1323                 :          32 :       else if (TREE_CODE (type_name) == TYPE_DECL)
    1324                 :          32 :         container->pot_dummy_types.add
    1325                 :          32 :                             (IDENTIFIER_POINTER (DECL_NAME (type_name)));
    1326                 :             :     }
    1327                 :             : }
    1328                 :             : 
    1329                 :             : /* Output the final value of a preprocessor macro or enum constant.
    1330                 :             :    This is called via htab_traverse_noresize.  */
    1331                 :             : 
    1332                 :             : static int
    1333                 :       13119 : go_print_macro (void **slot, void *arg ATTRIBUTE_UNUSED)
    1334                 :             : {
    1335                 :       13119 :   struct macro_hash_value *mhval = (struct macro_hash_value *) *slot;
    1336                 :       13119 :   fprintf (go_dump_file, "const _%s = %s\n", mhval->name, mhval->value);
    1337                 :       13119 :   return 1;
    1338                 :             : }
    1339                 :             : 
    1340                 :             : /* Build a hash table with the Go keywords.  */
    1341                 :             : 
    1342                 :             : static const char * const keywords[] = {
    1343                 :             :   "__asm__", "break", "case", "chan", "const", "continue", "default",
    1344                 :             :   "defer", "else", "fallthrough", "for", "func", "go", "goto", "if",
    1345                 :             :   "import", "interface", "map", "package", "range", "return", "select",
    1346                 :             :   "struct", "switch", "type", "var"
    1347                 :             : };
    1348                 :             : 
    1349                 :             : static void
    1350                 :           4 : keyword_hash_init (class godump_container *container)
    1351                 :             : {
    1352                 :           4 :   size_t i;
    1353                 :           4 :   size_t count = ARRAY_SIZE (keywords);
    1354                 :           4 :   void **slot;
    1355                 :             : 
    1356                 :         108 :   for (i = 0; i < count; i++)
    1357                 :             :     {
    1358                 :         104 :       slot = htab_find_slot (container->keyword_hash, keywords[i], INSERT);
    1359                 :         104 :       *slot = CONST_CAST (void *, (const void *) keywords[i]);
    1360                 :             :     }
    1361                 :           4 : }
    1362                 :             : 
    1363                 :             : /* Traversing the pot_dummy_types and seeing which types are present
    1364                 :             :    in the global types hash table and creating dummy definitions if
    1365                 :             :    not found.  This function is invoked by hash_set::traverse.  */
    1366                 :             : 
    1367                 :             : bool
    1368                 :         223 : find_dummy_types (const char *const &ptr, godump_container *adata)
    1369                 :             : {
    1370                 :         223 :   class godump_container *data = (class godump_container *) adata;
    1371                 :         223 :   const char *type = (const char *) ptr;
    1372                 :         223 :   void **slot;
    1373                 :         223 :   void **islot;
    1374                 :             : 
    1375                 :         223 :   slot = htab_find_slot (data->type_hash, type, NO_INSERT);
    1376                 :         223 :   islot = htab_find_slot (data->invalid_hash, type, NO_INSERT);
    1377                 :         223 :   if (slot == NULL || islot != NULL)
    1378                 :          21 :     fprintf (go_dump_file, "type _%s struct {}\n", type);
    1379                 :         223 :   return true;
    1380                 :             : }
    1381                 :             : 
    1382                 :             : /* Output symbols.  */
    1383                 :             : 
    1384                 :             : static void
    1385                 :           4 : go_finish (const char *filename)
    1386                 :             : {
    1387                 :           4 :   class godump_container container;
    1388                 :           4 :   unsigned int ix;
    1389                 :           4 :   tree decl;
    1390                 :             : 
    1391                 :           4 :   real_debug_hooks->finish (filename);
    1392                 :             : 
    1393                 :           4 :   container.type_hash = htab_create (100, htab_hash_string,
    1394                 :             :                                      htab_eq_string, NULL);
    1395                 :           4 :   container.invalid_hash = htab_create (10, htab_hash_string,
    1396                 :             :                                         htab_eq_string, NULL);
    1397                 :           4 :   container.keyword_hash = htab_create (50, htab_hash_string,
    1398                 :             :                                         htab_eq_string, NULL);
    1399                 :           4 :   obstack_init (&container.type_obstack);
    1400                 :             : 
    1401                 :           4 :   keyword_hash_init (&container);
    1402                 :             : 
    1403                 :        3724 :   FOR_EACH_VEC_SAFE_ELT (queue, ix, decl)
    1404                 :             :     {
    1405                 :        3716 :       switch (TREE_CODE (decl))
    1406                 :             :         {
    1407                 :        1876 :         case FUNCTION_DECL:
    1408                 :        1876 :           go_output_fndecl (&container, decl);
    1409                 :        1876 :           break;
    1410                 :             : 
    1411                 :        1501 :         case TYPE_DECL:
    1412                 :        1501 :           go_output_typedef (&container, decl);
    1413                 :        1501 :           break;
    1414                 :             : 
    1415                 :         339 :         case VAR_DECL:
    1416                 :         339 :           go_output_var (&container, decl);
    1417                 :         339 :           break;
    1418                 :             : 
    1419                 :           0 :         default:
    1420                 :           0 :           gcc_unreachable ();
    1421                 :             :         }
    1422                 :             :     }
    1423                 :             : 
    1424                 :           4 :   htab_traverse_noresize (macro_hash, go_print_macro, NULL);
    1425                 :             : 
    1426                 :             :   /* To emit dummy definitions.  */
    1427                 :           4 :   container.pot_dummy_types.traverse<godump_container *, find_dummy_types>
    1428                 :           4 :                         (&container);
    1429                 :             : 
    1430                 :           4 :   htab_delete (container.type_hash);
    1431                 :           4 :   htab_delete (container.invalid_hash);
    1432                 :           4 :   htab_delete (container.keyword_hash);
    1433                 :           4 :   obstack_free (&container.type_obstack, NULL);
    1434                 :             : 
    1435                 :           4 :   vec_free (queue);
    1436                 :             : 
    1437                 :           4 :   if (fclose (go_dump_file) != 0)
    1438                 :           0 :     error ("could not close Go dump file: %m");
    1439                 :           4 :   go_dump_file = NULL;
    1440                 :           4 : }
    1441                 :             : 
    1442                 :             : /* Set up our hooks.  */
    1443                 :             : 
    1444                 :             : const struct gcc_debug_hooks *
    1445                 :           4 : dump_go_spec_init (const char *filename, const struct gcc_debug_hooks *hooks)
    1446                 :             : {
    1447                 :           4 :   go_dump_file = fopen (filename, "w");
    1448                 :           4 :   if (go_dump_file == NULL)
    1449                 :             :     {
    1450                 :           0 :       error ("could not open Go dump file %qs: %m", filename);
    1451                 :           0 :       return hooks;
    1452                 :             :     }
    1453                 :             : 
    1454                 :           4 :   go_debug_hooks = *hooks;
    1455                 :           4 :   real_debug_hooks = hooks;
    1456                 :             : 
    1457                 :           4 :   go_debug_hooks.finish = go_finish;
    1458                 :           4 :   go_debug_hooks.define = go_define;
    1459                 :           4 :   go_debug_hooks.undef = go_undef;
    1460                 :           4 :   go_debug_hooks.function_decl = go_function_decl;
    1461                 :           4 :   go_debug_hooks.early_global_decl = go_early_global_decl;
    1462                 :           4 :   go_debug_hooks.late_global_decl = go_late_global_decl;
    1463                 :           4 :   go_debug_hooks.type_decl = go_type_decl;
    1464                 :             : 
    1465                 :           4 :   macro_hash = htab_create (100, macro_hash_hashval, macro_hash_eq,
    1466                 :             :                             macro_hash_del);
    1467                 :             : 
    1468                 :           4 :   return &go_debug_hooks;
    1469                 :             : }
    1470                 :             : 
    1471                 :             : #include "gt-godump.h"
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.