LCOV - code coverage report
Current view: top level - /mnt/build/buildbot/bld/build-lcov/gcc/m2/gm2-compiler-boot - M2StackAddress.c (source / functions) Coverage Total Hit
Test: gcc.info Lines: 69.1 % 97 67
Test Date: 2024-04-13 14:00:49 Functions: 66.7 % 12 8
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 M2StackAddress.  */
       2                 :             : /* M2StackAddress.mod provides a generic stack for ADDRESS sized objects.
       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                 :             : #   include "GStorage.h"
      33                 :             : #   include "Gmcrts.h"
      34                 :             : #if defined(__cplusplus)
      35                 :             : #   undef NULL
      36                 :             : #   define NULL 0
      37                 :             : #endif
      38                 :             : #define _M2StackAddress_H
      39                 :             : #define _M2StackAddress_C
      40                 :             : 
      41                 :             : #   include "GStorage.h"
      42                 :             : #   include "GM2Error.h"
      43                 :             : #   include "GM2Debug.h"
      44                 :             : 
      45                 :             : #   define MaxBucket 10
      46                 :             : typedef struct M2StackAddress__T1_r M2StackAddress__T1;
      47                 :             : 
      48                 :             : typedef struct M2StackAddress__T2_r M2StackAddress__T2;
      49                 :             : 
      50                 :             : typedef M2StackAddress__T2 *M2StackAddress_StackBucket;
      51                 :             : 
      52                 :             : typedef struct M2StackAddress__T3_a M2StackAddress__T3;
      53                 :             : 
      54                 :             : typedef M2StackAddress__T1 *M2StackAddress_StackOfAddress;
      55                 :             : 
      56                 :             : struct M2StackAddress__T1_r {
      57                 :             :                               M2StackAddress_StackBucket tail;
      58                 :             :                             };
      59                 :             : 
      60                 :             : struct M2StackAddress__T3_a { void * array[(MaxBucket-1)+1]; };
      61                 :             : struct M2StackAddress__T2_r {
      62                 :             :                               M2StackAddress__T3 bucket;
      63                 :             :                               unsigned int items;
      64                 :             :                               M2StackAddress_StackBucket prev;
      65                 :             :                             };
      66                 :             : 
      67                 :             : 
      68                 :             : /*
      69                 :             :    InitStackAddress - creates and returns a new stack.
      70                 :             : */
      71                 :             : 
      72                 :             : extern "C" M2StackAddress_StackOfAddress M2StackAddress_InitStackAddress (void);
      73                 :             : 
      74                 :             : /*
      75                 :             :    KillStackAddress - destroys a stack, returning NIL.
      76                 :             : */
      77                 :             : 
      78                 :             : extern "C" M2StackAddress_StackOfAddress M2StackAddress_KillStackAddress (M2StackAddress_StackOfAddress s);
      79                 :             : 
      80                 :             : /*
      81                 :             :    PushAddress - pushes a word, w, onto, s.
      82                 :             : */
      83                 :             : 
      84                 :             : extern "C" void M2StackAddress_PushAddress (M2StackAddress_StackOfAddress s, void * w);
      85                 :             : 
      86                 :             : /*
      87                 :             :    PopAddress - pops an element from stack, s.
      88                 :             : */
      89                 :             : 
      90                 :             : extern "C" void * M2StackAddress_PopAddress (M2StackAddress_StackOfAddress s);
      91                 :             : 
      92                 :             : /*
      93                 :             :    IsEmptyAddress - returns TRUE if stack, s, is empty.
      94                 :             : */
      95                 :             : 
      96                 :             : extern "C" bool M2StackAddress_IsEmptyAddress (M2StackAddress_StackOfAddress s);
      97                 :             : 
      98                 :             : /*
      99                 :             :    PeepAddress - returns the element at, n, items below in the stack.
     100                 :             :                  Top of stack can be seen via Peep(s, 1)
     101                 :             : */
     102                 :             : 
     103                 :             : extern "C" void * M2StackAddress_PeepAddress (M2StackAddress_StackOfAddress s, unsigned int n);
     104                 :             : 
     105                 :             : /*
     106                 :             :    ReduceAddress - reduce the stack by n elements.
     107                 :             : */
     108                 :             : 
     109                 :             : extern "C" void M2StackAddress_ReduceAddress (M2StackAddress_StackOfAddress s, unsigned int n);
     110                 :             : 
     111                 :             : /*
     112                 :             :    NoOfItemsInStackAddress - returns the number of items held in the stack, s.
     113                 :             : */
     114                 :             : 
     115                 :             : extern "C" unsigned int M2StackAddress_NoOfItemsInStackAddress (M2StackAddress_StackOfAddress s);
     116                 :             : 
     117                 :             : /*
     118                 :             :    KillBucket - destroys a StackBucket and returns, NIL.
     119                 :             : */
     120                 :             : 
     121                 :             : static M2StackAddress_StackBucket KillBucket (M2StackAddress_StackBucket b);
     122                 :             : 
     123                 :             : /*
     124                 :             :    InitBucket - returns an empty StackBucket.
     125                 :             : */
     126                 :             : 
     127                 :             : static M2StackAddress_StackBucket InitBucket (M2StackAddress_StackBucket l);
     128                 :             : 
     129                 :             : 
     130                 :             : /*
     131                 :             :    KillBucket - destroys a StackBucket and returns, NIL.
     132                 :             : */
     133                 :             : 
     134                 :      434154 : static M2StackAddress_StackBucket KillBucket (M2StackAddress_StackBucket b)
     135                 :             : {
     136                 :      434154 :   if (b != NULL)
     137                 :             :     {
     138                 :      210643 :       b = KillBucket (b->prev);
     139                 :      210643 :       Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     140                 :             :     }
     141                 :      434154 :   return NULL;
     142                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     143                 :             :   __builtin_unreachable ();
     144                 :             : }
     145                 :             : 
     146                 :             : 
     147                 :             : /*
     148                 :             :    InitBucket - returns an empty StackBucket.
     149                 :             : */
     150                 :             : 
     151                 :     2661425 : static M2StackAddress_StackBucket InitBucket (M2StackAddress_StackBucket l)
     152                 :             : {
     153                 :     2661425 :   M2StackAddress_StackBucket b;
     154                 :             : 
     155                 :           0 :   Storage_ALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     156                 :     2661425 :   b->items = 0;
     157                 :     2661425 :   b->prev = l;
     158                 :     2661425 :   return b;
     159                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     160                 :             :   __builtin_unreachable ();
     161                 :             : }
     162                 :             : 
     163                 :             : 
     164                 :             : /*
     165                 :             :    InitStackAddress - creates and returns a new stack.
     166                 :             : */
     167                 :             : 
     168                 :      301289 : extern "C" M2StackAddress_StackOfAddress M2StackAddress_InitStackAddress (void)
     169                 :             : {
     170                 :      301289 :   M2StackAddress_StackOfAddress s;
     171                 :             : 
     172                 :      301289 :   Storage_ALLOCATE ((void **) &s, sizeof (M2StackAddress__T1));
     173                 :      301289 :   s->tail = NULL;
     174                 :      301289 :   return s;
     175                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     176                 :             :   __builtin_unreachable ();
     177                 :             : }
     178                 :             : 
     179                 :             : 
     180                 :             : /*
     181                 :             :    KillStackAddress - destroys a stack, returning NIL.
     182                 :             : */
     183                 :             : 
     184                 :      223511 : extern "C" M2StackAddress_StackOfAddress M2StackAddress_KillStackAddress (M2StackAddress_StackOfAddress s)
     185                 :             : {
     186                 :      223511 :   if (s != NULL)
     187                 :             :     {
     188                 :      223511 :       s->tail = KillBucket (s->tail);
     189                 :      223511 :       Storage_DEALLOCATE ((void **) &s, sizeof (M2StackAddress__T1));
     190                 :             :     }
     191                 :      223511 :   return NULL;
     192                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     193                 :             :   __builtin_unreachable ();
     194                 :             : }
     195                 :             : 
     196                 :             : 
     197                 :             : /*
     198                 :             :    PushAddress - pushes a word, w, onto, s.
     199                 :             : */
     200                 :             : 
     201                 :   168207910 : extern "C" void M2StackAddress_PushAddress (M2StackAddress_StackOfAddress s, void * w)
     202                 :             : {
     203                 :   168207910 :   if (s == NULL)
     204                 :             :     {
     205                 :           0 :       M2Error_InternalError ((const char *) "stack has not been initialized", 30);
     206                 :             :     }
     207                 :             :   else
     208                 :             :     {
     209                 :   168207910 :       if ((s->tail == NULL) || (s->tail->items == MaxBucket))
     210                 :             :         {
     211                 :     2661425 :           s->tail = InitBucket (s->tail);
     212                 :             :         }
     213                 :   168207910 :       if (s->tail->items < MaxBucket)
     214                 :             :         {
     215                 :   168207910 :           s->tail->bucket.array[s->tail->items] = w;
     216                 :   168207910 :           s->tail->items += 1;
     217                 :             :         }
     218                 :             :     }
     219                 :   168207910 : }
     220                 :             : 
     221                 :             : 
     222                 :             : /*
     223                 :             :    PopAddress - pops an element from stack, s.
     224                 :             : */
     225                 :             : 
     226                 :   167128444 : extern "C" void * M2StackAddress_PopAddress (M2StackAddress_StackOfAddress s)
     227                 :             : {
     228                 :   167128444 :   M2StackAddress_StackBucket b;
     229                 :             : 
     230                 :   167128444 :   if (s == NULL)
     231                 :             :     {
     232                 :           0 :       M2Error_InternalError ((const char *) "stack has not been initialized", 30);
     233                 :             :     }
     234                 :             :   else
     235                 :             :     {
     236                 :   167128444 :       if (s->tail == NULL)
     237                 :             :         {
     238                 :           0 :           M2Error_InternalError ((const char *) "stack underflow", 15);
     239                 :             :         }
     240                 :             :       else
     241                 :             :         {
     242                 :   167128444 :           if (s->tail->items == 0)
     243                 :             :             {
     244                 :     1493288 :               b = s->tail;
     245                 :     1493288 :               if (b == NULL)
     246                 :             :                 {
     247                 :             :                   M2Error_InternalError ((const char *) "stack underflow", 15);
     248                 :             :                 }
     249                 :             :               else
     250                 :             :                 {
     251                 :     1493288 :                   s->tail = b->prev;
     252                 :             :                 }
     253                 :     1493288 :               Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     254                 :             :             }
     255                 :   167128444 :           s->tail->items -= 1;
     256                 :   167128444 :           return s->tail->bucket.array[s->tail->items];
     257                 :             :         }
     258                 :             :     }
     259                 :             :   ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2StackAddress.def", 20, 1);
     260                 :             :   __builtin_unreachable ();
     261                 :             : }
     262                 :             : 
     263                 :             : 
     264                 :             : /*
     265                 :             :    IsEmptyAddress - returns TRUE if stack, s, is empty.
     266                 :             : */
     267                 :             : 
     268                 :    27289609 : extern "C" bool M2StackAddress_IsEmptyAddress (M2StackAddress_StackOfAddress s)
     269                 :             : {
     270                 :    27289609 :   return (s == NULL) || (s->tail == NULL);
     271                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     272                 :             :   __builtin_unreachable ();
     273                 :             : }
     274                 :             : 
     275                 :             : 
     276                 :             : /*
     277                 :             :    PeepAddress - returns the element at, n, items below in the stack.
     278                 :             :                  Top of stack can be seen via Peep(s, 1)
     279                 :             : */
     280                 :             : 
     281                 :   165588546 : extern "C" void * M2StackAddress_PeepAddress (M2StackAddress_StackOfAddress s, unsigned int n)
     282                 :             : {
     283                 :   165588546 :   M2StackAddress_StackBucket b;
     284                 :             : 
     285                 :   165588546 :   if (s->tail == NULL)
     286                 :             :     {
     287                 :           0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     288                 :             :     }
     289                 :             :   else
     290                 :             :     {
     291                 :   165588546 :       if (s->tail->items == 0)
     292                 :             :         {
     293                 :      813857 :           b = s->tail;
     294                 :      813857 :           if (b == NULL)
     295                 :             :             {
     296                 :             :               M2Error_InternalError ((const char *) "stack underflow", 15);
     297                 :             :             }
     298                 :             :           else
     299                 :             :             {
     300                 :      813857 :               s->tail = b->prev;
     301                 :             :             }
     302                 :      813857 :           Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     303                 :             :         }
     304                 :   165588546 :       b = s->tail;
     305                 :   187482546 :       while (n >= 1)
     306                 :             :         {
     307                 :   187482546 :           if (b == NULL)
     308                 :             :             {
     309                 :           0 :               M2Error_InternalError ((const char *) "stack underflow", 15);
     310                 :             :             }
     311                 :   187482546 :           else if (b->items >= n)
     312                 :             :             {
     313                 :             :               /* avoid dangling else.  */
     314                 :   165588546 :               return b->bucket.array[b->items-n];
     315                 :             :             }
     316                 :             :           else
     317                 :             :             {
     318                 :             :               /* avoid dangling else.  */
     319                 :    21894000 :               M2Debug_Assert (b->items < n);
     320                 :    21894000 :               n -= b->items;
     321                 :    21894000 :               b = b->prev;
     322                 :             :             }
     323                 :             :         }
     324                 :           0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     325                 :             :     }
     326                 :             :   ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2StackAddress.def", 20, 1);
     327                 :             :   __builtin_unreachable ();
     328                 :             : }
     329                 :             : 
     330                 :             : 
     331                 :             : /*
     332                 :             :    ReduceAddress - reduce the stack by n elements.
     333                 :             : */
     334                 :             : 
     335                 :           0 : extern "C" void M2StackAddress_ReduceAddress (M2StackAddress_StackOfAddress s, unsigned int n)
     336                 :             : {
     337                 :           0 :   M2StackAddress_StackBucket b;
     338                 :             : 
     339                 :           0 :   if (s->tail == NULL)
     340                 :             :     {
     341                 :           0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     342                 :             :     }
     343                 :             :   else
     344                 :             :     {
     345                 :           0 :       if (s->tail->items == 0)
     346                 :             :         {
     347                 :           0 :           b = s->tail;
     348                 :           0 :           if (b == NULL)
     349                 :             :             {
     350                 :             :               M2Error_InternalError ((const char *) "stack underflow", 15);
     351                 :             :             }
     352                 :             :           else
     353                 :             :             {
     354                 :           0 :               s->tail = b->prev;
     355                 :             :             }
     356                 :           0 :           Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     357                 :             :         }
     358                 :           0 :       for (;;)
     359                 :             :       {
     360                 :           0 :         if (s->tail == NULL)
     361                 :             :           {
     362                 :           0 :             M2Error_InternalError ((const char *) "stack underflow", 15);
     363                 :             :           }
     364                 :           0 :         else if (s->tail->items >= n)
     365                 :             :           {
     366                 :             :             /* avoid dangling else.  */
     367                 :           0 :             s->tail->items -= n;
     368                 :           0 :             return ;  /* all done exit  */
     369                 :             :           }
     370                 :             :         else
     371                 :             :           {
     372                 :             :             /* avoid dangling else.  */
     373                 :           0 :             b = s->tail;
     374                 :           0 :             n -= b->items;
     375                 :           0 :             s->tail = s->tail->prev;
     376                 :           0 :             Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     377                 :             :           }
     378                 :             :       }
     379                 :             :     }
     380                 :             : }
     381                 :             : 
     382                 :             : 
     383                 :             : /*
     384                 :             :    NoOfItemsInStackAddress - returns the number of items held in the stack, s.
     385                 :             : */
     386                 :             : 
     387                 :    27289609 : extern "C" unsigned int M2StackAddress_NoOfItemsInStackAddress (M2StackAddress_StackOfAddress s)
     388                 :             : {
     389                 :    27289609 :   M2StackAddress_StackBucket b;
     390                 :    27289609 :   unsigned int n;
     391                 :             : 
     392                 :    27289609 :   if (M2StackAddress_IsEmptyAddress (s))
     393                 :             :     {
     394                 :             :       return 0;
     395                 :             :     }
     396                 :             :   else
     397                 :             :     {
     398                 :    27041171 :       n = 0;
     399                 :    27041171 :       b = s->tail;
     400                 :    54290194 :       while (b != NULL)
     401                 :             :         {
     402                 :    27249023 :           n += b->items;
     403                 :    27249023 :           b = b->prev;
     404                 :             :         }
     405                 :    27041171 :       return n;
     406                 :             :     }
     407                 :             :   /* static analysis guarentees a RETURN statement will be used before here.  */
     408                 :             :   __builtin_unreachable ();
     409                 :             : }
     410                 :             : 
     411                 :           0 : extern "C" void _M2_M2StackAddress_init (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     412                 :             : {
     413                 :           0 : }
     414                 :             : 
     415                 :           0 : extern "C" void _M2_M2StackAddress_fini (__attribute__((unused)) int argc,__attribute__((unused)) char *argv[],__attribute__((unused)) char *envp[])
     416                 :             : {
     417                 :           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.