1-- SPDX-FileCopyrightText: 2024 University of Bremen2-- SPDX-FileCopyrightText: 2025 Sören Tempel <soeren+git@soeren-tempel.net>3--4-- SPDX-License-Identifier: MIT AND GPL-3.0-only56module Language.QBE.CmdLine7 ( BasicArgs (..),8 basicArgs,9 entryFunc,10 parseEntryFile,11 )12where1314import Language.QBE (Program, parseAndFind)15import Language.QBE.Simulator.Memory qualified as MEM16import Language.QBE.Types qualified as QBE17import Options.Applicative qualified as OPT1819-- | t'BasicArgs' can be combined/extended with additional parsers using20-- the '<*>' applicative operator provided by "Options.Applicative".21data BasicArgs = BasicArgs22 { -- | Start address of the general-purpose memory.23 optMemStart :: MEM.Address,24 -- | Size of the memory in bytes.25 optMemSize :: MEM.Size,26 -- | Path to the QBE input file.27 optQBEFile :: FilePath28 }2930-- | "Options.Applicative" parser for t'BasicArgs'.31basicArgs :: OPT.Parser BasicArgs32basicArgs =33 BasicArgs34 <$> OPT.option35 OPT.auto36 ( OPT.long "memory-start"37 <> OPT.short 'm'38 <> OPT.value 0x039 )40 <*> OPT.option41 OPT.auto42 ( OPT.long "memory-size"43 <> OPT.short 's'44 <> OPT.value (1024 * 1024) -- 1 MB RAM45 <> OPT.help "Size of the memory region"46 )47 <*> OPT.argument OPT.str (OPT.metavar "FILE")4849------------------------------------------------------------------------5051-- | Name of the entry function.52entryFunc :: QBE.GlobalIdent53entryFunc = QBE.GlobalIdent "main"5455-- | Parse a file and find the 'entryFunc'.56parseEntryFile :: FilePath -> IO (Program, QBE.FuncDef)57parseEntryFile filePath =58 readFile filePath >>= parseAndFind entryFunc