86 lines
1.8 KiB
Haskell
86 lines
1.8 KiB
Haskell
{-# LANGUAGE NoFieldSelectors #-}
|
|
module Gyehoek.Options
|
|
( Options(..)
|
|
, Runtime(..)
|
|
, parser
|
|
)
|
|
where
|
|
|
|
import System.IO (Handle)
|
|
import Data.HashSet (HashSet)
|
|
import Options.Applicative
|
|
import System.FilePath
|
|
import qualified Data.HashSet as HS
|
|
import Control.Lens hiding (argument)
|
|
import GHC.Generics (Generic)
|
|
import Data.Foldable
|
|
|
|
|
|
data Runtime = Stackify | Wasm | CPS
|
|
deriving (Show, Generic)
|
|
|
|
data Options = MkOptions
|
|
{ dumpClosed :: Bool
|
|
, dumpCPS :: Bool
|
|
, dumpParsed :: Bool
|
|
, dumpStackified :: Bool
|
|
, runtime :: Maybe Runtime
|
|
, inspectWasm :: Bool
|
|
, output :: FilePath
|
|
, sourceFile :: FilePath
|
|
}
|
|
deriving (Show, Generic)
|
|
|
|
-- osPath :: ReadM _
|
|
-- osPath = eitherReader $
|
|
-- (_Left %~ show) . encodeUtf @(Either _)
|
|
|
|
-- parseDumpQBE =
|
|
-- optional $ strOption
|
|
-- ( long "dump-qbe"
|
|
-- <> metavar "FILE"
|
|
-- )
|
|
|
|
-- parseDumpANF =
|
|
-- optional $ strOption
|
|
-- ( long "dump-anf"
|
|
-- <> metavar "FILE"
|
|
-- )
|
|
|
|
parseOutput = strOption
|
|
( long "output"
|
|
<> short 'o'
|
|
<> metavar "FILE"
|
|
<> value "-"
|
|
)
|
|
|
|
parseRuntime = option rdr . fold $
|
|
[ long "runtime"
|
|
, short 'R'
|
|
, value Nothing
|
|
]
|
|
where
|
|
rdr = maybeReader \case
|
|
"stackify" -> Just (Just Stackify)
|
|
"wasm" -> Just (Just Wasm)
|
|
"cps" -> Just (Just CPS)
|
|
"none" -> Just Nothing
|
|
_ -> Nothing
|
|
|
|
parseDumpClosed = switch (long "dump-closed")
|
|
parseDumpCPS = switch (long "dump-cps")
|
|
parseDumpStackified = switch (long "dump-stackified")
|
|
parseDumpParsed = switch (long "dump-parsed")
|
|
parseInspectWasm = switch $ long "inspect-wasm" <> short 'p'
|
|
|
|
parser :: Parser Options
|
|
parser = MkOptions
|
|
<$> parseDumpClosed
|
|
<*> parseDumpCPS
|
|
<*> parseDumpParsed
|
|
<*> parseDumpStackified
|
|
<*> parseRuntime
|
|
<*> parseInspectWasm
|
|
<*> parseOutput
|
|
<*> argument str (metavar "FILE")
|