Format symbol file

This commit is contained in:
Joscha 2019-11-18 09:59:48 +00:00
parent ac03e6346f
commit 75304e8027

View file

@ -0,0 +1,30 @@
{-# LANGUAGE OverloadedStrings #-}
module Mima.Format.SymbolFile
( formatSymbolFile
) where
import qualified Data.Map as Map
import qualified Data.Set as Set
import qualified Data.Text as T
import Mima.Format.Common
import Mima.Word
type LabelName = T.Text
combineByAddress :: Map.Map LabelName MimaAddress -> Map.Map MimaAddress (Set.Set LabelName)
combineByAddress = ($ Map.empty )
. mconcat
. reverse
. map (\(l, a) -> Map.insertWith Set.union a (Set.singleton l))
. Map.assocs
fLabels :: Set.Set LabelName -> T.Text
fLabels = T.intercalate " " . Set.toAscList
fLine :: (MimaAddress, Set.Set LabelName) -> T.Text
fLine (a, s) = fixedWidthHexAddress a <> ": " <> fLabels s <> "\n"
formatSymbolFile :: Map.Map LabelName MimaAddress -> T.Text
formatSymbolFile = mconcat . map fLine . Map.assocs . combineByAddress