Add an inline helper function that masks a GenericValue to a specified
authorReid Spencer <rspencer@reidspencer.com>
Thu, 18 Jan 2007 02:12:10 +0000 (02:12 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Thu, 18 Jan 2007 02:12:10 +0000 (02:12 +0000)
bit width.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33325 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/Interpreter/Interpreter.h

index c62249bdb93f5aa8e8a56080ffeac9e92856530c..3007b0adb2a92ef90d4de9e52c92df47db9b2536 100644 (file)
@@ -231,8 +231,20 @@ private:  // Helper functions
   GenericValue executeCastOperation(Instruction::CastOps opcode, Value *SrcVal, 
                                     const Type *Ty, ExecutionContext &SF);
   void popStackAndReturnValueToCaller(const Type *RetTy, GenericValue Result);
+
 };
 
+inline void maskToBitWidth(GenericValue& GV, unsigned BitWidth) {
+  uint64_t BitMask = (1ull << BitWidth) - 1;
+  if (BitWidth <= 8)
+    GV.Int8Val &= BitMask;
+  else if (BitWidth <= 16)
+    GV.Int16Val &= BitMask;
+  else if (BitWidth <= 32)
+    GV.Int32Val &= BitMask;
+  else 
+    GV.Int64Val &= BitMask;
+}
 } // End llvm namespace
 
 #endif