diff options
| author | Sylvain Henry <sylvain@haskus.fr> | 2020-03-25 20:06:19 +0100 |
|---|---|---|
| committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-04-03 06:26:54 -0400 |
| commit | a485c3c4049fff09e989bfd7d2ba47035c92a69b (patch) | |
| tree | b1b87b24afa4b175ec4c74165d168783fcac7d32 /compiler/GHC/CmmToAsm/Ppr.hs | |
| parent | f7597aa0c028ced898ac97e344754dd961b70c57 (diff) | |
| download | haskell-a485c3c4049fff09e989bfd7d2ba47035c92a69b.tar.gz | |
Move blob handling into StgToCmm
Move handling of big literal strings from CmmToAsm to StgToCmm. It
avoids the use of `sdocWithDynFlags` (cf #10143). We might need to move
this handling even higher in the pipeline in the future (cf #17960):
this patch will make it easier.
Diffstat (limited to 'compiler/GHC/CmmToAsm/Ppr.hs')
| -rw-r--r-- | compiler/GHC/CmmToAsm/Ppr.hs | 32 |
1 files changed, 12 insertions, 20 deletions
diff --git a/compiler/GHC/CmmToAsm/Ppr.hs b/compiler/GHC/CmmToAsm/Ppr.hs index 324bad63c4..c0abb52ad3 100644 --- a/compiler/GHC/CmmToAsm/Ppr.hs +++ b/compiler/GHC/CmmToAsm/Ppr.hs @@ -14,7 +14,8 @@ module GHC.CmmToAsm.Ppr ( floatToBytes, doubleToBytes, pprASCII, - pprBytes, + pprString, + pprFileEmbed, pprSectionHeader ) @@ -26,11 +27,9 @@ import AsmUtils import GHC.Cmm.CLabel import GHC.Cmm import GHC.CmmToAsm.Config -import GHC.Driver.Session import FastString import Outputable import GHC.Platform -import FileCleanup import qualified Data.Array.Unsafe as U ( castSTUArray ) import Data.Array.ST @@ -43,7 +42,6 @@ import Data.ByteString (ByteString) import qualified Data.ByteString as BS import GHC.Exts import GHC.Word -import System.IO.Unsafe @@ -129,24 +127,18 @@ pprASCII str ] ord0 = 0x30 -- = ord '0' --- | Pretty print binary data. --- --- Use either the ".string" directive or a ".incbin" directive. --- See Note [Embedding large binary blobs] +-- | Emit a ".string" directive +pprString :: ByteString -> SDoc +pprString bs = text "\t.string " <> doubleQuotes (pprASCII bs) + +-- | Emit a ".incbin" directive -- -- A NULL byte is added after the binary data. --- -pprBytes :: ByteString -> SDoc -pprBytes bs = sdocWithDynFlags $ \dflags -> - if binBlobThreshold dflags == 0 - || fromIntegral (BS.length bs) <= binBlobThreshold dflags - then text "\t.string " <> doubleQuotes (pprASCII bs) - else unsafePerformIO $ do - bFile <- newTempName dflags TFL_CurrentModule ".dat" - BS.writeFile bFile bs - return $ text "\t.incbin " - <> pprFilePathString bFile -- proper escape (see #16389) - <> text "\n\t.byte 0" +pprFileEmbed :: FilePath -> SDoc +pprFileEmbed path + = text "\t.incbin " + <> pprFilePathString path -- proper escape (see #16389) + <> text "\n\t.byte 0" {- Note [Embedding large binary blobs] |
