From 9c7c178f70f8a78dc638d5f4301407893351b4fd Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Mon, 10 May 2010 14:17:25 -0700 Subject: added save state for ic regs map common --- host/lib/ic_reg_maps/common.py | 41 +++++++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) (limited to 'host/lib/ic_reg_maps/common.py') diff --git a/host/lib/ic_reg_maps/common.py b/host/lib/ic_reg_maps/common.py index 4aa1ef35e..e27c2816d 100644 --- a/host/lib/ic_reg_maps/common.py +++ b/host/lib/ic_reg_maps/common.py @@ -29,30 +29,59 @@ COMMON_TMPL = """\ \#ifndef INCLUDED_$(name.upper())_HPP \#define INCLUDED_$(name.upper())_HPP +\#include \#include +\#include +\#include -struct $(name)_t{ - +class $(name)_t{ +public: #for $reg in $regs - #if $reg.get_enums() + #if $reg.get_enums() enum $reg.get_type(){ #for $i, $enum in enumerate($reg.get_enums()) #set $end_comma = ',' if $i < len($reg.get_enums())-1 else '' $(reg.get_name().upper())_$(enum[0].upper()) = $enum[1]$end_comma #end for }; - #end if + #end if $reg.get_type() $reg.get_name(); #end for $(name)_t(void){ - #for $reg in $regs + _state = NULL; + #for $reg in $regs $reg.get_name() = $reg.get_default(); - #end for + #end for + } + + ~$(name)_t(void){ + delete _state; } $body + void save_state(void){ + if (_state == NULL) _state = new $(name)_t(); + #for $reg in $regs + _state->$reg.get_name() = this->$reg.get_name(); + #end for + } + + template std::set get_changed_addrs(void){ + if (_state == NULL) throw std::runtime_error("no saved state"); + //check each register for changes + std::set addrs; + #for $reg in $regs + if(_state->$reg.get_name() != this->$reg.get_name()){ + addrs.insert($reg.get_addr()); + } + #end for + return addrs; + } + +private: + $(name)_t *_state; }; \#endif /* INCLUDED_$(name.upper())_HPP */ -- cgit v1.2.3