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/utils/Outputable.hs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'compiler/utils/Outputable.hs') diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index 7133951d67..6f6a335ed7 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -71,7 +71,7 @@ module Outputable ( neverQualify, neverQualifyNames, neverQualifyModules, alwaysQualifyPackages, neverQualifyPackages, QualifyName(..), queryQual, - sdocWithDynFlags, sdocWithPlatform, sdocOption, + sdocWithDynFlags, sdocOption, updSDocContext, SDocContext (..), sdocWithContext, getPprStyle, withPprStyle, setStyleColoured, @@ -96,7 +96,7 @@ import GhcPrelude import {-# SOURCE #-} GHC.Driver.Session ( DynFlags, hasPprDebug, hasNoDebugOutput - , targetPlatform, pprUserLength, pprCols + , pprUserLength, pprCols , unsafeGlobalDynFlags, initSDocContext ) import {-# SOURCE #-} Module( UnitId, Module, ModuleName, moduleName ) @@ -106,7 +106,6 @@ import BufWrite (BufHandle) import FastString import qualified Pretty import Util -import GHC.Platform import qualified PprColour as Col import Pretty ( Doc, Mode(..) ) import Panic @@ -346,7 +345,6 @@ data SDocContext = SDC -- ^ True if Unicode encoding is supported -- and not disable by GHC_NO_UNICODE environment variable , sdocHexWordLiterals :: !Bool - , sdocDebugLevel :: !Int , sdocPprDebug :: !Bool , sdocPrintUnicodeSyntax :: !Bool , sdocPrintCaseAsLet :: !Bool @@ -422,9 +420,6 @@ getPprStyle df = SDoc $ \ctx -> runSDoc (df (sdocStyle ctx)) ctx sdocWithDynFlags :: (DynFlags -> SDoc) -> SDoc sdocWithDynFlags f = SDoc $ \ctx -> runSDoc (f (sdocDynFlags ctx)) ctx -sdocWithPlatform :: (Platform -> SDoc) -> SDoc -sdocWithPlatform f = sdocWithDynFlags (f . targetPlatform) - sdocWithContext :: (SDocContext -> SDoc) -> SDoc sdocWithContext f = SDoc $ \ctx -> runSDoc (f ctx) ctx -- cgit v1.2.1