summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-20 17:31:57 -0500
committerBen Gamari <ben@smart-cactus.org>2020-11-20 17:35:46 -0500
commit612b4f9a296cf6634a3e85ab16befe1435f64fc6 (patch)
treefbbb43921a26bcfb75148b9fd0acfb8cc84a3d44
parent8150f6546e6fd0006252e245d5697f13ffd8ce3e (diff)
downloadhaskell-wip/dump-c.tar.gz
Implement -ddump-c-backend argumentwip/dump-c
To dump output of the C backend.
-rw-r--r--compiler/GHC/Driver/CodeOutput.hs8
-rw-r--r--compiler/GHC/Driver/Flags.hs1
-rw-r--r--compiler/GHC/Driver/Session.hs2
-rw-r--r--docs/users_guide/debugging.rst9
4 files changed, 19 insertions, 1 deletions
diff --git a/compiler/GHC/Driver/CodeOutput.hs b/compiler/GHC/Driver/CodeOutput.hs
index 4886d5a2ee..2bb30656dd 100644
--- a/compiler/GHC/Driver/CodeOutput.hs
+++ b/compiler/GHC/Driver/CodeOutput.hs
@@ -138,7 +138,13 @@ outputC dflags filenm cmm_stream packages =
hPutStr h ("/* GHC_PACKAGES " ++ unwords pkg_names ++ "\n*/\n")
hPutStr h "#include \"Stg.h\"\n"
let platform = targetPlatform dflags
- writeC = printForC dflags h . cmmToC platform
+ writeC cmm = do
+ let doc = cmmToC platform cmm
+ dumpIfSet_dyn dflags Opt_D_dump_c_backend
+ "C backend output"
+ FormatC
+ doc
+ printForC dflags h doc
Stream.consume cmm_stream writeC
{-
diff --git a/compiler/GHC/Driver/Flags.hs b/compiler/GHC/Driver/Flags.hs
index b7d3d4d459..25acaab359 100644
--- a/compiler/GHC/Driver/Flags.hs
+++ b/compiler/GHC/Driver/Flags.hs
@@ -49,6 +49,7 @@ data DumpFlag
| Opt_D_dump_asm_conflicts
| Opt_D_dump_asm_stats
| Opt_D_dump_asm_expanded
+ | Opt_D_dump_c_backend
| Opt_D_dump_llvm
| Opt_D_dump_core_stats
| Opt_D_dump_deriv
diff --git a/compiler/GHC/Driver/Session.hs b/compiler/GHC/Driver/Session.hs
index 687c6e1598..4e9fd45fe3 100644
--- a/compiler/GHC/Driver/Session.hs
+++ b/compiler/GHC/Driver/Session.hs
@@ -2551,6 +2551,8 @@ dynamic_flags_deps = [
(setDumpFlag Opt_D_dump_asm_expanded)
, make_ord_flag defGhcFlag "ddump-llvm"
(NoArg $ setObjBackend LLVM >> setDumpFlag' Opt_D_dump_llvm)
+ , make_ord_flag defGhcFlag "ddump-c-backend"
+ (NoArg $ setDumpFlag' Opt_D_dump_c_backend)
, make_ord_flag defGhcFlag "ddump-deriv"
(setDumpFlag Opt_D_dump_deriv)
, make_ord_flag defGhcFlag "ddump-ds"
diff --git a/docs/users_guide/debugging.rst b/docs/users_guide/debugging.rst
index 75728ae7d7..221b402d86 100644
--- a/docs/users_guide/debugging.rst
+++ b/docs/users_guide/debugging.rst
@@ -547,6 +547,15 @@ LLVM code generator
LLVM code from the :ref:`LLVM code generator <llvm-code-gen>`
+C code generator
+~~~~~~~~~~~~~~~~
+
+.. ghc-flag:: -ddump-c-backend
+ :shortdesc: Dump C code produced by the C (unregisterised) backend.
+ :type: dynamic
+
+ :shortdesc: Dump C code produced by the C (unregisterised) backend.
+
Native code generator
~~~~~~~~~~~~~~~~~~~~~