#pragma once #include "debug.h" #include "concept.h" namespace dark { template struct Register { private: static_assert(0 < _Len && _Len <= kMaxLength, "Register: _Len must be in range [1, kMaxLength]."); friend class Visitor; max_size_t _M_old : _Len; max_size_t _M_new : _Len; [[no_unique_address]] debug::DebugValue _M_assigned; void sync() { if (this->_M_assigned) { this->_M_assigned = false; this->_M_old = this->_M_new; } } public: static constexpr bool _Bit_Len = _Len; explicit Register() : _M_old(), _M_new(), _M_assigned() {} Register(Register &&) = delete; Register(const Register &) = delete; Register &operator=(Register &&) = delete; Register &operator=(const Register &rhs) = delete; template _Tp> void operator <= (_Tp &&value) { debug::assert(!this->_M_assigned, "Register is double assigned in this cycle."); this->_M_assigned = true; this->_M_new = static_cast (value); } explicit operator max_size_t() const { return this->_M_old; } }; } // namespace dark