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