diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2016-01-13 13:04:43 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2016-01-13 13:04:52 +0100 |
commit | ce62adbbf15a76b055c060c1758a740294519131 (patch) | |
tree | dadf6ca22f5f3482b471083ab49280f4a2a8aaa1 | |
parent | 25146fc5f9b116d41ee45fd41ac5a71f419396c4 (diff) |
add command line tool
-rw-r--r-- | lambdacube-compiler.cabal | 14 | ||||
-rw-r--r-- | tool/Compiler.hs | 32 |
2 files changed, 46 insertions, 0 deletions
diff --git a/lambdacube-compiler.cabal b/lambdacube-compiler.cabal index ad4a64e9..c0fb78c0 100644 --- a/lambdacube-compiler.cabal +++ b/lambdacube-compiler.cabal | |||
@@ -148,3 +148,17 @@ executable lambdacube-compiler-coverage-test-suite | |||
148 | text >= 1.2 && <1.3, | 148 | text >= 1.2 && <1.3, |
149 | lambdacube-ir, | 149 | lambdacube-ir, |
150 | vector >= 0.11 && <0.12 | 150 | vector >= 0.11 && <0.12 |
151 | |||
152 | |||
153 | executable lc | ||
154 | hs-source-dirs: tool | ||
155 | main-is: Compiler.hs | ||
156 | default-language: Haskell2010 | ||
157 | |||
158 | -- CAUTION: When the build-depends change, please bump the git submodule in lambdacube-docker repository | ||
159 | build-depends: | ||
160 | base < 4.9, | ||
161 | lambdacube-compiler, | ||
162 | optparse-applicative == 0.11.*, | ||
163 | aeson == 0.9.*, | ||
164 | bytestring == 0.10.* | ||
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 #-} | ||
2 | import Options.Applicative | ||
3 | import Data.Aeson | ||
4 | import qualified Data.ByteString.Lazy as B | ||
5 | import LambdaCube.Compiler.Driver | ||
6 | |||
7 | data Config | ||
8 | = Config | ||
9 | { srcName :: String | ||
10 | , backend :: Backend | ||
11 | } | ||
12 | |||
13 | sample :: Parser Config | ||
14 | sample = Config | ||
15 | <$> argument str (metavar "SOURCE_FILE") | ||
16 | <*> flag OpenGL33 WebGL1 (long "webgl" <> help "generate WebGL 1.0 pipeline" ) | ||
17 | |||
18 | main :: IO () | ||
19 | main = 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 | |||
26 | compile :: Config -> IO () | ||
27 | compile 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 | ||