mini-llvm 0.1.0
Loading...
Searching...
No Matches
ZExt.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <bit>
6#include <concepts>
7#include <cstdlib>
8#include <type_traits>
9
10namespace mini_llvm::ops {
11
12template <typename To>
13 requires std::integral<To>
14struct ZExt {
15 template <typename From>
16 requires std::integral<From>
17 To operator()(From) const noexcept {
18 abort();
19 }
20
21 template <typename From>
22 requires (std::integral<From> && !std::same_as<From, bool> && sizeof(To) >= sizeof(From))
23 To operator()(From x) const noexcept {
24 return std::bit_cast<To>(static_cast<std::make_unsigned_t<To>>(std::bit_cast<std::make_unsigned_t<From>>(x)));
25 }
26
27 To operator()(bool x) const noexcept {
28 return static_cast<To>(x);
29 }
30};
31
32template <>
33struct ZExt<bool> {
34 template <typename From>
35 requires std::integral<From>
36 bool operator()(From) const noexcept {
37 abort();
38 }
39
40 bool operator()(bool x) const noexcept {
41 return x;
42 }
43};
44
45} // namespace mini_llvm::ops
Definition Add.h:9
bool operator()(From) const noexcept
Definition ZExt.h:36
bool operator()(bool x) const noexcept
Definition ZExt.h:40
Definition ZExt.h:14
To operator()(From) const noexcept
Definition ZExt.h:17
To operator()(bool x) const noexcept
Definition ZExt.h:27