Skip to content

Commit

Permalink
refactor: rename pm-type-name
Browse files Browse the repository at this point in the history
poor-type-name is more legible
  • Loading branch information
diegonehab committed Mar 5, 2025
1 parent 0f488cb commit 3abb800
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 28 deletions.
4 changes: 2 additions & 2 deletions src/find-pmas-entry.h → src/find-pma.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 FIND_ADDRESS_RANGE_H
#define FIND_ADDRESS_RANGE_H
#ifndef FIND_PMA_H
#define FIND_PMA_H

#include <cstdint>

Expand Down
6 changes: 3 additions & 3 deletions src/i-state-access.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "dump.h"
#include "i-prefer-shadow-state.h"
#include "meta.h"
#include "pm-type-name.h"
#include "poor-type-name.h"
#include "tlb.h"

namespace cartesi {
Expand Down Expand Up @@ -332,7 +332,7 @@ class i_state_access { // CRTP
derived().template do_read_memory_word<T, A>(faddr, pma_index, pval);
[[maybe_unused]] const auto fast_addr_name = std::is_same_v<fast_addr, uint64_t> ? "phys_addr" : "fast_addr";
DSA_PRINTF("%s::read_memory_word<%s,%s>(%s{0x%" PRIx64 "}, %" PRIu64 ") = %" PRIu64 "(0x%" PRIx64 ")\n",
get_name(), pm_type_name_v<T>, pm_type_name_v<A>, fast_addr_name, faddr, pma_index,
get_name(), poor_type_name_v<T>, poor_type_name_v<A>, fast_addr_name, faddr, pma_index,
static_cast<uint64_t>(*pval), static_cast<uint64_t>(*pval));
}

Expand All @@ -349,7 +349,7 @@ class i_state_access { // CRTP
derived().template do_write_memory_word<T, A>(faddr, pma_index, val);
[[maybe_unused]] const auto fast_addr_name = std::is_same_v<fast_addr, uint64_t> ? "phys_addr" : "fast_addr";
DSA_PRINTF("%s::write_memory_word<%s,%s>(%s{0x%" PRIx64 "}, %" PRIu64 ", %" PRIu64 "(0x%" PRIx64 "))\n",
get_name(), pm_type_name_v<T>, pm_type_name_v<A>, fast_addr_name, faddr, pma_index,
get_name(), poor_type_name_v<T>, poor_type_name_v<A>, fast_addr_name, faddr, pma_index,
static_cast<uint64_t>(val), static_cast<uint64_t>(val));
}

Expand Down
2 changes: 1 addition & 1 deletion src/interpret.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
#include "compiler-defines.h"
#include "device-state-access.h"
#include "dump.h"
#include "find-pmas-entry.h"
#include "find-pma.h"
#include "i-accept-counters.h"
#include "i-interactive-state-access.h"
#include "i-state-access.h"
Expand Down
4 changes: 2 additions & 2 deletions src/jsonrpc-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ void jsonrpc_machine::do_send_cmio_response(uint16_t reason, const unsigned char
request("machine.send_cmio_response", std::tie(reason, b64), result);
}

access_log jsonrpc_machine::do_log_send_cmio_response(uint16_t reason, const unsigned char *data,
uint64_t length, const access_log::type &log_type) {
access_log jsonrpc_machine::do_log_send_cmio_response(uint16_t reason, const unsigned char *data, uint64_t length,
const access_log::type &log_type) {
not_default_constructible<access_log> result;
std::string b64 = cartesi::encode_base64(data, length);
request("machine.log_send_cmio_response", std::tie(reason, b64, log_type), result);
Expand Down
2 changes: 1 addition & 1 deletion src/machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "i-machine.h"
#include "interpret.h"
#include "json-util.h"
#include "local-machine.h"
#include "machine-c-api-internal.h"
#include "machine-config.h"
#include "machine-merkle-tree.h"
Expand All @@ -45,7 +46,6 @@
#include "machine.h"
#include "os-features.h"
#include "pmas-defines.h"
#include "local-machine.h"

static_assert(AR_CMIO_RX_BUFFER_START_DEF == CM_AR_CMIO_RX_BUFFER_START);
static_assert(AR_CMIO_RX_BUFFER_LOG2_SIZE_DEF == CM_AR_CMIO_RX_BUFFER_LOG2_SIZE);
Expand Down
6 changes: 3 additions & 3 deletions src/machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ void machine::check_address_range(const address_range &ar, register_where where)
if (!where.interpret && !where.merkle) {
throw std::runtime_error{"address range "s + ar.get_description() + " must be registered somwhere"s};
}
if (where.interpret && m_s.pmas.size() >= PMA_MAX) {
throw std::runtime_error{"too many address ranges when adding "s + ar.get_description()};
}
const auto start = ar.get_start();
const auto length = ar.get_length();
// Checks if new range is machine addressable space (safe unsigned overflows)
Expand Down Expand Up @@ -491,6 +488,9 @@ void machine::init_plic_ar(const plic_config &p) {
void machine::init_pmas_contents(memory_address_range &pmas) const {
static_assert(sizeof(pmas_state) == PMA_MAX * 2 * sizeof(uint64_t), "inconsistent PMAs state length");
static_assert(AR_PMAS_LENGTH >= sizeof(pmas_state), "PMAs address range too short");
if (m_s.pmas.size() >= PMA_MAX - 1) { // Leave room for a sentinel empty address range after all others
throw std::runtime_error{"too many address ranges"};
}
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast)
auto &dest = *reinterpret_cast<pmas_state *>(pmas.get_host_memory());
std::ranges::transform(m_s.pmas, dest.begin(),
Expand Down
2 changes: 1 addition & 1 deletion src/mock-address-range.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static inline mock_address_range make_mock_address_range(uint64_t istart, uint64

template <typename ABRT>
address_range &get_mock_address_range(mock_address_range &mock, ABRT abrt) {
//??D I'm hoping the compiler optimizes this to what amounts to an if and a cast
//??D I'm hoping the compiler optimizes this to what amounts to a cast
static_assert(std::is_same_v<std::variant_alternative_t<0, mock_address_range>, std::monostate>);
switch (mock.index()) {
case 1:
Expand Down
28 changes: 14 additions & 14 deletions src/pm-type-name.h → src/poor-type-name.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,35 @@
// with this program (see COPYING). If not, see <https://www.gnu.org/licenses/>.
//

#ifndef PM_TYPE_NAME_H
#define PM_TYPE_NAME_H
#ifndef POOR_TYPE_NAME_H
#define POOR_TYPE_NAME_H

namespace cartesi {

//?DD Poor man's rtti that works in microarchitecture
template <typename T>
struct pm_type_name {
struct poor_type_name {
static constexpr const char *value = "unknown";
};

template <typename T>
constexpr const char *pm_type_name_v = pm_type_name<T>::value;
constexpr const char *poor_type_name_v = poor_type_name<T>::value;

// NOLINTBEGIN(cppcoreguidelines-macro-usage)
#define PM_TYPE_NAME(type) \
#define POOR_TYPE_NAME(type) \
template <> \
struct pm_type_name<type> { \
struct poor_type_name<type> { \
static constexpr const char *value = #type; \
}

PM_TYPE_NAME(uint8_t);
PM_TYPE_NAME(int8_t);
PM_TYPE_NAME(uint16_t);
PM_TYPE_NAME(int16_t);
PM_TYPE_NAME(uint32_t);
PM_TYPE_NAME(int32_t);
PM_TYPE_NAME(uint64_t);
PM_TYPE_NAME(int64_t);
POOR_TYPE_NAME(uint8_t);
POOR_TYPE_NAME(int8_t);
POOR_TYPE_NAME(uint16_t);
POOR_TYPE_NAME(int16_t);
POOR_TYPE_NAME(uint32_t);
POOR_TYPE_NAME(int32_t);
POOR_TYPE_NAME(uint64_t);
POOR_TYPE_NAME(int64_t);
// NOLINTEND(cppcoreguidelines-macro-usage)

} // namespace cartesi
Expand Down
2 changes: 1 addition & 1 deletion src/translate-virtual-address.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#include <cstdint>

#include "compiler-defines.h"
#include "find-pmas-entry.h"
#include "find-pma.h"
#include "riscv-constants.h"

namespace cartesi {
Expand Down

0 comments on commit 3abb800

Please sign in to comment.