Skip to content

Commit

Permalink
Refine script pretty printing.
Browse files Browse the repository at this point in the history
  • Loading branch information
geo2a committed Feb 18, 2018
1 parent bdc7851 commit fcd214f
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/Redfin/Listing.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit fcd214f

Please sign in to comment.