class BytecodeBufferReader : public BytecodeParser {
private:
const unsigned char *Buffer;
- int Length;
bool MustDelete;
BytecodeBufferReader(const BytecodeBufferReader&); // Do not implement
}
BytecodeBufferReader::BytecodeBufferReader(const unsigned char *Buf,
- unsigned Len,
+ unsigned Length,
const std::string &ModuleID)
{
// If not aligned, allocate a new buffer to hold the bytecode...
const unsigned char *ParseBegin = 0;
- unsigned Offset = 0;
if ((intptr_t)Buf & 3) {
- Length = Len+4;
- Buffer = new unsigned char[Length];
- Offset = 4 - ((intptr_t)Buf & 3); // Make sure it's aligned
+ Buffer = new unsigned char[Length+4];
+ unsigned Offset = 4 - ((intptr_t)Buf & 3); // Make sure it's aligned
ParseBegin = Buffer + Offset;
- memcpy((unsigned char*)ParseBegin, Buf, Len); // Copy it over
+ memcpy((unsigned char*)ParseBegin, Buf, Length); // Copy it over
MustDelete = true;
} else {
// If we don't need to copy it over, just use the caller's copy
ParseBegin = Buffer = Buf;
- Length = Len;
MustDelete = false;
}
- ParseBytecode(ParseBegin, Len, ModuleID);
+ ParseBytecode(ParseBegin, Length, ModuleID);
}
BytecodeBufferReader::~BytecodeBufferReader() {
public:
BytecodeStdinReader();
- ~BytecodeStdinReader();
};
}
-#define ALIGN_PTRS 0
-
BytecodeStdinReader::BytecodeStdinReader() {
int BlockSize;
unsigned char Buffer[4096*4];
if (FileData.empty())
throw std::string("Standard Input empty!");
-#if ALIGN_PTRS
- FileBuf = (unsigned char*)mmap(0, FileData.size(), PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
- assert((Buf != (unsigned char*)-1) && "mmap returned error!");
- memcpy(Buf, &FileData[0], FileData.size());
-#else
FileBuf = &FileData[0];
-#endif
-
ParseBytecode(FileBuf, FileData.size(), "<stdin>");
}
-BytecodeStdinReader::~BytecodeStdinReader() {
-#if ALIGN_PTRS
- munmap((char*)FileBuf, FileData.size()); // Free mmap'd data area
-#endif
-}
-
/////////////////////////////////////////////////////////////////////////////
//
// Wrapper functions
M = AMP->releaseModule();
delete AMP;
} catch (std::string &err) {
+ if (ErrorStr) ErrorStr = err;
return 0;
}
return M;
M = AMP->releaseModule();
delete AMP;
} catch (std::string &err) {
+ if (ErrorStr) ErrorStr = err;
return 0;
}
return M;