summaryrefslogtreecommitdiff
path: root/tool
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2016-01-13 13:04:43 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2016-01-13 13:04:52 +0100
commitce62adbbf15a76b055c060c1758a740294519131 (patch)
treedadf6ca22f5f3482b471083ab49280f4a2a8aaa1 /tool
parent25146fc5f9b116d41ee45fd41ac5a71f419396c4 (diff)
add command line tool
Diffstat (limited to 'tool')
-rw-r--r--tool/Compiler.hs32
1 files changed, 32 insertions, 0 deletions
diff --git a/tool/Compiler.hs b/tool/Compiler.hs
new file mode 100644
index 00000000..2195f0c6
--- /dev/null
+++ b/tool/Compiler.hs
@@ -0,0 +1,32 @@
1{-# LANGUAGE RecordWildCards #-}
2import Options.Applicative
3import Data.Aeson
4import qualified Data.ByteString.Lazy as B
5import LambdaCube.Compiler.Driver
6
7data Config
8 = Config
9 { srcName :: String
10 , backend :: Backend
11 }
12
13sample :: Parser Config
14sample = Config
15 <$> argument str (metavar "SOURCE_FILE")
16 <*> flag OpenGL33 WebGL1 (long "webgl" <> help "generate WebGL 1.0 pipeline" )
17
18main :: IO ()
19main = execParser opts >>= compile
20 where
21 opts = info (helper <*> sample)
22 ( fullDesc
23 <> progDesc "compiles LambdaCube graphics pipeline source to JSON IR"
24 <> header "LambdaCube 3D compiler" )
25
26compile :: Config -> IO ()
27compile Config{..} = do
28 pplRes <- compileMain ["."] backend srcName
29 case pplRes of
30 Left err -> putStrLn err
31 Right ppl -> do
32 B.writeFile (srcName <> ".json") $ encode ppl