public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-13] gcov-tool: Support file input from stdin
@ 2022-04-28 19:41 Sebastian Huber
  0 siblings, 0 replies; only message in thread
From: Sebastian Huber @ 2022-04-28 19:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:e543d9d2cf597773556ce0db2594335444eec304

commit r13-13-ge543d9d2cf597773556ce0db2594335444eec304
Author: Sebastian Huber <sebastian.huber@embedded-brains.de>
Date:   Wed Mar 30 21:40:55 2022 +0200

    gcov-tool: Support file input from stdin
    
    gcc/
    
            * gcov-io.cc (GCOV_MODE_STDIN): Define.
            (gcov_position): For gcov-tool, return calculated position if file is
            stdin.
            (gcov_open):  For gcov-tool, use stdin if filename is NULL.
            (gcov_close): For gcov-tool, do not close stdin.
            (gcov_read_bytes): For gcov-tool, update position if file is stdin.
            (gcov_sync): For gcov-tool, discard input if file is stdin.

Diff:
---
 gcc/gcov-io.cc | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/gcc/gcov-io.cc b/gcc/gcov-io.cc
index fee3130f94a..7e1fb10b612 100644
--- a/gcc/gcov-io.cc
+++ b/gcc/gcov-io.cc
@@ -35,8 +35,13 @@ struct gcov_var
   int error;			/* < 0 overflow, > 0 disk error.  */
   int mode;			/* < 0 writing, > 0 reading.  */
   int endian;			/* Swap endianness.  */
+#ifdef IN_GCOV_TOOL
+  gcov_position_t pos;		/* File position for stdin support.  */
+#endif
 } gcov_var;
 
+#define GCOV_MODE_STDIN 2
+
 /* Save the current position in the gcov file.  */
 /* We need to expose this function when compiling for gcov-tool.  */
 #ifndef IN_GCOV_TOOL
@@ -45,6 +50,10 @@ static inline
 gcov_position_t
 gcov_position (void)
 {
+#ifdef IN_GCOV_TOOL
+  if (gcov_var.mode == GCOV_MODE_STDIN)
+    return gcov_var.pos;
+#endif
   return ftell (gcov_var.file);
 }
 
@@ -108,6 +117,16 @@ gcov_open (const char *name, int mode)
 #if !IN_LIBGCOV || defined (IN_GCOV_TOOL)
   gcov_var.endian = 0;
 #endif
+#ifdef IN_GCOV_TOOL
+  gcov_var.pos = 0;
+  if (!name)
+    {
+      gcov_nonruntime_assert (gcov_var.mode > 0);
+      gcov_var.file = stdin;
+      gcov_var.mode = GCOV_MODE_STDIN;
+      return 1;
+    }
+#endif
 #if GCOV_LOCKED
   if (mode > 0)
     {
@@ -190,6 +209,11 @@ gcov_open (const char *name, int mode)
 GCOV_LINKAGE int
 gcov_close (void)
 {
+#ifdef IN_GCOV_TOOL
+  if (gcov_var.file == stdin)
+    gcov_var.file = 0;
+  else
+#endif
   if (gcov_var.file)
     {
       if (fclose (gcov_var.file))
@@ -363,6 +387,9 @@ gcov_read_bytes (void *buffer, unsigned count)
   if (read != 1)
     return NULL;
 
+#ifdef IN_GCOV_TOOL
+  gcov_var.pos += count;
+#endif
   return buffer;
 }
 
@@ -499,6 +526,17 @@ gcov_sync (gcov_position_t base, gcov_unsigned_t length)
 {
   gcov_nonruntime_assert (gcov_var.mode > 0);
   base += length;
+#ifdef IN_GCOV_TOOL
+  if (gcov_var.mode == GCOV_MODE_STDIN)
+    {
+      while (gcov_var.pos < base)
+	{
+	  ++gcov_var.pos;
+	  (void)fgetc (gcov_var.file);
+	}
+      return;
+    }
+#endif
   fseek (gcov_var.file, base, SEEK_SET);
 }
 #endif


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-28 19:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-28 19:41 [gcc r13-13] gcov-tool: Support file input from stdin Sebastian Huber

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).