LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - SymbolConversion.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 58.8 % 85 50
Test Date: 2024-04-20 14:03:02 Functions: 58.3 % 12 7
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* do not edit automatically generated by mc from SymbolConversion.  */
       2                 :             : /* SymbolConversion.mod mapping between m2 symbols and gcc symbols.
       3                 :             : 
       4                 :             : Copyright (C) 2001-2024 Free Software Foundation, Inc.
       5                 :             : Contributed by Gaius Mulley <gaius.mulley@southwales.ac.uk>.
       6                 :             : 
       7                 :             : This file is part of GNU Modula-2.
       8                 :             : 
       9                 :             : GNU Modula-2 is free software; you can redistribute it and/or modify
      10                 :             : it under the terms of the GNU General Public License as published by
      11                 :             : the Free Software Foundation; either version 3, or (at your option)
      12                 :             : any later version.
      13                 :             : 
      14                 :             : GNU Modula-2 is distributed in the hope that it will be useful, but
      15                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      16                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17                 :             : General Public License for more details.
      18                 :             : 
      19                 :             : You should have received a copy of the GNU General Public License
      20                 :             : along with GNU Modula-2; see the file COPYING3.  If not see
      21                 :             : <http://www.gnu.org/licenses/>.  */
      22                 :             : 
      23                 :             : #include "config.h"
      24                 :             : #include "system.h"
      25                 :             : #include <stdbool.h>
      26                 :             : #   if !defined (PROC_D)
      27                 :             : #      define PROC_D
      28                 :             :        typedef void (*PROC_t) (void);
      29                 :             :        typedef struct { PROC_t proc; } PROC;
      30                 :             : #   endif
      31                 :             : 
      32                 :             : #   if !defined (TRUE)
      33                 :             : #      define TRUE (1==1)
      34                 :             : #   endif
      35                 :             : 
      36                 :             : #if defined(__cplusplus)
      37                 :             : #   undef NULL
      38                 :             : #   define NULL 0
      39                 :             : #endif
      40                 :             : #define _SymbolConversion_H
      41                 :             : #define _SymbolConversion_C
      42                 :             : 
      43                 :             : #   include "GNameKey.h"
      44                 :             : #   include "GIndexing.h"
      45                 :             : #   include "GSymbolTable.h"
      46                 :             : #   include "GM2Error.h"
      47                 :             : #   include "GM2ALU.h"
      48                 :             : #   include "Gm2block.h"
      49                 :             : #   include "Gm2tree.h"
      50                 :             : #   include "GM2Printf.h"
      51                 :             : #   include "GStorage.h"
      52                 :             : #   include "GSYSTEM.h"
      53                 :             : 
      54                 :             : #   define USEPOISON true
      55                 :             : #   define GGCPOISON 0x0A5A5A5A5
      56                 :             : typedef unsigned int *SymbolConversion_PtrToCardinal;
      57                 :             : 
      58                 :             : static Indexing_Index mod2gcc;
      59                 :             : static void * PoisonedSymbol;
      60                 :             : 
      61                 :             : /*
      62                 :             :    Mod2Gcc - given a modula-2 symbol, sym, return the gcc equivalent.
      63                 :             : */
      64                 :             : 
      65                 :             : extern "C" m2tree_Tree SymbolConversion_Mod2Gcc (unsigned int sym);
      66                 :             : 
      67                 :             : /*
      68                 :             :    Gcc2Mod - given a gcc tree return the modula-2 symbol.
      69                 :             : */
      70                 :             : 
      71                 :             : extern "C" unsigned int SymbolConversion_Gcc2Mod (m2tree_Tree tree);
      72                 :             : 
      73                 :             : /*
      74                 :             :    AddModGcc - adds the tuple [ sym, gcc ] into the database.
      75                 :             : */
      76                 :             : 
      77                 :             : extern "C" void SymbolConversion_AddModGcc (unsigned int sym, m2tree_Tree gcc);
      78                 :             : 
      79                 :             : /*
      80                 :             :    RemoveMod2Gcc - removes the gcc symbol from the lookup table.
      81                 :             : */
      82                 :             : 
      83                 :             : extern "C" void SymbolConversion_RemoveMod2Gcc (unsigned int sym);
      84                 :             : 
      85                 :             : /*
      86                 :             :    GccKnowsAbout - returns TRUE if gcc knows about the symbol, sym.
      87                 :             : */
      88                 :             : 
      89                 :             : extern "C" bool SymbolConversion_GccKnowsAbout (unsigned int sym);
      90                 :             : 
      91                 :             : /*
      92                 :             :    AddTemporaryKnown - adds a temporary gcc symbol against the modula-2 sym.
      93                 :             : */
      94                 :             : 
      95                 :             : extern "C" void SymbolConversion_AddTemporaryKnown (unsigned int sym);
      96                 :             : 
      97                 :             : /*
      98                 :             :    RemoveTemporaryKnown - removes the temporary symbol.
      99                 :             : */
     100                 :             : 
     101                 :             : extern "C" void SymbolConversion_RemoveTemporaryKnown (unsigned int sym);
     102                 :             : 
     103                 :             : /*
     104                 :             :    Poison - poisons a symbol.
     105                 :             : */
     106                 :             : 
     107                 :             : extern "C" void SymbolConversion_Poison (unsigned int sym);
     108                 :             : 
     109                 :             : /*
     110                 :             :    Mod2GccWithoutGCCPoison - given a modula-2 symbol, sym, return
     111                 :             :                              the gcc equivalent, it does not check to see
     112                 :             :                              whether the gcc symbol has been poisoned.
     113                 :             : */
     114                 :             : 
     115                 :             : static m2tree_Tree Mod2GccWithoutGCCPoison (unsigned int sym);
     116                 :             : 
     117                 :             : /*
     118                 :             :    Init - create both binary trees.
     119                 :             : */
     120                 :             : 
     121                 :             : static void Init (void);
     122                 :             : 
     123                 :             : 
     124                 :             : /*
     125                 :             :    Mod2GccWithoutGCCPoison - given a modula-2 symbol, sym, return
     126                 :             :                              the gcc equivalent, it does not check to see
     127                 :             :                              whether the gcc symbol has been poisoned.
     128                 :             : */
     129                 :             : 
     130                 :      745950 : static m2tree_Tree Mod2GccWithoutGCCPoison (unsigned int sym)
     131                 :             : {
     132                 :      745950 :   NameKey_Name n;
     133                 :      745950 :   m2tree_Tree tr;
     134                 :             : 
     135                 :      745950 :   if (Indexing_InBounds (mod2gcc, sym))
     136                 :             :     {
     137                 :      745950 :       tr = (m2tree_Tree) (Indexing_GetIndice (mod2gcc, sym));
     138                 :      745950 :       if (tr == PoisonedSymbol)
     139                 :             :         {
     140                 :           0 :           n = SymbolTable_GetSymName (sym);
     141                 :             :           /* not poisoned by the garbage collector, but by the gm2 front end.  */
     142                 :           0 :           M2Printf_printf1 ((const char *) "the gm2 front end poisoned this symbol (%a)\\n", 45, (const unsigned char *) &n, (sizeof (n)-1));
     143                 :           0 :           M2Error_InternalError ((const char *) "attempting to use a gcc symbol which is no longer in scope", 58);
     144                 :             :         }
     145                 :             :       return tr;
     146                 :             :     }
     147                 :             :   else
     148                 :             :     {
     149                 :             :       return NULL;
     150                 :             :     }
     151                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     152                 :             :   __builtin_unreachable ();
     153                 :             : }
     154                 :             : 
     155                 :             : 
     156                 :             : /*
     157                 :             :    Init - create both binary trees.
     158                 :             : */
     159                 :             : 
     160                 :       16817 : static void Init (void)
     161                 :             : {
     162                 :       16817 :   mod2gcc = Indexing_InitIndexTuned (1, (1024*1024) / 16, 16);
     163                 :       16817 :   Storage_ALLOCATE (&PoisonedSymbol, 1);
     164                 :       16817 : }
     165                 :             : 
     166                 :             : 
     167                 :             : /*
     168                 :             :    Mod2Gcc - given a modula-2 symbol, sym, return the gcc equivalent.
     169                 :             : */
     170                 :             : 
     171                 :    31877973 : extern "C" m2tree_Tree SymbolConversion_Mod2Gcc (unsigned int sym)
     172                 :             : {
     173                 :    31877973 :   NameKey_Name n;
     174                 :    31877973 :   SymbolConversion_PtrToCardinal t;
     175                 :    31877973 :   m2tree_Tree tr;
     176                 :             : 
     177                 :    31877973 :   if (USEPOISON)
     178                 :             :     {
     179                 :    31877973 :       if (Indexing_InBounds (mod2gcc, sym))
     180                 :             :         {
     181                 :    31697527 :           t = (SymbolConversion_PtrToCardinal) (Indexing_GetIndice (mod2gcc, sym));
     182                 :    31697527 :           if ((t != NULL) && ((*t) == GGCPOISON))
     183                 :             :             {
     184                 :           0 :               M2Error_InternalError ((const char *) "gcc symbol has been poisoned", 28);
     185                 :             :             }
     186                 :             :         }
     187                 :             :     }
     188                 :    31877973 :   if (Indexing_InBounds (mod2gcc, sym))
     189                 :             :     {
     190                 :    31697527 :       tr = (m2tree_Tree) (Indexing_GetIndice (mod2gcc, sym));
     191                 :    31697527 :       if (tr == PoisonedSymbol)
     192                 :             :         {
     193                 :           0 :           n = SymbolTable_GetSymName (sym);
     194                 :             :           /* not poisoned by the garbage collector, but by the gm2 front end  */
     195                 :           0 :           M2Printf_printf1 ((const char *) "the gm2 front end poisoned this symbol (%a)\\n", 45, (const unsigned char *) &n, (sizeof (n)-1));
     196                 :           0 :           M2Error_InternalError ((const char *) "attempting to use a gcc symbol which is no longer in scope", 58);
     197                 :             :         }
     198                 :             :       return tr;
     199                 :             :     }
     200                 :             :   else
     201                 :             :     {
     202                 :             :       return NULL;
     203                 :             :     }
     204                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     205                 :             :   __builtin_unreachable ();
     206                 :             : }
     207                 :             : 
     208                 :             : 
     209                 :             : /*
     210                 :             :    Gcc2Mod - given a gcc tree return the modula-2 symbol.
     211                 :             : */
     212                 :             : 
     213                 :           0 : extern "C" unsigned int SymbolConversion_Gcc2Mod (m2tree_Tree tree)
     214                 :             : {
     215                 :           0 :   unsigned int high;
     216                 :           0 :   unsigned int i;
     217                 :             : 
     218                 :           0 :   i = 1;
     219                 :           0 :   high = Indexing_HighIndice (mod2gcc);
     220                 :           0 :   while (i <= high)
     221                 :             :     {
     222                 :           0 :       if ((Indexing_GetIndice (mod2gcc, i)) == tree)
     223                 :             :         {
     224                 :           0 :           return i;
     225                 :             :         }
     226                 :           0 :       i += 1;
     227                 :             :     }
     228                 :             :   return SymbolTable_NulSym;
     229                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     230                 :             :   __builtin_unreachable ();
     231                 :             : }
     232                 :             : 
     233                 :             : 
     234                 :             : /*
     235                 :             :    AddModGcc - adds the tuple [ sym, gcc ] into the database.
     236                 :             : */
     237                 :             : 
     238                 :    11549627 : extern "C" void SymbolConversion_AddModGcc (unsigned int sym, m2tree_Tree gcc)
     239                 :             : {
     240                 :    11549627 :   m2tree_Tree old;
     241                 :    11549627 :   SymbolConversion_PtrToCardinal t;
     242                 :             : 
     243                 :    11549627 :   if (gcc == (m2block_GetErrorNode ()))
     244                 :             :     {
     245                 :           0 :       M2Error_InternalError ((const char *) "error node generated during symbol conversion", 45);
     246                 :             :     }
     247                 :    11549627 :   if (USEPOISON)
     248                 :             :     {
     249                 :    11549627 :       t = (SymbolConversion_PtrToCardinal) (gcc);
     250                 :    11549627 :       if ((gcc != ((m2tree_Tree) (NULL))) && ((*t) == GGCPOISON))
     251                 :             :         {
     252                 :           0 :           M2Error_InternalError ((const char *) "gcc symbol has been poisoned", 28);
     253                 :             :         }
     254                 :             :     }
     255                 :    11549627 :   old = SymbolConversion_Mod2Gcc (sym);
     256                 :    11549627 :   if (old == ((m2tree_Tree) (NULL)))
     257                 :             :     {
     258                 :             :       /* absent - add it  */
     259                 :    11338068 :       Indexing_PutIndice (mod2gcc, sym, gcc);
     260                 :    11338068 :       if ((Indexing_GetIndice (mod2gcc, sym)) != gcc)
     261                 :             :         {
     262                 :           0 :           M2Error_InternalError ((const char *) "failed to add gcc <-> mod2 symbol", 33);
     263                 :             :         }
     264                 :    11338068 :       gcc = m2block_RememberConstant (gcc);
     265                 :             :     }
     266                 :             :   /* do nothing, as it is already stored  */
     267                 :      211559 :   else if (old == gcc)
     268                 :             :     {
     269                 :             :       /* avoid dangling else.  */
     270                 :             :     }
     271                 :           0 :   else if (old == (m2block_GetErrorNode ()))
     272                 :             :     {
     273                 :             :       /* avoid dangling else.  */
     274                 :           0 :       M2Error_InternalError ((const char *) "replacing a temporary symbol (currently unexpected)", 51);
     275                 :             :     }
     276                 :             :   else
     277                 :             :     {
     278                 :             :       /* avoid dangling else.  */
     279                 :           0 :       M2Error_InternalError ((const char *) "should not be replacing a symbol", 32);
     280                 :             :     }
     281                 :    11549627 :   if ((SymbolTable_IsConst (sym)) && (! (SymbolTable_IsValueSolved (sym))))
     282                 :             :     {
     283                 :      350390 :       M2ALU_PushTypeOfTree (sym, gcc);
     284                 :      350390 :       SymbolTable_PopValue (sym);
     285                 :             :     }
     286                 :    11549627 : }
     287                 :             : 
     288                 :             : 
     289                 :             : /*
     290                 :             :    RemoveMod2Gcc - removes the gcc symbol from the lookup table.
     291                 :             : */
     292                 :             : 
     293                 :           0 : extern "C" void SymbolConversion_RemoveMod2Gcc (unsigned int sym)
     294                 :             : {
     295                 :           0 :   Indexing_PutIndice (mod2gcc, sym, NULL);
     296                 :           0 : }
     297                 :             : 
     298                 :             : 
     299                 :             : /*
     300                 :             :    GccKnowsAbout - returns TRUE if gcc knows about the symbol, sym.
     301                 :             : */
     302                 :             : 
     303                 :    27224046 : extern "C" bool SymbolConversion_GccKnowsAbout (unsigned int sym)
     304                 :             : {
     305                 :    27224046 :   return (Indexing_InBounds (mod2gcc, sym)) && ((Indexing_GetIndice (mod2gcc, sym)) != NULL);
     306                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     307                 :             :   __builtin_unreachable ();
     308                 :             : }
     309                 :             : 
     310                 :             : 
     311                 :             : /*
     312                 :             :    AddTemporaryKnown - adds a temporary gcc symbol against the modula-2 sym.
     313                 :             : */
     314                 :             : 
     315                 :           0 : extern "C" void SymbolConversion_AddTemporaryKnown (unsigned int sym)
     316                 :             : {
     317                 :             :   /* we add the error node against symbol, sym.  We expect it to be retacted later.  */
     318                 :           0 :   Indexing_PutIndice (mod2gcc, sym, m2block_GetErrorNode ());
     319                 :           0 : }
     320                 :             : 
     321                 :             : 
     322                 :             : /*
     323                 :             :    RemoveTemporaryKnown - removes the temporary symbol.
     324                 :             : */
     325                 :             : 
     326                 :           0 : extern "C" void SymbolConversion_RemoveTemporaryKnown (unsigned int sym)
     327                 :             : {
     328                 :           0 :   if ((SymbolConversion_Mod2Gcc (sym)) == (m2block_GetErrorNode ()))
     329                 :             :     {
     330                 :           0 :       Indexing_PutIndice (mod2gcc, sym, NULL);
     331                 :             :     }
     332                 :             :   else
     333                 :             :     {
     334                 :           0 :       M2Error_InternalError ((const char *) "attempting to remove a symbol which is not present in the tree", 62);
     335                 :             :     }
     336                 :           0 : }
     337                 :             : 
     338                 :             : 
     339                 :             : /*
     340                 :             :    Poison - poisons a symbol.
     341                 :             : */
     342                 :             : 
     343                 :      776185 : extern "C" void SymbolConversion_Poison (unsigned int sym)
     344                 :             : {
     345                 :      776185 :   void * a;
     346                 :             : 
     347                 :      776185 :   if (! (SymbolTable_IsConst (sym)))
     348                 :             :     {
     349                 :      745950 :       a = Mod2GccWithoutGCCPoison (sym);
     350                 :      745950 :       if (a != NULL)
     351                 :             :         {
     352                 :      743638 :           Indexing_PutIndice (mod2gcc, sym, PoisonedSymbol);
     353                 :             :         }
     354                 :             :     }
     355                 :      776185 : }
     356                 :             : 
     357                 :       16817 : extern "C" void _M2_SymbolConversion_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     358                 :             : {
     359                 :       16817 :   Init ();
     360                 :       16817 : }
     361                 :             : 
     362                 :           0 : extern "C" void _M2_SymbolConversion_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     363                 :             : {
     364                 :           0 : }
        

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.