Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemoryBlock take the array ownership from SimProc #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 6 additions & 12 deletions src/MemoryBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,18 @@

//! @param[in] _nextBlock pointer to the next memory block (NULL if none)
//! @param[in] _startAddr start address of the region of memory represented.
//! @param[in] numWords Number of words in the array supplied
//! @param[in] wordArray Array of words with which to initialize the memory.
//! @param[in] numBytes Number of bytes in the array supplied
//! @param[in] byteArray Array of bytes with which to initialize the memory.
//-----------------------------------------------------------------------------
MemoryBlock::MemoryBlock (MemoryBlock *_nextBlock,
uint32_t _startAddr,
int numBytes,
uint8_t *byteArray) :
nextBlock (_nextBlock),
startAddr (_startAddr),
byteSize (numBytes)
byteSize (numBytes),
memory (byteArray)
{
memory = new uint8_t [byteSize];

for (int b = 0 ; b < numBytes ; b++ )
{
memory[b] = byteArray[b];
}
} // MemoryBlock ()


Expand All @@ -78,10 +73,9 @@ MemoryBlock::MemoryBlock (MemoryBlock *_nextBlock,
bool targetIsLittleEndianP) :
nextBlock (_nextBlock),
startAddr (_startAddr),
byteSize (numWords * BYTES_PER_WORD)
byteSize (numWords * BYTES_PER_WORD),
memory (reinterpret_cast<uint8_t *>(wordArray))
{
memory = new uint8_t [byteSize];

for (int w = 0 ; w < numWords ; w++ )
{
int b = w * BYTES_PER_WORD;
Expand Down
14 changes: 6 additions & 8 deletions src/SimProc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -981,7 +981,7 @@ SimProc::parseSpecificMemoryClause (ScannerObject memoryType)
else
{
// Error recovery time. We should never get here, so if we do scan until
// we find either the start ofa new memory clause or EOF.
// we find either the start of a new memory clause or EOF.
parseError ("Memory specification expected, but not found. Skipping.");
skipBlock ();
return;
Expand Down Expand Up @@ -1068,18 +1068,16 @@ SimProc::parseSpecificMemoryClause (ScannerObject memoryType)
if (SO_BYTE == memoryType)
{
uint8_t *byteArray = new uint8_t [byteSize];
parseMemoryValues (memoryType, (int)byteSize, (void *)byteArray);
parseMemoryValues (memoryType, byteSize, byteArray);
memList = new MemoryBlock (memList, baseAddr, byteSize, byteArray);
delete [] byteArray;
}
else
{
uint32_t wordSize = byteSize / BYTES_PER_WORD;
uint32_t *wordArray = new uint32_t [wordSize];
parseMemoryValues (memoryType, (int)wordSize, (void *)wordArray);
parseMemoryValues (memoryType, wordSize, wordArray);
memList = new MemoryBlock (memList, baseAddr, wordSize, wordArray,
isLittleEndianP);
delete [] wordArray;
}
}
} // parseSpecificMemoryClause ()
Expand Down Expand Up @@ -1192,13 +1190,13 @@ SimProc::parseMemoryParams (uint32_t &baseAddr,
//-----------------------------------------------------------------------------
void
SimProc::parseMemoryValues (ScannerObject memoryType,
int arraySize,
uint32_t arraySize,
void *memArray)
{
uint8_t *byteArray = (uint8_t *)memArray;
uint32_t *wordArray = (uint32_t *)memArray;

int nextMem = 0;
uint32_t nextMem = 0;

#ifdef PARSE_DEBUG
cout << "-- parseMemoryvalues" << endl;
Expand All @@ -1216,7 +1214,7 @@ SimProc::parseMemoryValues (ScannerObject memoryType,
{
if (SO_BYTE == memoryType)
{
byteArray[nextMem] = (uint32_t)numberLval;
byteArray[nextMem] = (uint8_t)numberLval;
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/SimProc.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ class SimProc
void parseMemoryParams (uint32_t &baseAddr,
uint32_t &byteSize);
void parseMemoryValues (ScannerObject memoryType,
int arraySize,
uint32_t arraySize,
void *memArray);

// Parser support functions
Expand Down