From cc2918a0407e1581e824ebd90a1fcbb0637d5744 Mon Sep 17 00:00:00 2001 From: Sylvain Henry Date: Tue, 31 Mar 2020 18:49:01 +0200 Subject: Refactor CmmStatics In !2959 we noticed that there was some redundant code (in GHC.Cmm.Utils and GHC.Cmm.StgToCmm.Utils) used to deal with `CmmStatics` datatype (before SRT generation) and `RawCmmStatics` datatype (after SRT generation). This patch removes this redundant code by using a single GADT for (Raw)CmmStatics. --- compiler/GHC/Cmm.hs | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'compiler/GHC/Cmm.hs') diff --git a/compiler/GHC/Cmm.hs b/compiler/GHC/Cmm.hs index 9973db8d0d..fe5109aa6f 100644 --- a/compiler/GHC/Cmm.hs +++ b/compiler/GHC/Cmm.hs @@ -1,5 +1,8 @@ -- Cmm representations using Hoopl's Graph CmmNode e x. {-# LANGUAGE GADTs #-} +{-# LANGUAGE KindSignatures #-} +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE ExplicitNamespaces #-} module GHC.Cmm ( -- * Cmm top-level datatypes @@ -7,7 +10,8 @@ module GHC.Cmm ( CmmDecl, CmmDeclSRTs, GenCmmDecl(..), CmmGraph, GenCmmGraph(..), CmmBlock, RawCmmDecl, - Section(..), SectionType(..), CmmStatics(..), RawCmmStatics(..), CmmStatic(..), + Section(..), SectionType(..), + GenCmmStatics(..), type CmmStatics, type RawCmmStatics, CmmStatic(..), isSecConstant, -- ** Blocks containing lists @@ -206,21 +210,22 @@ data CmmStatic -- ^ an embedded binary file -- Static data before SRT generation -data CmmStatics - = CmmStatics - CLabel -- Label of statics - CmmInfoTable - CostCentreStack - [CmmLit] -- Payload - | CmmStaticsRaw - CLabel -- Label of statics - [CmmStatic] -- The static data itself - --- Static data, after SRTs are generated -data RawCmmStatics - = RawCmmStatics - CLabel -- Label of statics - [CmmStatic] -- The static data itself +data GenCmmStatics (rawOnly :: Bool) where + CmmStatics + :: CLabel -- Label of statics + -> CmmInfoTable + -> CostCentreStack + -> [CmmLit] -- Payload + -> GenCmmStatics 'False + + -- | Static data, after SRTs are generated + CmmStaticsRaw + :: CLabel -- Label of statics + -> [CmmStatic] -- The static data itself + -> GenCmmStatics a + +type CmmStatics = GenCmmStatics 'False +type RawCmmStatics = GenCmmStatics 'True -- ----------------------------------------------------------------------------- -- Basic blocks consisting of lists -- cgit v1.2.1