LCOV - code coverage report
Current view: top level - gcc - wide-int-print.cc (source / functions) Hit Total Coverage
Test: gcc.info Lines: 56 56 100.0 %
Date: 2020-04-04 11:58:09 Functions: 8 8 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : /* Printing operations with very long integers.
       2                 :            :    Copyright (C) 2012-2020 Free Software Foundation, Inc.
       3                 :            :    Contributed by Kenneth Zadeck <zadeck@naturalbridge.com>
       4                 :            : 
       5                 :            : This file is part of GCC.
       6                 :            : 
       7                 :            : GCC is free software; you can redistribute it and/or modify it
       8                 :            : under the terms of the GNU General Public License as published by the
       9                 :            : Free Software Foundation; either version 3, or (at your option) any
      10                 :            : later version.
      11                 :            : 
      12                 :            : GCC is distributed in the hope that it will be useful, but WITHOUT
      13                 :            : ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :            : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :            : for more details.
      16                 :            : 
      17                 :            : You should have received a copy of the GNU General Public License
      18                 :            : along with GCC; see the file COPYING3.  If not see
      19                 :            : <http://www.gnu.org/licenses/>.  */
      20                 :            : 
      21                 :            : #include "config.h"
      22                 :            : #include "system.h"
      23                 :            : #include "coretypes.h"
      24                 :            : 
      25                 :            : /*
      26                 :            :  * public printing routines.
      27                 :            :  */
      28                 :            : 
      29                 :            : #define BLOCKS_NEEDED(PREC) \
      30                 :            :   (((PREC) + HOST_BITS_PER_WIDE_INT - 1) / HOST_BITS_PER_WIDE_INT)
      31                 :            : 
      32                 :            : void
      33                 :     140789 : print_dec (const wide_int_ref &wi, char *buf, signop sgn)
      34                 :            : {
      35                 :     140789 :   if (sgn == SIGNED)
      36                 :       5079 :     print_decs (wi, buf);
      37                 :            :   else
      38                 :     135710 :     print_decu (wi, buf);
      39                 :     140789 : }
      40                 :            : 
      41                 :            : void
      42                 :       1918 : print_dec (const wide_int_ref &wi, FILE *file, signop sgn)
      43                 :            : {
      44                 :       1918 :   if (sgn == SIGNED)
      45                 :       1818 :     print_decs (wi, file);
      46                 :            :   else
      47                 :        100 :     print_decu (wi, file);
      48                 :       1918 : }
      49                 :            : 
      50                 :            : 
      51                 :            : /* Try to print the signed self in decimal to BUF if the number fits
      52                 :            :    in a HWI.  Other print in hex.  */
      53                 :            : 
      54                 :            : void
      55                 :       8176 : print_decs (const wide_int_ref &wi, char *buf)
      56                 :            : {
      57                 :       8176 :   if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
      58                 :       8176 :       || (wi.get_len () == 1))
      59                 :            :     {
      60                 :       8152 :       if (wi::neg_p (wi))
      61                 :       2424 :         sprintf (buf, "-" HOST_WIDE_INT_PRINT_UNSIGNED,
      62                 :       2424 :                  -(unsigned HOST_WIDE_INT) wi.to_shwi ());
      63                 :            :       else
      64                 :      11456 :         sprintf (buf, HOST_WIDE_INT_PRINT_DEC, wi.to_shwi ());
      65                 :            :     }
      66                 :            :   else
      67                 :         24 :     print_hex (wi, buf);
      68                 :       8176 : }
      69                 :            : 
      70                 :            : /* Try to print the signed self in decimal to FILE if the number fits
      71                 :            :    in a HWI.  Other print in hex.  */
      72                 :            : 
      73                 :            : void
      74                 :       3097 : print_decs (const wide_int_ref &wi, FILE *file)
      75                 :            : {
      76                 :       3097 :   char buf[WIDE_INT_PRINT_BUFFER_SIZE];
      77                 :       3097 :   print_decs (wi, buf);
      78                 :       3097 :   fputs (buf, file);
      79                 :       3097 : }
      80                 :            : 
      81                 :            : /* Try to print the unsigned self in decimal to BUF if the number fits
      82                 :            :    in a HWI.  Other print in hex.  */
      83                 :            : 
      84                 :            : void
      85                 :     206616 : print_decu (const wide_int_ref &wi, char *buf)
      86                 :            : {
      87                 :     206616 :   if ((wi.get_precision () <= HOST_BITS_PER_WIDE_INT)
      88                 :     276068 :       || (wi.get_len () == 1 && !wi::neg_p (wi)))
      89                 :     410344 :     sprintf (buf, HOST_WIDE_INT_PRINT_UNSIGNED, wi.to_uhwi ());
      90                 :            :   else
      91                 :       1444 :     print_hex (wi, buf);
      92                 :     206616 : }
      93                 :            : 
      94                 :            : /* Try to print the signed self in decimal to FILE if the number fits
      95                 :            :    in a HWI.  Other print in hex.  */
      96                 :            : 
      97                 :            : void
      98                 :      70888 : print_decu (const wide_int_ref &wi, FILE *file)
      99                 :            : {
     100                 :      70888 :   char buf[WIDE_INT_PRINT_BUFFER_SIZE];
     101                 :      70888 :   print_decu (wi, buf);
     102                 :      70888 :   fputs (buf, file);
     103                 :      70888 : }
     104                 :            : 
     105                 :            : void
     106                 :      79516 : print_hex (const wide_int_ref &val, char *buf)
     107                 :            : {
     108                 :      79516 :   if (val == 0)
     109                 :      16288 :     buf += sprintf (buf, "0x0");
     110                 :            :   else
     111                 :            :     {
     112                 :      63228 :       buf += sprintf (buf, "0x");
     113                 :      63228 :       int start = ROUND_DOWN (val.get_precision (), HOST_BITS_PER_WIDE_INT);
     114                 :      63228 :       int width = val.get_precision () - start;
     115                 :      63228 :       bool first_p = true;
     116                 :     148794 :       for (int i = start; i >= 0; i -= HOST_BITS_PER_WIDE_INT)
     117                 :            :         {
     118                 :      85566 :           unsigned HOST_WIDE_INT uhwi = wi::extract_uhwi (val, i, width);
     119                 :      85566 :           if (!first_p)
     120                 :       1507 :             buf += sprintf (buf, HOST_WIDE_INT_PRINT_PADDED_HEX, uhwi);
     121                 :      84059 :           else if (uhwi != 0)
     122                 :            :             {
     123                 :      63228 :               buf += sprintf (buf, HOST_WIDE_INT_PRINT_HEX_PURE, uhwi);
     124                 :      63228 :               first_p = false;
     125                 :            :             }
     126                 :      85566 :           width = HOST_BITS_PER_WIDE_INT;
     127                 :            :         }
     128                 :            :     }
     129                 :      79516 : }
     130                 :            : 
     131                 :            : /* Print one big hex number to FILE.  Note that some assemblers may not
     132                 :            :    accept this for large modes.  */
     133                 :            : void
     134                 :      77459 : print_hex (const wide_int_ref &wi, FILE *file)
     135                 :            : {
     136                 :      77459 :   char buf[WIDE_INT_PRINT_BUFFER_SIZE];
     137                 :      77459 :   print_hex (wi, buf);
     138                 :      77459 :   fputs (buf, file);
     139                 :      77459 : }
     140                 :            : 

Generated by: LCOV version 1.0

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 --enable-host-shared. GCC test suite is run with the built compiler.