dev: Fix compilation errors

'backing' was initialized after being used.
'buffer' was initialized after its data() was used
by the constructor.

Change-Id: I0f8d0f6efb5d4b7abc5fc6c2c3ecca2c9b0a2eaf
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44366
Reviewed-by: Gabe Black <gabe.black@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Daniel R. Carvalho
2021-04-11 10:37:44 -03:00
committed by Daniel Carvalho
parent a6fc2797e8
commit 0a80511aea
2 changed files with 27 additions and 7 deletions

View File

@@ -30,6 +30,8 @@
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstdint>
#include <cstring>
#include <functional>
#include <initializer_list>
@@ -432,6 +434,21 @@ class RegisterBank : public RegisterBankBase
// The buffer's owner is responsible for serializing it.
void serialize(std::ostream &os) const override {}
bool unserialize(const std::string &s) override { return true; }
protected:
/**
* This method exists so that derived classes that need to initialize
* their buffers before they can be set can do so.
*
* @param buf The pointer to the backing buffer.
*/
void
setBuffer(void *buf)
{
assert(_ptr == nullptr);
assert(buf != nullptr);
_ptr = buf;
}
};
// Same as above, but which keeps its storage locally.
@@ -442,8 +459,10 @@ class RegisterBank : public RegisterBankBase
std::array<uint8_t, BufBytes> buffer;
RegisterLBuf(const std::string &new_name) :
RegisterBuf(new_name, buffer.data(), BufBytes)
{}
RegisterBuf(new_name, nullptr, BufBytes)
{
this->setBuffer(buffer.data());
}
void
serialize(std::ostream &os) const override

View File

@@ -244,16 +244,17 @@ class RegisterBufTest : public testing::Test
protected:
static constexpr size_t RegSize = 4;
RegisterBankLE::RegisterBuf reg;
std::array<uint8_t, RegSize * 3> buf;
std::array<uint8_t, RegSize * 3> backing;
RegisterBankLE::RegisterBuf reg;
public:
RegisterBufTest() : reg("buf_reg", backing.data() + RegSize, RegSize),
buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc},
RegisterBufTest()
: buf{0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0xa, 0xb, 0xc},
backing{0x10, 0x20, 0x30, 0x40, 0x50, 0x60,
0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0}
0x70, 0x80, 0x90, 0xa0, 0xb0, 0xc0},
reg("buf_reg", backing.data() + RegSize, RegSize)
{}
};
// Needed by C++14 and lower