diff options
author | Scott Johnson <scott.johnson@arilinc.com> | 2022-12-01 09:53:49 -0800 |
---|---|---|
committer | Scott Johnson <scott.johnson@arilinc.com> | 2022-12-01 09:53:49 -0800 |
commit | 1327dc6f6e0b39c775a527106d95b76291dd61c1 (patch) | |
tree | fb587ec7f5f61c2e07a75c650e4a0d4509ae66ec /riscv | |
parent | a078ef221f222ca5536307c6e695999b60b2a1ff (diff) | |
download | riscv-isa-sim-1327dc6f6e0b39c775a527106d95b76291dd61c1.zip riscv-isa-sim-1327dc6f6e0b39c775a527106d95b76291dd61c1.tar.gz riscv-isa-sim-1327dc6f6e0b39c775a527106d95b76291dd61c1.tar.bz2 |
Use std::optional for detect_trap_match in trigger_t hierarchy
Goal is to remove match_result_t.fire field to eliminate dont-care
fields.
Diffstat (limited to 'riscv')
-rw-r--r-- | riscv/triggers.cc | 16 | ||||
-rw-r--r-- | riscv/triggers.h | 6 |
2 files changed, 11 insertions, 11 deletions
diff --git a/riscv/triggers.cc b/riscv/triggers.cc index 0839acf..20135e2 100644 --- a/riscv/triggers.cc +++ b/riscv/triggers.cc @@ -184,7 +184,7 @@ void itrigger_t::tdata1_write(processor_t * const proc, const reg_t val, const b action = legalize_action(get_field(val, CSR_ITRIGGER_ACTION)); } -match_result_t itrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept +std::optional<match_result_t> itrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept { state_t * const state = proc->get_state(); if ((state->prv == PRV_M && !m) || @@ -192,7 +192,7 @@ match_result_t itrigger_t::detect_trap_match(processor_t * const proc, const tra (!state->v && state->prv == PRV_U && !u) || (state->v && state->prv == PRV_S && !vs) || (state->v && state->prv == PRV_U && !vu)) { - return match_result_t(false); + return std::nullopt; } auto xlen = proc->get_xlen(); @@ -203,7 +203,7 @@ match_result_t itrigger_t::detect_trap_match(processor_t * const proc, const tra hit = true; return match_result_t(true, TIMING_AFTER, action); } - return match_result_t(false); + return std::nullopt; } reg_t etrigger_t::tdata1_read(const processor_t * const proc) const noexcept @@ -236,7 +236,7 @@ void etrigger_t::tdata1_write(processor_t * const proc, const reg_t val, const b action = legalize_action(get_field(val, CSR_ETRIGGER_ACTION)); } -match_result_t etrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept +std::optional<match_result_t> etrigger_t::detect_trap_match(processor_t * const proc, const trap_t& t) noexcept { state_t * const state = proc->get_state(); if ((state->prv == PRV_M && !m) || @@ -244,7 +244,7 @@ match_result_t etrigger_t::detect_trap_match(processor_t * const proc, const tra (!state->v && state->prv == PRV_U && !u) || (state->v && state->prv == PRV_S && !vs) || (state->v && state->prv == PRV_U && !vu)) { - return match_result_t(false); + return std::nullopt; } auto xlen = proc->get_xlen(); @@ -255,7 +255,7 @@ match_result_t etrigger_t::detect_trap_match(processor_t * const proc, const tra hit = true; return match_result_t(true, TIMING_AFTER, action); } - return match_result_t(false); + return std::nullopt; } module_t::module_t(unsigned count) : triggers(count) { @@ -367,8 +367,8 @@ std::optional<match_result_t> module_t::detect_trap_match(const trap_t& t) noexc return std::nullopt; for (auto trigger: triggers) { - match_result_t result = trigger->detect_trap_match(proc, t); - if (result.fire) + auto result = trigger->detect_trap_match(proc, t); + if (result.has_value()) return result; } return std::nullopt; diff --git a/riscv/triggers.h b/riscv/triggers.h index a782acc..4d7e365 100644 --- a/riscv/triggers.h +++ b/riscv/triggers.h @@ -69,7 +69,7 @@ public: virtual std::optional<match_result_t> detect_memory_access_match(processor_t UNUSED * const proc, operation_t UNUSED operation, reg_t UNUSED address, std::optional<reg_t> UNUSED data) noexcept { return std::nullopt; } - virtual match_result_t detect_trap_match(processor_t UNUSED * const proc, const trap_t UNUSED & t) noexcept { return match_result_t(false); } + virtual std::optional<match_result_t> detect_trap_match(processor_t UNUSED * const proc, const trap_t UNUSED & t) noexcept { return std::nullopt; } protected: action_t legalize_action(reg_t val) const noexcept; @@ -95,7 +95,7 @@ public: bool get_dmode() const override { return dmode; } virtual action_t get_action() const override { return action; } - virtual match_result_t detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override; + virtual std::optional<match_result_t> detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override; private: bool dmode; @@ -117,7 +117,7 @@ public: bool get_dmode() const override { return dmode; } virtual action_t get_action() const override { return action; } - virtual match_result_t detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override; + virtual std::optional<match_result_t> detect_trap_match(processor_t * const proc, const trap_t& t) noexcept override; private: bool dmode; |