X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FBytecode%2FReader%2FReaderInternals.h;h=2e9a0e927ed464945442406c333d095b56af6bd3;hb=3446ae833754df5b139d056de025797dbacc10e5;hp=c8905454e670c39745f97da37bd6445b0d38e961;hpb=095be96096d7137956f0dec2a96b84269defee4f;p=oota-llvm.git diff --git a/lib/Bytecode/Reader/ReaderInternals.h b/lib/Bytecode/Reader/ReaderInternals.h index c8905454e67..2e9a0e927ed 100644 --- a/lib/Bytecode/Reader/ReaderInternals.h +++ b/lib/Bytecode/Reader/ReaderInternals.h @@ -14,14 +14,16 @@ #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 #include +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 ParsedBasicBlocks; - // GlobalRefs - This maintains a mapping between '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 '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, Value*> GlobalRefsType; - GlobalRefsType GlobalRefs; + typedef std::map, 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 > FunctionSignatureList; + std::vector 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 LazyFunctionLoadMap; + std::map 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 &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 @@ -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 ConstPHolder; @@ -226,4 +231,6 @@ static inline void readBlock(const unsigned char *&Buf, #endif } +} // End llvm namespace + #endif