macaw/macaw-ppc/tests/Shared.hs
Tristan Ravitch 9664914923 Update the PowerPC tests to deal with the latest macaw-semmc changes
The new binary loading interface does manage to simplify things
2018-05-21 14:32:29 -07:00

20 lines
636 B
Haskell

{-# LANGUAGE DataKinds #-}
module Shared (
withELF
) where
import qualified Data.ByteString as B
import qualified Data.ElfEdit as E
withELF :: FilePath -> (E.Elf 64 -> IO ()) -> IO ()
withELF fp k = do
bytes <- B.readFile fp
case E.parseElf bytes of
E.ElfHeaderError off msg ->
error ("Error parsing ELF header at offset " ++ show off ++ ": " ++ msg)
E.Elf32Res [] _e32 -> error "ELF32 is unsupported in the test suite"
E.Elf64Res [] e64 -> k e64
E.Elf32Res errs _ -> error ("Errors while parsing ELF file: " ++ show errs)
E.Elf64Res errs _ -> error ("Errors while parsing ELF file: " ++ show errs)