summaryrefslogtreecommitdiff
path: root/src/elf_model/endianness.lem
blob: 9adba6cd7281fe5041c89ec4888d1311ab38f877 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(** [endian.lem] defines a type for describing the endianness of an ELF file,
  * and functions and other operations over that type.
  *)

open import String

open import Show

(** Type [endianness] describes the endianness of an ELF file.  This is deduced from
  * the first few bytes (magic number, etc.) of the ELF header.
  *)
type endianness
  = Big    (* Big endian *)
  | Little (* Little endian *)

(** [default_endianness] is a default endianness to use when reading in the ELF header
  * before we have deduced from its entries what the rest of the file is encoded
  * with.
  *)
val default_endianness : endianness
let default_endianness = Little

(** [string_of_endianness e] produces a string representation of the [endianness] value
  * [e].
  *)
val string_of_endianness : endianness -> string
let string_of_endianness e =
  match e with
    | Big    -> "Big"
    | Little -> "Little"
  end

instance (Show endianness)
  let show = string_of_endianness
end