| Copyright | (C) 2012-2016 University of Twente 2016-2017 Myrtle Software Ltd 2017 QBayLogic Google Inc. 2020-2024 QBayLogic 2022 Google Inc. 2026 Martijn Bastiaan |
|---|---|
| License | BSD2 (see the file LICENSE) |
| Maintainer | QBayLogic B.V. <devops@qbaylogic.com> |
| Safe Haskell | Safe-Inferred |
| Language | Haskell2010 |
Clash.Driver
Description
Module that connects all the parts of the Clash compiler library
Synopsis
- splitTopAnn :: TyConMap -> SrcSpan -> Type -> TopEntity -> TopEntity
- splitTopEntityT :: HasCallStack => TyConMap -> BindingMap -> TopEntityT -> TopEntityT
- removeForAll :: TopEntityT -> TopEntityT
- selectTopEntities :: [TopEntityT] -> Maybe (TopEntityT, [TopEntityT]) -> [TopEntityT]
- getClashModificationDate :: IO UTCTime
- hdlFromBackend :: forall backend. Backend backend => Proxy backend -> HDL
- replaceChar :: Char -> Char -> String -> String
- removeHistoryFile :: Maybe FilePath -> IO ()
- prefixModuleName :: HDL -> Maybe Text -> Maybe TopEntity -> String -> (String, Maybe String)
- generateHDL :: forall backend. Backend backend => ClashEnv -> ClashDesign -> Maybe backend -> (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))) -> Evaluator -> Evaluator -> Maybe (TopEntityT, [TopEntityT]) -> UTCTime -> IO ()
- data InterpretFunctionType
- data InterpretFunctionRequest = InterpretFunctionRequest {}
- interpretFunctionRequestToModuleName :: InterpretFunctionRequest -> ModuleName
- data InterpretFunctionResult
- type InterpretResults = HashMap InterpretFunctionRequest (Either (NonEmpty InterpreterError) InterpretFunctionResult)
- hintLanguageExtensions :: [Extension]
- neededInterpRequests :: ResolvedPrimitive -> [InterpretFunctionRequest]
- interpretFunctions :: [FilePath] -> [FilePath] -> FilePath -> [InterpretFunctionRequest] -> IO InterpretResults
- knownBlackBoxFunctions :: HashMap String BlackBoxFunction
- knownTemplateFunctions :: HashMap String TemplateFunction
- compilePrimitives :: [FilePath] -> [FilePath] -> FilePath -> ResolvedPrimMap -> IO CompiledPrimMap
- compilePrimitive :: [FilePath] -> [FilePath] -> FilePath -> ResolvedPrimitive -> IO CompiledPrimitive
- lookupInterpResult :: InterpretResults -> InterpretFunctionRequest -> IO (Either (NonEmpty InterpreterError) InterpretFunctionResult)
- compilePrimitiveWith :: (InterpretFunctionRequest -> IO (Either (NonEmpty InterpreterError) InterpretFunctionResult)) -> ResolvedPrimitive -> IO CompiledPrimitive
- newtype HintError = HintError String
- processHintErrors :: (MonadThrow m, Monad m) => String -> Text -> Either (NonEmpty InterpreterError) t -> m t
- createHDL :: Backend backend => backend -> ClashOpts -> IdentifierText -> IdentifierSet -> ComponentMap -> HashMap Text VDomainConfiguration -> Component -> IdentifierText -> ([(String, Doc)], [(String, FilePath)], [(String, String)])
- writeEdam :: FilePath -> (Identifier, Unique) -> HashMap Unique [Unique] -> HashMap Unique [EdamFile] -> [(FilePath, ByteString)] -> IO (HashMap Unique [EdamFile], [(FilePath, ByteString)])
- createEDAM :: (Identifier, Unique) -> HashMap Unique [Unique] -> HashMap Unique [EdamFile] -> [FilePath] -> (HashMap Unique [EdamFile], Edam)
- asEdamFile :: Identifier -> FilePath -> EdamFile
- prepareDir :: FilePath -> ClashOpts -> Maybe [UnexpectedModification] -> IO ()
- writeAndHash :: FilePath -> ByteString -> IO ByteString
- writeHDL :: FilePath -> (FilePath, Doc) -> IO ByteString
- writeMemoryDataFiles :: FilePath -> [(FilePath, String)] -> IO [ByteString]
- copyDataFiles :: FilePath -> [(FilePath, FilePath)] -> IO [ByteString]
- normalizeEntity :: ClashEnv -> BindingMap -> (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))) -> Evaluator -> Evaluator -> [Id] -> Supply -> Id -> IO BindingMap
- sortTop :: BindingMap -> [TopEntityT] -> ([TopEntityT], HashMap Unique [Unique])
Documentation
Arguments
| :: TyConMap | |
| -> SrcSpan | Source location of top entity (for error reporting) |
| -> Type | Top entity body |
| -> TopEntity | Port annotations for top entity |
| -> TopEntity | New top entity with split ports (or the old one if not applicable) |
Worker function of splitTopEntityT
splitTopEntityT :: HasCallStack => TyConMap -> BindingMap -> TopEntityT -> TopEntityT Source #
removeForAll :: TopEntityT -> TopEntityT Source #
Remove constraints such as 'a ~ 3'.
selectTopEntities :: [TopEntityT] -> Maybe (TopEntityT, [TopEntityT]) -> [TopEntityT] Source #
Given a list of all found top entities and _maybe_ a top entity (+dependencies) passed in by '-main-is', return the list of top entities Clash needs to compile.
getClashModificationDate :: IO UTCTime Source #
Get modification data of current clash binary.
hdlFromBackend :: forall backend. Backend backend => Proxy backend -> HDL Source #
prefixModuleName :: HDL -> Maybe Text -> Maybe TopEntity -> String -> (String, Maybe String) Source #
Arguments
| :: forall backend. Backend backend | |
| => ClashEnv | |
| -> ClashDesign | |
| -> Maybe backend | |
| -> (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))) | Hardcoded |
| -> Evaluator | Hardcoded evaluator for partial evaluation |
| -> Evaluator | Hardcoded evaluator for WHNF (old evaluator) |
| -> Maybe (TopEntityT, [TopEntityT]) | Main top entity to compile. If Nothing, all top entities in the
|
| -> UTCTime | |
| -> IO () |
Create a set of target HDL files for a set of functions
data InterpretFunctionType Source #
Whether a function should be interpreted as a BlackBoxFunction or a
TemplateFunction.
Constructors
| InterpretBlackBoxFunction | |
| InterpretTemplateFunction |
Instances
data InterpretFunctionRequest Source #
A single function that needs to be interpreted with Hint in order to compile a primitive. Multiple primitives referencing the same function map to the same request, so interpreting the distinct requests of a primitive map compiles each function exactly once.
Constructors
| InterpretFunctionRequest | |
Fields
| |
Instances
interpretFunctionRequestToModuleName :: InterpretFunctionRequest -> ModuleName Source #
Module the function of an InterpretFunctionRequest lives in, as a
qualified module name
data InterpretFunctionResult Source #
The result of interpreting an InterpretFunctionRequest
Constructors
| InterpretBBF BlackBoxFunction | |
| InterpretTF TemplateFunction |
type InterpretResults = HashMap InterpretFunctionRequest (Either (NonEmpty InterpreterError) InterpretFunctionResult) Source #
hintLanguageExtensions :: [Extension] Source #
Language extensions in effect when interpreting inline primitive sources
neededInterpRequests :: ResolvedPrimitive -> [InterpretFunctionRequest] Source #
The functions a primitive needs interpreted before it can be compiled by
compilePrimitiveWith. Functions in knownBlackBoxFunctions or
knownTemplateFunctions need no interpretation and yield no request.
Arguments
| :: [FilePath] | Import directories (-i flag) |
| -> [FilePath] | Package databases |
| -> FilePath | The folder in which the GHC bootstrap libraries (base, containers, etc.) can be found |
| -> [InterpretFunctionRequest] | Functions to interpret |
| -> IO InterpretResults |
Interpret the given functions in a single shared Hint session. Starting a session is expensive (it initializes a full GHC session, including reading all package databases), so sharing one session over all requests is much faster than a session per function. For each request this action tries two things:
- Interpret without explicitly loading the module. This will succeed if
the module can be found in the package databases (passed in as
-package-dbinterpreter arguments). - If (1) fails, try to load the module explicitly: either from the inline source a primitive provided, or from the import directories. If this also fails, an error is recorded for the request.
All (1) attempts run before the first (2) attempt, so that interpreting
against the package databases is never influenced by locally loaded
modules. Note that loadModules resets previously loaded modules, so
(2) attempts cannot see each other's modules either.
knownBlackBoxFunctions :: HashMap String BlackBoxFunction Source #
List of known BlackBoxFunctions used to prevent Hint from firing. This improves Clash startup times.
knownTemplateFunctions :: HashMap String TemplateFunction Source #
List of known TemplateFunctions used to prevent Hint from firing. This improves Clash startup times.
Arguments
| :: [FilePath] | Import directories (-i flag) |
| -> [FilePath] | Package databases |
| -> FilePath | The folder in which the GHC bootstrap libraries (base, containers, etc.) can be found |
| -> ResolvedPrimMap | Primitives to compile |
| -> IO CompiledPrimMap |
Compiles the blackbox functions of and parses the blackbox templates in
a primitive map. All blackbox functions are interpreted in a single shared
Hint session (see interpretFunctions), and every distinct function is
interpreted exactly once, no matter how many primitives reference it.
Arguments
| :: [FilePath] | Import directories (-i flag) |
| -> [FilePath] | Package databases |
| -> FilePath | The folder in which the GHC bootstrap libraries (base, containers, etc.) can be found |
| -> ResolvedPrimitive | Primitive to compile |
| -> IO CompiledPrimitive |
Compiles a single primitive. Provided for backwards compatibility; when
compiling multiple primitives, compilePrimitives only pays the cost of
starting a Hint session once.
lookupInterpResult :: InterpretResults -> InterpretFunctionRequest -> IO (Either (NonEmpty InterpreterError) InterpretFunctionResult) Source #
Look up the interpreter result of a request. All requests are
interpreted before primitives are compiled, so a missing result is an
internal error: neededInterpRequests diverged from the requests
compilePrimitiveWith consumes.
Arguments
| :: (InterpretFunctionRequest -> IO (Either (NonEmpty InterpreterError) InterpretFunctionResult)) | Look up the interpreter result for a request |
| -> ResolvedPrimitive | Primitive to compile |
| -> IO CompiledPrimitive |
Compiles the blackbox functions of and parses the blackbox templates in
a primitive, given an action that produces the interpreted functions the
primitive needs (see neededInterpRequests).
Instances
| Exception HintError Source # | |
Defined in Clash.Driver Methods toException :: HintError -> SomeException # fromException :: SomeException -> Maybe HintError # displayException :: HintError -> String # | |
| Show HintError Source # | |
Arguments
| :: (MonadThrow m, Monad m) | |
| => String | Function to interpret |
| -> Text | BlackBox function name |
| -> Either (NonEmpty InterpreterError) t | Hint result |
| -> m t |
Arguments
| :: Backend backend | |
| => backend | Backend |
| -> ClashOpts | Global Clash options |
| -> IdentifierText | Module hierarchy root |
| -> IdentifierSet | Component names |
| -> ComponentMap | List of components |
| -> HashMap Text VDomainConfiguration | Known domains to configurations |
| -> Component | Top component |
| -> IdentifierText | Name of the manifest file |
| -> ([(String, Doc)], [(String, FilePath)], [(String, String)]) | The pretty-printed HDL documents + The data files that need to be copied |
Pretty print Components to HDL Documents
writeEdam :: FilePath -> (Identifier, Unique) -> HashMap Unique [Unique] -> HashMap Unique [EdamFile] -> [(FilePath, ByteString)] -> IO (HashMap Unique [EdamFile], [(FilePath, ByteString)]) Source #
Arguments
| :: (Identifier, Unique) | |
| -> HashMap Unique [Unique] | Top entity dependency map |
| -> HashMap Unique [EdamFile] | Edam files of each top entity |
| -> [FilePath] | Files to include in Edam file |
| -> (HashMap Unique [EdamFile], Edam) | (updated map, edam) |
Create an Edalize metadata file for using Edalize to build the project.
TODO: Handle libraries. Also see: https://github.com/olofk/edalize/issues/220
asEdamFile :: Identifier -> FilePath -> EdamFile Source #
Arguments
| :: FilePath | HDL directory to prepare |
| -> ClashOpts | Relevant options: |
| -> Maybe [UnexpectedModification] | Did directory contain unexpected modifications? See |
| -> IO () |
Prepares directory for writing HDL files.
writeAndHash :: FilePath -> ByteString -> IO ByteString Source #
Write a file to disk in chunks. Returns SHA256 sum of file contents.
writeHDL :: FilePath -> (FilePath, Doc) -> IO ByteString Source #
Writes a HDL file to the given directory. Returns SHA256 hash of written file.
Arguments
| :: FilePath | Directory to copy files to |
| -> [(FilePath, String)] | (filename, content) |
| -> IO [ByteString] |
Copy given files
Arguments
| :: FilePath | Directory to copy to |
| -> [(FilePath, FilePath)] |
|
| -> IO [ByteString] | SHA256 hashes of written files |
Copy data files added with ~FILE, assumes the files are canonicalized already. Throws an error on relative paths as sanity check.
Arguments
| :: ClashEnv | |
| -> BindingMap | All bindings |
| -> (CustomReprs -> TyConMap -> Type -> State HWMap (Maybe (Either String FilteredHWType))) | Hardcoded |
| -> Evaluator | Hardcoded evaluator for partial evaluation |
| -> Evaluator | Hardcoded evaluator for WHNF (old evaluator) |
| -> [Id] | TopEntities |
| -> Supply | Unique supply |
| -> Id | root of the hierarchy |
| -> IO BindingMap |
Normalize a complete hierarchy
sortTop :: BindingMap -> [TopEntityT] -> ([TopEntityT], HashMap Unique [Unique]) Source #
Reverse topologically sort given top entities. Also returns a mapping that maps a top entity to its reverse topologically sorted transitive dependencies.