Skip to content

Commit

Permalink
refactor: rename send_cmio_response state accesses
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed Jan 8, 2025
1 parent 8af3b46 commit d5cb327
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 32 deletions.
8 changes: 4 additions & 4 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@
#include "pma-constants.h"
#include "pma-defines.h"
#include "pma.h"
#include "record-state-access.h"
#include "record-send-cmio-state-access.h"
#include "record-step-state-access.h"
#include "replay-state-access.h"
#include "replay-send-cmio-state-access.h"
#include "replay-step-state-access.h"
#include "riscv-constants.h"
#include "send-cmio-response.h"
Expand Down Expand Up @@ -2111,7 +2111,7 @@ access_log machine::log_send_cmio_response(uint16_t reason, const unsigned char
hash_type root_hash_before;
get_root_hash(root_hash_before);
// Call send_cmio_response with the recording state accessor
record_state_access a(*this, log_type);
record_send_cmio_state_access a(*this, log_type);
a.push_bracket(bracket_type::begin, "send cmio response");
cartesi::send_cmio_response(a, reason, data, length);
a.push_bracket(bracket_type::end, "send cmio response");
Expand All @@ -2131,7 +2131,7 @@ void machine::verify_send_cmio_response(uint16_t reason, const unsigned char *da
}

// Verify all intermediate state transitions
replay_state_access a(log, root_hash_before);
replay_send_cmio_state_access a(log, root_hash_before);
cartesi::send_cmio_response(a, reason, data, length);
a.finish();

Expand Down
26 changes: 13 additions & 13 deletions src/record-state-access.h → src/record-send-cmio-state-access.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#ifndef RECORD_STATE_ACCESS_H
#define RECORD_STATE_ACCESS_H
#ifndef RECORD_SEND_CMIO_STATE_ACCESS_H
#define RECORD_SEND_CMIO_STATE_ACCESS_H

/// \file
/// \brief State access implementation that records state accesses to an access log.
Expand All @@ -38,10 +38,10 @@

namespace cartesi {

/// \class record_state_access
/// \details This ....
/// access to the machine state. No logs are kept.
class record_state_access : public i_state_access<record_state_access, pma_entry> {
/// \class record_send_cmio_state_access
/// \details This records all state accesses that happen during the execution of
/// a machine::send_cmio_response() function call
class record_send_cmio_state_access : public i_state_access<record_send_cmio_state_access, pma_entry> {
using hasher_type = machine_merkle_tree::hasher_type;
using hash_type = machine_merkle_tree::hash_type;
// NOLINTBEGIN(cppcoreguidelines-avoid-const-or-ref-data-members)
Expand All @@ -58,23 +58,23 @@ class record_state_access : public i_state_access<record_state_access, pma_entry
public:
/// \brief Constructor from machine state.
/// \param m Pointer to machine state.
explicit record_state_access(machine &m, access_log::type log_type) :
explicit record_send_cmio_state_access(machine &m, access_log::type log_type) :
m_m(m),
m_s(m.get_state()),
m_log(std::make_shared<access_log>(log_type)) {
;
}

/// \brief No copy constructor
record_state_access(const record_state_access &) = delete;
record_send_cmio_state_access(const record_send_cmio_state_access &) = delete;
/// \brief No copy assignment
record_state_access &operator=(const record_state_access &) = delete;
record_send_cmio_state_access &operator=(const record_send_cmio_state_access &) = delete;
/// \brief No move constructor
record_state_access(record_state_access &&) = delete;
record_send_cmio_state_access(record_send_cmio_state_access &&) = delete;
/// \brief No move assignment
record_state_access &operator=(record_state_access &&) = delete;
record_send_cmio_state_access &operator=(record_send_cmio_state_access &&) = delete;
/// \brief Default destructor
~record_state_access() = default;
~record_send_cmio_state_access() = default;

/// \brief Returns const pointer to access log.
std::shared_ptr<const access_log> get_log() const {
Expand Down Expand Up @@ -193,7 +193,7 @@ class record_state_access : public i_state_access<record_state_access, pma_entry
}

// Declare interface as friend to it can forward calls to the "overridden" methods.
friend i_state_access<record_state_access, pma_entry>;
friend i_state_access<record_send_cmio_state_access, pma_entry>;

void do_push_bracket(bracket_type &type, const char *text) {
m_log->push_bracket(type, text);
Expand Down
22 changes: 11 additions & 11 deletions src/replay-state-access.h → src/replay-send-cmio-state-access.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#ifndef REPLAY_STATE_ACCESS_H
#define REPLAY_STATE_ACCESS_H
#ifndef REPLAY_SEND_CMIO_STATE_ACCESS_H
#define REPLAY_SEND_CMIO_STATE_ACCESS_H

/// \file
/// \brief State access implementation that replays recorded state accesses
Expand All @@ -41,8 +41,8 @@

namespace cartesi {

/// \brief Allows replaying a uarch reset operation from an access log.
class replay_state_access : public i_state_access<replay_state_access, pma_entry> {
/// \brief Allows replaying a machine::send_cmio_response() from an access log.
class replay_send_cmio_state_access : public i_state_access<replay_send_cmio_state_access, pma_entry> {
using tree_type = machine_merkle_tree;
using hash_type = tree_type::hash_type;
using hasher_type = tree_type::hasher_type;
Expand All @@ -61,7 +61,7 @@ class replay_state_access : public i_state_access<replay_state_access, pma_entry
/// \brief Constructor from access log
/// \param log Access log to be replayed
/// \param initial_hash Initial root hash
explicit replay_state_access(const access_log &log, const hash_type &initial_hash) :
explicit replay_send_cmio_state_access(const access_log &log, const hash_type &initial_hash) :
m_accesses(log.get_accesses()),
m_root_hash{initial_hash} {
if (m_accesses.empty()) {
Expand All @@ -70,15 +70,15 @@ class replay_state_access : public i_state_access<replay_state_access, pma_entry
}

/// \brief No copy constructor
replay_state_access(const replay_state_access &) = delete;
replay_send_cmio_state_access(const replay_send_cmio_state_access &) = delete;
/// \brief No copy assignment
replay_state_access &operator=(const replay_state_access &) = delete;
replay_send_cmio_state_access &operator=(const replay_send_cmio_state_access &) = delete;
/// \brief No move constructor
replay_state_access(replay_state_access &&) = delete;
replay_send_cmio_state_access(replay_send_cmio_state_access &&) = delete;
/// \brief No move assignment
replay_state_access &operator=(replay_state_access &&) = delete;
replay_send_cmio_state_access &operator=(replay_send_cmio_state_access &&) = delete;
/// \brief Default destructor
~replay_state_access() = default;
~replay_send_cmio_state_access() = default;

void get_root_hash(machine_merkle_tree::hash_type &hash) const {
hash = m_root_hash;
Expand All @@ -92,7 +92,7 @@ class replay_state_access : public i_state_access<replay_state_access, pma_entry
}

private:
friend i_state_access<replay_state_access, pma_entry>;
friend i_state_access<replay_send_cmio_state_access, pma_entry>;

std::string access_to_report() const {
auto index = m_next_access + 1;
Expand Down
10 changes: 6 additions & 4 deletions src/send-cmio-response.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

// NOLINTBEGIN(google-readability-casting,misc-const-correctness,modernize-use-auto,hicpp-use-auto)

#include "record-state-access.h"
#include "replay-state-access.h"
#include "record-send-cmio-state-access.h"
#include "replay-send-cmio-state-access.h"
#include "state-access.h"

#include "send-cmio-response.h"
Expand Down Expand Up @@ -64,10 +64,12 @@ void send_cmio_response(STATE_ACCESS &a, uint16 reason, bytes data, uint32 dataL
template void send_cmio_response(state_access &a, uint16_t reason, const unsigned char *data, uint32 length);

// Explicit instantiation for record_state_access
template void send_cmio_response(record_state_access &a, uint16_t reason, const unsigned char *data, uint32 length);
template void send_cmio_response(record_send_cmio_state_access &a, uint16_t reason, const unsigned char *data,
uint32 length);

// Explicit instantiation for replay_state_access
template void send_cmio_response(replay_state_access &a, uint16_t reason, const unsigned char *data, uint32 length);
template void send_cmio_response(replay_send_cmio_state_access &a, uint16_t reason, const unsigned char *data,
uint32 length);

} // namespace cartesi
// NOLINTEND(google-readability-casting,misc-const-correctness,modernize-use-auto,hicpp-use-auto)

0 comments on commit d5cb327

Please sign in to comment.