packages feed

cap-1.0: src/Language/Cap/Debug/TraceMode.hs

module Language.Cap.Debug.TraceMode
       (TraceMode(..),DebugMode(..)
       ,MapMode(..),FileType(..)
       ,Options(..),options) where

import List (isSuffixOf)

-- | Dictates what mode tracing should occur in
data TraceMode = Stat
               | AlgorithmicDebug DebugMode
               deriving Show

data DebugMode = FDT MapMode
               | EDT
               deriving Show

data MapMode = OnTheFly
             | Index
             | IndexFunctions
             deriving Show

data FileType = Program
              | Trace
              deriving (Show,Eq)

-- | The different options the program can be started with
data Options = Options
  { mode     :: TraceMode
  , fileType :: FileType
  , fileName :: String}
  deriving Show

{- | Works out what options the user called the program with.
-}
options :: [String] -> Options
options [] = Options {mode=Stat, fileType=Program, fileName="trace.cap"}
options [x] = Options {mode=Stat, fileType=inferType x, fileName=x}
options ("-s":xs) = (options xs) {mode=Stat}
options ("-ad":xs) =
  case xs of
    ("fdt":xs') -> 
      case xs' of
        "-o":xs'' -> (options xs'') {mode=AlgorithmicDebug (FDT OnTheFly)}
        _         -> (options xs') {mode=AlgorithmicDebug (FDT Index)}
    ("edt":xs') -> (options xs') {mode=AlgorithmicDebug EDT}
    _           -> (options xs) {mode=AlgorithmicDebug (FDT Index)}
options ("-p":x:xs) = (options xs) {fileType=Program, fileName=x}
options ("-t":x:xs) = (options xs) {fileType=Trace, fileName=x}
options (x:xs) = options xs

{- | Attempts to infer whether the program has been given a trace file or
     program file based on the extension.
-}
inferType :: String -> FileType
inferType x
  | ".cat" `isSuffixOf` x = Trace
  | ".cap" `isSuffixOf` x = Program
  | otherwise             = Program