-- |
-- Module      : Data.ELF.Constants
-- Description : Definitions of constants used in ELF files
-- Copyright   : (c) Aleksey Makarov, 2021
-- License     : BSD 3-Clause License
-- Maintainer  : aleksey.makarov@gmail.com
-- Stability   : experimental
-- Portability : portable
--
-- Definitions of constants used in ELF files

-- https://stackoverflow.com/questions/10672981/export-template-haskell-generated-definitions

module Data.Elf.Constants (
    -- $docs
    module Data.Elf.Constants.Data
    ) where
import Data.Elf.Constants.Data

{- $docs

Constants defined here are declared using Template Haskell,
so the full documentation is supported only starting from @template-haskell@ version 2.18.
For the older versions see the sources or the documents describing ELF file format.

Data types, patterns and instances are generated by @mkDeclarations@ TH macros.
Below is an example of how it works.  The code

@
$(mkDeclarations BaseWord16 \"TypeName\" \"ValuePrefix\"
    [ (\"_A\", 0, "Doc strig for ValuePrefix_A")
    , (\"_B\", 1, "Doc strig for ValuePrefix_B")
    ])
@

produces this:

@
    newtype TypeName = TypeName Word16 deriving (Eq, Ord, Enum, Num, Real, Integral, Bits, FiniteBits)

    instance Show TypeName where
        show (TypeName 0) = (\"ValuePrefix\" ++ "_A")
        show (TypeName 1) = (\"ValuePrefix\" ++ "_B")
        show (TypeName n_a5QI) = (\"TypeName\" ++ (\" \" ++ show n_a5QI))

    pattern ValuePrefix_A :: TypeName
    pattern ValuePrefix_A = TypeName 0

    pattern ValuePrefix_B :: TypeName
    pattern ValuePrefix_B = TypeName 1

    instance Binary (Le TypeName) where
        get = (Le \<$\> (TypeName \<$\> getWord16le))
        put (Le (TypeName n_a5QK)) = putWord16le n_a5QK

    instance Binary (Be TypeName) where
        get = (Be \<$\> (TypeName \<$\> getWord16be))
        put (Be (TypeName n_a5QL)) = putWord16be n_a5QL
@
-}