mini-llvm 0.1.0
Loading...
Searching...
No Matches
I1Constant.h
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2
3#pragma once
4
5#include <cstdint>
6#include <memory>
7#include <string>
8#include <typeinfo>
9
14#include "mini-llvm/ir/Type.h"
16#include "mini-llvm/ir/Value.h"
17
18namespace mini_llvm::ir {
19
20class I1Constant final : public IntegerConstant {
21public:
22 explicit I1Constant(bool value) : value_(value) {}
23
24 bool value() const {
25 return value_;
26 }
27
28 int64_t signExtendedValue() const override {
29 return ops::SExt<int64_t>()(value());
30 }
31
32 int64_t zeroExtendedValue() const override {
33 return ops::ZExt<int64_t>()(value());
34 }
35
36 void accept(ConstantVisitor &visitor) override {
37 visitor.visitI1Constant(*this);
38 }
39
40 void accept(ConstantVisitor &visitor) const override {
41 visitor.visitI1Constant(*this);
42 }
43
44 std::unique_ptr<Type> type() const override {
45 return std::make_unique<I1>();
46 }
47
48 std::string format() const override {
49 return value() ? "true" : "false";
50 }
51
52 std::unique_ptr<Value> clone() const override {
53 return std::make_unique<I1Constant>(value());
54 }
55
56protected:
57 bool equals(const Constant &other) const override {
58 return typeid(*this) == typeid(other) && value() == static_cast<const I1Constant &>(other).value();
59 }
60
61private:
62 bool value_;
63};
64
65} // namespace mini_llvm::ir
Definition ConstantVisitor.h:26
virtual void visitI1Constant(I1Constant &C)
Definition ConstantVisitor.h:44
Definition Constant.h:13
std::unique_ptr< Value > clone() const override
Definition I1Constant.h:52
bool equals(const Constant &other) const override
Definition I1Constant.h:57
std::string format() const override
Definition I1Constant.h:48
bool value() const
Definition I1Constant.h:24
void accept(ConstantVisitor &visitor) const override
Definition I1Constant.h:40
int64_t signExtendedValue() const override
Definition I1Constant.h:28
I1Constant(bool value)
Definition I1Constant.h:22
std::unique_ptr< Type > type() const override
Definition I1Constant.h:44
int64_t zeroExtendedValue() const override
Definition I1Constant.h:32
void accept(ConstantVisitor &visitor) override
Definition I1Constant.h:36
Definition IntegerConstant.h:13
Definition Argument.h:13
Definition SExt.h:14
Definition ZExt.h:14