From fcd214fb3e9cf1eb6d80ba831d77598c30eaa561 Mon Sep 17 00:00:00 2001 From: Georgy Lukyanov Date: Sun, 18 Feb 2018 20:40:56 +0000 Subject: [PATCH] Refine script pretty printing. --- src/Redfin/Listing.hs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Redfin/Listing.hs b/src/Redfin/Listing.hs index 90b6a29..e40ee41 100644 --- a/src/Redfin/Listing.hs +++ b/src/Redfin/Listing.hs @@ -1,18 +1,26 @@ -{-# LANGUAGE BinaryLiterals #-} +{-# LANGUAGE BinaryLiterals, OverloadedStrings #-} module Redfin.Listing ( - showInstructionCode, showScript + showInstructionCode, showScript, prettyPrintScript ) where +import qualified Data.Text.Lazy as T +import Text.Pretty.Simple (pPrint) import Redfin import Redfin.Assembly import Redfin.Decode -showScript :: Script -> String +prettyPrintScript :: Script -> IO () +prettyPrintScript = pPrint . showScript + +showScript :: Script -> T.Text showScript script = - unlines $ map showInstructionCode $ reverse $ snd $ runWriter script [] + T.replace " :: SInt8" "" . + T.replace " :: SWord8" "" . + T.pack . unlines $ + map showInstructionCode $ reverse $ snd $ runWriter script [] --- | TODO: This might be probably unified with 'decode' somehow. +-- | TODO: This might be unified with 'decode' somehow. showInstructionCode :: InstructionCode -> String showInstructionCode code = let opcode = decodeOpcode code