[llvm-commits] [llvm] r79212 - in /llvm/trunk: include/llvm/Constants.h lib/VMCore/Constants.cpp

Erick Tryzelaar idadesub at users.sourceforge.net
Sun Aug 16 16:36:33 PDT 2009


Author: erickt
Date: Sun Aug 16 18:36:33 2009
New Revision: 79212

URL: http://llvm.org/viewvc/llvm-project?rev=79212&view=rev
Log:
Add helper functions to ConstantInt and ConstantFP to accept strings.

Modified:
    llvm/trunk/include/llvm/Constants.h
    llvm/trunk/lib/VMCore/Constants.cpp

Modified: llvm/trunk/include/llvm/Constants.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Constants.h?rev=79212&r1=79211&r2=79212&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Constants.h (original)
+++ llvm/trunk/include/llvm/Constants.h Sun Aug 16 18:36:33 2009
@@ -83,6 +83,11 @@
   /// Return a ConstantInt with the specified value and an implied Type. The
   /// type is the integer type that corresponds to the bit width of the value.
   static ConstantInt* get(LLVMContext &Context, const APInt& V);
+
+  /// Return a ConstantInt constructed from the string strStart with the given
+  /// radix. 
+  static ConstantInt* get(const IntegerType* Ty, const StringRef& Str,
+                          uint8_t radix);
   
   /// If Ty is a vector type, return a Constant with a splat of the given
   /// value. Otherwise return a ConstantInt for the given value.
@@ -250,6 +255,7 @@
   /// only be used for simple constant values like 2.0/1.0 etc, that are
   /// known-valid both as host double and as the target format.
   static Constant* get(const Type* Ty, double V);
+  static Constant* get(const Type* Ty, const StringRef& Str);
   static ConstantFP* get(LLVMContext &Context, const APFloat& V);
   static ConstantFP* getNegativeZero(const Type* Ty);
   

Modified: llvm/trunk/lib/VMCore/Constants.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Constants.cpp?rev=79212&r1=79211&r2=79212&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Constants.cpp (original)
+++ llvm/trunk/lib/VMCore/Constants.cpp Sun Aug 16 18:36:33 2009
@@ -314,6 +314,11 @@
   return C;
 }
 
+ConstantInt* ConstantInt::get(const IntegerType* Ty, const StringRef& Str,
+                              uint8_t radix) {
+  return get(Ty->getContext(), APInt(Ty->getBitWidth(), Str, radix));
+}
+
 //===----------------------------------------------------------------------===//
 //                                ConstantFP
 //===----------------------------------------------------------------------===//
@@ -352,6 +357,22 @@
   return C;
 }
 
+
+Constant* ConstantFP::get(const Type* Ty, const StringRef& Str) {
+  LLVMContext &Context = Ty->getContext();
+
+  APFloat FV(*TypeToFloatSemantics(Ty->getScalarType()), Str);
+  Constant *C = get(Context, FV);
+
+  // For vectors, broadcast the value.
+  if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
+    return ConstantVector::get(
+      std::vector<Constant *>(VTy->getNumElements(), C));
+
+  return C; 
+}
+
+
 ConstantFP* ConstantFP::getNegativeZero(const Type* Ty) {
   LLVMContext &Context = Ty->getContext();
   APFloat apf = cast <ConstantFP>(Constant::getNullValue(Ty))->getValueAPF();





More information about the llvm-commits mailing list