module Pretty (prettyShow) where
import qualified CoreSyn
+import qualified Module
+import qualified HscTypes
import Text.PrettyPrint.HughesPJClass
import Outputable ( showSDoc, ppr, Outputable, OutputableBndr)
import Flatten
pPrint _ = text "TODO"
instance Pretty VHDLSession where
- pPrint (VHDLSession nameCount funcs) =
- text "NameCount: " $$ nest 15 (int nameCount)
+ pPrint (VHDLSession mod nameCount funcs) =
+ text "Module: " $$ nest 15 (text modname)
+ $+$ text "NameCount: " $$ nest 15 (int nameCount)
$+$ text "Functions: " $$ nest 15 (vcat (map ppfunc funcs))
where
ppfunc (hsfunc, (flatfunc)) =
pPrint hsfunc $+$ (text "Flattened: " $$ nest 15 (pPrint flatfunc))
+ modname = showSDoc $ Module.pprModule (HscTypes.cm_module mod)
instance (OutputableBndr b) => Pretty (CoreSyn.Bind b) where
pPrint (CoreSyn.NonRec b expr) =
let binds = Maybe.mapMaybe (findBind (cm_binds core)) ["sfull_adder"]
liftIO $ putStr $ prettyShow binds
-- Turn bind into VHDL
- let (vhdl, sess) = State.runState (mkVHDL binds) (VHDLSession 0 [])
+ let (vhdl, sess) = State.runState (mkVHDL binds) (VHDLSession core 0 [])
liftIO $ putStr $ render $ ForSyDe.Backend.Ppr.ppr vhdl
liftIO $ ForSyDe.Backend.VHDL.FileIO.writeDesignFile vhdl "../vhdl/vhdl/output.vhdl"
liftIO $ putStr $ "\n\nFinal session:\n" ++ prettyShow sess ++ "\n\n"
module TranslatorTypes where
import qualified Control.Monad.State as State
+import qualified HscTypes
import Flatten
type FuncMap = [(HsFunction,
(FlatFunction))]
data VHDLSession = VHDLSession {
+ coreMod :: HscTypes.CoreModule, -- The current module
nameCount :: Int, -- A counter that can be used to generate unique names
funcs :: FuncMap -- A map from HsFunction to FlatFunction, HWFunction, VHDL Entity and Architecture
-} deriving (Show)
+}
-- Add the function to the session
addFunc :: HsFunction -> FlatFunction -> VHDLState ()
fs <- State.gets funcs -- Get the funcs element from the session
State.modify (\x -> x {funcs = (hsfunc, flatfunc) : fs }) -- Prepend name and f
+getModule :: VHDLState HscTypes.CoreModule
+getModule = State.gets coreMod -- Get the coreMod element from the session
+
type VHDLState = State.State VHDLSession
-- Makes the given name unique by appending a unique number.