sEMU
载入中...
搜索中...
未找到
wrapper.hpp
浏览该文件的文档.
1#pragma once
2
3#include "sEMU/core.hpp"
4#include <cstdint>
5#include <string>
6
14private:
15 const Core* core_;
16
17public:
18 explicit CoreCommitState(const Core* core) noexcept : core_(core) {}
19
20 [[nodiscard]] inline bool is_commit_valid() const noexcept {
21 return core_->is_commit_valid();
22 }
23
24 [[nodiscard]] inline uint32_t get_commit_pc() const noexcept {
25 return core_->get_commit_pc();
26 }
27
28 [[nodiscard]] inline uint32_t get_commit_wdata() const noexcept {
29 return core_->get_commit_wdata();
30 }
31
32 [[nodiscard]] inline uint8_t get_commit_rd() const noexcept {
33 return core_->get_commit_rd();
34 }
35
36 [[nodiscard]] inline bool is_commit_wen() const noexcept {
37 return core_->is_commit_wen();
38 }
39
40 [[nodiscard]] inline uint32_t get_reg_by_name(const std::string& name) const noexcept {
41 return core_->get_reg_by_name(name);
42 }
43
44 [[nodiscard]] inline const Core* get_core() const noexcept {
45 return core_;
46 }
47};
48
56private:
58 bool is_end_;
59
60 inline void advance() noexcept {
61 if (core_ && core_->state == CoreState::RUNNING) {
62 core_->step();
63 if (core_->state != CoreState::RUNNING) {
64 is_end_ = true;
65 }
66 } else {
67 is_end_ = true;
68 }
69 }
70
71public:
72 explicit CoreIterator(Core* core, bool is_end = false) noexcept
73 : core_(core), is_end_(is_end || (core && core_->state != CoreState::RUNNING)) {}
74
75 inline CoreIterator& operator++() noexcept {
76 advance();
77 return *this;
78 }
79
80 [[nodiscard]] inline CoreCommitState operator*() const noexcept {
81 return CoreCommitState{core_};
82 }
83
84 [[nodiscard]] inline bool operator!=(const CoreIterator& other) const noexcept {
85 return this->is_end_ != other.is_end_;
86 }
87
88 [[nodiscard]] inline bool operator==(const CoreIterator& other) const noexcept {
89 return this->is_end_ == other.is_end_;
90 }
91};
92
100private:
102
103public:
104 explicit CoreSimRange(Core* core) noexcept : core_(core) {}
105
106 [[nodiscard]] inline CoreIterator begin() noexcept {
107 return CoreIterator{core_, false};
108 }
109
110 [[nodiscard]] inline CoreIterator end() const noexcept {
111 return CoreIterator{core_, true};
112 }
113};
114
121template <typename Range, typename Action>
122inline void run_simulation(Range&& range, Action&& action) noexcept {
123 for (auto state : range) {
124 action(state);
125 }
126}
状态代理 (Proxy Pattern)
定义 wrapper.hpp:13
bool is_commit_valid() const noexcept
定义 wrapper.hpp:20
uint8_t get_commit_rd() const noexcept
定义 wrapper.hpp:32
const Core * get_core() const noexcept
定义 wrapper.hpp:44
uint32_t get_commit_wdata() const noexcept
定义 wrapper.hpp:28
uint32_t get_commit_pc() const noexcept
定义 wrapper.hpp:24
CoreCommitState(const Core *core) noexcept
定义 wrapper.hpp:18
bool is_commit_wen() const noexcept
定义 wrapper.hpp:36
const Core * core_
定义 wrapper.hpp:15
uint32_t get_reg_by_name(const std::string &name) const noexcept
定义 wrapper.hpp:40
迭代器封装 (Iterator Pattern)
定义 wrapper.hpp:55
bool operator==(const CoreIterator &other) const noexcept
定义 wrapper.hpp:88
CoreIterator & operator++() noexcept
定义 wrapper.hpp:75
bool operator!=(const CoreIterator &other) const noexcept
定义 wrapper.hpp:84
CoreIterator(Core *core, bool is_end=false) noexcept
定义 wrapper.hpp:72
void advance() noexcept
定义 wrapper.hpp:60
Core * core_
定义 wrapper.hpp:57
CoreCommitState operator*() const noexcept
定义 wrapper.hpp:80
bool is_end_
定义 wrapper.hpp:58
CoreIterator end() const noexcept
定义 wrapper.hpp:110
CoreSimRange(Core *core) noexcept
定义 wrapper.hpp:104
Core * core_
定义 wrapper.hpp:101
CoreIterator begin() noexcept
定义 wrapper.hpp:106
处理器核心仿真封装类
定义 core.hpp:28
CoreState
仿真核心 (Core) 的当前运行状态枚举
定义 core.hpp:10
@ RUNNING
核心正在正常运行并执行指令
定义 core.hpp:12
void run_simulation(Range &&range, Action &&action) noexcept
泛型主执行器 (Generic Algorithm)
定义 wrapper.hpp:122