Skip to content

Commit

Permalink
elf: Full set of bitmask operators for bitmask types
Browse files Browse the repository at this point in the history
  • Loading branch information
Austin Clements committed Sep 28, 2013
1 parent 1de7640 commit 95019e8
Showing 1 changed file with 60 additions and 4 deletions.
64 changes: 60 additions & 4 deletions elf/data.hh
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,44 @@ enum class shf : Elf64::Xword
maskproc = 0xF0000000, // Processor-specific use
};

static inline shf operator&(shf a, shf b)
static inline constexpr shf operator&(shf a, shf b)
{
return (shf)((std::uint64_t)a & (std::uint64_t)b);
}

static inline shf operator|(shf a, shf b)
static inline constexpr shf operator|(shf a, shf b)
{
return (shf)((std::uint64_t)a | (std::uint64_t)b);
}

static inline constexpr shf operator^(shf a, shf b)
{
return (shf)((std::uint64_t)a ^ (std::uint64_t)b);
}

static inline constexpr shf operator~(shf a)
{
return (shf)~((std::uint64_t)a);
}

static inline shf& operator&=(shf &a, shf b)
{
a = a & b;
return a;
}

static inline shf& operator|=(shf &a, shf b)
{
a = a | b;
return a;
}

static inline shf& operator^=(shf &a, shf b)
{
a = a ^ b;
return a;
}

// Section header (ELF32 figure 1-8, ELF64 figure 3)
template<typename E = Elf64, byte_order Order = byte_order::native>
struct Shdr
Expand Down Expand Up @@ -254,16 +282,44 @@ enum class pf : ElfTypes::Word
maskproc = 0xFF000000, // Processor-specific use
};

static inline pf operator&(pf a, pf b)
static inline constexpr pf operator&(pf a, pf b)
{
return (pf)((std::uint64_t)a & (std::uint64_t)b);
}

static inline pf operator|(pf a, pf b)
static inline constexpr pf operator|(pf a, pf b)
{
return (pf)((std::uint64_t)a | (std::uint64_t)b);
}

static inline constexpr pf operator^(pf a, pf b)
{
return (pf)((std::uint64_t)a ^ (std::uint64_t)b);
}

static inline constexpr pf operator~(pf a)
{
return (pf)~((std::uint64_t)a);
}

static inline pf& operator&=(pf &a, pf b)
{
a = a & b;
return a;
}

static inline pf& operator|=(pf &a, pf b)
{
a = a | b;
return a;
}

static inline pf& operator^=(pf &a, pf b)
{
a = a ^ b;
return a;
}

// Program header (ELF32 figure 2-1, ELF64 figure 6)
template<typename E = Elf64, byte_order Order = byte_order::native>
struct Phdr;
Expand Down

0 comments on commit 95019e8

Please sign in to comment.