@@ -6,6 +6,7 @@ import Ohua.Prelude
6
6
import Data.Aeson as A
7
7
import qualified Data.ByteString.Lazy.Char8 as L (writeFile )
8
8
import qualified Data.Char as C (toLower )
9
+ import qualified Data.HashSet as HS (fromList , member )
9
10
import Data.List (intercalate , lookup )
10
11
import Language.Haskell.TH
11
12
import Lens.Micro.Internal (Index , IxValue , Ixed , ix )
@@ -29,6 +30,7 @@ newtype DumpOpts = DumpOpts
29
30
data BuildOpts = BuildOpts
30
31
{ outputFormat :: CodeGenSelection
31
32
, useStdlib :: Bool
33
+ , stageHandlingOpt :: StageHandling
32
34
}
33
35
34
36
data Command
@@ -156,7 +158,7 @@ main = do
156
158
" ' to '" <>
157
159
outPath <>
158
160
" '"
159
- Build BuildOpts {outputFormat, useStdlib} -> do
161
+ Build BuildOpts {outputFormat, useStdlib, stageHandlingOpt } -> do
160
162
when useStdlib $ void $ insertDirectly modTracker stdlib
161
163
mainMod <-
162
164
registerAnd modTracker (rawMainMod ^. name) $
@@ -166,7 +168,7 @@ main = do
166
168
let (mainArity, completeExpr) = mainToEnv expr
167
169
gr <-
168
170
compile
169
- def
171
+ ( def & stageHandling .~ stageHandlingOpt)
170
172
(def {passAfterDFLowering = cleanUnits})
171
173
completeExpr
172
174
(nameSuggest, code) <-
@@ -224,15 +226,33 @@ main = do
224
226
O. switch
225
227
(long " with-stdlib" <>
226
228
help
227
- " Link the `ohua.std` namespace of higher order functions into the program. (experimental)" )
229
+ " Link the `ohua.std` namespace of higher order functions into the program. (experimental)" ) <*>
230
+ ((\ stopOn dumpStages sname ->
231
+ ( if sname `HS.member` HS. fromList dumpStages
232
+ then DumpPretty
233
+ else Don'tDump
234
+ , stopOn == sname)) <$>
235
+ O. strOption
236
+ (long " stop-on" <> help " Stop execution after this stage." <>
237
+ metavar " STAGE" ) <*>
238
+ many
239
+ (O. strOption
240
+ (long " dump-stage" <>
241
+ help
242
+ " Dump the code at this stage. (can be supplied multiple times)" <>
243
+ metavar " STAGE" )))
228
244
optsParser =
229
245
CmdOpts <$>
230
246
hsubparser
231
247
(command
232
248
" build"
233
- (info (Build <$> buildOpts) (progDesc " Build the ohua graph" )) <>
249
+ (info
250
+ (Build <$> buildOpts)
251
+ (progDesc $
252
+ " Build the ohua graph. " <>
253
+ " The options --dump-stage and --stop-on pertain to stages. See https://ohua.rtfd.io/en/latest/debugging.html#stages" )) <>
234
254
command
235
- " dump-main -type"
255
+ " dump-ma in -type"
236
256
(info
237
257
(DumpType <$> dumpOpts)
238
258
(progDesc " Dump the type of the main function" ))) <*>
0 commit comments