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.4 % 98 68
Test Date: 2026-02-28 14:20:25 Functions: 75.0 % 12 9
Legend: Lines:     hit not hit

            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-2026 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_C
      39              : 
      40              : #include "GM2StackAddress.h"
      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__opaque;
      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       568740 : static M2StackAddress_StackBucket KillBucket (M2StackAddress_StackBucket b)
     135              : {
     136       568740 :   if (b != NULL)
     137              :     {
     138       277026 :       b = KillBucket (b->prev);
     139       277026 :       Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     140              :     }
     141       568740 :   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     13102695 : static M2StackAddress_StackBucket InitBucket (M2StackAddress_StackBucket l)
     152              : {
     153     13102695 :   M2StackAddress_StackBucket b;
     154              : 
     155            0 :   Storage_ALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     156     13102695 :   b->items = 0;
     157     13102695 :   b->prev = l;
     158     13102695 :   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       381426 : extern "C" M2StackAddress_StackOfAddress M2StackAddress_InitStackAddress (void)
     169              : {
     170       381426 :   M2StackAddress_StackOfAddress__opaque s;
     171              : 
     172       381426 :   Storage_ALLOCATE ((void **) &s, sizeof (M2StackAddress__T1));
     173       381426 :   s->tail = NULL;
     174       381426 :   return static_cast<M2StackAddress_StackOfAddress> (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       291714 : extern "C" M2StackAddress_StackOfAddress M2StackAddress_KillStackAddress (M2StackAddress_StackOfAddress s)
     185              : {
     186       291714 :   if (s != NULL)
     187              :     {
     188       291714 :       static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = KillBucket (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail);
     189       291714 :       Storage_DEALLOCATE ((void **) &s, sizeof (M2StackAddress__T1));
     190              :     }
     191       291714 :   return static_cast<M2StackAddress_StackOfAddress> (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    519109667 : extern "C" void M2StackAddress_PushAddress (M2StackAddress_StackOfAddress s, void * w)
     202              : {
     203    519109667 :   if (s == NULL)
     204              :     {
     205            0 :       M2Error_InternalError ((const char *) "stack has not been initialized", 30);
     206              :     }
     207              :   else
     208              :     {
     209    519109667 :       if ((static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL) || (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items == MaxBucket))
     210              :         {
     211     13102695 :           static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = InitBucket (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail);
     212              :         }
     213    519109667 :       if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items < MaxBucket)
     214              :         {
     215    519109667 :           static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->bucket.array[static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items] = w;
     216    519109667 :           static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items += 1;
     217              :         }
     218              :     }
     219    519109667 : }
     220              : 
     221              : 
     222              : /*
     223              :    PopAddress - pops an element from stack, s.
     224              : */
     225              : 
     226    516938649 : extern "C" void * M2StackAddress_PopAddress (M2StackAddress_StackOfAddress s)
     227              : {
     228    516938649 :   M2StackAddress_StackBucket b;
     229              : 
     230    516938649 :   if (s == NULL)
     231              :     {
     232            0 :       M2Error_InternalError ((const char *) "stack has not been initialized", 30);
     233              :     }
     234              :   else
     235              :     {
     236    516938649 :       if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL)
     237              :         {
     238            0 :           M2Error_InternalError ((const char *) "stack underflow", 15);
     239              :         }
     240              :       else
     241              :         {
     242    516938649 :           if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items == 0)
     243              :             {
     244     10365092 :               b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     245     10365092 :               if (b == NULL)
     246              :                 {
     247              :                   M2Error_InternalError ((const char *) "stack underflow", 15);
     248              :                 }
     249              :               else
     250              :                 {
     251     10365092 :                   static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = b->prev;
     252              :                 }
     253     10365092 :               Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     254              :             }
     255    516938649 :           if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL)
     256              :             {
     257            6 :               M2Error_InternalError ((const char *) "stack underflow", 15);
     258              :             }
     259              :           else
     260              :             {
     261    516938643 :               static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items -= 1;
     262    516938643 :               return static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->bucket.array[static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items];
     263              :             }
     264              :         }
     265              :     }
     266              :   ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2StackAddress.def", 20, 1);
     267              :   __builtin_unreachable ();
     268              : }
     269              : 
     270              : 
     271              : /*
     272              :    IsEmptyAddress - returns TRUE if stack, s, is empty.
     273              : */
     274              : 
     275     90185842 : extern "C" bool M2StackAddress_IsEmptyAddress (M2StackAddress_StackOfAddress s)
     276              : {
     277     90185842 :   return (s == NULL) || (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL);
     278              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     279              :   __builtin_unreachable ();
     280              : }
     281              : 
     282              : 
     283              : /*
     284              :    PeepAddress - returns the element at, n, items below in the stack.
     285              :                  Top of stack can be seen via Peep(s, 1)
     286              : */
     287              : 
     288    540619791 : extern "C" void * M2StackAddress_PeepAddress (M2StackAddress_StackOfAddress s, unsigned int n)
     289              : {
     290    540619791 :   M2StackAddress_StackBucket b;
     291              : 
     292    540619791 :   if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL)
     293              :     {
     294            0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     295              :     }
     296              :   else
     297              :     {
     298    540619791 :       if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items == 0)
     299              :         {
     300      2202947 :           b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     301      2202947 :           if (b == NULL)
     302              :             {
     303              :               M2Error_InternalError ((const char *) "stack underflow", 15);
     304              :             }
     305              :           else
     306              :             {
     307      2202947 :               static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = b->prev;
     308              :             }
     309      2202947 :           Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     310              :         }
     311    540619791 :       b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     312    652749906 :       while (n >= 1)
     313              :         {
     314    652749906 :           if (b == NULL)
     315              :             {
     316            0 :               M2Error_InternalError ((const char *) "stack underflow", 15);
     317              :             }
     318    652749906 :           else if (b->items >= n)
     319              :             {
     320              :               /* avoid dangling else.  */
     321    540619791 :               return b->bucket.array[b->items-n];
     322              :             }
     323              :           else
     324              :             {
     325              :               /* avoid dangling else.  */
     326    112130115 :               M2Debug_Assert (b->items < n);
     327    112130115 :               n -= b->items;
     328    112130115 :               b = b->prev;
     329              :             }
     330              :         }
     331            0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     332              :     }
     333              :   ReturnException ("/home/worker/buildworker/tiber-lcov/build/gcc/m2/gm2-compiler/M2StackAddress.def", 20, 1);
     334              :   __builtin_unreachable ();
     335              : }
     336              : 
     337              : 
     338              : /*
     339              :    ReduceAddress - reduce the stack by n elements.
     340              : */
     341              : 
     342            0 : extern "C" void M2StackAddress_ReduceAddress (M2StackAddress_StackOfAddress s, unsigned int n)
     343              : {
     344            0 :   M2StackAddress_StackBucket b;
     345              : 
     346            0 :   if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL)
     347              :     {
     348            0 :       M2Error_InternalError ((const char *) "stack underflow", 15);
     349              :     }
     350              :   else
     351              :     {
     352            0 :       if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items == 0)
     353              :         {
     354            0 :           b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     355            0 :           if (b == NULL)
     356              :             {
     357              :               M2Error_InternalError ((const char *) "stack underflow", 15);
     358              :             }
     359              :           else
     360              :             {
     361            0 :               static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = b->prev;
     362              :             }
     363            0 :           Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     364              :         }
     365            0 :       for (;;)
     366              :       {
     367            0 :         if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail == NULL)
     368              :           {
     369            0 :             M2Error_InternalError ((const char *) "stack underflow", 15);
     370              :           }
     371            0 :         else if (static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items >= n)
     372              :           {
     373              :             /* avoid dangling else.  */
     374            0 :             static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->items -= n;
     375            0 :             return;  /* all done exit  */
     376              :           }
     377              :         else
     378              :           {
     379              :             /* avoid dangling else.  */
     380            0 :             b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     381            0 :             n -= b->items;
     382            0 :             static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail->prev;
     383            0 :             Storage_DEALLOCATE ((void **) &b, sizeof (M2StackAddress__T2));
     384              :           }
     385              :       }
     386              :     }
     387              : }
     388              : 
     389              : 
     390              : /*
     391              :    NoOfItemsInStackAddress - returns the number of items held in the stack, s.
     392              : */
     393              : 
     394     90185842 : extern "C" unsigned int M2StackAddress_NoOfItemsInStackAddress (M2StackAddress_StackOfAddress s)
     395              : {
     396     90185842 :   M2StackAddress_StackBucket b;
     397     90185842 :   unsigned int n;
     398              : 
     399     90185842 :   if (M2StackAddress_IsEmptyAddress (s))
     400              :     {
     401              :       return 0;
     402              :     }
     403              :   else
     404              :     {
     405     89895883 :       n = 0;
     406     89895883 :       b = static_cast<M2StackAddress_StackOfAddress__opaque> (s)->tail;
     407    199980068 :       while (b != NULL)
     408              :         {
     409    110084185 :           n += b->items;
     410    110084185 :           b = b->prev;
     411              :         }
     412              :       return n;
     413              :     }
     414              :   /* static analysis guarentees a RETURN statement will be used before here.  */
     415              :   __builtin_unreachable ();
     416              : }
     417              : 
     418            0 : extern "C" void _M2_M2StackAddress_init (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     419              : {
     420            0 : }
     421              : 
     422            0 : extern "C" void _M2_M2StackAddress_fini (__attribute__((unused)) int argc, __attribute__((unused)) char *argv[], __attribute__((unused)) char *envp[])
     423              : {
     424            0 : }
        

Generated by: LCOV version 2.4-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.