MLLIF
a MLIR-based Language to Language Interoperability Flyover
Loading...
Searching...
No Matches
BuiltinType.cxx
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#include "pch.h"
18
20
21auto mllif::mlir::builtin::BuiltinType::From(const ::mlir::Type &type, const std::shared_ptr<::mlir::ModuleOp>& /**/) -> std::shared_ptr<BuiltinType> {
22 if (const auto i = dyn_cast<::mlir::IntegerType>(type)) {
23
24 auto sign = i.getSignedness();
25 if (sign == ::mlir::IntegerType::Signless) {
26 // Signedness defaults to signed
27 sign = ::mlir::IntegerType::Signed;
28 }
29
30 return std::make_shared<BuiltinIntType>(
31 i.getWidth(),
32 sign == ::mlir::IntegerType::Signed);
33 }
34 if (type.isF16()) {
35 return std::make_shared<BuiltinFPType>(16);
36 }
37 if (type.isF32()) {
38 return std::make_shared<BuiltinFPType>(32);
39 }
40 if (type.isF64()) {
41 return std::make_shared<BuiltinFPType>(64);
42 }
43 if (type.isF128()) {
44 return std::make_shared<BuiltinFPType>(128);
45 }
46
47 return nullptr;
48}
49
51 std::stringstream ss;
52 ss << (signed_() ? 's' : 'u') << width();
53 return ss.str();
54}
55
57 std::stringstream ss;
58 ss << "fp" << width();
59 return ss.str();
60}
A tree struct for symbol tree. It's just a simple wrapper for root node.
Definition Tree.h:147
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
size_t & width()
Gets bit-width of float.
Definition BuiltinType.h:88
size_t & width()
Gets bit-width of integer.
Definition BuiltinType.h:50
bool & signed_()
Gets signedness of integer.
Definition BuiltinType.h:63
std::string store(Tree &symbols) const override
Stores this type into symbol tree if necessary and Returns reference string for this type.
static auto From(const ::mlir::Type &type, const std::shared_ptr<::mlir::ModuleOp > &module) -> std::shared_ptr< BuiltinType >