From 207e5dfdc7735ac75e987c735bd18b110bbef881 Mon Sep 17 00:00:00 2001
From: sof <unknown>
Date: Fri, 15 Jan 1999 17:59:27 +0000
Subject: [PATCH] [project @ 1999-01-15 17:59:26 by sof] Added options that
 3.xx supported for dumping out selected chunks of the .hi file to stdout,
 i.e.,

   -hi-with-imports      = prints out the import 'section' of the .hi file
   -hi-with-declarations = print  out just decls

(Only) useful when working with runstdtest, where we just want
to look at selected portions of the generated interface file.
---
 ghc/driver/ghc-iface.lprl | 42 +++++++++++++++++++++++++++++++++++++--
 ghc/driver/ghc.lprl       |  2 ++
 2 files changed, 42 insertions(+), 2 deletions(-)

diff --git a/ghc/driver/ghc-iface.lprl b/ghc/driver/ghc-iface.lprl
index 1666b7866ecc..02c079391e47 100644
--- a/ghc/driver/ghc-iface.lprl
+++ b/ghc/driver/ghc-iface.lprl
@@ -49,9 +49,21 @@ sub postprocessHiFile {
     }
 
     # if we produced an interface file "no matter what",
-    # print what we got on stderr (ToDo: honor -ohi flag)
+    # print what we got on stderr.
     if ( $HiOnStdout ) {
-	system("$Cat $new_hi 1>&2");
+        if ( $HiWith ne '' ) {
+	    # output some of the sections
+	    local($hi_after)  = "$Tmp_prefix.hi-now";
+
+	    foreach $hi ( split(' ',$HiWith) ) { 
+	    	$HiSection{$hi} = 1; 
+	    }
+	    &hiSectionsOnly($new_hi, $hi_after);
+
+	    system("$Cat $hi_after 1>&2 ; $Rm $hi_after; ");
+	} else {
+            system("$Cat $new_hi 1>&2");
+	}
     } else {
 	&run_something("$Cmp -s $hifile_target $new_hi || ( $Rm $hifile_target && $Cp $new_hi $hifile_target )",
 	   "Replace .$HiSuffix file, if changed");
@@ -76,6 +88,32 @@ sub deUsagifyHi {
 }
 \end{code}
 
+\begin{code}
+sub hiSectionsOnly {
+    local($ifile,$ofile) = @_;
+
+    open(OLDHIF, "< $ifile") || &tidy_up_and_die(1,"Can't open $ifile (read)\n");
+    open(NEWHIF, "> $ofile") || &tidy_up_and_die(1,"Can't open $ofile (write)\n");
+
+    # read up to _usages_ line
+    $_ = <OLDHIF>;
+    while ($_ ne '' ) {
+	if ( /^__export/ && $HiSection {'exports'} 	     ||
+	     /^import /  && $HiSection {'imports'} 	     ||
+	     /^\d+ ([^ ]+ :: |type |data |class |newtype )/  && $HiSection {'declarations'} ||
+	     /^instance / && $HiSection {'instances'} ) {
+       	     print NEWHIF $_;
+       	     $_ = <OLDHIF>;
+        } else {
+          $_ = <OLDHIF>;
+	}
+    }
+
+    close(OLDHIF) || &tidy_up_and_die(1,"Failed reading from $ifile\n");
+    close(NEWHIF) || &tidy_up_and_die(1,"Failed writing to $ofile\n");
+}
+\end{code}
+
 \begin{code}
 sub constructNewHiFile {
     local($hsc_hi,	    # The iface info produced by hsc.
diff --git a/ghc/driver/ghc.lprl b/ghc/driver/ghc.lprl
index 5d4bca7ed698..b87d9b37e65a 100644
--- a/ghc/driver/ghc.lprl
+++ b/ghc/driver/ghc.lprl
@@ -2792,6 +2792,8 @@ arg: while($_ = $Args[0]) {
 
     /^-hi$/	         && do { $HiOnStdout = 1; $ProduceHi = '-hifile='; next arg; };
     # _do_ generate an interface; usually used as: -noC -hi
+    /^-hi-with-(.*)$/    && do { $HiOnStdout = 1; $HiWith .= " $1" ; $ProduceHi = '-hifile='; next arg; };
+    # limit ourselves to outputting a particular section.
 
     /^-nohi$/	    && do { $ProduceHi = '-nohifile='; next arg; };
     # don't generate an interface (even if generating C)
-- 
GitLab