diff --git a/src/MemoryBlock.cpp b/src/MemoryBlock.cpp index ba44112..a07e091 100644 --- a/src/MemoryBlock.cpp +++ b/src/MemoryBlock.cpp @@ -36,8 +36,8 @@ //! @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, @@ -45,14 +45,9 @@ MemoryBlock::MemoryBlock (MemoryBlock *_nextBlock, 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 () @@ -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(wordArray)) { - memory = new uint8_t [byteSize]; - for (int w = 0 ; w < numWords ; w++ ) { int b = w * BYTES_PER_WORD; diff --git a/src/SimProc.cpp b/src/SimProc.cpp index 18ef4fd..41cd39c 100644 --- a/src/SimProc.cpp +++ b/src/SimProc.cpp @@ -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; @@ -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, (void *)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, (void *)wordArray); memList = new MemoryBlock (memList, baseAddr, wordSize, wordArray, isLittleEndianP); - delete [] wordArray; } } } // parseSpecificMemoryClause () @@ -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; @@ -1216,7 +1214,7 @@ SimProc::parseMemoryValues (ScannerObject memoryType, { if (SO_BYTE == memoryType) { - byteArray[nextMem] = (uint32_t)numberLval; + byteArray[nextMem] = (uint8_t)numberLval; } else { diff --git a/src/SimProc.h b/src/SimProc.h index b2c475d..142adf1 100644 --- a/src/SimProc.h +++ b/src/SimProc.h @@ -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