Debian Codegraph @

llvm-project/llvm/projects/llvm-spirv/lib/SPIRV/Mangler/FunctionDescriptor.cpp

raw
1 //===---------------------- FunctionDescriptor.cpp -----------------------===//
2 //
3 // SPIR Tools
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===---------------------------------------------------------------------===//
9 /*
10 * Contributed by: Intel Corporation.
11 */
12
13 #include "FunctionDescriptor.h"
14 #include "ParameterType.h"
15 #include <sstream>
16
17 namespace SPIR {
18
19 std::string FunctionDescriptor::nullString() {
20 return std::string("<invalid>");
21 }
22
23 std::string FunctionDescriptor::toString() const {
24 std::stringstream Stream;
25 if (isNull()) {
26 return FunctionDescriptor::nullString();
27 }
28 Stream << Name << "(";
29 size_t ParamCount = Parameters.size();
30 if (ParamCount > 0) {
31 for (size_t I = 0; I < ParamCount - 1; ++I)
32 Stream << Parameters[I]->toString() << ", ";
33 Stream << Parameters[ParamCount - 1]->toString();
34 }
35 Stream << ")";
36 return Stream.str();
37 }
38
39 static bool equal(const TypeVector &L, const TypeVector &R) {
40 if (&L == &R)
41 return true;
42 if (L.size() != R.size())
43 return false;
44 TypeVector::const_iterator Itl = L.begin(), Itr = R.begin(), Endl = L.end();
45 while (Itl != Endl) {
46 if (!(*Itl)->equals(*Itr))
47 return false;
48 ++Itl;
49 ++Itr;
50 }
51 return true;
52 }
53
54 //
55 // FunctionDescriptor
56 //
57
58 bool FunctionDescriptor::operator==(const FunctionDescriptor &That) const {
59 if (this == &That)
60 return true;
61 if (Name != That.Name)
62 return false;
63 return equal(Parameters, That.Parameters);
64 }
65
66 bool FunctionDescriptor::operator<(const FunctionDescriptor &That) const {
67 int StrCmp = Name.compare(That.Name);
68 if (StrCmp)
69 return (StrCmp < 0);
70 size_t Len = Parameters.size(), ThatLen = That.Parameters.size();
71 if (Len != ThatLen)
72 return Len < ThatLen;
73 TypeVector::const_iterator It = Parameters.begin(), E = Parameters.end(),
74 Thatit = That.Parameters.begin();
75 while (It != E) {
76 int Cmp = (*It)->toString().compare((*Thatit)->toString());
77 if (Cmp)
78 return (Cmp < 0);
79 ++Thatit;
80 ++It;
81 }
82 return false;
83 }
84
85 bool FunctionDescriptor::isNull() const {
86 return (Name.empty() && Parameters.empty());
87 }
88
89 FunctionDescriptor FunctionDescriptor::null() {
90 FunctionDescriptor Fd;
91 Fd.Name = "";
92 return Fd;
93 }
94
95 } // namespace SPIR