From 2e82465fff5851f00449131fdc8bacd3ca95f90f Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Sun, 1 Mar 2020 16:37:59 +0100 Subject: Refactor CmmToAsm (disentangle DynFlags) This patch disentangles a bit more DynFlags from the native code generator (CmmToAsm). In more details: - add a new NCGConfig datatype in GHC.CmmToAsm.Config which contains the configuration of a native code generation session - explicitly pass NCGConfig/Platform arguments when necessary - as a consequence `sdocWithPlatform` is gone and there are only a few `sdocWithDynFlags` left - remove the use of `unsafeGlobalDynFlags` from GHC.CmmToAsm.CFG - remove `sdocDebugLevel` (now we pass the debug level via NCGConfig) There are still some places where DynFlags is used, especially because of pretty-printing (CLabel), because of Cmm helpers (such as `cmmExprType`) and because of `Outputable` instance for the instructions. These are left for future refactoring as this patch is already big. --- compiler/GHC/CmmToC.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'compiler/GHC/CmmToC.hs') diff --git a/compiler/GHC/CmmToC.hs b/compiler/GHC/CmmToC.hs index 6e6f58ba7d..7944f6a0fc 100644 --- a/compiler/GHC/CmmToC.hs +++ b/compiler/GHC/CmmToC.hs @@ -406,7 +406,7 @@ pprLoad dflags e ty -- (For tagging to work, I had to avoid unaligned loads. --ARY) -> pprAsPtrReg r <> brackets (ppr (off `shiftR` wordShift dflags)) - _other -> cLoad e ty + _other -> cLoad (targetPlatform dflags) e ty where width = typeWidth ty @@ -1145,10 +1145,9 @@ te_Reg _ = return () cCast :: SDoc -> CmmExpr -> SDoc cCast ty expr = parens ty <> pprExpr1 expr -cLoad :: CmmExpr -> CmmType -> SDoc -cLoad expr rep - = sdocWithPlatform $ \platform -> - if bewareLoadStoreAlignment (platformArch platform) +cLoad :: Platform -> CmmExpr -> CmmType -> SDoc +cLoad platform expr rep + = if bewareLoadStoreAlignment (platformArch platform) then let decl = machRepCType rep <+> text "x" <> semi struct = text "struct" <+> braces (decl) packed_attr = text "__attribute__((packed))" -- cgit v1.2.1