Parse command-line parameters
This commit is contained in:
parent
04036bb047
commit
8f9b082eb4
2 changed files with 57 additions and 4 deletions
41
app/MimaRun.hs
Normal file
41
app/MimaRun.hs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
module MimaRun where
|
||||
|
||||
import Options.Applicative
|
||||
|
||||
data Settings = Settings
|
||||
{ file :: String
|
||||
, steps :: Maybe Integer
|
||||
, memoryDump :: Maybe FilePath
|
||||
, quiet :: Bool
|
||||
, sparseOutput :: Bool
|
||||
} deriving (Show)
|
||||
|
||||
settings :: Parser Settings
|
||||
settings = Settings
|
||||
<$> strArgument
|
||||
(metavar "INFILE"
|
||||
<> help "The memory dump to load and execute")
|
||||
<*> (optional . option auto)
|
||||
(long "steps"
|
||||
<> short 'n'
|
||||
<> metavar "N"
|
||||
<> help "How many instructions to execute (if not specified, runs until HALT or execution exception)")
|
||||
<*> (optional . strOption)
|
||||
(long "dump"
|
||||
<> short 'd'
|
||||
<> metavar "OUTFILE"
|
||||
<> help "If specified, the MiMa's memory is dumped to this file after execution is finished")
|
||||
<*> flag False True
|
||||
(long "quiet"
|
||||
<> short 'q'
|
||||
<> help "Whether to print the memory after execution is finished")
|
||||
<*> flag False True
|
||||
(long "sparse"
|
||||
<> short 's'
|
||||
<> help "Whether to print memory locations that contain 0")
|
||||
|
||||
opts :: ParserInfo Settings
|
||||
opts = info (helper <*> settings) $ fullDesc <> failureCode 1
|
||||
|
||||
main :: IO ()
|
||||
main = execParser opts >>= print
|
||||
20
package.yaml
20
package.yaml
|
|
@ -19,15 +19,27 @@ extra-source-files:
|
|||
description: Please see the README on GitHub at <https://github.com/Garmelon/mima-tools#readme>
|
||||
|
||||
dependencies:
|
||||
- base >= 4.7 && < 5
|
||||
- bytestring >= 0.10.8 && < 0.11
|
||||
- containers >= 0.6.0 && < 0.7
|
||||
- text >= 1.2.3 && < 1.3
|
||||
- base >= 4.7 && < 5
|
||||
- bytestring >= 0.10.8 && < 0.11
|
||||
- containers >= 0.6.0 && < 0.7
|
||||
- text >= 1.2.3 && < 1.3
|
||||
- optparse-applicative >= 0.14.3 && < 0.15
|
||||
|
||||
library:
|
||||
source-dirs: src
|
||||
|
||||
executables:
|
||||
mima-run:
|
||||
main: MimaRun.hs
|
||||
source-dirs: app
|
||||
ghc-options:
|
||||
- -main-is MimaRun
|
||||
- -threaded
|
||||
- -rtsopts
|
||||
- -with-rtsopts=-N
|
||||
dependencies:
|
||||
- mima-tools
|
||||
|
||||
mima-tools-exe:
|
||||
main: Main.hs
|
||||
source-dirs: app
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue