Skip to content

Commit ca9481c

Browse files
committed
[#12] Added cmd line options for dumping
1 parent c9ec0f1 commit ca9481c

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

app/Main.hs

+25-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import Ohua.Prelude
66
import Data.Aeson as A
77
import qualified Data.ByteString.Lazy.Char8 as L (writeFile)
88
import qualified Data.Char as C (toLower)
9+
import qualified Data.HashSet as HS (fromList, member)
910
import Data.List (intercalate, lookup)
1011
import Language.Haskell.TH
1112
import Lens.Micro.Internal (Index, IxValue, Ixed, ix)
@@ -29,6 +30,7 @@ newtype DumpOpts = DumpOpts
2930
data BuildOpts = BuildOpts
3031
{ outputFormat :: CodeGenSelection
3132
, useStdlib :: Bool
33+
, stageHandlingOpt :: StageHandling
3234
}
3335

3436
data Command
@@ -156,7 +158,7 @@ main = do
156158
"' to '" <>
157159
outPath <>
158160
"'"
159-
Build BuildOpts {outputFormat, useStdlib} -> do
161+
Build BuildOpts {outputFormat, useStdlib, stageHandlingOpt} -> do
160162
when useStdlib $ void $ insertDirectly modTracker stdlib
161163
mainMod <-
162164
registerAnd modTracker (rawMainMod ^. name) $
@@ -166,7 +168,7 @@ main = do
166168
let (mainArity, completeExpr) = mainToEnv expr
167169
gr <-
168170
compile
169-
def
171+
(def & stageHandling .~ stageHandlingOpt)
170172
(def {passAfterDFLowering = cleanUnits})
171173
completeExpr
172174
(nameSuggest, code) <-
@@ -224,15 +226,33 @@ main = do
224226
O.switch
225227
(long "with-stdlib" <>
226228
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")))
228244
optsParser =
229245
CmdOpts <$>
230246
hsubparser
231247
(command
232248
"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")) <>
234254
command
235-
"dump-main-type"
255+
"dump-ma in-type"
236256
(info
237257
(DumpType <$> dumpOpts)
238258
(progDesc "Dump the type of the main function"))) <*>

stack.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ packages:
33
- .
44
- location:
55
git: https://github.com/ohua-dev/ohua-core
6-
commit: 5ba86ba858f76640c22bf53f1464288f7e270b03
6+
commit: 75803248998933fd9a8e4f1172fe4c93e0c3bb61
77
extra-dep: true
88
- location:
99
git: https://github.com/ohua-dev/alang-clike-parser

0 commit comments

Comments
 (0)