-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is almost identical to the version proposed by @basile-henry in issue #2020: #2020 (comment)
- Loading branch information
1 parent
53d32a6
commit 8abfe3d
Showing
6 changed files
with
95 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
NEW: `clashCompileError`: make HDL generation error out with a custom error | ||
message. Simulation in Clash will also error when the function is evaluated, | ||
including a call stack. HDL generation unfortunately does not include a call | ||
stack. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{-| | ||
Copyright : (C) 2022 , Myrtle.ai, | ||
2023 , QBayLogic B.V., | ||
License : BSD2 (see the file LICENSE) | ||
Maintainer : QBayLogic B.V. <devops@qbaylogic.com> | ||
Blackbox functions for primitives in one of the @Prelude@ modules. | ||
-} | ||
|
||
module Clash.Primitives.Prelude | ||
( clashCompileErrorBBF | ||
) where | ||
|
||
import Control.Monad.State (State) | ||
import GHC.Stack (HasCallStack) | ||
import Prelude | ||
|
||
import Clash.Backend (Backend) | ||
import Clash.Netlist.BlackBox.Types (BlackBoxFunction, emptyBlackBoxMeta) | ||
import Clash.Netlist.BlackBox.Util (exprToString) | ||
import Clash.Netlist.Types | ||
(BlackBox(..), BlackBoxContext(..), TemplateFunction(..)) | ||
import Data.Text.Prettyprint.Doc.Extra (Doc) | ||
|
||
clashCompileErrorBBF :: HasCallStack => BlackBoxFunction | ||
clashCompileErrorBBF _isD _primName _args _ty = | ||
pure (Right (emptyBlackBoxMeta, bb)) | ||
where | ||
bb = BBFunction (show 'clashCompileErrorBBF) 0 clashCompileErrorTF | ||
clashCompileErrorTF | ||
| ( _hasCallStack | ||
: msg | ||
: _ ) <- [0..] | ||
= TemplateFunction [msg] (const True) clashCompileErrorTemplate | ||
| otherwise = undefined | ||
|
||
clashCompileErrorTemplate :: | ||
HasCallStack => | ||
Backend s => | ||
BlackBoxContext -> | ||
State s Doc | ||
clashCompileErrorTemplate bbCtx | ||
| [ _hasCallStack | ||
, (msgE, _, _) | ||
] <- bbInputs bbCtx | ||
= case exprToString msgE of | ||
Just msg -> | ||
errorWithoutStackTrace $ "clashCompileError: " <> msg | ||
Nothing -> | ||
error $ "Error while processing clashCompileError: 'msg' argument " <> | ||
"does not reduce to a string: " <> show msgE | ||
| otherwise | ||
= error $ "Error while processing clashCompileError: bad bbContext: " <> | ||
show bbCtx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters