| 
 Copyright    : ( c ) Galois Inc , 2016 
 Maintainer   :  

 Common datatypes for creating a memory from a binary file . 

Copyright   : (c) Galois Inc, 2016
Maintainer  : 

Common datatypes for creating a memory from a binary file.
-}
module Data.Macaw.Memory.LoadCommon
  ( LoadOptions(..)
  , loadRegionIndex
  , loadRegionBaseOffset
  , defaultLoadOptions
  , LoadStyle(..)
  ) where

import Data.Macaw.Memory
import Data.Word

------------------------------------------------------------------------
  LoadOptions

  | How to load Elf file .
data LoadStyle
   = LoadBySection
     -- ^ Load loadable sections in Elf file.
   | LoadBySegment
     -- ^ Load segments in Elf file.
  deriving (Eq)

-- | This contains options for loading.
newtype LoadOptions =
  LoadOptions { loadOffset :: Maybe Word64
  ^ If set , the Elf file should be loaded at a specific offset .
              }

loadRegionIndex :: LoadOptions -> Maybe RegionIndex
loadRegionIndex opts =
  case loadOffset opts of
    Nothing -> Nothing
    Just _ -> Just 0

loadRegionBaseOffset :: LoadOptions -> Integer
loadRegionBaseOffset opts =
  case loadOffset opts of
    Nothing -> 0
    Just o -> toInteger o

defaultLoadOptions :: LoadOptions
defaultLoadOptions = LoadOptions { loadOffset = Nothing }

----------------------------------------------------------------------
 ^ Load loadable sections in Elf file.
 ^ Load segments in Elf file.
 | This contains options for loading.
| 
 Copyright    : ( c ) Galois Inc , 2016 
 Maintainer   :  

 Common datatypes for creating a memory from a binary file . 

Copyright   : (c) Galois Inc, 2016
Maintainer  : 

Common datatypes for creating a memory from a binary file.
-}
module Data.Macaw.Memory.LoadCommon
  ( LoadOptions(..)
  , loadRegionIndex
  , loadRegionBaseOffset
  , defaultLoadOptions
  , LoadStyle(..)
  ) where

import Data.Macaw.Memory
import Data.Word

  LoadOptions

  | How to load Elf file .
data LoadStyle
   = LoadBySection
   | LoadBySegment
  deriving (Eq)

newtype LoadOptions =
  LoadOptions { loadOffset :: Maybe Word64
  ^ If set , the Elf file should be loaded at a specific offset .
              }

loadRegionIndex :: LoadOptions -> Maybe RegionIndex
loadRegionIndex opts =
  case loadOffset opts of
    Nothing -> Nothing
    Just _ -> Just 0

loadRegionBaseOffset :: LoadOptions -> Integer
loadRegionBaseOffset opts =
  case loadOffset opts of
    Nothing -> 0
    Just o -> toInteger o

defaultLoadOptions :: LoadOptions
defaultLoadOptions = LoadOptions { loadOffset = Nothing }
