Export symbol and flag files
This commit is contained in:
parent
02b6d65b8f
commit
9ace3632bc
2 changed files with 79 additions and 7 deletions
|
|
@ -1,17 +1,52 @@
|
||||||
|
{-# LANGUAGE OverloadedStrings #-}
|
||||||
|
|
||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import Control.Monad.Trans.Class
|
import Control.Monad.Trans.Class
|
||||||
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Text.IO as T
|
||||||
import Options.Applicative
|
import Options.Applicative
|
||||||
|
import System.FilePath
|
||||||
|
|
||||||
|
import Mima.Flag
|
||||||
|
import Mima.Format.FlagFile
|
||||||
|
import Mima.Format.SymbolFile
|
||||||
import Mima.IO
|
import Mima.IO
|
||||||
|
import Mima.Label
|
||||||
import Mima.Load
|
import Mima.Load
|
||||||
|
import Mima.Options
|
||||||
import Mima.Parse.Assembly
|
import Mima.Parse.Assembly
|
||||||
|
|
||||||
data Settings = Settings
|
data Settings = Settings
|
||||||
{ infile :: String
|
{ infile :: String
|
||||||
, outfile :: String
|
, outfile :: String
|
||||||
|
, discover :: Bool
|
||||||
|
, flagFile :: Maybe FilePath
|
||||||
|
, symbolFile :: Maybe FilePath
|
||||||
} deriving (Show)
|
} deriving (Show)
|
||||||
|
|
||||||
|
getFlagFile :: Settings -> File
|
||||||
|
getFlagFile settings =
|
||||||
|
case flagFile settings of
|
||||||
|
Just path -> RequiredFile path
|
||||||
|
Nothing -> case discover settings of
|
||||||
|
False -> NoFile
|
||||||
|
True -> OptionalFile discoveredPath
|
||||||
|
where
|
||||||
|
discoveredPath = dropExtension (infile settings) ++ ".mima-flags"
|
||||||
|
|
||||||
|
getSymbolFile :: Settings -> File
|
||||||
|
getSymbolFile settings =
|
||||||
|
case symbolFile settings of
|
||||||
|
Just path -> RequiredFile path
|
||||||
|
Nothing -> case discover settings of
|
||||||
|
False -> NoFile
|
||||||
|
True -> OptionalFile discoveredPath
|
||||||
|
where
|
||||||
|
discoveredPath = dropExtension (infile settings) ++ ".mima-symbols"
|
||||||
|
|
||||||
|
{- Command-line parameters -}
|
||||||
|
|
||||||
settingsParser :: Parser Settings
|
settingsParser :: Parser Settings
|
||||||
settingsParser = Settings
|
settingsParser = Settings
|
||||||
<$> strArgument
|
<$> strArgument
|
||||||
|
|
@ -24,17 +59,54 @@ settingsParser = Settings
|
||||||
<> help "The .mima file to write the assembled result to"
|
<> help "The .mima file to write the assembled result to"
|
||||||
<> value "out.mima"
|
<> value "out.mima"
|
||||||
<> showDefault)
|
<> showDefault)
|
||||||
|
<*> switchWithNo "discover" True
|
||||||
|
"Derive the file names for the .mima-flags and .mima-symbols files from the name of the input file"
|
||||||
|
<*> (optional . strOption)
|
||||||
|
(long "flag-file"
|
||||||
|
<> short 'f'
|
||||||
|
<> metavar "FLAGFILE"
|
||||||
|
<> help "A file containing extension memory flags, specified in the .mima-flags format")
|
||||||
|
<*> (optional . strOption)
|
||||||
|
(long "symbol-file"
|
||||||
|
<> short 's'
|
||||||
|
<> metavar "SYMBOLFILE"
|
||||||
|
<> help "A file containing label names and addresses, specified in the .mima-symbols format")
|
||||||
|
|
||||||
opts :: ParserInfo Settings
|
opts :: ParserInfo Settings
|
||||||
opts = info (helper <*> settingsParser) $ fullDesc <> failureCode 1
|
opts = info (helper <*> settingsParser) $ fullDesc <> failureCode 1
|
||||||
|
|
||||||
|
{- Saving supplemental files -}
|
||||||
|
|
||||||
|
printFile :: T.Text -> File -> Run ()
|
||||||
|
printFile name NoFile =
|
||||||
|
lift $ T.putStrLn $ "Not saving " <> name <> ": No file specified and discovery turned off"
|
||||||
|
printFile name (OptionalFile path) =
|
||||||
|
lift $ T.putStrLn $ "Saving " <> name <> " to " <> T.pack path
|
||||||
|
printFile name (RequiredFile path) =
|
||||||
|
lift $ T.putStrLn $ "Saving " <> name <> " to " <> T.pack path
|
||||||
|
|
||||||
|
saveFlags :: RawFlags -> Settings -> Run ()
|
||||||
|
saveFlags flags settings = do
|
||||||
|
let file = getFlagFile settings
|
||||||
|
printFile "flags" file
|
||||||
|
storeFile' file (formatFlagFile flags)
|
||||||
|
|
||||||
|
saveSymbols :: LabelSpec -> Settings -> Run ()
|
||||||
|
saveSymbols labels settings = do
|
||||||
|
let file = getSymbolFile settings
|
||||||
|
printFile "symbols" file
|
||||||
|
storeFile' file (formatSymbolFile labels)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = doRun_ $ do
|
main = doRun_ $ do
|
||||||
settings <- lift $ execParser opts
|
settings <- lift $ execParser opts
|
||||||
|
|
||||||
lift $ putStrLn $ "Loading assembly file at " ++ infile settings
|
lift $ putStrLn $ "Loading assembly file at " ++ infile settings
|
||||||
(state, _, _) <- loadFile readAssembly (infile settings)
|
(state, labels, flags) <- loadFile readAssembly (infile settings)
|
||||||
lift $ putStrLn "Parsing successful"
|
lift $ putStrLn "Parsing successful"
|
||||||
|
|
||||||
lift $ putStrLn $ "Writing result to " ++ outfile settings
|
lift $ putStrLn $ "Writing result to " ++ outfile settings
|
||||||
saveStateToFile (outfile settings) state
|
saveStateToFile (outfile settings) state
|
||||||
|
|
||||||
|
saveFlags flags settings
|
||||||
|
saveSymbols labels settings
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ settingsParser = Settings
|
||||||
<> metavar "OUTFILE"
|
<> metavar "OUTFILE"
|
||||||
<> help "If specified, write the memory dump to this file after execution is finished")
|
<> help "If specified, write the memory dump to this file after execution is finished")
|
||||||
<*> switchWithNo "discover" True
|
<*> switchWithNo "discover" True
|
||||||
"Try to load .mima-flags and .mima-symbols corresponding to the .mima input file"
|
"Derive the file names for the .mima-flags and .mima-symbols files from the name of the input file"
|
||||||
<*> (optional . strOption)
|
<*> (optional . strOption)
|
||||||
(long "flag-file"
|
(long "flag-file"
|
||||||
<> short 'f'
|
<> short 'f'
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue