-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFullReadVNVMProvider.cpp
37 lines (33 loc) · 1.34 KB
/
FullReadVNVMProvider.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <FullReadVNVMProvider.h>
#include <assert.h>
static const int RegistersOffset = 2 * sizeof(Word);
static const int RegistersSize = sizeof(Word);
FullReadNVVMProvider::FullReadNVVMProvider(std::istream& inputStream) :
stackSize(0),
registersCount(RegistersSize),
executableSize(0)
{
bool readStatus = static_cast<bool>(inputStream.read(reinterpret_cast<char*>(&stackSize), sizeof(Word)));
assert(readStatus);
assert(stackSize > 0);
readStatus = static_cast<bool>(inputStream.read(reinterpret_cast<char*>(&executableSize), sizeof(Word)));
assert(readStatus);
assert(executableSize > 0);
inputStream.seekg(0, std::ios::end);
int fullSize = inputStream.tellg();
assert(executableSize > RegistersOffset + registersCount * RegistersSize);
assert(fullSize <= executableSize + stackSize);
inputStream.seekg(0, std::ios::beg);
values.resize(executableSize + stackSize);
readStatus = static_cast<bool>(inputStream.read(&values[0], fullSize));
assert(readStatus);
}
Word* FullReadNVVMProvider::GetRegistryAt(std::byte i)
{
unsigned char registerIndex = static_cast<unsigned char>(i);
return reinterpret_cast<Word*>(values.data() + RegistersOffset + RegistersSize * registerIndex);
}
char* FullReadNVVMProvider::GetStackPtr()
{
return reinterpret_cast<char*>(&values[executableSize]);
}