Format flag file
This commit is contained in:
parent
f3c7cdf8b3
commit
5b172ad57f
2 changed files with 48 additions and 0 deletions
19
src/Mima/Format/Common.hs
Normal file
19
src/Mima/Format/Common.hs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
module Mima.Format.Common
|
||||||
|
( toHex
|
||||||
|
, fixedWidthHex
|
||||||
|
, fixedWidthHexAddress
|
||||||
|
) where
|
||||||
|
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import Numeric
|
||||||
|
|
||||||
|
import Mima.Word
|
||||||
|
|
||||||
|
toHex :: (Integral a, Show a) => a -> T.Text
|
||||||
|
toHex a = T.pack $ showHex a ""
|
||||||
|
|
||||||
|
fixedWidthHex :: (Integral a, Show a) => Int -> a -> T.Text
|
||||||
|
fixedWidthHex n = T.justifyRight n '0' . toHex
|
||||||
|
|
||||||
|
fixedWidthHexAddress :: MimaAddress -> T.Text
|
||||||
|
fixedWidthHexAddress = fixedWidthHex 5
|
||||||
29
src/Mima/Format/FlagFile.hs
Normal file
29
src/Mima/Format/FlagFile.hs
Normal file
|
|
@ -0,0 +1,29 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
|
module Mima.Format.FlagFile
|
||||||
|
( formatFlagFile
|
||||||
|
) where
|
||||||
|
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
import qualified Data.Set as Set
|
||||||
|
import qualified Data.Text as T
|
||||||
|
|
||||||
|
import Mima.Flag
|
||||||
|
import Mima.Format.Common
|
||||||
|
|
||||||
|
fFlagSet :: Set.Set Char -> T.Text
|
||||||
|
fFlagSet = T.pack . Set.toAscList
|
||||||
|
|
||||||
|
fRange :: AddressRange -> T.Text
|
||||||
|
fRange r
|
||||||
|
| lower == upper = fixedWidthHexAddress lower
|
||||||
|
| otherwise = fixedWidthHexAddress lower <> "-" <> fixedWidthHexAddress upper
|
||||||
|
where
|
||||||
|
lower = lowerAddress r
|
||||||
|
upper = upperAddress r
|
||||||
|
|
||||||
|
fLine :: (AddressRange, Set.Set Char) -> T.Text
|
||||||
|
fLine (r, s) = fRange r <> ": " <> fFlagSet s <> "\n"
|
||||||
|
|
||||||
|
formatFlagFile :: AllFlags -> T.Text
|
||||||
|
formatFlagFile = mconcat . map fLine . Map.assocs
|
||||||
Loading…
Add table
Add a link
Reference in a new issue