#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
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 {
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.
// 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
// 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) {
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);
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>
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;
#endif
}
+} // End llvm namespace
+
#endif