2001-10-24 09:15:12 +08:00
|
|
|
//===- Reader.cpp - Code to read bytecode files ---------------------------===//
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
|
|
|
// This library implements the functionality defined in llvm/Bytecode/Reader.h
|
|
|
|
//
|
|
|
|
// Note that this library should be as fast as possible, reentrant, and
|
|
|
|
// threadsafe!!
|
|
|
|
//
|
2002-08-18 06:01:27 +08:00
|
|
|
// TODO: Return error messages to caller instead of printing them out directly.
|
2001-06-07 04:29:01 +08:00
|
|
|
// TODO: Allow passing in an option to ignore the symbol table
|
|
|
|
//
|
2001-10-24 09:15:12 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-12-04 02:02:31 +08:00
|
|
|
#include "ReaderInternals.h"
|
2001-06-07 04:29:01 +08:00
|
|
|
#include "llvm/Bytecode/Reader.h"
|
|
|
|
#include "llvm/Bytecode/Format.h"
|
|
|
|
#include "llvm/Module.h"
|
2002-04-29 03:55:58 +08:00
|
|
|
#include "llvm/Constants.h"
|
2001-12-04 02:02:31 +08:00
|
|
|
#include "llvm/iPHINode.h"
|
2001-06-07 04:29:01 +08:00
|
|
|
#include "llvm/iOther.h"
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
2002-01-21 06:54:45 +08:00
|
|
|
#include <sys/mman.h>
|
2001-06-07 04:29:01 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
bool BytecodeParser::getTypeSlot(const Type *Ty, unsigned &Slot) {
|
|
|
|
if (Ty->isPrimitiveType()) {
|
|
|
|
Slot = Ty->getPrimitiveID();
|
|
|
|
} else {
|
2003-03-07 01:15:19 +08:00
|
|
|
// Check the function level types first...
|
2003-03-07 01:18:14 +08:00
|
|
|
TypeValuesListTy::iterator I = find(FunctionTypeValues.begin(),
|
|
|
|
FunctionTypeValues.end(), Ty);
|
|
|
|
if (I != FunctionTypeValues.end()) {
|
2001-09-08 00:37:43 +08:00
|
|
|
Slot = FirstDerivedTyID+ModuleTypeValues.size()+
|
2003-03-07 01:18:14 +08:00
|
|
|
(&*I - &FunctionTypeValues[0]);
|
2001-09-08 00:37:43 +08:00
|
|
|
} else {
|
|
|
|
I = find(ModuleTypeValues.begin(), ModuleTypeValues.end(), Ty);
|
|
|
|
if (I == ModuleTypeValues.end()) return true; // Didn't find type!
|
|
|
|
Slot = FirstDerivedTyID + (&*I - &ModuleTypeValues[0]);
|
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
2002-01-21 06:54:45 +08:00
|
|
|
//cerr << "getTypeSlot '" << Ty->getName() << "' = " << Slot << "\n";
|
2001-06-07 04:29:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const Type *BytecodeParser::getType(unsigned ID) {
|
2002-10-23 08:51:54 +08:00
|
|
|
if (ID < Type::NumPrimitiveIDs) {
|
|
|
|
const Type *T = Type::getPrimitiveType((Type::PrimitiveID)ID);
|
|
|
|
if (T) return T;
|
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2002-01-21 06:54:45 +08:00
|
|
|
//cerr << "Looking up Type ID: " << ID << "\n";
|
2002-10-23 08:51:54 +08:00
|
|
|
const Value *V = getValue(Type::TypeTy, ID, false);
|
|
|
|
return cast_or_null<Type>(V);
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-01-21 06:54:45 +08:00
|
|
|
int BytecodeParser::insertValue(Value *Val, std::vector<ValueList> &ValueTab) {
|
2001-06-07 04:29:01 +08:00
|
|
|
unsigned type;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (getTypeSlot(Val->getType(), type)) return -1;
|
2001-09-08 00:37:43 +08:00
|
|
|
assert(type != Type::TypeTyID && "Types should never be insertValue'd!");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
if (ValueTab.size() <= type)
|
|
|
|
ValueTab.resize(type+1, ValueList());
|
|
|
|
|
|
|
|
//cerr << "insertValue Values[" << type << "][" << ValueTab[type].size()
|
2002-01-21 06:54:45 +08:00
|
|
|
// << "] = " << Val << "\n";
|
2001-09-08 00:37:43 +08:00
|
|
|
ValueTab[type].push_back(Val);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-10-13 14:47:01 +08:00
|
|
|
return ValueTab[type].size()-1;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Value *BytecodeParser::getValue(const Type *Ty, unsigned oNum, bool Create) {
|
|
|
|
unsigned Num = oNum;
|
|
|
|
unsigned type; // The type plane it lives in...
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (getTypeSlot(Ty, type)) return 0;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
if (type == Type::TypeTyID) { // The 'type' plane has implicit values
|
2001-09-08 00:37:43 +08:00
|
|
|
assert(Create == false);
|
2002-10-23 08:51:54 +08:00
|
|
|
if (Num < Type::NumPrimitiveIDs) {
|
|
|
|
const Type *T = Type::getPrimitiveType((Type::PrimitiveID)Num);
|
|
|
|
if (T) return (Value*)T; // Asked for a primitive type...
|
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// Otherwise, derived types need offset...
|
|
|
|
Num -= FirstDerivedTyID;
|
2001-09-08 00:37:43 +08:00
|
|
|
|
|
|
|
// Is it a module level type?
|
|
|
|
if (Num < ModuleTypeValues.size())
|
2001-10-13 14:47:01 +08:00
|
|
|
return (Value*)ModuleTypeValues[Num].get();
|
2001-09-08 00:37:43 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// Nope, is it a function level type?
|
2001-09-08 00:37:43 +08:00
|
|
|
Num -= ModuleTypeValues.size();
|
2003-03-07 01:18:14 +08:00
|
|
|
if (Num < FunctionTypeValues.size())
|
|
|
|
return (Value*)FunctionTypeValues[Num].get();
|
2001-09-08 00:37:43 +08:00
|
|
|
|
|
|
|
return 0;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
if (type < ModuleValues.size()) {
|
|
|
|
if (Num < ModuleValues[type].size())
|
2001-06-07 04:29:01 +08:00
|
|
|
return ModuleValues[type][Num];
|
|
|
|
Num -= ModuleValues[type].size();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Values.size() > type && Values[type].size() > Num)
|
|
|
|
return Values[type][Num];
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (!Create) return 0; // Do not create a placeholder?
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
Value *d = 0;
|
|
|
|
switch (Ty->getPrimitiveID()) {
|
2002-03-29 11:51:11 +08:00
|
|
|
case Type::FunctionTyID:
|
2003-03-07 01:15:19 +08:00
|
|
|
std::cerr << "Creating function pholder! : " << type << ":" << oNum << " "
|
2003-03-07 00:32:25 +08:00
|
|
|
<< Ty->getName() << "\n";
|
2002-08-18 06:01:27 +08:00
|
|
|
d = new FunctionPHolder(Ty, oNum);
|
|
|
|
if (insertValue(d, LateResolveModuleValues) == -1) return 0;
|
2001-06-07 04:29:01 +08:00
|
|
|
return d;
|
2002-08-18 06:01:27 +08:00
|
|
|
case Type::LabelTyID:
|
|
|
|
d = new BBPHolder(Ty, oNum);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
d = new ValPHolder(Ty, oNum);
|
|
|
|
break;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
assert(d != 0 && "How did we not make something?");
|
2002-08-18 06:01:27 +08:00
|
|
|
if (insertValue(d, LateResolveValues) == -1) return 0;
|
2001-06-07 04:29:01 +08:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2002-10-14 11:33:02 +08:00
|
|
|
/// getConstantValue - Just like getValue, except that it returns a null pointer
|
|
|
|
/// only on error. It always returns a constant (meaning that if the value is
|
|
|
|
/// defined, but is not a constant, that is an error). If the specified
|
|
|
|
/// constant hasn't been parsed yet, a placeholder is defined and used. Later,
|
|
|
|
/// after the real value is parsed, the placeholder is eliminated.
|
|
|
|
///
|
|
|
|
Constant *BytecodeParser::getConstantValue(const Type *Ty, unsigned Slot) {
|
|
|
|
if (Value *V = getValue(Ty, Slot, false))
|
|
|
|
return dyn_cast<Constant>(V); // If we already have the value parsed...
|
|
|
|
|
2003-03-07 00:32:25 +08:00
|
|
|
GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(Ty, Slot));
|
2002-10-14 11:33:02 +08:00
|
|
|
if (I != GlobalRefs.end()) {
|
|
|
|
BCR_TRACE(5, "Previous forward ref found!\n");
|
|
|
|
return cast<Constant>(I->second);
|
|
|
|
} else {
|
|
|
|
// Create a placeholder for the constant reference and
|
|
|
|
// keep track of the fact that we have a forward ref to recycle it
|
|
|
|
BCR_TRACE(5, "Creating new forward ref to a constant!\n");
|
|
|
|
Constant *C = new ConstPHolder(Ty, Slot);
|
|
|
|
|
|
|
|
// Keep track of the fact that we have a forward ref to recycle it
|
2003-03-07 00:32:25 +08:00
|
|
|
GlobalRefs.insert(std::make_pair(std::make_pair(Ty, Slot), C));
|
2002-10-14 11:33:02 +08:00
|
|
|
return C;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
bool BytecodeParser::postResolveValues(ValueTable &ValTab) {
|
|
|
|
bool Error = false;
|
2001-06-28 07:41:11 +08:00
|
|
|
for (unsigned ty = 0; ty < ValTab.size(); ++ty) {
|
2001-06-07 04:29:01 +08:00
|
|
|
ValueList &DL = ValTab[ty];
|
|
|
|
unsigned Size;
|
|
|
|
while ((Size = DL.size())) {
|
|
|
|
unsigned IDNumber = getValueIDNumberFromPlaceHolder(DL[Size-1]);
|
|
|
|
|
|
|
|
Value *D = DL[Size-1];
|
|
|
|
DL.pop_back();
|
|
|
|
|
|
|
|
Value *NewDef = getValue(D->getType(), IDNumber, false);
|
|
|
|
if (NewDef == 0) {
|
|
|
|
Error = true; // Unresolved thinger
|
2003-03-07 00:32:25 +08:00
|
|
|
std::cerr << "Unresolvable reference found: <"
|
|
|
|
<< D->getType()->getDescription() << ">:" << IDNumber <<"!\n";
|
2001-06-07 04:29:01 +08:00
|
|
|
} else {
|
|
|
|
// Fixup all of the uses of this placeholder def...
|
|
|
|
D->replaceAllUsesWith(NewDef);
|
|
|
|
|
|
|
|
// Now that all the uses are gone, delete the placeholder...
|
|
|
|
// If we couldn't find a def (error case), then leak a little
|
|
|
|
delete D; // memory, 'cause otherwise we can't remove all uses!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return Error;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool BytecodeParser::ParseBasicBlock(const uchar *&Buf, const uchar *EndBuf,
|
|
|
|
BasicBlock *&BB) {
|
|
|
|
BB = new BasicBlock();
|
|
|
|
|
|
|
|
while (Buf < EndBuf) {
|
2001-09-08 00:37:43 +08:00
|
|
|
Instruction *Inst;
|
2002-08-22 06:55:27 +08:00
|
|
|
if (ParseInstruction(Buf, EndBuf, Inst,
|
|
|
|
/*HACK*/BB)) {
|
2001-06-07 04:29:01 +08:00
|
|
|
delete BB;
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (Inst == 0) { delete BB; return true; }
|
|
|
|
if (insertValue(Inst, Values) == -1) { delete BB; return true; }
|
2001-09-08 00:37:43 +08:00
|
|
|
|
|
|
|
BB->getInstList().push_back(Inst);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(4, Inst);
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
bool BytecodeParser::ParseSymbolTable(const uchar *&Buf, const uchar *EndBuf,
|
|
|
|
SymbolTable *ST) {
|
2001-06-07 04:29:01 +08:00
|
|
|
while (Buf < EndBuf) {
|
|
|
|
// Symtab block header: [num entries][type id number]
|
|
|
|
unsigned NumEntries, Typ;
|
|
|
|
if (read_vbr(Buf, EndBuf, NumEntries) ||
|
2002-08-18 06:01:27 +08:00
|
|
|
read_vbr(Buf, EndBuf, Typ)) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
const Type *Ty = getType(Typ);
|
2002-08-18 06:01:27 +08:00
|
|
|
if (Ty == 0) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(3, "Plane Type: '" << Ty << "' with " << NumEntries <<
|
|
|
|
" entries\n");
|
|
|
|
|
2001-06-28 07:41:11 +08:00
|
|
|
for (unsigned i = 0; i < NumEntries; ++i) {
|
2001-06-07 04:29:01 +08:00
|
|
|
// Symtab entry: [def slot #][name]
|
|
|
|
unsigned slot;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, EndBuf, slot)) return true;
|
2002-01-21 06:54:45 +08:00
|
|
|
std::string Name;
|
2001-06-07 04:29:01 +08:00
|
|
|
if (read(Buf, EndBuf, Name, false)) // Not aligned...
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
Value *D = getValue(Ty, slot, false); // Find mapping...
|
2001-09-08 00:37:43 +08:00
|
|
|
if (D == 0) {
|
2002-01-21 06:54:45 +08:00
|
|
|
BCR_TRACE(3, "FAILED LOOKUP: Slot #" << slot << "\n");
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-09-08 00:37:43 +08:00
|
|
|
}
|
|
|
|
BCR_TRACE(4, "Map: '" << Name << "' to #" << slot << ":" << D;
|
2003-03-07 00:32:25 +08:00
|
|
|
if (!isa<Instruction>(D)) std::cerr << "\n");
|
2001-09-08 00:37:43 +08:00
|
|
|
|
|
|
|
D->setName(Name, ST);
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (Buf > EndBuf) return true;
|
2001-07-29 01:50:18 +08:00
|
|
|
return false;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
void BytecodeParser::ResolveReferencesToValue(Value *NewV, unsigned Slot) {
|
2003-03-07 00:32:25 +08:00
|
|
|
GlobalRefsType::iterator I = GlobalRefs.find(std::make_pair(NewV->getType(),
|
|
|
|
Slot));
|
2002-08-18 06:01:27 +08:00
|
|
|
if (I == GlobalRefs.end()) return; // Never forward referenced?
|
2002-07-15 07:04:18 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
BCR_TRACE(3, "Mutating forward refs!\n");
|
|
|
|
Value *VPH = I->second; // Get the placeholder...
|
2002-07-15 07:04:18 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
// Loop over all of the uses of the Value. What they are depends
|
|
|
|
// on what NewV is. Replacing a use of the old reference takes the
|
|
|
|
// use off the use list, so loop with !use_empty(), not the use_iterator.
|
|
|
|
while (!VPH->use_empty()) {
|
|
|
|
Constant *C = cast<Constant>(VPH->use_back());
|
|
|
|
unsigned numReplaced = C->mutateReferences(VPH, NewV);
|
|
|
|
assert(numReplaced > 0 && "Supposed user wasn't really a user?");
|
2001-10-13 14:47:01 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (GlobalValue* GVal = dyn_cast<GlobalValue>(NewV)) {
|
|
|
|
// Remove the placeholder GlobalValue from the module...
|
|
|
|
GVal->getParent()->getGlobalList().remove(cast<GlobalVariable>(VPH));
|
2001-10-13 14:47:01 +08:00
|
|
|
}
|
|
|
|
}
|
2002-07-15 07:04:18 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
delete VPH; // Delete the old placeholder
|
|
|
|
GlobalRefs.erase(I); // Remove the map entry for it
|
2002-07-15 07:04:18 +08:00
|
|
|
}
|
|
|
|
|
2003-03-07 01:18:14 +08:00
|
|
|
bool BytecodeParser::ParseFunction(const uchar *&Buf, const uchar *EndBuf) {
|
2001-06-07 04:29:01 +08:00
|
|
|
// Clear out the local values table...
|
|
|
|
Values.clear();
|
2002-08-18 06:01:27 +08:00
|
|
|
if (FunctionSignatureList.empty()) {
|
2002-03-29 11:51:11 +08:00
|
|
|
Error = "Function found, but FunctionSignatureList empty!";
|
2003-03-07 01:15:19 +08:00
|
|
|
return true; // Unexpected function!
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
const PointerType *PMTy = FunctionSignatureList.back().first; // PtrMeth
|
2002-03-29 11:51:11 +08:00
|
|
|
const FunctionType *MTy = dyn_cast<FunctionType>(PMTy->getElementType());
|
2003-03-07 01:15:19 +08:00
|
|
|
if (MTy == 0) return true; // Not ptr to function!
|
2001-10-03 22:53:21 +08:00
|
|
|
|
2001-11-27 02:56:10 +08:00
|
|
|
unsigned isInternal;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, EndBuf, isInternal)) return true;
|
2001-11-27 02:56:10 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
unsigned MethSlot = FunctionSignatureList.back().second;
|
|
|
|
FunctionSignatureList.pop_back();
|
2002-03-29 11:51:11 +08:00
|
|
|
Function *M = new Function(MTy, isInternal != 0);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
BCR_TRACE(2, "FUNCTION TYPE: " << MTy << "\n");
|
2001-09-08 00:37:43 +08:00
|
|
|
|
2002-03-29 11:51:11 +08:00
|
|
|
const FunctionType::ParamTypes &Params = MTy->getParamTypes();
|
2002-10-14 04:57:00 +08:00
|
|
|
Function::aiterator AI = M->abegin();
|
2002-03-29 11:51:11 +08:00
|
|
|
for (FunctionType::ParamTypes::const_iterator It = Params.begin();
|
2002-10-14 04:57:00 +08:00
|
|
|
It != Params.end(); ++It, ++AI) {
|
|
|
|
if (insertValue(AI, Values) == -1) {
|
2003-03-07 01:15:19 +08:00
|
|
|
Error = "Error reading function arguments!\n";
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true;
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
while (Buf < EndBuf) {
|
|
|
|
unsigned Type, Size;
|
2003-03-07 01:03:28 +08:00
|
|
|
const unsigned char *OldBuf = Buf;
|
2001-10-24 09:15:12 +08:00
|
|
|
if (readBlock(Buf, EndBuf, Type, Size)) {
|
2002-03-29 11:51:11 +08:00
|
|
|
Error = "Error reading Function level block!";
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true;
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
switch (Type) {
|
|
|
|
case BytecodeFormat::ConstantPool:
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(2, "BLOCK BytecodeFormat::ConstantPool: {\n");
|
2003-03-07 01:18:14 +08:00
|
|
|
if (ParseConstantPool(Buf, Buf+Size, Values, FunctionTypeValues)) {
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BytecodeFormat::BasicBlock: {
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(2, "BLOCK BytecodeFormat::BasicBlock: {\n");
|
2001-06-07 04:29:01 +08:00
|
|
|
BasicBlock *BB;
|
|
|
|
if (ParseBasicBlock(Buf, Buf+Size, BB) ||
|
2001-10-13 14:47:01 +08:00
|
|
|
insertValue(BB, Values) == -1) {
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true; // Parse error... :(
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-06-26 00:13:21 +08:00
|
|
|
M->getBasicBlockList().push_back(BB);
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BytecodeFormat::SymbolTable:
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(2, "BLOCK BytecodeFormat::SymbolTable: {\n");
|
2002-11-21 02:36:02 +08:00
|
|
|
if (ParseSymbolTable(Buf, Buf+Size, &M->getSymbolTable())) {
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(2, "BLOCK <unknown>:ignored! {\n");
|
2001-06-07 04:29:01 +08:00
|
|
|
Buf += Size;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (OldBuf > Buf) return true; // Wrap around!
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(2, "} end block\n");
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
if (align32(Buf, EndBuf)) {
|
2002-03-29 11:51:11 +08:00
|
|
|
Error = "Error aligning Function level block!";
|
2001-06-07 04:29:01 +08:00
|
|
|
delete M; // Malformed bc file, read past end of block.
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (postResolveValues(LateResolveValues) ||
|
|
|
|
postResolveValues(LateResolveModuleValues)) {
|
2003-03-07 01:15:19 +08:00
|
|
|
Error = "Error resolving function values!";
|
2002-08-18 06:01:27 +08:00
|
|
|
delete M; return true; // Unresolvable references!
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
Value *FunctionPHolder = getValue(PMTy, MethSlot, false);
|
2003-03-07 01:18:14 +08:00
|
|
|
assert(FunctionPHolder && "Something is broken, no placeholder found!");
|
2002-08-18 06:01:27 +08:00
|
|
|
assert(isa<Function>(FunctionPHolder) && "Not a function?");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
unsigned type; // Type slot
|
|
|
|
assert(!getTypeSlot(MTy, type) && "How can meth type not exist?");
|
2001-10-03 22:53:21 +08:00
|
|
|
getTypeSlot(PMTy, type);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
TheModule->getFunctionList().push_back(M);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// Replace placeholder with the real function pointer...
|
2001-06-07 04:29:01 +08:00
|
|
|
ModuleValues[type][MethSlot] = M;
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// Clear out function level types...
|
2003-03-07 01:18:14 +08:00
|
|
|
FunctionTypeValues.clear();
|
2001-09-15 06:03:42 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// If anyone is using the placeholder make them use the real function instead
|
2002-08-18 06:01:27 +08:00
|
|
|
FunctionPHolder->replaceAllUsesWith(M);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// We don't need the placeholder anymore!
|
2002-08-18 06:01:27 +08:00
|
|
|
delete FunctionPHolder;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
ResolveReferencesToValue(M, MethSlot);
|
2001-10-13 14:47:01 +08:00
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
bool BytecodeParser::ParseModuleGlobalInfo(const uchar *&Buf, const uchar *End){
|
2002-08-18 06:01:27 +08:00
|
|
|
if (!FunctionSignatureList.empty()) {
|
2001-10-24 09:15:12 +08:00
|
|
|
Error = "Two ModuleGlobalInfo packets found!";
|
2002-08-18 06:01:27 +08:00
|
|
|
return true; // Two ModuleGlobal blocks?
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-09-10 15:58:01 +08:00
|
|
|
// Read global variables...
|
|
|
|
unsigned VarType;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, End, VarType)) return true;
|
2001-09-10 15:58:01 +08:00
|
|
|
while (VarType != Type::VoidTyID) { // List is terminated by Void
|
2001-11-27 02:56:10 +08:00
|
|
|
// VarType Fields: bit0 = isConstant, bit1 = hasInitializer,
|
|
|
|
// bit2 = isInternal, bit3+ = slot#
|
|
|
|
const Type *Ty = getType(VarType >> 3);
|
2002-05-07 00:15:30 +08:00
|
|
|
if (!Ty || !isa<PointerType>(Ty)) {
|
2001-10-24 09:15:12 +08:00
|
|
|
Error = "Global not pointer type! Ty = " + Ty->getDescription();
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-09-10 15:58:01 +08:00
|
|
|
}
|
|
|
|
|
2001-10-03 22:53:21 +08:00
|
|
|
const PointerType *PTy = cast<const PointerType>(Ty);
|
2001-12-04 08:03:30 +08:00
|
|
|
const Type *ElTy = PTy->getElementType();
|
2001-10-03 22:53:21 +08:00
|
|
|
|
2001-12-04 06:26:30 +08:00
|
|
|
Constant *Initializer = 0;
|
2001-09-18 12:01:05 +08:00
|
|
|
if (VarType & 2) { // Does it have an initalizer?
|
|
|
|
// Do not improvise... values must have been stored in the constant pool,
|
|
|
|
// which should have been read before now.
|
|
|
|
//
|
|
|
|
unsigned InitSlot;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, End, InitSlot)) return true;
|
2001-09-18 12:01:05 +08:00
|
|
|
|
2001-10-13 14:47:01 +08:00
|
|
|
Value *V = getValue(ElTy, InitSlot, false);
|
2002-08-18 06:01:27 +08:00
|
|
|
if (V == 0) return true;
|
2001-12-04 06:26:30 +08:00
|
|
|
Initializer = cast<Constant>(V);
|
2001-09-18 12:01:05 +08:00
|
|
|
}
|
|
|
|
|
2001-09-10 15:58:01 +08:00
|
|
|
// Create the global variable...
|
2001-11-27 02:56:10 +08:00
|
|
|
GlobalVariable *GV = new GlobalVariable(ElTy, VarType & 1, VarType & 4,
|
|
|
|
Initializer);
|
2001-10-13 14:47:01 +08:00
|
|
|
int DestSlot = insertValue(GV, ModuleValues);
|
2002-08-18 06:01:27 +08:00
|
|
|
if (DestSlot == -1) return true;
|
2001-10-13 14:47:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
TheModule->getGlobalList().push_back(GV);
|
2001-10-13 14:47:01 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
ResolveReferencesToValue(GV, (unsigned)DestSlot);
|
2001-10-13 14:47:01 +08:00
|
|
|
|
|
|
|
BCR_TRACE(2, "Global Variable of type: " << PTy->getDescription()
|
2002-01-21 06:54:45 +08:00
|
|
|
<< " into slot #" << DestSlot << "\n");
|
2001-09-10 15:58:01 +08:00
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, End, VarType)) return true;
|
2001-09-10 15:58:01 +08:00
|
|
|
}
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// Read the function signatures for all of the functions that are coming, and
|
2001-06-07 04:29:01 +08:00
|
|
|
// create fillers in the Value tables.
|
2002-08-18 06:01:27 +08:00
|
|
|
unsigned FnSignature;
|
|
|
|
if (read_vbr(Buf, End, FnSignature)) return true;
|
|
|
|
while (FnSignature != Type::VoidTyID) { // List is terminated by Void
|
|
|
|
const Type *Ty = getType(FnSignature);
|
2001-10-03 22:53:21 +08:00
|
|
|
if (!Ty || !isa<PointerType>(Ty) ||
|
2002-03-29 11:51:11 +08:00
|
|
|
!isa<FunctionType>(cast<PointerType>(Ty)->getElementType())) {
|
|
|
|
Error = "Function not ptr to func type! Ty = " + Ty->getDescription();
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
2002-10-23 08:51:54 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// We create functions by passing the underlying FunctionType to create...
|
2001-12-04 08:03:30 +08:00
|
|
|
Ty = cast<PointerType>(Ty)->getElementType();
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
// When the ModuleGlobalInfo section is read, we load the type of each
|
|
|
|
// function and the 'ModuleValues' slot that it lands in. We then load a
|
|
|
|
// placeholder into its slot to reserve it. When the function is loaded,
|
|
|
|
// this placeholder is replaced.
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// Insert the placeholder...
|
2002-08-18 06:01:27 +08:00
|
|
|
Value *Val = new FunctionPHolder(Ty, 0);
|
|
|
|
if (insertValue(Val, ModuleValues) == -1) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// Figure out which entry of its typeslot it went into...
|
|
|
|
unsigned TypeSlot;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (getTypeSlot(Val->getType(), TypeSlot)) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
unsigned SlotNo = ModuleValues[TypeSlot].size()-1;
|
|
|
|
|
|
|
|
// Keep track of this information in a linked list that is emptied as
|
2003-03-07 01:15:19 +08:00
|
|
|
// functions are loaded...
|
2001-06-07 04:29:01 +08:00
|
|
|
//
|
2002-08-18 06:01:27 +08:00
|
|
|
FunctionSignatureList.push_back(
|
2003-03-07 00:32:25 +08:00
|
|
|
std::make_pair(cast<const PointerType>(Val->getType()), SlotNo));
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, End, FnSignature)) return true;
|
2002-03-29 11:51:11 +08:00
|
|
|
BCR_TRACE(2, "Function of type: " << Ty << "\n");
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2002-08-18 06:01:27 +08:00
|
|
|
if (align32(Buf, End)) return true;
|
|
|
|
|
|
|
|
// Now that the function signature list is set up, reverse it so that we can
|
|
|
|
// remove elements efficiently from the back of the vector.
|
|
|
|
std::reverse(FunctionSignatureList.begin(), FunctionSignatureList.end());
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// This is for future proofing... in the future extra fields may be added that
|
|
|
|
// we don't understand, so we transparently ignore them.
|
|
|
|
//
|
|
|
|
Buf = End;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
bool BytecodeParser::ParseModule(const uchar *Buf, const uchar *EndBuf) {
|
2001-06-07 04:29:01 +08:00
|
|
|
unsigned Type, Size;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (readBlock(Buf, EndBuf, Type, Size)) return true;
|
2001-10-24 09:15:12 +08:00
|
|
|
if (Type != BytecodeFormat::Module || Buf+Size != EndBuf) {
|
|
|
|
Error = "Expected Module packet!";
|
2002-08-18 06:01:27 +08:00
|
|
|
return true; // Hrm, not a class?
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(0, "BLOCK BytecodeFormat::Module: {\n");
|
2002-08-18 06:01:27 +08:00
|
|
|
FunctionSignatureList.clear(); // Just in case...
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
// Read into instance variables...
|
2002-08-18 06:01:27 +08:00
|
|
|
if (read_vbr(Buf, EndBuf, FirstDerivedTyID)) return true;
|
|
|
|
if (align32(Buf, EndBuf)) return true;
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(1, "FirstDerivedTyID = " << FirstDerivedTyID << "\n");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
while (Buf < EndBuf) {
|
2003-03-07 01:03:28 +08:00
|
|
|
const unsigned char *OldBuf = Buf;
|
2003-03-07 01:15:19 +08:00
|
|
|
if (readBlock(Buf, EndBuf, Type, Size)) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
switch (Type) {
|
2001-09-08 00:37:43 +08:00
|
|
|
case BytecodeFormat::ConstantPool:
|
|
|
|
BCR_TRACE(1, "BLOCK BytecodeFormat::ConstantPool: {\n");
|
2003-03-07 01:15:19 +08:00
|
|
|
if (ParseConstantPool(Buf, Buf+Size, ModuleValues, ModuleTypeValues))
|
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
|
2001-09-08 00:37:43 +08:00
|
|
|
case BytecodeFormat::ModuleGlobalInfo:
|
|
|
|
BCR_TRACE(1, "BLOCK BytecodeFormat::ModuleGlobalInfo: {\n");
|
2003-03-07 01:15:19 +08:00
|
|
|
if (ParseModuleGlobalInfo(Buf, Buf+Size)) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
|
2002-03-29 11:51:11 +08:00
|
|
|
case BytecodeFormat::Function: {
|
|
|
|
BCR_TRACE(1, "BLOCK BytecodeFormat::Function: {\n");
|
2003-03-07 01:18:14 +08:00
|
|
|
if (ParseFunction(Buf, Buf+Size)) return true; // Error parsing function
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BytecodeFormat::SymbolTable:
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(1, "BLOCK BytecodeFormat::SymbolTable: {\n");
|
2003-03-07 01:15:19 +08:00
|
|
|
if (ParseSymbolTable(Buf, Buf+Size, &TheModule->getSymbolTable()))
|
|
|
|
return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2001-10-24 09:15:12 +08:00
|
|
|
Error = "Expected Module Block!";
|
2001-06-07 04:29:01 +08:00
|
|
|
Buf += Size;
|
2002-08-18 06:01:27 +08:00
|
|
|
if (OldBuf > Buf) return true; // Wrap around!
|
2001-06-07 04:29:01 +08:00
|
|
|
break;
|
|
|
|
}
|
2001-09-08 00:37:43 +08:00
|
|
|
BCR_TRACE(1, "} end block\n");
|
2003-03-07 01:15:19 +08:00
|
|
|
if (align32(Buf, EndBuf)) return true;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
if (!FunctionSignatureList.empty()) { // Expected more functions!
|
2002-03-29 11:51:11 +08:00
|
|
|
Error = "Function expected, but bytecode stream at end!";
|
2002-08-18 06:01:27 +08:00
|
|
|
return true;
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-09-08 00:37:43 +08:00
|
|
|
|
|
|
|
BCR_TRACE(0, "} end block\n\n");
|
2001-06-07 04:29:01 +08:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
static inline Module *Error(std::string *ErrorStr, const char *Message) {
|
|
|
|
if (ErrorStr) *ErrorStr = Message;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
Module *BytecodeParser::ParseBytecode(const uchar *Buf, const uchar *EndBuf) {
|
|
|
|
LateResolveValues.clear();
|
|
|
|
unsigned Sig;
|
|
|
|
// Read and check signature...
|
|
|
|
if (read(Buf, EndBuf, Sig) ||
|
2003-03-07 01:15:19 +08:00
|
|
|
Sig != ('l' | ('l' << 8) | ('v' << 16) | 'm' << 24))
|
|
|
|
return ::Error(&Error, "Invalid bytecode signature!");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:15:19 +08:00
|
|
|
TheModule = new Module();
|
|
|
|
if (ParseModule(Buf, EndBuf)) {
|
|
|
|
delete TheModule;
|
|
|
|
TheModule = 0;
|
|
|
|
}
|
|
|
|
return TheModule;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-03-07 00:50:32 +08:00
|
|
|
Module *ParseBytecodeBuffer(const unsigned char *Buffer, unsigned Length,
|
|
|
|
std::string *ErrorStr) {
|
2001-06-07 04:29:01 +08:00
|
|
|
BytecodeParser Parser;
|
2003-03-07 00:50:32 +08:00
|
|
|
Module *R = Parser.ParseBytecode(Buffer, Buffer+Length);
|
|
|
|
if (ErrorStr) *ErrorStr = Parser.getError();
|
|
|
|
return R;
|
2001-06-07 04:29:01 +08:00
|
|
|
}
|
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
|
|
|
|
/// FDHandle - Simple handle class to make sure a file descriptor gets closed
|
|
|
|
/// when the object is destroyed.
|
|
|
|
class FDHandle {
|
|
|
|
int FD;
|
|
|
|
public:
|
|
|
|
FDHandle(int fd) : FD(fd) {}
|
|
|
|
operator int() const { return FD; }
|
|
|
|
~FDHandle() {
|
|
|
|
if (FD != -1) close(FD);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-06-07 04:29:01 +08:00
|
|
|
// Parse and return a class file...
|
|
|
|
//
|
2002-01-21 06:54:45 +08:00
|
|
|
Module *ParseBytecodeFile(const std::string &Filename, std::string *ErrorStr) {
|
2001-06-07 04:29:01 +08:00
|
|
|
Module *Result = 0;
|
|
|
|
|
2002-01-21 06:54:45 +08:00
|
|
|
if (Filename != std::string("-")) { // Read from a file...
|
2003-03-07 01:03:28 +08:00
|
|
|
FDHandle FD = open(Filename.c_str(), O_RDONLY);
|
|
|
|
if (FD == -1)
|
|
|
|
return Error(ErrorStr, "Error opening file!");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
// Stat the file to get its length...
|
2003-03-07 00:50:32 +08:00
|
|
|
struct stat StatBuf;
|
2003-03-07 01:03:28 +08:00
|
|
|
if (fstat(FD, &StatBuf) == -1 || StatBuf.st_size == 0)
|
|
|
|
return Error(ErrorStr, "Error stat'ing file!");
|
2003-03-07 00:50:32 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
// mmap in the file all at once...
|
2003-03-07 00:50:32 +08:00
|
|
|
int Length = StatBuf.st_size;
|
|
|
|
unsigned char *Buffer = (unsigned char*)mmap(0, Length, PROT_READ,
|
|
|
|
MAP_PRIVATE, FD, 0);
|
2003-03-07 01:03:28 +08:00
|
|
|
if (Buffer == (unsigned char*)MAP_FAILED)
|
|
|
|
return Error(ErrorStr, "Error mmapping file!");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
// Parse the bytecode we mmapped in
|
2003-03-07 00:50:32 +08:00
|
|
|
Result = ParseBytecodeBuffer(Buffer, Length, ErrorStr);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
// Unmmap the bytecode...
|
2001-06-07 04:29:01 +08:00
|
|
|
munmap((char*)Buffer, Length);
|
|
|
|
} else { // Read from stdin
|
|
|
|
int BlockSize;
|
2003-03-07 01:03:28 +08:00
|
|
|
uchar Buffer[4096*4];
|
|
|
|
std::vector<unsigned char> FileData;
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
// Read in all of the data from stdin, we cannot mmap stdin...
|
|
|
|
while ((BlockSize = read(0 /*stdin*/, Buffer, 4096*4))) {
|
|
|
|
if (BlockSize == -1)
|
|
|
|
return Error(ErrorStr, "Error reading from stdin!");
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
FileData.insert(FileData.end(), Buffer, Buffer+BlockSize);
|
2001-10-24 09:15:12 +08:00
|
|
|
}
|
2001-06-07 04:29:01 +08:00
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
if (FileData.empty())
|
|
|
|
return Error(ErrorStr, "Standard Input empty!");
|
|
|
|
|
2002-08-18 08:38:32 +08:00
|
|
|
#define ALIGN_PTRS 0
|
2001-06-07 04:29:01 +08:00
|
|
|
#if ALIGN_PTRS
|
2003-03-07 01:03:28 +08:00
|
|
|
uchar *Buf = (uchar*)mmap(0, FileData.size(), PROT_READ|PROT_WRITE,
|
2001-06-07 04:29:01 +08:00
|
|
|
MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
|
|
|
|
assert((Buf != (uchar*)-1) && "mmap returned error!");
|
2003-03-07 01:03:28 +08:00
|
|
|
memcpy(Buf, &FileData[0], FileData.size());
|
2001-06-07 04:29:01 +08:00
|
|
|
#else
|
2003-03-07 01:03:28 +08:00
|
|
|
unsigned char *Buf = &FileData[0];
|
2001-06-07 04:29:01 +08:00
|
|
|
#endif
|
|
|
|
|
2003-03-07 01:03:28 +08:00
|
|
|
Result = ParseBytecodeBuffer(Buf, FileData.size(), ErrorStr);
|
2001-06-07 04:29:01 +08:00
|
|
|
|
|
|
|
#if ALIGN_PTRS
|
2003-03-07 01:03:28 +08:00
|
|
|
munmap((char*)Buf, FileData.size()); // Free mmap'd data area
|
2001-06-07 04:29:01 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
}
|