diff options
author | Sylvain Henry <sylvain@haskus.fr> | 2020-03-31 18:49:01 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-04-03 06:26:54 -0400 |
commit | cc2918a0407e1581e824ebd90a1fcbb0637d5744 (patch) | |
tree | 42cdc286b9b2557252f59db47373305c1cfc9c36 /compiler/GHC/Cmm/Utils.hs | |
parent | a485c3c4049fff09e989bfd7d2ba47035c92a69b (diff) | |
download | haskell-cc2918a0407e1581e824ebd90a1fcbb0637d5744.tar.gz |
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.
Diffstat (limited to 'compiler/GHC/Cmm/Utils.hs')
-rw-r--r-- | compiler/GHC/Cmm/Utils.hs | 21 |
1 files changed, 14 insertions, 7 deletions
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 |