|
1 | 1 | {-|
|
2 | 2 | Copyright : (C) 2015-2016, University of Twente,
|
3 |
| - 2016-2017, Myrtle Software Ltd |
| 3 | + 2016-2017, Myrtle Software Ltd, |
| 4 | + 2021, QBayLogic B.V. |
4 | 5 | License : BSD2 (see the file LICENSE)
|
5 |
| - Maintainer : Christiaan Baaij <christiaan.baaij@gmail.com> |
| 6 | + Maintainer : QBayLogic B.V. <devops@qbaylogic.com> |
6 | 7 | -}
|
7 | 8 |
|
8 | 9 | {-# LANGUAGE CPP #-}
|
@@ -54,9 +55,12 @@ parseClashFlagsFull flagsAvialable args = do
|
54 | 55 | flagsClash :: IORef ClashOpts -> [Flag IO]
|
55 | 56 | flagsClash r = [
|
56 | 57 | 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)) |
57 | 61 | , 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) |
60 | 64 | , defFlag "fclash-debug-history" $ AnySuffix (liftEwM . (setRewriteHistoryFile r))
|
61 | 65 | , defFlag "fclash-hdldir" $ SepArg (setHdlDir r)
|
62 | 66 | , defFlag "fclash-hdlsyn" $ SepArg (setHdlSyn r)
|
@@ -136,31 +140,92 @@ setSpecLimit :: IORef ClashOpts
|
136 | 140 | -> IO ()
|
137 | 141 | setSpecLimit r n = modifyIORef r (\c -> c {opt_specLimit = n})
|
138 | 142 |
|
| 143 | +setDebugInvariants :: IORef ClashOpts -> IO () |
| 144 | +setDebugInvariants r = |
| 145 | + modifyIORef r $ \c -> |
| 146 | + c { opt_debug = (opt_debug c) { dbg_invariants = True } } |
| 147 | + |
| 148 | +setDebugCountTransformations :: IORef ClashOpts -> IO () |
| 149 | +setDebugCountTransformations r = |
| 150 | + modifyIORef r $ \c -> |
| 151 | + c { opt_debug = (opt_debug c) { dbg_countTransformations = True } } |
| 152 | + |
139 | 153 | setDebugTransformations :: IORef ClashOpts -> String -> EwM IO ()
|
140 | 154 | setDebugTransformations r s =
|
141 |
| - liftEwM (modifyIORef r (\c -> c {opt_dbgTransformations = transformations})) |
| 155 | + liftEwM (modifyIORef r (setTransformations transformations)) |
142 | 156 | where
|
143 | 157 | transformations = Set.fromList (filter (not . null) (map trim (splitOn "," s)))
|
144 | 158 | trim = dropWhileEnd isSpace . dropWhile isSpace
|
145 | 159 |
|
146 |
| -setDebugTransformationsFrom :: IORef ClashOpts -> Maybe Int -> EwM IO () |
147 |
| -setDebugTransformationsFrom r (Just n) = |
148 |
| - liftEwM (modifyIORef r (\c -> c {opt_dbgTransformationsFrom = n})) |
149 |
| -setDebugTransformationsFrom _r Nothing = pure () |
150 |
| - |
151 |
| -setDebugTransformationsLimit :: IORef ClashOpts -> Maybe Int -> EwM IO () |
152 |
| -setDebugTransformationsLimit r (Just n) = |
153 |
| - liftEwM (modifyIORef r (\c -> c {opt_dbgTransformationsLimit = n})) |
154 |
| -setDebugTransformationsLimit _r Nothing = pure () |
155 |
| - |
156 |
| -setDebugLevel :: IORef ClashOpts |
157 |
| - -> String |
158 |
| - -> EwM IO () |
159 |
| -setDebugLevel r s = case readMaybe s of |
160 |
| - Just dbgLvl -> liftEwM $ do |
161 |
| - modifyIORef r (\c -> c {opt_dbgLevel = dbgLvl}) |
162 |
| - when (dbgLvl > DebugNone) $ setNoCache r -- when debugging disable cache |
163 |
| - Nothing -> addWarn (s ++ " is an invalid debug level") |
| 160 | + setTransformations xs opts = |
| 161 | + opts { opt_debug = (opt_debug opts) { dbg_transformations = xs } } |
| 162 | + |
| 163 | +setDebugTransformationsFrom :: IORef ClashOpts -> Int -> EwM IO () |
| 164 | +setDebugTransformationsFrom r n = |
| 165 | + liftEwM (modifyIORef r (setFrom (fromIntegral n))) |
| 166 | + where |
| 167 | + setFrom from opts = |
| 168 | + opts { opt_debug = (opt_debug opts) { dbg_transformationsFrom = Just from } } |
| 169 | + |
| 170 | +setDebugTransformationsLimit :: IORef ClashOpts -> Int -> EwM IO () |
| 171 | +setDebugTransformationsLimit r n = |
| 172 | + liftEwM (modifyIORef r (setLimit (fromIntegral n))) |
| 173 | + where |
| 174 | + setLimit limit opts = |
| 175 | + opts { opt_debug = (opt_debug opts) { dbg_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") |
| 212 | + where |
| 213 | + setLevel lvl opts = |
| 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) { dbg_transformationInfo = info } } |
164 | 229 |
|
165 | 230 | setNoCache :: IORef ClashOpts -> IO ()
|
166 | 231 | setNoCache r = modifyIORef r (\c -> c {opt_cachehdl = False})
|
@@ -251,4 +316,7 @@ setRewriteHistoryFile r arg = do
|
251 | 316 | let fileNm = case drop (length "-fclash-debug-history=") arg of
|
252 | 317 | [] -> "history.dat"
|
253 | 318 | str -> str
|
254 |
| - modifyIORef r (\c -> c {opt_dbgRewriteHistoryFile = Just fileNm}) |
| 319 | + modifyIORef r (setFile fileNm) |
| 320 | + where |
| 321 | + setFile file opts = |
| 322 | + opts { opt_debug = (opt_debug opts) { dbg_historyFile = Just file } } |
0 commit comments