[llvm-commits] CVS: llvm/lib/Bytecode/Reader/Reader.cpp Reader.h

Chris Lattner lattner at cs.uiuc.edu
Wed Jan 25 15:08:28 PST 2006



Changes in directory llvm/lib/Bytecode/Reader:

Reader.cpp updated: 1.186 -> 1.187
Reader.h updated: 1.26 -> 1.27
---
Log message:

add bc reader/writer support for inline asm


---
Diffs of the changes:  (+33 -10)

 Reader.cpp |   39 +++++++++++++++++++++++++++++++--------
 Reader.h   |    4 ++--
 2 files changed, 33 insertions(+), 10 deletions(-)


Index: llvm/lib/Bytecode/Reader/Reader.cpp
diff -u llvm/lib/Bytecode/Reader/Reader.cpp:1.186 llvm/lib/Bytecode/Reader/Reader.cpp:1.187
--- llvm/lib/Bytecode/Reader/Reader.cpp:1.186	Wed Jan 25 11:18:50 2006
+++ llvm/lib/Bytecode/Reader/Reader.cpp	Wed Jan 25 17:08:15 2006
@@ -22,6 +22,7 @@
 #include "llvm/BasicBlock.h"
 #include "llvm/CallingConv.h"
 #include "llvm/Constants.h"
+#include "llvm/InlineAsm.h"
 #include "llvm/Instructions.h"
 #include "llvm/SymbolTable.h"
 #include "llvm/Bytecode/Format.h"
@@ -1404,7 +1405,7 @@
 }
 
 /// Parse a single constant value
-Constant *BytecodeReader::ParseConstantValue(unsigned TypeID) {
+Value *BytecodeReader::ParseConstantPoolValue(unsigned TypeID) {
   // We must check for a ConstantExpr before switching by type because
   // a ConstantExpr can be of any type, and has no explicit value.
   //
@@ -1412,11 +1413,32 @@
   unsigned isExprNumArgs = read_vbr_uint();
 
   if (isExprNumArgs) {
-    // 'undef' is encoded with 'exprnumargs' == 1.
-    if (!hasNoUndefValue)
-      if (--isExprNumArgs == 0)
+    if (!hasNoUndefValue) {
+      // 'undef' is encoded with 'exprnumargs' == 1.
+      if (isExprNumArgs == 1)
         return UndefValue::get(getType(TypeID));
 
+      // Inline asm is encoded with exprnumargs == ~0U.
+      if (isExprNumArgs == ~0U) {
+        std::string AsmStr = read_str();
+        std::string ConstraintStr = read_str();
+        unsigned Flags = read_vbr_uint();
+        
+        const PointerType *PTy = dyn_cast<PointerType>(getType(TypeID));
+        const FunctionType *FTy = 
+          PTy ? dyn_cast<FunctionType>(PTy->getElementType()) : 0;
+
+        if (!FTy || !InlineAsm::Verify(FTy, ConstraintStr))
+          error("Invalid constraints for inline asm");
+        if (Flags & ~1U)
+          error("Invalid flags for inline asm");
+        bool HasSideEffects = Flags & 1;
+        return InlineAsm::get(FTy, AsmStr, ConstraintStr, HasSideEffects);
+      }
+      
+      --isExprNumArgs;
+    }
+
     // FIXME: Encoding of constant exprs could be much more compact!
     std::vector<Constant*> ArgVec;
     ArgVec.reserve(isExprNumArgs);
@@ -1695,9 +1717,9 @@
       ParseStringConstants(NumEntries, Tab);
     } else {
       for (unsigned i = 0; i < NumEntries; ++i) {
-        Constant *C = ParseConstantValue(Typ);
-        assert(C && "ParseConstantValue returned NULL!");
-        unsigned Slot = insertValue(C, Typ, Tab);
+        Value *V = ParseConstantPoolValue(Typ);
+        assert(V && "ParseConstantPoolValue returned NULL!");
+        unsigned Slot = insertValue(V, Typ, Tab);
 
         // If we are reading a function constant table, make sure that we adjust
         // the slot number to be the real global constant number.
@@ -1705,7 +1727,8 @@
         if (&Tab != &ModuleValues && Typ < ModuleValues.size() &&
             ModuleValues[Typ])
           Slot += ModuleValues[Typ]->size();
-        ResolveReferencesToConstant(C, Typ, Slot);
+        if (Constant *C = dyn_cast<Constant>(V))
+          ResolveReferencesToConstant(C, Typ, Slot);
       }
     }
   }


Index: llvm/lib/Bytecode/Reader/Reader.h
diff -u llvm/lib/Bytecode/Reader/Reader.h:1.26 llvm/lib/Bytecode/Reader/Reader.h:1.27
--- llvm/lib/Bytecode/Reader/Reader.h:1.26	Thu Jan 19 00:57:58 2006
+++ llvm/lib/Bytecode/Reader/Reader.h	Wed Jan 25 17:08:15 2006
@@ -229,8 +229,8 @@
   void ParseConstantPool(ValueTable& Values, TypeListTy& Types,
                          bool isFunction);
 
-  /// @brief Parse a single constant value
-  Constant* ParseConstantValue(unsigned TypeID);
+  /// @brief Parse a single constant pool value
+  Value *ParseConstantPoolValue(unsigned TypeID);
 
   /// @brief Parse a block of types constants
   void ParseTypes(TypeListTy &Tab, unsigned NumEntries);






More information about the llvm-commits mailing list