1
1
import Data.Monoid
2
2
import Control.Monad
3
3
import Options.Applicative
4
+ import Data.Either
4
5
import Data.Aeson
5
6
import qualified Data.ByteString.Lazy as B
6
7
import System.FilePath
@@ -20,10 +21,17 @@ main = join $ execParser $ addInfo i $ versionOption <*> subparser (
20
21
<*> pure [" ." ]
21
22
<*> optional (strOption (long " output" <> short ' o' <> metavar " FILENAME" <> help " output file name" ))
22
23
)
24
+ <> command " dump" (addInfo (progDesc " dumps LambdaCube3D core" ) $ dump
25
+ <$> argument str (metavar " SOURCE_FILE" )
26
+ <*> flag OpenGL33 WebGL1 (long " webgl" <> help " generate WebGL 1.0 pipeline" )
27
+ <*> pure [" ." ]
28
+ <*> optional (strOption (long " output" <> short ' o' <> metavar " FILENAME" <> help " output file name" ))
29
+ )
23
30
<> command " pretty" (addInfo (progDesc " pretty prints JSON IR" ) $ prettyPrint
24
31
<$> argument str (metavar " SOURCE_FILE" )
25
32
<*> optional (strOption (long " output" <> short ' o' <> metavar " FILENAME" <> help " output file name" ))
26
- )) <|> compile'
33
+ )
34
+ ) <|> compile'
27
35
where
28
36
compile' = (compile
29
37
<$> argument str (metavar " SOURCE_FILE" )
@@ -60,6 +68,12 @@ parse srcName backend includePaths output = do
60
68
Left err -> fail $ show err
61
69
Right ppl -> maybe (putStrLn ppl) (`writeFile` ppl) output
62
70
71
+ dump srcName backend includePaths output = do
72
+ res <- runMM (ioFetch includePaths) $ getDef srcName " main" (Just outputType)
73
+ let Right e = snd $ fromRight (error " compile error: can not dump the core, try regular compile to get the error message" ) $ snd res
74
+ coreDump = show $ mkDoc (False ,True ) e
75
+ maybe (putStrLn coreDump) (`writeFile` coreDump) output
76
+
63
77
compile srcName backend includePaths output = do
64
78
let ext = takeExtension srcName
65
79
baseName | ext == " .lc" = dropExtension srcName
0 commit comments