Jlm
Loading...
Searching...
No Matches
FunctionType.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Nico Reißmann <nico.reissmann@gmail.com>
3 * Copyright 2025 Helge Bahmann <hcb@chaoticmind.net>
4 * See COPYING for terms of redistribution.
5 */
6
7#include <sstream>
8
10#include <jlm/util/Hash.hpp>
11
12namespace jlm::rvsdg
13{
14
16
18 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> argumentTypes,
19 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> resultTypes)
20 : jlm::rvsdg::Type(),
21 ArgumentTypes_(std::move(argumentTypes)),
22 ResultTypes_(std::move(resultTypes))
23{}
24
25std::string
27{
28 std::stringstream ss;
29 ss << "fun (";
30 bool first = true;
31 for (const auto & argtype : ArgumentTypes_)
32 {
33 if (!first)
34 {
35 ss << ", ";
36 }
37 first = false;
39 }
40
41 ss << ") -> (";
42 first = true;
43 for (const auto & restype : ResultTypes_)
44 {
45 if (!first)
46 {
47 ss << ", ";
48 }
49 first = false;
50 ss << restype->debug_string();
51 }
52 ss << ")";
53 return ss.str();
54}
55
56bool
58{
59 if (auto fn = dynamic_cast<const FunctionType *>(&other))
60 {
61 if (ArgumentTypes_.size() != fn->ArgumentTypes_.size()
62 || ResultTypes_.size() != fn->ResultTypes_.size())
63 {
64 return false;
65 }
66 for (std::size_t n = 0; n < ArgumentTypes_.size(); ++n)
67 {
68 if (*ArgumentTypes_[n] != *fn->ArgumentTypes_[n])
69 {
70 return false;
71 }
72 }
73 for (std::size_t n = 0; n < ResultTypes_.size(); ++n)
74 {
75 if (*ResultTypes_[n] != *fn->ResultTypes_[n])
76 {
77 return false;
78 }
79 }
80 return true;
81 }
82 else
83 {
84 return false;
85 }
86}
87
88std::size_t
90{
91 std::size_t seed = typeid(FunctionType).hash_code();
92
94 for (auto argumentType : ArgumentTypes_)
95 {
97 }
98
100 for (auto resultType : ResultTypes_)
101 {
103 }
104
105 return seed;
106}
107
113
114std::shared_ptr<const FunctionType>
116 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> argumentTypes,
117 std::vector<std::shared_ptr<const jlm::rvsdg::Type>> resultTypes)
118{
119 return std::make_shared<FunctionType>(std::move(argumentTypes), std::move(resultTypes));
120}
121
122}
Function type class.
std::vector< std::shared_ptr< const jlm::rvsdg::Type > > ResultTypes_
static std::shared_ptr< const FunctionType > Create(std::vector< std::shared_ptr< const jlm::rvsdg::Type > > argumentTypes, std::vector< std::shared_ptr< const jlm::rvsdg::Type > > resultTypes)
~FunctionType() noexcept override
std::string debug_string() const override
bool operator==(const jlm::rvsdg::Type &other) const noexcept override
TypeKind Kind() const noexcept override
Return the kind of this type.
std::vector< std::shared_ptr< const jlm::rvsdg::Type > > ArgumentTypes_
std::size_t ComputeHash() const noexcept override
virtual std::string debug_string() const =0
TypeKind
The kinds of types supported in rvsdg.
Definition type.hpp:22
@ Value
Designate a value type.
NodeType * TryGetOwnerNode(const rvsdg::Input &input) noexcept
Checks if this is an input to a node of specified type.
Definition node.hpp:872
void combineHashesWithSeed(std::size_t &seed, std::size_t hash, Args... args)
Definition Hash.hpp:45