diff options
author | David Brownell <dbrownell@users.sourceforge.net> | 2009-11-05 21:59:39 -0800 |
---|---|---|
committer | David Brownell <dbrownell@users.sourceforge.net> | 2009-11-05 21:59:39 -0800 |
commit | db116b1ea3c77a3c5850fccbce9e0795faa21dda (patch) | |
tree | 9c9f456f726fe99b098324750b6942bf6c2bd497 /src/target/arm720t.h | |
parent | b7e4c26b9bb10e6e0ebfb07e5d43f0d62526cde2 (diff) | |
download | riscv-openocd-db116b1ea3c77a3c5850fccbce9e0795faa21dda.zip riscv-openocd-db116b1ea3c77a3c5850fccbce9e0795faa21dda.tar.gz riscv-openocd-db116b1ea3c77a3c5850fccbce9e0795faa21dda.tar.bz2 |
target: provide container_of()
Provide a cleaner way to handle single inheritance of targets
in C, using the same model Linux does: structs containing other
structs, un-nested via calls to a "container_of()" macro that
are packaged in typesafe inline functions.
Targets already use this containment idiom, but make it much
more complicated because they un-nest using embedded "void *"
pointers ... in chains of up to five per target, which is all
pure needless complication. (Example: arm92x core, arm9tdmi,
arm7_9, armv4_5 ... on top of the base "target" class.)
Applying this scheme consistently simplifies things, and gets
rid of many error-prone untyped pointers. It won't change any
part of the type model though -- it just simplifies things.
(And facilitates more cleanup later on.)
Rule of thumb: where there's an X->arch_info void* pointer,
access to that pointer can and should be removed. It may be
convenient to set up pointers to some of the embedded structs;
and shrink their current "*_common" names (annoyingly long).
Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Diffstat (limited to 'src/target/arm720t.h')
-rw-r--r-- | src/target/arm720t.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/target/arm720t.h b/src/target/arm720t.h index c769626..0689e44 100644 --- a/src/target/arm720t.h +++ b/src/target/arm720t.h @@ -35,4 +35,11 @@ typedef struct arm720t_common_s uint32_t far_reg; } arm720t_common_t; +static inline struct arm720t_common_s * +target_to_arm720(struct target_s *target) +{ + return container_of(target->arch_info, struct arm720t_common_s, + arm7tdmi_common.arm7_9_common.armv4_5_common); +} + #endif /* ARM720T_H */ |