MimIR 0.1
MimIR is my Intermediate Representation
Loading...
Searching...
No Matches
util.h File Reference
#include <optional>
#include <queue>
#include <stack>
#include <type_traits>
#include <absl/container/flat_hash_map.h>
#include <absl/container/flat_hash_set.h>
#include <absl/container/node_hash_map.h>
#include <absl/container/node_hash_set.h>
#include <fe/assert.h>
#include "mim/util/hash.h"
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  mim::unique_stack< Set >
 
class  mim::unique_queue< Set >
 
struct  mim::GIDHash< T >
 
struct  mim::GIDEq< T >
 
struct  mim::GIDLt< T >
 

Namespaces

namespace  mim
 

Macros

#define MIM_ENUM_OPERATORS(E)
 Use this to declare all kind of bit and comparison operators for an enum E.
 

Typedefs

GID
template<class K , class V >
using mim::GIDMap = absl::flat_hash_map<K, V, GIDHash<K>, GIDEq<K>>
 
template<class K >
using mim::GIDSet = absl::flat_hash_set<K, GIDHash<K>, GIDEq<K>>
 
template<class K , class V >
using mim::GIDNodeMap = absl::node_hash_map<K, V, GIDHash<K>, GIDEq<K>>
 
template<class K >
using mim::GIDNodeSet = absl::node_hash_set<K, GIDHash<K>, GIDEq<K>>
 

Functions

Utility Functions
template<class This , class T >
T & mim::lazy_init (const This *self, std::unique_ptr< T > &ptr)
 
template<class D , class S >
mim::bitcast (const S &src)
 A bitcast from src of type S to D.
 
template<class T >
bool mim::get_sign (T val)
 
u64 mim::pad (u64 offset, u64 align)
 
Algorithms
template<class I , class T , class Cmp >
mim::binary_find (I begin, I end, T val, Cmp cmp)
 
std::string_view mim::subview (std::string_view s, size_t i, size_t n=std::string_view::npos)
 Like std::string::substr, but works on std::string_view instead.
 
void mim::find_and_replace (std::string &str, std::string_view what, std::string_view repl)
 Replaces all occurrences of what with repl.
 
Helpers for Containers
template<class S >
auto mim::pop (S &s) -> decltype(s.top(), typename S::value_type())
 
template<class Q >
auto mim::pop (Q &q) -> decltype(q.front(), typename Q::value_type())
 
template<class C , class K >
auto mim::lookup (const C &container, const K &key)
 Yields pointer to element (or the element itself if it is already a pointer), if found and nullptr otherwise.
 
template<class C , class... Args>
auto mim::assert_emplace (C &container, Args &&... args)
 Invokes emplace on container, asserts that insertion actually happened, and returns the iterator.
 

Macro Definition Documentation

◆ MIM_ENUM_OPERATORS

#define MIM_ENUM_OPERATORS ( E)
Value:
constexpr auto operator&( E x, E y) { return std::underlying_type_t<E>(x) & std::underlying_type_t<E>(y); } \
constexpr auto operator&(std::underlying_type_t<E> x, E y) { return x & std::underlying_type_t<E>(y); } \
constexpr auto operator&( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) & y ; } \
constexpr auto operator|( E x, E y) { return std::underlying_type_t<E>(x) | std::underlying_type_t<E>(y); } \
constexpr auto operator|(std::underlying_type_t<E> x, E y) { return x | std::underlying_type_t<E>(y); } \
constexpr auto operator|( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) | y ; } \
constexpr auto operator^( E x, E y) { return std::underlying_type_t<E>(x) ^ std::underlying_type_t<E>(y); } \
constexpr auto operator^(std::underlying_type_t<E> x, E y) { return x ^ std::underlying_type_t<E>(y); } \
constexpr auto operator^( E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) ^ y ; } \
constexpr std::strong_ordering operator<=>(std::underlying_type_t<E> x, E y) { return x <=> std::underlying_type_t<E>(y); } \
constexpr std::strong_ordering operator<=>(E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) <=> y; } \
constexpr bool operator==(std::underlying_type_t<E> x, E y) { return x == std::underlying_type_t<E>(y); } \
constexpr bool operator==(E x, std::underlying_type_t<E> y) { return std::underlying_type_t<E>(x) == y; }

Use this to declare all kind of bit and comparison operators for an enum E.

Note that the bit operators return E's underlying type and not the original enum E. This is because the result may not be a valid enum value. For the same reason, it doesn't make sense to declare operators such as &=.

Definition at line 189 of file util.h.