import HscTypes ( cm_binds, cm_types )
import MonadUtils ( liftIO )
import Outputable ( showSDoc, ppr, showSDocDebug )
-import GHC.Paths ( libdir )
import DynFlags ( defaultDynFlags )
import qualified UniqSupply
import List ( find )
import CLasH.VHDL.VHDLTypes
import qualified CLasH.VHDL as VHDL
-makeVHDL :: String -> String -> Bool -> IO ()
-makeVHDL filename name stateful = do
+makeVHDL :: FilePath -> String -> String -> Bool -> IO ()
+makeVHDL libdir filename name stateful = do
-- Load the module
- (core, env) <- loadModule filename
+ (core, env) <- loadModule libdir filename
-- Translate to VHDL
vhdl <- moduleToVHDL env core [(name, stateful)]
-- Write VHDL to file
mapM (writeVHDL dir) vhdl
return ()
-makeVHDLAnn :: String -> Bool -> IO ()
-makeVHDLAnn filename stateful = do
- (core, top, init, env) <- loadModuleAnn filename
+makeVHDLAnn :: FilePath -> String -> IO ()
+makeVHDLAnn libdir filename = do
+ (core, top, init, env) <- loadModuleAnn libdir filename
let top_entity = head top
vhdl <- case init of
[] -> moduleToVHDLAnn env core [top_entity]
mapM (writeVHDL dir) vhdl
return ()
-listBindings :: String -> IO [()]
-listBindings filename = do
- (core, env) <- loadModule filename
+listBindings :: FilePath -> String -> IO [()]
+listBindings libdir filename = do
+ (core, env) <- loadModule libdir filename
let binds = CoreSyn.flattenBinds $ cm_binds core
mapM (listBinding) binds
putStr "\n\n"
-- | Show the core structure of the given binds in the given file.
-listBind :: String -> String -> IO ()
-listBind filename name = do
- (core, env) <- loadModule filename
+listBind :: FilePath -> String -> String -> IO ()
+listBind libdir filename name = do
+ (core, env) <- loadModule libdir filename
let [(b, expr)] = findBinds core [name]
putStr "\n"
putStr $ prettyShow expr
Language.VHDL.FileIO.writeDesignFile vhdl fname
-- | Loads the given file and turns it into a core module.
-loadModule :: String -> IO (HscTypes.CoreModule, HscTypes.HscEnv)
-loadModule filename =
+loadModule :: FilePath -> String -> IO (HscTypes.CoreModule, HscTypes.HscEnv)
+loadModule libdir filename =
defaultErrorHandler defaultDynFlags $ do
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
return (core, env)
-- | Loads the given file and turns it into a core module.
-loadModuleAnn :: String -> IO (HscTypes.CoreModule, [CoreSyn.CoreBndr], [CoreSyn.CoreBndr], HscTypes.HscEnv)
-loadModuleAnn filename =
+loadModuleAnn :: FilePath -> String -> IO (HscTypes.CoreModule, [CoreSyn.CoreBndr], [CoreSyn.CoreBndr], HscTypes.HscEnv)
+loadModuleAnn libdir filename =
defaultErrorHandler defaultDynFlags $ do
runGhc (Just libdir) $ do
dflags <- getSessionDynFlags
-- GHC API
import qualified GHC
-import qualified GHC.Paths
import qualified DynFlags
import qualified TcRnMonad
import qualified MonadUtils
-- don't have side effects themselves (Or rather, that don't use
-- unsafePerformIO themselves, since normal side effectful function would
-- just return an IO monad when they are evaluated).
-unsafeRunGhc :: GHC.Ghc a -> a
-unsafeRunGhc m =
- System.IO.Unsafe.unsafePerformIO $
- GHC.runGhc (Just GHC.Paths.libdir) $ do
+unsafeRunGhc :: FilePath -> GHC.Ghc a -> a
+unsafeRunGhc libDir m =
+ System.IO.Unsafe.unsafePerformIO $ do
+ GHC.runGhc (Just libDir) $ do
dflags <- GHC.getSessionDynFlags
GHC.setSessionDynFlags dflags
m
-runTcM :: TcRnMonad.TcM a -> IO a
-runTcM thing_inside = do
- GHC.runGhc (Just GHC.Paths.libdir) $ do
- dflags <- GHC.getSessionDynFlags
- GHC.setSessionDynFlags dflags
- env <- GHC.getSession
- HscTypes.ioMsgMaybe . MonadUtils.liftIO . TcRnMonad.initTcPrintErrors env PrelNames.iNTERACTIVE $ do
- thing_inside
+-- runTcM :: TcRnMonad.TcM a -> IO a
+-- runTcM thing_inside = do
+-- GHC.runGhc (Just GHC.Paths.libdir) $ do
+-- dflags <- GHC.getSessionDynFlags
+-- GHC.setSessionDynFlags dflags
+-- env <- GHC.getSession
+-- HscTypes.ioMsgMaybe . MonadUtils.liftIO . TcRnMonad.initTcPrintErrors env PrelNames.iNTERACTIVE $ do
+-- thing_inside
maintainer: christiaan.baaij@gmail.com & matthijs@stdin.nl
Cabal-Version: >= 1.2
-flag out-ghc-tree
- description: Are we outside a GHC tree?
- default: False
- manual: True
-
Library
- if flag(out-ghc-tree)
- build-depends: ghc-paths
- else
- cpp-options: -DIN_GHC_TREE
-
build-depends: ghc >= 6.11, pretty, vhdl, haskell98, syb, data-accessor,
containers, base >= 4, transformers, filepath,
template-haskell, data-accessor-template, prettyclass
- extensions: CPP
-
exposed-modules: CLasH.Translator,
CLasH.Translator.Annotations