MLLIF
a MLIR-based Language to Language Interoperability Flyover
Loading...
Searching...
No Matches
CIRType.h
Go to the documentation of this file.
1/*
2 * Copyright 2025 Yeong-won Seo
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <memory>
21
22namespace mlir {
23 class Type;
24}
25
26namespace mllif::mlir::cir {
27
31 class CIRType : public Type {
32
33 protected:
34 CIRType() = default;
35
36 public:
37 static auto From(const ::mlir::Type &type, const std::shared_ptr<::mlir::ModuleOp> &module) -> std::shared_ptr<CIRType>;
38 };
39
43 class CIRBoolType final : public CIRType {
44 public:
45 CIRBoolType() = default;
46
47 std::string store(Tree &symbols) const override;
48 };
49
53 class CIRIntegerType final : public CIRType {
54 size_t _width;
55 bool _signed;
56
57 public:
58 CIRIntegerType(size_t width, bool _signed) : _width(width), _signed(_signed) {}
59
60 size_t &width() { return _width; }
61 size_t width() const { return _width; }
62 bool &signed_() { return _signed; }
63 bool signed_() const { return _signed; }
64
65 std::string store(Tree &symbols) const override;
66 };
67
71 class CIRFloatType final : public CIRType {
72 size_t _width;
73
74 public:
75 CIRFloatType(const size_t width) : _width(width) {}
76
77 size_t &width() { return _width; }
78 size_t width() const { return _width; }
79
80 std::string store(Tree &symbols) const override;
81 };
82
86 class CIRPointerType final : public CIRType {
87 std::shared_ptr<CIRType> _pointee;
88
89 public:
90 explicit CIRPointerType(const std::shared_ptr<CIRType> &type) : _pointee(type) {}
91
92 std::shared_ptr<CIRType> &pointee() { return _pointee; }
93 const std::shared_ptr<CIRType> &pointee() const { return _pointee; }
94
95 std::string store(Tree &symbols) const override;
96 };
97
101 class CIRStructType final : public CIRType {
102 std::deque<std::string> _path;
103 size_t _size;
104 size_t _align;
105
106 public:
107 CIRStructType(const std::deque<std::string> &path, const size_t size, const size_t align) : _path(path), _size(size), _align(align) {}
108
109 std::deque<std::string> &path() { return _path; }
110 const std::deque<std::string> &path() const { return _path; }
111 size_t size() { return _size; }
112 size_t size() const { return _size; }
113 size_t align() { return _align; }
114 size_t align() const { return _align; }
115
116 std::string store(Tree &symbols) const override;
117 };
118
119} // namespace mllif::mlir::cir
A tree struct for symbol tree. It's just a simple wrapper for root node.
Definition Tree.h:147
A wrapper class of mlir::Type that serializes it into simple-and-plain text.
Definition Type.h:25
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
Definition CIRType.cxx:84
CIRFloatType(const size_t width)
Definition CIRType.h:75
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
Definition CIRType.cxx:94
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
Definition CIRType.cxx:88
CIRIntegerType(size_t width, bool _signed)
Definition CIRType.h:58
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
Definition CIRType.cxx:100
const std::shared_ptr< CIRType > & pointee() const
Definition CIRType.h:93
std::shared_ptr< CIRType > & pointee()
Definition CIRType.h:92
CIRPointerType(const std::shared_ptr< CIRType > &type)
Definition CIRType.h:90
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
Definition CIRType.cxx:106
const std::deque< std::string > & path() const
Definition CIRType.h:110
CIRStructType(const std::deque< std::string > &path, const size_t size, const size_t align)
Definition CIRType.h:107
std::deque< std::string > & path()
Definition CIRType.h:109
static auto From(const ::mlir::Type &type, const std::shared_ptr<::mlir::ModuleOp > &module) -> std::shared_ptr< CIRType >
Definition CIRType.cxx:40
constexpr std::string Type
Definition annotation.h:31