[Git][ghc/ghc][master] compiler: make -ddump-asm work with wasm backend NCG

Marge Bot (@marge-bot) gitlab at gitlab.haskell.org
Wed Jul 26 14:18:43 UTC 2023



Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC


Commits:
9393df83 by Gavin Zhao at 2023-07-26T10:18:16-04:00
compiler: make -ddump-asm work with wasm backend NCG

Fixes #23503.

Now the `-ddump-asm` flag is respected in the wasm backend
NCG, so developers can directly view the generated ASM instead of
needing to pass `-S` or `-keep-tmp-files` and manually find & open
the assembly file.

Ideally, we should be able to output the assembly files in smaller
chunks like in other NCG backends. This would also make dumping assembly
stats easier. However, this would require a large refactoring, so for
short-term debugging purposes I think the current approach works fine.

Signed-off-by: Gavin Zhao <git at gzgz.dev>

- - - - -


2 changed files:

- compiler/GHC/CmmToAsm.hs
- compiler/GHC/CmmToAsm/Wasm.hs


Changes:

=====================================
compiler/GHC/CmmToAsm.hs
=====================================
@@ -170,7 +170,7 @@ nativeCodeGen logger ts config modLoc h us cmms
       ArchLoongArch64->panic "nativeCodeGen: No NCG for LoongArch64"
       ArchUnknown   -> panic "nativeCodeGen: No NCG for unknown arch"
       ArchJavaScript-> panic "nativeCodeGen: No NCG for JavaScript"
-      ArchWasm32    -> Wasm32.ncgWasm platform ts us modLoc h cmms
+      ArchWasm32    -> Wasm32.ncgWasm logger platform ts us modLoc h cmms
 
 -- | Data accumulated during code generation. Mostly about statistics,
 -- but also collects debug data for DWARF generation.


=====================================
compiler/GHC/CmmToAsm/Wasm.hs
=====================================
@@ -5,6 +5,7 @@
 module GHC.CmmToAsm.Wasm (ncgWasm) where
 
 import Data.ByteString.Builder
+import Data.ByteString.Lazy.Char8 (unpack)
 import Data.Maybe
 import Data.Semigroup
 import GHC.Cmm
@@ -12,15 +13,18 @@ import GHC.CmmToAsm.Wasm.Asm
 import GHC.CmmToAsm.Wasm.FromCmm
 import GHC.CmmToAsm.Wasm.Types
 import GHC.Data.Stream (Stream, StreamS (..), runStream)
+import GHC.Driver.DynFlags
 import GHC.Platform
 import GHC.Prelude
 import GHC.Settings
 import GHC.Types.Unique.Supply
 import GHC.Unit
-import GHC.Utils.CliOption
+import GHC.Utils.Logger
+import GHC.Utils.Outputable (text)
 import System.IO
 
 ncgWasm ::
+  Logger ->
   Platform ->
   ToolSettings ->
   UniqSupply ->
@@ -28,15 +32,24 @@ ncgWasm ::
   Handle ->
   Stream IO RawCmmGroup a ->
   IO a
-ncgWasm platform ts us loc h cmms = do
+ncgWasm logger platform ts us loc h cmms = do
   (r, s) <- streamCmmGroups platform us cmms
-  hPutBuilder h $ "# " <> string7 (fromJust $ ml_hs_file loc) <> "\n\n"
-  hPutBuilder h $ execWasmAsmM do_tail_call $ asmTellEverything TagI32 s
+  outputWasm $ "# " <> string7 (fromJust $ ml_hs_file loc) <> "\n\n"
+  outputWasm $ execWasmAsmM do_tail_call $ asmTellEverything TagI32 s
   pure r
   where
     -- See Note [WasmTailCall]
     do_tail_call = doTailCall ts
 
+    outputWasm builder = do
+      putDumpFileMaybe
+        logger
+        Opt_D_dump_asm
+        "Asm Code"
+        FormatASM
+        (text . unpack $ toLazyByteString builder)
+      hPutBuilder h builder
+
 streamCmmGroups ::
   Platform ->
   UniqSupply ->



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9393df839707b31d87ae00d7370401c0ef3df6a0

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/9393df839707b31d87ae00d7370401c0ef3df6a0
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20230726/c53c7c8f/attachment-0001.html>


More information about the ghc-commits mailing list