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