Skip to content

Commit 1237446

Browse files
author
Alex McKenna
committed
More granular debug options
The old DebugLevel style debug options are replaced with a more granular style, where different options can be set independently. This allows things not previously possible, such as counting transformations without having to print any normalized core. The old -fclash-debug flag still works for backwards compatibility. Additional command line flags are now available to directly set options from the new type: -fclash-debug-invariants checks for invariants and displays warnings / errors. Setting this alone is equivalent to DebugSilent. -fclash-debug-info sets the amount of information to display when applying transformations. This overlaps a lot with the old DebugLevel type, but is named more consistently. -fclash-debug-count-transformations counts the number of transformations applied (without showing any normalized core like DebugCount did)
1 parent f7d9044 commit 1237446

File tree

13 files changed

+383
-224
lines changed

13 files changed

+383
-224
lines changed

Clash.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ doHDL b src = do
6363

6464
generateHDL (buildCustomReprs reprs) domainConfs bindingsMap (Just b) primMap tcm tupTcm
6565
(ghcTypeToHWType WORD_SIZE_IN_BITS True) evaluator topEntities Nothing
66-
defClashOpts{opt_cachehdl = False, opt_dbgLevel = DebugSilent, opt_clear = True}
66+
defClashOpts{opt_cachehdl = False, opt_debug = debugSilent, opt_clear = True}
6767
(startTime,prepTime)
6868

6969
main :: IO ()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CHANGED: Clash now supports more expressive debug options at the command line [#1800](https://github.com/clash-lang/clash-compiler/issues/1800).
2+
3+
With the old `DebugLevel` type for setting debug options, it was not possible to set certain debug options without implying others, i.e. counting transformations was not possible without also printing at least the final normalized core for a term. It is now possible to set options individually with new flags:
4+
5+
* -fclash-debug-invariants to check invariants and print warnings / errors
6+
* -fclash-debug-info to choose how much information to show about individual transformations
7+
* -fclash-debug-count-transformations to print a tally of each transformation applied
8+
9+
The old -fclash-debug flag is still available for backwards compatibility, and each `DebugLevel` is now a synonym for setting these options together.
10+

clash-ghc/src-ghc/Clash/GHC/ClashFlags.hs

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
{-|
22
Copyright : (C) 2015-2016, University of Twente,
3-
2016-2017, Myrtle Software Ltd
3+
2016-2017, Myrtle Software Ltd,
4+
2021, QBayLogic B.V.
45
License : BSD2 (see the file LICENSE)
5-
Maintainer : Christiaan Baaij <christiaan.baaij@gmail.com>
6+
Maintainer : QBayLogic B.V. <devops@qbaylogic.com>
67
-}
78

89
{-# LANGUAGE CPP #-}
@@ -54,9 +55,12 @@ parseClashFlagsFull flagsAvialable args = do
5455
flagsClash :: IORef ClashOpts -> [Flag IO]
5556
flagsClash r = [
5657
defFlag "fclash-debug" $ SepArg (setDebugLevel r)
58+
, defFlag "fclash-debug-info" $ SepArg (setDebugInfo r)
59+
, defFlag "fclash-debug-invariants" $ NoArg (liftEwM (setDebugInvariants r))
60+
, defFlag "fclash-debug-count-transformations" $ NoArg (liftEwM (setDebugCountTransformations r))
5761
, defFlag "fclash-debug-transformations" $ SepArg (setDebugTransformations r)
58-
, defFlag "fclash-debug-transformations-from" $ OptIntSuffix (setDebugTransformationsFrom r)
59-
, defFlag "fclash-debug-transformations-limit" $ OptIntSuffix (setDebugTransformationsLimit r)
62+
, defFlag "fclash-debug-transformations-from" $ IntSuffix (setDebugTransformationsFrom r)
63+
, defFlag "fclash-debug-transformations-limit" $ IntSuffix (setDebugTransformationsLimit r)
6064
, defFlag "fclash-debug-history" $ AnySuffix (liftEwM . (setRewriteHistoryFile r))
6165
, defFlag "fclash-hdldir" $ SepArg (setHdlDir r)
6266
, defFlag "fclash-hdlsyn" $ SepArg (setHdlSyn r)
@@ -136,6 +140,16 @@ setSpecLimit :: IORef ClashOpts
136140
-> IO ()
137141
setSpecLimit r n = modifyIORef r (\c -> c {opt_specLimit = n})
138142

143+
setDebugInvariants :: IORef ClashOpts -> IO ()
144+
setDebugInvariants r =
145+
modifyIORef r $ \c ->
146+
c { opt_debug = (opt_debug c) { opt_invariants = True } }
147+
148+
setDebugCountTransformations :: IORef ClashOpts -> IO ()
149+
setDebugCountTransformations r =
150+
modifyIORef r $ \c ->
151+
c { opt_debug = (opt_debug c) { opt_countTransformations = True } }
152+
139153
setDebugTransformations :: IORef ClashOpts -> String -> EwM IO ()
140154
setDebugTransformations r s =
141155
liftEwM (modifyIORef r (setTransformations transformations))
@@ -146,35 +160,72 @@ setDebugTransformations r s =
146160
setTransformations xs opts =
147161
opts { opt_debug = (opt_debug opts) { opt_transformations = xs } }
148162

149-
setDebugTransformationsFrom :: IORef ClashOpts -> Maybe Int -> EwM IO ()
150-
setDebugTransformationsFrom r (Just n) =
163+
setDebugTransformationsFrom :: IORef ClashOpts -> Int -> EwM IO ()
164+
setDebugTransformationsFrom r n =
151165
liftEwM (modifyIORef r (setFrom (fromIntegral n)))
152166
where
153167
setFrom from opts =
154-
opts { opt_debug = (opt_debug opts) { opt_transformationsFrom = from } }
168+
opts { opt_debug = (opt_debug opts) { opt_transformationsFrom = Just from } }
155169

156-
setDebugTransformationsFrom _r Nothing = pure ()
157-
158-
setDebugTransformationsLimit :: IORef ClashOpts -> Maybe Int -> EwM IO ()
159-
setDebugTransformationsLimit r (Just n) =
170+
setDebugTransformationsLimit :: IORef ClashOpts -> Int -> EwM IO ()
171+
setDebugTransformationsLimit r n =
160172
liftEwM (modifyIORef r (setLimit (fromIntegral n)))
161173
where
162174
setLimit limit opts =
163-
opts { opt_debug = (opt_debug opts) { opt_transformationsLimit = limit } }
164-
165-
setDebugTransformationsLimit _r Nothing = pure ()
166-
167-
setDebugLevel :: IORef ClashOpts
168-
-> String
169-
-> EwM IO ()
170-
setDebugLevel r s = case readMaybe s of
171-
Just dbgLvl -> liftEwM $ do
172-
modifyIORef r (setLevel dbgLvl)
173-
when (dbgLvl > DebugNone) $ setNoCache r -- when debugging disable cache
174-
Nothing -> addWarn (s ++ " is an invalid debug level")
175+
opts { opt_debug = (opt_debug opts) { opt_transformationsLimit = Just limit } }
176+
177+
setDebugLevel :: IORef ClashOpts -> String -> EwM IO ()
178+
setDebugLevel r s =
179+
case s of
180+
"DebugNone" ->
181+
liftEwM $ modifyIORef r (setLevel debugNone)
182+
"DebugSilent" ->
183+
liftEwM $ do
184+
modifyIORef r (setLevel debugSilent)
185+
setNoCache r
186+
"DebugFinal" ->
187+
liftEwM $ do
188+
modifyIORef r (setLevel debugFinal)
189+
setNoCache r
190+
"DebugCount" ->
191+
liftEwM $ do
192+
modifyIORef r (setLevel debugCount)
193+
setNoCache r
194+
"DebugName" ->
195+
liftEwM $ do
196+
modifyIORef r (setLevel debugName)
197+
setNoCache r
198+
"DebugTry" ->
199+
liftEwM $ do
200+
modifyIORef r (setLevel debugTry)
201+
setNoCache r
202+
"DebugApplied" ->
203+
liftEwM $ do
204+
modifyIORef r (setLevel debugApplied)
205+
setNoCache r
206+
"DebugAll" ->
207+
liftEwM $ do
208+
modifyIORef r (setLevel debugAll)
209+
setNoCache r
210+
_ ->
211+
addWarn (s ++ " is an invalid debug level")
175212
where
176213
setLevel lvl opts =
177-
opts { opt_debug = (opt_debug opts) { opt_level = lvl } }
214+
opts { opt_debug = lvl }
215+
216+
setDebugInfo :: IORef ClashOpts -> String -> EwM IO ()
217+
setDebugInfo r s =
218+
case readMaybe s of
219+
Just info ->
220+
liftEwM $ do
221+
modifyIORef r (setInfo info)
222+
when (info /= None) (setNoCache r)
223+
224+
Nothing ->
225+
addWarn (s ++ " is an invalid debug info")
226+
where
227+
setInfo info opts =
228+
opts { opt_debug = (opt_debug opts) { opt_transformationInfo = info } }
178229

179230
setNoCache :: IORef ClashOpts -> IO ()
180231
setNoCache r = modifyIORef r (\c -> c {opt_cachehdl = False})
@@ -268,4 +319,4 @@ setRewriteHistoryFile r arg = do
268319
modifyIORef r (setFile fileNm)
269320
where
270321
setFile file opts =
271-
opts { opt_debug = (opt_debug opts) { opt_rewriteHistoryFile = Just file } }
322+
opts { opt_debug = (opt_debug opts) { opt_historyFile = Just file } }

clash-lib/src/Clash/Driver.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ generateHDL
292292
-> IO ()
293293
generateHDL reprs domainConfs bindingsMap hdlState primMap tcm tupTcm typeTrans eval
294294
topEntities0 mainTopEntity opts (startTime,prepTime) = do
295-
case opt_rewriteHistoryFile (opt_debug opts) of
295+
case opt_historyFile (opt_debug opts) of
296296
Nothing -> pure ()
297297
Just histFile -> whenM (Directory.doesFileExist histFile) (Directory.removeFile histFile)
298298
let (tes, deps) = sortTop bindingsMap topEntities1

clash-lib/src/Clash/Driver/Manifest.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ readFreshManifest tops (bindingsMap, topId) primMap opts@(ClashOpts{..}) clashMo
372372

373373
-- 1. Debug
374374
opt_debug = opt_debug
375-
{ opt_level = DebugNone
375+
{ opt_invariants = False
376376
, opt_transformations = Set.empty
377-
, opt_rewriteHistoryFile = Nothing
377+
, opt_historyFile = Nothing
378378
}
379379

380380
-- 2. Caching

0 commit comments

Comments
 (0)