* finegrainify namespacification of ArchiveReader.cpp
[oota-llvm.git] / lib / Bytecode / Reader / ReaderInternals.h
index c8905454e670c39745f97da37bd6445b0d38e961..2e9a0e927ed464945442406c333d095b56af6bd3 100644 (file)
 #ifndef READER_INTERNALS_H
 #define READER_INTERNALS_H
 
-#include "llvm/Constant.h"
+#include "ReaderPrimitives.h"
+#include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Function.h"
 #include "llvm/ModuleProvider.h"
-#include "llvm/Bytecode/Primitives.h"
 #include <utility>
 #include <map>
 
+namespace llvm {
+
 // Enable to trace to figure out what the heck is going on when parsing fails
 //#define TRACE_LEVEL 10
 //#define DEBUG_OUTPUT
@@ -35,7 +37,8 @@
 
 struct LazyFunctionInfo {
   const unsigned char *Buf, *EndBuf;
-  unsigned FunctionSlot;
+  LazyFunctionInfo(const unsigned char *B = 0, const unsigned char *EB = 0)
+    : Buf(B), EndBuf(EB) {}
 };
 
 class BytecodeParser : public ModuleProvider {
@@ -102,13 +105,13 @@ private:
 
   std::vector<BasicBlock*> ParsedBasicBlocks;
 
-  // GlobalRefs - This maintains a mapping between <Type, Slot #>'s and forward
-  // references to global values or constants.  Such values may be referenced
-  // before they are defined, and if so, the temporary object that they
-  // represent is held here.
+  // ConstantFwdRefs - This maintains a mapping between <Type, Slot #>'s and
+  // forward references to constants.  Such values may be referenced before they
+  // are defined, and if so, the temporary object that they represent is held
+  // here.
   //
-  typedef std::map<std::pair<const Type *, unsigned>, Value*>  GlobalRefsType;
-  GlobalRefsType GlobalRefs;
+  typedef std::map<std::pair<const Type*,unsigned>, Constant*> ConstantRefsType;
+  ConstantRefsType ConstantFwdRefs;
 
   // TypesLoaded - This vector mirrors the Values[TypeTyID] plane.  It is used
   // to deal with forward references to types.
@@ -121,7 +124,7 @@ private:
   // each function in the module.  When the function is loaded, this function is
   // filled in.
   //
-  std::vector<std::pair<Function*, unsigned> > FunctionSignatureList;
+  std::vector<Function*> FunctionSignatureList;
 
   // Constant values are read in after global variables.  Because of this, we
   // must defer setting the initializers on global variables until after module
@@ -134,7 +137,7 @@ private:
   // information about each function: its begin and end pointer in the buffer
   // and its FunctionSlot.
   // 
-  std::map<Function*, LazyFunctionInfo*> LazyFunctionLoadMap;
+  std::map<Function*, LazyFunctionInfo> LazyFunctionLoadMap;
   
 private:
   void freeTable(ValueTable &Tab) {
@@ -159,7 +162,9 @@ private:
   BasicBlock *ParseBasicBlock(const unsigned char *&Buf,
                               const unsigned char *End,
                               unsigned BlockNo);
-
+  unsigned ParseInstructionList(Function *F, const unsigned char *&Buf,
+                                const unsigned char *EndBuf);
+  
   void ParseInstruction(const unsigned char *&Buf, const unsigned char *End,
                         std::vector<unsigned> &Args, BasicBlock *BB);
 
@@ -167,26 +172,27 @@ private:
                          ValueTable &Tab, TypeValuesListTy &TypeTab);
   Constant *parseConstantValue(const unsigned char *&Buf,
                                const unsigned char *End,
-                               const Type *Ty);
+                               unsigned TypeID);
   void parseTypeConstants(const unsigned char *&Buf,
                           const unsigned char *EndBuf,
                           TypeValuesListTy &Tab, unsigned NumEntries);
   const Type *parseTypeConstant(const unsigned char *&Buf,
                                 const unsigned char *EndBuf);
 
-  Value      *getValue(const Type *Ty, unsigned num, bool Create = true);
   Value      *getValue(unsigned TypeID, unsigned num, bool Create = true);
   const Type *getType(unsigned ID);
   BasicBlock *getBasicBlock(unsigned ID);
-  Constant   *getConstantValue(const Type *Ty, unsigned num);
+  Constant   *getConstantValue(unsigned TypeID, unsigned num);
+  Constant   *getConstantValue(const Type *Ty, unsigned num) {
+    return getConstantValue(getTypeSlot(Ty), num);
+  }
 
-  unsigned insertValue(Value *V, ValueTable &Table);
   unsigned insertValue(Value *V, unsigned Type, ValueTable &Table);
 
   unsigned getTypeSlot(const Type *Ty);
 
-  // resolve all references to the placeholder (if any) for the given value
-  void ResolveReferencesToValue(Value *Val, unsigned Slot);
+  // resolve all references to the placeholder (if any) for the given constant
+  void ResolveReferencesToConstant(Constant *C, unsigned Slot);
 };
 
 template<class SuperType>
@@ -199,10 +205,9 @@ public:
   unsigned getID() { return ID; }
 };
 
-struct ConstantPlaceHolderHelper : public Constant {
+struct ConstantPlaceHolderHelper : public ConstantExpr {
   ConstantPlaceHolderHelper(const Type *Ty)
-    : Constant(Ty) {}
-  virtual bool isNullValue() const { return false; }
+    : ConstantExpr(Instruction::UserOp1, Constant::getNullValue(Ty), Ty) {}
 };
 
 typedef PlaceholderDef<ConstantPlaceHolderHelper>  ConstPHolder;
@@ -226,4 +231,6 @@ static inline void readBlock(const unsigned char *&Buf,
 #endif
 }
 
+} // End llvm namespace
+
 #endif