Skip to content

Commit ef09f14

Browse files
committed
add core dump option to cli
1 parent 3acea61 commit ef09f14

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

tool/Compiler.hs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Data.Monoid
22
import Control.Monad
33
import Options.Applicative
4+
import Data.Either
45
import Data.Aeson
56
import qualified Data.ByteString.Lazy as B
67
import System.FilePath
@@ -20,10 +21,17 @@ main = join $ execParser $ addInfo i $ versionOption <*> subparser (
2021
<*> pure ["."]
2122
<*> optional (strOption (long "output" <> short 'o' <> metavar "FILENAME" <> help "output file name"))
2223
)
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+
)
2330
<> command "pretty" (addInfo (progDesc "pretty prints JSON IR") $ prettyPrint
2431
<$> argument str (metavar "SOURCE_FILE")
2532
<*> optional (strOption (long "output" <> short 'o' <> metavar "FILENAME" <> help "output file name"))
26-
)) <|> compile'
33+
)
34+
) <|> compile'
2735
where
2836
compile' = (compile
2937
<$> argument str (metavar "SOURCE_FILE")
@@ -60,6 +68,12 @@ parse srcName backend includePaths output = do
6068
Left err -> fail $ show err
6169
Right ppl -> maybe (putStrLn ppl) (`writeFile` ppl) output
6270

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+
6377
compile srcName backend includePaths output = do
6478
let ext = takeExtension srcName
6579
baseName | ext == ".lc" = dropExtension srcName

0 commit comments

Comments
 (0)