From 12e6d200597bb5d61ed56ccf9d70a52614956a70 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 30 Apr 2008 03:55:40 +0000 Subject: [PATCH] add a method for comparing to see if a value has a specified name. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@50465 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Value.h | 4 ++++ lib/VMCore/Value.cpp | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/include/llvm/Value.h b/include/llvm/Value.h index 4604dae6ed9..c1c728270e4 100644 --- a/include/llvm/Value.h +++ b/include/llvm/Value.h @@ -95,6 +95,10 @@ public: /// their end. This always returns a non-null pointer. const char *getNameStart() const; + /// isName - Return true if this value has the name specified by the provided + /// nul terminated string. + bool isName(const char *N) const; + /// getNameLen - Return the length of the string, correctly handling nul /// characters embedded into them. unsigned getNameLen() const; diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index a61a1a02472..cf696fe44fe 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -136,6 +136,13 @@ unsigned Value::getNameLen() const { return Name ? Name->getKeyLength() : 0; } +/// isName - Return true if this value has the name specified by the provided +/// nul terminated string. +bool Value::isName(const char *N) const { + unsigned InLen = strlen(N); + return InLen = getNameLen() && memcmp(getNameStart(), N, InLen) == 0; +} + std::string Value::getNameStr() const { if (Name == 0) return "";