Discover assembly output file

This commit is contained in:
Joscha 2019-11-25 13:12:01 +00:00
parent 9ace3632bc
commit e5728a0fb4

View file

@ -18,13 +18,21 @@ import Mima.Options
import Mima.Parse.Assembly
data Settings = Settings
{ infile :: String
, outfile :: String
{ infile :: FilePath
, outfile :: Maybe FilePath
, discover :: Bool
, flagFile :: Maybe FilePath
, symbolFile :: Maybe FilePath
} deriving (Show)
getOutfile :: Settings -> FilePath
getOutfile settings =
case outfile settings of
Just path -> path
Nothing -> discoveredPath
where
discoveredPath = dropExtension (infile settings) ++ ".mima"
getFlagFile :: Settings -> File
getFlagFile settings =
case flagFile settings of
@ -52,12 +60,11 @@ settingsParser = Settings
<$> strArgument
(metavar "INFILE"
<> help "The .mimasm file to assemble")
<*> strOption
<*> (optional . strOption)
(long "out"
<> short 'o'
<> metavar "OUTFILE"
<> help "The .mima file to write the assembled result to"
<> value "out.mima"
<> showDefault)
<*> switchWithNo "discover" True
"Derive the file names for the .mima-flags and .mima-symbols files from the name of the input file"
@ -105,8 +112,8 @@ main = doRun_ $ do
(state, labels, flags) <- loadFile readAssembly (infile settings)
lift $ putStrLn "Parsing successful"
lift $ putStrLn $ "Writing result to " ++ outfile settings
saveStateToFile (outfile settings) state
lift $ putStrLn $ "Writing result to " ++ getOutfile settings
saveStateToFile (getOutfile settings) state
saveFlags flags settings
saveSymbols labels settings