Data.Accessor allows for (automatically) defining accessor functions for
reading and writing record fields. This is a field test to see if it's
useful.
import qualified Data.Foldable as Foldable
import Name
import qualified Data.Map as Map
import qualified Data.Foldable as Foldable
import Name
import qualified Data.Map as Map
import Data.Generics
import NameEnv ( lookupNameEnv )
import qualified HscTypes
import Data.Generics
import NameEnv ( lookupNameEnv )
import qualified HscTypes
mapM addBuiltIn builtin_funcs
-- Create entities and architectures for them
Monad.zipWithM processBind statefuls binds
mapM addBuiltIn builtin_funcs
-- Create entities and architectures for them
Monad.zipWithM processBind statefuls binds
- modFuncMap $ Map.map (\fdata -> fdata {flatFunc = fmap nameFlatFunction (flatFunc fdata)})
- modFuncMap $ Map.mapWithKey (\hsfunc fdata -> fdata {funcEntity = VHDL.createEntity hsfunc fdata})
+ modFuncMap $ Map.map (fdFlatFunc ^: (fmap nameFlatFunction))
+ modFuncMap $ Map.mapWithKey (\hsfunc fdata -> fdEntity ^= (VHDL.createEntity hsfunc fdata) $ fdata)
- modFuncMap $ Map.mapWithKey (\hsfunc fdata -> fdata {funcArch = VHDL.createArchitecture funcs hsfunc fdata})
+ modFuncMap $ Map.mapWithKey (\hsfunc fdata -> fdArch ^= (VHDL.createArchitecture funcs hsfunc fdata) $ fdata)
funcs <- getFuncs
return $ VHDL.getDesignFiles (map snd funcs)
funcs <- getFuncs
return $ VHDL.getDesignFiles (map snd funcs)
-- Simple module providing some types used by Translator. These are in a
-- separate module to prevent circular dependencies in Pretty for example.
--
-- Simple module providing some types used by Translator. These are in a
-- separate module to prevent circular dependencies in Pretty for example.
--
+{-# LANGUAGE TemplateHaskell #-}
module TranslatorTypes where
import qualified Control.Monad.State as State
import qualified Data.Map as Map
module TranslatorTypes where
import qualified Control.Monad.State as State
import qualified Data.Map as Map
+import qualified Data.Accessor.Template
+import Data.Accessor
import qualified HscTypes
import qualified HscTypes
-- | Some stuff we collect about a function along the way.
data FuncData = FuncData {
-- | Some stuff we collect about a function along the way.
data FuncData = FuncData {
- flatFunc :: Maybe FlatFunction,
- funcEntity :: Maybe Entity,
- funcArch :: Maybe AST.ArchBody
+ fdFlatFunc_ :: Maybe FlatFunction,
+ fdEntity_ :: Maybe Entity,
+ fdArch_ :: Maybe AST.ArchBody
+-- Derive accessors
+$( Data.Accessor.Template.deriveAccessors ''FuncData )
+
data VHDLSession = VHDLSession {
coreMod :: HscTypes.CoreModule, -- The current module
nameCount :: Int, -- A counter that can be used to generate unique names
data VHDLSession = VHDLSession {
coreMod :: HscTypes.CoreModule, -- The current module
nameCount :: Int, -- A counter that can be used to generate unique names
-- | Sets the FlatFunction for the given HsFunction in the current session.
setFlatFunc :: HsFunction -> FlatFunction -> VHDLState ()
setFlatFunc hsfunc flatfunc =
-- | Sets the FlatFunction for the given HsFunction in the current session.
setFlatFunc :: HsFunction -> FlatFunction -> VHDLState ()
setFlatFunc hsfunc flatfunc =
- modFunc (\d -> d { flatFunc = Just flatfunc }) hsfunc
+ modFunc (fdFlatFunc ^= Just flatfunc) hsfunc
-- | Sets the Entity for the given HsFunction in the current session.
setEntity :: HsFunction -> Entity -> VHDLState ()
setEntity hsfunc entity =
-- | Sets the Entity for the given HsFunction in the current session.
setEntity :: HsFunction -> Entity -> VHDLState ()
setEntity hsfunc entity =
- modFunc (\d -> d { funcEntity = Just entity }) hsfunc
+ modFunc (fdEntity ^= Just entity) hsfunc
-- | Sets the Entity for the given HsFunction in the current session.
setArchitecture :: HsFunction -> AST.ArchBody -> VHDLState ()
setArchitecture hsfunc arch =
-- | Sets the Entity for the given HsFunction in the current session.
setArchitecture :: HsFunction -> AST.ArchBody -> VHDLState ()
setArchitecture hsfunc arch =
- modFunc (\d -> d { funcArch = Just arch }) hsfunc
+ modFunc (fdArch ^= Just arch) hsfunc
-- | Modify a function in the map using the given function
modFunc :: (FuncData -> FuncData) -> HsFunction -> VHDLState ()
-- | Modify a function in the map using the given function
modFunc :: (FuncData -> FuncData) -> HsFunction -> VHDLState ()
import qualified Control.Arrow as Arrow
import qualified Data.Traversable as Traversable
import qualified Data.Monoid as Monoid
import qualified Control.Arrow as Arrow
import qualified Data.Traversable as Traversable
import qualified Data.Monoid as Monoid
import qualified Type
import qualified TysWiredIn
import qualified Type
import qualified TysWiredIn
--- Entity for builtin functions.
createEntity hsfunc fdata =
--- Entity for builtin functions.
createEntity hsfunc fdata =
+ case fdata ^. fdFlatFunc of
-- Skip (builtin) functions without a FlatFunction
-- Skip (builtin) functions without a FlatFunction
- Nothing -> funcEntity fdata
+ Nothing -> fdata ^. fdEntity
-- Create an entity for all other functions
Just flatfunc ->
let
-- Create an entity for all other functions
Just flatfunc ->
let
-> Maybe AST.ArchBody -- ^ The architecture for this function
createArchitecture funcs hsfunc fdata =
-> Maybe AST.ArchBody -- ^ The architecture for this function
createArchitecture funcs hsfunc fdata =
+ case fdata ^. fdFlatFunc of
-- Skip (builtin) functions without a FlatFunction
-- Skip (builtin) functions without a FlatFunction
- Nothing -> funcArch fdata
+ Nothing -> fdata ^. fdArch
-- Create an architecture for all other functions
Just flatfunc ->
let
-- Create an architecture for all other functions
Just flatfunc ->
let
fdata_maybe
entity = Maybe.fromMaybe
(error $ "Using function '" ++ (prettyShow hsfunc) ++ "' without entity declaration? This should not happen!")
fdata_maybe
entity = Maybe.fromMaybe
(error $ "Using function '" ++ (prettyShow hsfunc) ++ "' without entity declaration? This should not happen!")
entity_id = ent_id entity
label = (AST.fromVHDLId entity_id) ++ "_" ++ (show num)
-- Add a clk port if we have state
entity_id = ent_id entity
label = (AST.fromVHDLId entity_id) ++ "_" ++ (show num)
-- Add a clk port if we have state
-- | Extracts the generated entity id from the given funcdata
getEntityId :: FuncData -> Maybe AST.VHDLId
getEntityId fdata =
-- | Extracts the generated entity id from the given funcdata
getEntityId :: FuncData -> Maybe AST.VHDLId
getEntityId fdata =
- case funcEntity fdata of
+ case fdata ^. fdEntity of
Nothing -> Nothing
Just e -> case ent_decl e of
Nothing -> Nothing
Nothing -> Nothing
Just e -> case ent_decl e of
Nothing -> Nothing
-> [AST.LibraryUnit] -- | The entity, architecture and optional package for the function
getLibraryUnits fdata =
-> [AST.LibraryUnit] -- | The entity, architecture and optional package for the function
getLibraryUnits fdata =
- case funcEntity fdata of
+ case fdata ^. fdEntity of
Nothing -> []
Just ent ->
case ent_decl ent of
Nothing -> []
Just decl ->
Nothing -> []
Just ent ->
case ent_decl ent of
Nothing -> []
Just decl ->
+ case fdata ^. fdArch of
Nothing -> []
Just arch ->
[AST.LUEntity decl, AST.LUArch arch]
Nothing -> []
Just arch ->
[AST.LUEntity decl, AST.LUArch arch]