From 8f274f5b1dc74ace7d5b17a09096b3d1c16e1678 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 10 Dec 2012 14:40:43 +0900 Subject: [PATCH] Add convenience functions for getting a def's offset and size. --- tools/qfcc/include/def.h | 18 ++++++++++++++++++ tools/qfcc/source/def.c | 15 +++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/tools/qfcc/include/def.h b/tools/qfcc/include/def.h index 774a16242..3f917bcb8 100644 --- a/tools/qfcc/include/def.h +++ b/tools/qfcc/include/def.h @@ -254,6 +254,24 @@ void initialize_def (struct symbol_s *sym, struct type_s *type, \return 1 if the defs overlap, 0 otherwise. */ int def_overlap (def_t *d1, def_t *d2); + +/** Convenience function for obtaining a def's actual offset. + + Takes care of an alias def's relative offset. + + \param def The def of which to obtain the offset. May be an alias def. + \return The actual offset of the def in the def's defspace. +*/ +int def_offset (def_t *def); + +/** Convenience function for obtaining a def's size. + + Whether the def is an alias or not is irrelevant. + + \param def The def of which to obtain the size. + \return The size of the def. +*/ +int def_size (def_t *def); //@} #endif//__def_h diff --git a/tools/qfcc/source/def.c b/tools/qfcc/source/def.c index 82b79b9e1..ebe8bf7b5 100644 --- a/tools/qfcc/source/def.c +++ b/tools/qfcc/source/def.c @@ -611,3 +611,18 @@ def_overlap (def_t *d1, def_t *d2) return 1; return 0; } + +int +def_offset (def_t *def) +{ + int offset = def->offset; + if (def->alias) + offset += def->alias->offset; + return offset; +} + +int +def_size (def_t *def) +{ + return type_size (def->type); +}