summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2012-02-15 22:34:20 +0000
committerBill Wendling <isanbard@gmail.com>2012-02-15 22:34:20 +0000
commitf20f281368f75239c852fe99c3b3a19278ba38fd (patch)
treefcf30d30a0352d6012e77559124efb36897b36cf
parent01d53ec176a6be4585df1f43af11151988ca4b35 (diff)
downloadllvm-f20f281368f75239c852fe99c3b3a19278ba38fd.tar.gz
llvm-f20f281368f75239c852fe99c3b3a19278ba38fd.tar.bz2
llvm-f20f281368f75239c852fe99c3b3a19278ba38fd.tar.xz
Add a module flags accessor method which returns the flags in a vector.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@150623 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Module.h11
-rw-r--r--lib/VMCore/Module.cpp15
2 files changed, 26 insertions, 0 deletions
diff --git a/include/llvm/Module.h b/include/llvm/Module.h
index 046798845b..e068f93deb 100644
--- a/include/llvm/Module.h
+++ b/include/llvm/Module.h
@@ -179,6 +179,14 @@ public:
/// values.
enum ModAttrBehavior { Error = 1, Warning = 2, Require = 3, Override = 4 };
+ struct ModuleFlagEntry {
+ unsigned Behavior;
+ MDString *Key;
+ Value *Val;
+ ModuleFlagEntry(unsigned B, MDString *K, Value *V)
+ : Behavior(B), Key(K), Val(V) {}
+ };
+
/// @}
/// @name Member Variables
/// @{
@@ -401,6 +409,9 @@ public:
/// @name Module Flags Accessors
/// @{
+ /// getModuleFlagsMetadata - Returns the module flags in the provided vector.
+ void getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const;
+
/// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
/// represents module-level flags. This method returns null if there are no
/// module-level flags.
diff --git a/lib/VMCore/Module.cpp b/lib/VMCore/Module.cpp
index 09468184cc..9de5db5a2b 100644
--- a/lib/VMCore/Module.cpp
+++ b/lib/VMCore/Module.cpp
@@ -328,6 +328,21 @@ void Module::eraseNamedMetadata(NamedMDNode *NMD) {
NamedMDList.erase(NMD);
}
+/// getModuleFlagsMetadata - Returns the module flags in the provided vector.
+void Module::
+getModuleFlagsMetadata(SmallVectorImpl<ModuleFlagEntry> &Flags) const {
+ const NamedMDNode *ModFlags = getModuleFlagsMetadata();
+ if (!ModFlags) return;
+
+ for (unsigned i = 0, e = ModFlags->getNumOperands(); i != e; ++i) {
+ MDNode *Flag = ModFlags->getOperand(i);
+ ConstantInt *Behavior = cast<ConstantInt>(Flag->getOperand(0));
+ MDString *Key = cast<MDString>(Flag->getOperand(1));
+ Value *Val = Flag->getOperand(2);
+ Flags.push_back(ModuleFlagEntry(Behavior->getZExtValue(), Key, Val));
+ }
+}
+
/// getModuleFlagsMetadata - Returns the NamedMDNode in the module that
/// represents module-level flags. This method returns null if there are no
/// module-level flags.