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 nullString()19std::string FunctionDescriptor::nullString() { 20 return std::string("<invalid>"); 21 } 22 toString() const23std::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 equal(const TypeVector & l,const TypeVector & r)39static 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(), 45 endl = l.end(); 46 while (itl != endl) { 47 if (!(*itl)->equals(*itr)) 48 return false; 49 ++itl; 50 ++itr; 51 } 52 return true; 53 } 54 55 // 56 // FunctionDescriptor 57 // 58 operator ==(const FunctionDescriptor & that) const59bool FunctionDescriptor::operator == (const FunctionDescriptor& that) const { 60 if (this == &that) 61 return true; 62 if (name != that.name) 63 return false; 64 return equal(parameters, that.parameters); 65 } 66 operator <(const FunctionDescriptor & that) const67bool FunctionDescriptor::operator < (const FunctionDescriptor& that) const { 68 int strCmp = name.compare(that.name); 69 if (strCmp) 70 return (strCmp < 0); 71 size_t len = parameters.size(), thatLen = that.parameters.size(); 72 if (len != thatLen) 73 return len < thatLen; 74 TypeVector::const_iterator it = parameters.begin(), 75 e = parameters.end(), thatit = that.parameters.begin(); 76 while (it != e) { 77 int cmp = (*it)->toString().compare((*thatit)->toString()); 78 if (cmp) 79 return (cmp < 0); 80 ++thatit; 81 ++it; 82 } 83 return false; 84 } 85 isNull() const86bool FunctionDescriptor::isNull() const { 87 return (name.empty() && parameters.empty()); 88 } 89 null()90FunctionDescriptor FunctionDescriptor::null() { 91 FunctionDescriptor fd; 92 fd.name = ""; 93 return fd; 94 } 95 96 } // End SPIR namespace 97