From 6346c669215c797abb977cf875da4e4238f5d064 Mon Sep 17 00:00:00 2001
From: Cheng Shao <terrorjack@type.dance>
Date: Wed, 29 May 2024 12:31:55 +0000
Subject: [PATCH] compiler: fix -ddump-cmm-raw when compiling .cmm

This patch fixes missing -ddump-cmm-raw output when compiling .cmm,
which is useful for debugging cmm related codegen issues.
---
 compiler/GHC/Driver/Main.hs | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/compiler/GHC/Driver/Main.hs b/compiler/GHC/Driver/Main.hs
index 08e2aafb4364..72c8a6faf193 100644
--- a/compiler/GHC/Driver/Main.hs
+++ b/compiler/GHC/Driver/Main.hs
@@ -2092,10 +2092,15 @@ hscCompileCmmFile hsc_env original_filename filename output_filename = runHsc hs
           putDumpFileMaybe logger Opt_D_dump_cmm "Output Cmm"
             FormatCMM (pdoc platform cmmgroup)
 
-        rawCmms <- case cmmToRawCmmHook hooks of
+        rawCmms0 <- case cmmToRawCmmHook hooks of
           Nothing -> cmmToRawCmm logger profile (Stream.yield cmmgroup)
           Just h  -> h           dflags Nothing (Stream.yield cmmgroup)
 
+        let dump a = do
+              unless (null a) $ putDumpFileMaybe logger Opt_D_dump_cmm_raw "Raw Cmm" FormatCMM (pdoc platform a)
+              return a
+            rawCmms = Stream.mapM dump rawCmms0
+
         let foreign_stubs _
               | not $ null ipe_ents =
                   let ip_init = ipInitCode do_info_table platform cmm_mod
-- 
GitLab