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/Utils.hs | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) (limited to 'compiler/GHC/Cmm/Utils.hs') diff --git a/compiler/GHC/Cmm/Utils.hs b/compiler/GHC/Cmm/Utils.hs index 0b0c848eb7..c23975bb44 100644 --- a/compiler/GHC/Cmm/Utils.hs +++ b/compiler/GHC/Cmm/Utils.hs @@ -20,7 +20,7 @@ module GHC.Cmm.Utils( -- CmmLit zeroCLit, mkIntCLit, mkWordCLit, packHalfWordsCLit, - mkByteStringCLit, + mkByteStringCLit, mkFileEmbedLit, mkDataLits, mkRODataLits, mkStgWordCLit, @@ -197,20 +197,27 @@ mkWordCLit platform wd = CmmInt wd (wordWidth platform) -- | We make a top-level decl for the string, and return a label pointing to it mkByteStringCLit - :: CLabel -> ByteString -> (CmmLit, GenCmmDecl RawCmmStatics info stmt) + :: CLabel -> ByteString -> (CmmLit, GenCmmDecl (GenCmmStatics raw) info stmt) mkByteStringCLit lbl bytes - = (CmmLabel lbl, CmmData (Section sec lbl) $ RawCmmStatics lbl [CmmString bytes]) + = (CmmLabel lbl, CmmData (Section sec lbl) $ CmmStaticsRaw lbl [CmmString bytes]) where -- This can not happen for String literals (as there \NUL is replaced by -- C0 80). However, it can happen with Addr# literals. sec = if 0 `BS.elem` bytes then ReadOnlyData else CString -mkDataLits :: Section -> CLabel -> [CmmLit] -> GenCmmDecl RawCmmStatics info stmt --- Build a data-segment data block +-- | We make a top-level decl for the embedded binary file, and return a label pointing to it +mkFileEmbedLit + :: CLabel -> FilePath -> (CmmLit, GenCmmDecl (GenCmmStatics raw) info stmt) +mkFileEmbedLit lbl path + = (CmmLabel lbl, CmmData (Section ReadOnlyData lbl) (CmmStaticsRaw lbl [CmmFileEmbed path])) + + +-- | Build a data-segment data block +mkDataLits :: Section -> CLabel -> [CmmLit] -> GenCmmDecl (GenCmmStatics raw) info stmt mkDataLits section lbl lits - = CmmData section (RawCmmStatics lbl $ map CmmStaticLit lits) + = CmmData section (CmmStaticsRaw lbl $ map CmmStaticLit lits) -mkRODataLits :: CLabel -> [CmmLit] -> GenCmmDecl RawCmmStatics info stmt +mkRODataLits :: CLabel -> [CmmLit] -> GenCmmDecl (GenCmmStatics raw) info stmt -- Build a read-only data block mkRODataLits lbl lits = mkDataLits section lbl lits -- cgit v1.2.1