module Kempe.Debug ( armDebug
                   ) where

import qualified Kempe.Asm.Arm.ControlFlow as Arm
import qualified Kempe.Asm.Arm.Type        as Arm
import           Kempe.Asm.Liveness
import           Kempe.Module
import           Kempe.Pipeline
import           Prettyprinter             (Doc)

-- | Helper function displays calculated live ranges for debugging
armDebug :: FilePath -> IO (Doc ann)
armDebug :: FilePath -> IO (Doc ann)
armDebug FilePath
fp =
      [Arm AbsReg Liveness] -> Doc ann
forall reg ann.
(As32 reg, Pretty reg) =>
[Arm reg Liveness] -> Doc ann
Arm.prettyDebugAsm
    ([Arm AbsReg Liveness] -> Doc ann)
-> ((Int, Declarations AlexPosn AlexPosn AlexPosn)
    -> [Arm AbsReg Liveness])
-> (Int, Declarations AlexPosn AlexPosn AlexPosn)
-> Doc ann
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Arm AbsReg ControlAnn] -> [Arm AbsReg Liveness]
forall (p :: * -> *).
(Copointed p, Functor p) =>
[p ControlAnn] -> [p Liveness]
reconstruct
    ([Arm AbsReg ControlAnn] -> [Arm AbsReg Liveness])
-> ((Int, Declarations AlexPosn AlexPosn AlexPosn)
    -> [Arm AbsReg ControlAnn])
-> (Int, Declarations AlexPosn AlexPosn AlexPosn)
-> [Arm AbsReg Liveness]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Arm AbsReg ()] -> [Arm AbsReg ControlAnn]
Arm.mkControlFlow
    ([Arm AbsReg ()] -> [Arm AbsReg ControlAnn])
-> ((Int, Declarations AlexPosn AlexPosn AlexPosn)
    -> [Arm AbsReg ()])
-> (Int, Declarations AlexPosn AlexPosn AlexPosn)
-> [Arm AbsReg ControlAnn]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Int -> Declarations AlexPosn AlexPosn AlexPosn -> [Arm AbsReg ()])
-> (Int, Declarations AlexPosn AlexPosn AlexPosn)
-> [Arm AbsReg ()]
forall a b c. (a -> b -> c) -> (a, b) -> c
uncurry Int -> Declarations AlexPosn AlexPosn AlexPosn -> [Arm AbsReg ()]
forall a c b.
Typeable a =>
Int -> Declarations a c b -> [Arm AbsReg ()]
armParsed ((Int, Declarations AlexPosn AlexPosn AlexPosn) -> Doc ann)
-> IO (Int, Declarations AlexPosn AlexPosn AlexPosn)
-> IO (Doc ann)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> FilePath -> IO (Int, Declarations AlexPosn AlexPosn AlexPosn)
parseProcess FilePath
fp