Add mima-asm program
This commit is contained in:
parent
bd8bd20224
commit
6c7b47a18d
2 changed files with 55 additions and 0 deletions
45
app/MimaAsm/Main.hs
Normal file
45
app/MimaAsm/Main.hs
Normal file
|
|
@ -0,0 +1,45 @@
|
||||||
|
module Main where
|
||||||
|
|
||||||
|
import qualified Data.Text.IO as T
|
||||||
|
import Options.Applicative
|
||||||
|
import Text.Megaparsec
|
||||||
|
|
||||||
|
import Mima.Assembler.Parser
|
||||||
|
import Mima.Load
|
||||||
|
|
||||||
|
data Settings = Settings
|
||||||
|
{ infile :: String
|
||||||
|
, outfile :: String
|
||||||
|
} deriving (Show)
|
||||||
|
|
||||||
|
settingsParser :: Parser Settings
|
||||||
|
settingsParser = Settings
|
||||||
|
<$> strArgument
|
||||||
|
(metavar "INFILE"
|
||||||
|
<> help "The .mimasm file to assemble")
|
||||||
|
<*> strOption
|
||||||
|
(long "out"
|
||||||
|
<> short 'o'
|
||||||
|
<> metavar "OUTFILE"
|
||||||
|
<> help "The .mima file to write the assembled result to"
|
||||||
|
<> value "out.mima"
|
||||||
|
<> showDefault)
|
||||||
|
|
||||||
|
opts :: ParserInfo Settings
|
||||||
|
opts = info (helper <*> settingsParser) $ fullDesc <> failureCode 1
|
||||||
|
|
||||||
|
main :: IO ()
|
||||||
|
main = do
|
||||||
|
settings <- execParser opts
|
||||||
|
|
||||||
|
putStrLn $ "Loading assembly file at " ++ infile settings
|
||||||
|
asm <- T.readFile (infile settings)
|
||||||
|
|
||||||
|
putStrLn "Parsing assembly"
|
||||||
|
let parsed = parse parseState (infile settings) asm
|
||||||
|
case parsed of
|
||||||
|
Left errorBundle -> putStrLn $ errorBundlePretty errorBundle
|
||||||
|
Right (state, _) -> do
|
||||||
|
putStrLn "Parsing successful"
|
||||||
|
putStrLn $ "Writing result to " ++ outfile settings
|
||||||
|
saveStateToFile (outfile settings) state
|
||||||
10
package.yaml
10
package.yaml
|
|
@ -44,6 +44,16 @@ executables:
|
||||||
dependencies:
|
dependencies:
|
||||||
- mima-tools
|
- mima-tools
|
||||||
|
|
||||||
|
mima-asm:
|
||||||
|
main: Main.hs
|
||||||
|
source-dirs: app/MimaAsm
|
||||||
|
ghc-options:
|
||||||
|
- -threaded
|
||||||
|
- -rtsopts
|
||||||
|
- -with-rtsopts=-N
|
||||||
|
dependencies:
|
||||||
|
- mima-tools
|
||||||
|
|
||||||
tests:
|
tests:
|
||||||
mima-tools-test:
|
mima-tools-test:
|
||||||
main: Spec.hs
|
main: Spec.hs
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue