From a315193ab08abc3aaaa1885370253992c110b6ec Mon Sep 17 00:00:00 2001 From: Scott Johnson Date: Thu, 1 Dec 2022 09:21:58 -0800 Subject: [PATCH] Convert triggers::module_t::detect_memory_access_match to std::optional Goal is to remove match_result_t.fire field to eliminate dont-care fields when fire=false. --- riscv/mmu.cc | 10 +++++----- riscv/triggers.cc | 6 +++--- riscv/triggers.h | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/riscv/mmu.cc b/riscv/mmu.cc index e4fba3d0..1d15b917 100644 --- a/riscv/mmu.cc +++ b/riscv/mmu.cc @@ -157,18 +157,18 @@ void mmu_t::check_triggers(triggers::operation_t operation, reg_t address, std:: if (matched_trigger || !proc) return; - triggers::match_result_t match = proc->TM.detect_memory_access_match(operation, address, data); + auto match = proc->TM.detect_memory_access_match(operation, address, data); - if (match.fire) - switch (match.timing) { + if (match.has_value()) + switch (match->timing) { case triggers::TIMING_BEFORE: - throw triggers::matched_t(operation, address, match.action); + throw triggers::matched_t(operation, address, match->action); case triggers::TIMING_AFTER: // We want to take this exception on the next instruction. We check // whether to do so in the I$ refill path, so flush the I$. flush_icache(); - matched_trigger = new triggers::matched_t(operation, address, match.action); + matched_trigger = new triggers::matched_t(operation, address, match->action); } } diff --git a/riscv/triggers.cc b/riscv/triggers.cc index 7f3817e4..12a06d78 100644 --- a/riscv/triggers.cc +++ b/riscv/triggers.cc @@ -331,11 +331,11 @@ bool module_t::tdata2_write(processor_t * const proc, unsigned index, const reg_ return true; } -match_result_t module_t::detect_memory_access_match(operation_t operation, reg_t address, std::optional data) noexcept +std::optional module_t::detect_memory_access_match(operation_t operation, reg_t address, std::optional data) noexcept { state_t * const state = proc->get_state(); if (state->debug_mode) - return match_result_t(false); + return std::nullopt; bool chain_ok = true; @@ -357,7 +357,7 @@ match_result_t module_t::detect_memory_access_match(operation_t operation, reg_t chain_ok = result.fire || !trigger->get_chain(); } - return match_result_t(false); + return std::nullopt; } match_result_t module_t::detect_trap_match(const trap_t& t) noexcept diff --git a/riscv/triggers.h b/riscv/triggers.h index 0b587984..27f1c0ee 100644 --- a/riscv/triggers.h +++ b/riscv/triggers.h @@ -186,7 +186,7 @@ public: unsigned count() const { return triggers.size(); } - match_result_t detect_memory_access_match(operation_t operation, reg_t address, std::optional data) noexcept; + std::optional detect_memory_access_match(operation_t operation, reg_t address, std::optional data) noexcept; match_result_t detect_trap_match(const trap_t& t) noexcept; processor_t *proc;