[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Simulavr-devel] [PATCH] use static callbacks instead of template param
From: |
panic |
Subject: |
[Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg |
Date: |
Thu, 15 Jun 2017 22:37:00 +0000 |
Hi,
I've looked a bit through the code and discovered that the IOReg class
is implemented as a template class with template instantiations for the
(many) peripherals/HW components.
This leads to a (IMHO) complex class structure/hierarchy (see
...original.png)
After having spent a day trying to understand the motivation for this, I
believe to know it: it is necessary to know the type (peripheral class)
for the callback function/function pointer.
The attached patch is my proposal to fix this and simplify the structure
(see ...without_template.png)
Instead of using a template parameter for every HW type, I'm using
static methods, for instance
> static void SetPcifr(void *this_ptr, unsigned pcifrBit) throw() {
> static_cast<HWPcir*>(this_ptr)->SetPcifr(pcifrBit);
> }
that use a void* as first parameter and then simply wrap the object
methods. In IOReg class we can now drop to explicitly mention the target
type (and instantiate a template class).
In most cases, it is not necessary to manually wrap the getter/setters;
I defined some handy macros for this:
> IOREG_SETGET_UCHAR(HWPort, Pin)
which, in this case, defines two static/class methods (GetPin and
SetPin) in class HWPort.
All the static methods are excluded via #ifndef from SWIG.
I had to rename the GetPin method due to a name ambiguity to GetPhysPin
(returns a Pin& instead of normal GetPin method returning the PINx
register).
(make check runs fine, after fixing a rounfing bug in two ADC test cases)
It would be nice if this change could be added...
Cheers,
panic
classRWMemoryMember__inherit__graph-original.png
Description: PNG image
0001-use-static-callbacks-instead-of-template-param-for-I.patch
Description: Text Data
classRWMemoryMember__inherit__graph-without_template.png
Description: PNG image
- [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg,
panic <=
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, Klaus Rudolph, 2017/06/16
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/16
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/16
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, Klaus Rudolph, 2017/06/17
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/17
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, Michael Hennebry, 2017/06/17
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/17
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/17
- Re: [Simulavr-devel] [PATCH] use static callbacks instead of template param for IOReg, panic, 2017/06/17
- [Simulavr-devel] SBI vs. PINx and interrupt flag registers, Michael Hennebry, 2017/06/19