#include "defines.h"
#include "enumerate.h"
#include "struct_union.h"
#include "util.h"
#include "vsignal.h"
Functions | |
static int | struct_union_length (struct_union *su) |
void | struct_union_add_member (struct_union *su, su_member *mem) |
su_member * | struct_union_add_member_void (struct_union *su) |
Allocates, initializes and adds a new void member to the given struct/union. | |
su_member * | struct_union_add_member_sig (struct_union *su, vsignal *sig) |
Allocates, initializes and adds a new signal member to the given struct/union. | |
su_member * | struct_union_add_member_typedef (struct_union *su, typedef_item *tdi) |
Allocates, initializes and adds a new typedef member to the given struct/union. | |
su_member * | struct_union_add_member_enum (struct_union *su, enum_item *ei) |
Allocates, initializes and adds a new enum member to the given struct/union. | |
su_member * | struct_union_add_member_struct_union (struct_union *su, struct_union *sui) |
Allocates, initializes and adds a new struct/union member to the given struct/union. | |
struct_union * | struct_union_create (const char *name, sig_range *range, int type, bool packed, bool is_signed, func_unit *funit) |
Allocates, initializes and adds a new enumerated item to the given functional unit. | |
static void | struct_union_member_dealloc (su_member *mem) |
void | struct_union_dealloc (struct_union *su) |
Deallocates given struct/union. | |
void | struct_union_dealloc_list (func_unit *funit) |
Deallocates struct/union list from given functional unit. |
void struct_union_add_member | ( | struct_union * | su, | |
su_member * | mem | |||
) |
Adds the given struct/union member to the given struct/union member list.
su | Pointer to struct/union to add member to | |
mem | Pointer to struct/union member to add |
References struct_union_s::mem_head, struct_union_s::mem_tail, su_member_s::next, PROFILE, and PROFILE_END.
su_member* struct_union_add_member_enum | ( | struct_union * | su, | |
enum_item * | ei | |||
) |
Allocates, initializes and adds a new enum member to the given struct/union.
Allocates, initializes and adds an 'enum' type struct/union member to the given struct/union.
su | Pointer to struct/union to add member to | |
ei | Pointer to enumerated item to add |
References su_member_s::ei, su_member_s::elem, malloc_safe, su_member_s::pos, PROFILE, PROFILE_END, struct_union_length(), SU_MEMTYPE_ENUM, and su_member_s::type.
00157 { PROFILE(STRUCT_UNION_ADD_MEMBER_ENUM); 00158 00159 su_member* mem; /* Pointer to newly created struct/union member */ 00160 00161 /* Allocate memory for the new member */ 00162 mem = (su_member*)malloc_safe( sizeof( su_member ) ); 00163 00164 /* Initialize the contents of the member */ 00165 mem->type = SU_MEMTYPE_ENUM; 00166 mem->pos = struct_union_length( su ); 00167 mem->elem.ei = ei; 00168 00169 PROFILE_END; 00170 00171 return( mem ); 00172 00173 }
su_member* struct_union_add_member_sig | ( | struct_union * | su, | |
vsignal * | sig | |||
) |
Allocates, initializes and adds a new signal member to the given struct/union.
Allocates, initializes and adds a 'signal' type struct/union member to the given struct/union.
su | Pointer to struct/union to add member to | |
sig | Pointer to signal item to add |
References su_member_s::elem, malloc_safe, su_member_s::pos, PROFILE, PROFILE_END, su_member_s::sig, struct_union_length(), SU_MEMTYPE_SIG, and su_member_s::type.
00105 { PROFILE(STRUCT_UNION_ADD_MEMBER_SIG); 00106 00107 su_member* mem; /* Pointer to newly created struct/union member */ 00108 00109 /* Allocate memory for the new member */ 00110 mem = (su_member*)malloc_safe( sizeof( su_member ) ); 00111 00112 /* Initialize the contents of the member */ 00113 mem->type = SU_MEMTYPE_SIG; 00114 mem->pos = struct_union_length( su ); 00115 mem->elem.sig = sig; 00116 00117 PROFILE_END; 00118 00119 return( mem ); 00120 00121 }
su_member* struct_union_add_member_struct_union | ( | struct_union * | su, | |
struct_union * | sui | |||
) |
Allocates, initializes and adds a new struct/union member to the given struct/union.
Allocates, initializes and adds a 'struct/union' type struct/union member to the given struct/union.
su | Pointer to struct/union to add member to | |
sui | Pointer to struct/union item to add |
References su_member_s::elem, malloc_safe, su_member_s::pos, PROFILE, PROFILE_END, struct_union_length(), su_member_s::su, SU_MEMTYPE_SU, and su_member_s::type.
00183 { PROFILE(STRUCT_UNION_ADD_MEMBER_STRUCT_UNION); 00184 00185 su_member* mem; /* Pointer to newly created struct/union member */ 00186 00187 /* Allocate memory for the new member */ 00188 mem = (su_member*)malloc_safe( sizeof( su_member ) ); 00189 00190 /* Initialize the contents of the member */ 00191 mem->type = SU_MEMTYPE_SU; 00192 mem->pos = struct_union_length( su ); 00193 mem->elem.su = sui; 00194 00195 PROFILE_END; 00196 00197 return( mem ); 00198 00199 }
su_member* struct_union_add_member_typedef | ( | struct_union * | su, | |
typedef_item * | tdi | |||
) |
Allocates, initializes and adds a new typedef member to the given struct/union.
Allocates, initializes and adds a 'typedef' type struct/union member to the given struct/union.
su | Pointer to struct/union to add member to | |
tdi | Pointer to typdef item to add |
References su_member_s::elem, malloc_safe, su_member_s::pos, PROFILE, PROFILE_END, struct_union_length(), SU_MEMTYPE_TYPEDEF, su_member_s::tdi, and su_member_s::type.
00131 { PROFILE(STRUCT_UNION_ADD_MEMBER_TYPEDEF); 00132 00133 su_member* mem; /* Pointer to newly created struct/union member */ 00134 00135 /* Allocate memory for the new member */ 00136 mem = (su_member*)malloc_safe( sizeof( su_member ) ); 00137 00138 /* Initialize the contents of the member */ 00139 mem->type = SU_MEMTYPE_TYPEDEF; 00140 mem->pos = struct_union_length( su ); 00141 mem->elem.tdi = tdi; 00142 00143 PROFILE_END; 00144 00145 return( mem ); 00146 00147 }
su_member* struct_union_add_member_void | ( | struct_union * | su | ) |
Allocates, initializes and adds a new void member to the given struct/union.
Allocates, initializes and adds a 'void' type struct/union member to the given struct/union.
su | Pointer to struct/union to add member to |
References su_member_s::elem, malloc_safe, su_member_s::pos, PROFILE, PROFILE_END, su_member_s::sig, struct_union_length(), SU_MEMTYPE_VOID, and su_member_s::type.
00079 { PROFILE(STRUCT_UNION_ADD_MEMBER_VOID); 00080 00081 su_member* mem; /* Pointer to newly created struct/union member */ 00082 00083 /* Allocate memory for the new member */ 00084 mem = (su_member*)malloc_safe( sizeof( su_member ) ); 00085 00086 /* Initialize the contents of the member */ 00087 mem->type = SU_MEMTYPE_VOID; 00088 mem->pos = struct_union_length( su ); 00089 mem->elem.sig = NULL; 00090 00091 PROFILE_END; 00092 00093 return( mem ); 00094 00095 }
struct_union* struct_union_create | ( | const char * | name, | |
sig_range * | range, | |||
int | type, | |||
bool | packed, | |||
bool | is_signed, | |||
func_unit * | funit | |||
) |
Allocates, initializes and adds a new enumerated item to the given functional unit.
Allocates, intializes and adds a new struct/union structure to the given functional unit's list of struct/union members.
name | Name of struct/union being added | |
range | Pointer to multi-dimensional range associated with this struct/union | |
type | Specifies struct, union or tagged union type of this structure | |
packed | Specifies if this struct/union should be handled as a packed structure or not | |
is_signed | Specifies if this struct/union should be handled as signed or not | |
funit | Pointer to functional unit that contains this struct/union |
References struct_union_s::is_signed, malloc_safe, struct_union_s::mem_head, struct_union_s::mem_tail, struct_union_s::name, struct_union_s::next, struct_union_s::packed, PROFILE, PROFILE_END, strdup_safe, func_unit_s::su_head, func_unit_s::su_tail, and struct_union_s::type.
00214 { PROFILE(STRUCT_UNION_CREATE); 00215 00216 struct_union* su; /* Pointer to newly allocated struct/union structure */ 00217 00218 /* Allocate memory */ 00219 su = (struct_union*)malloc_safe( sizeof( struct_union ) ); 00220 00221 /* Initialize */ 00222 su->name = strdup_safe( name ); 00223 su->type = type; 00224 su->packed = packed; 00225 su->is_signed = is_signed; 00226 su->mem_head = NULL; 00227 su->mem_tail = NULL; 00228 su->next = NULL; 00229 00230 /* Add the new struct/union to the given functional unit */ 00231 if( funit->su_head == NULL ) { 00232 funit->su_head = funit->su_tail = su; 00233 } else { 00234 funit->su_tail->next = su; 00235 funit->su_tail = su; 00236 } 00237 00238 PROFILE_END; 00239 00240 return( su ); 00241 00242 }
void struct_union_dealloc | ( | struct_union * | su | ) |
Deallocates given struct/union.
Deallocates all memory associated with the given struct/union member.
su | Pointer to struct/union to deallocate |
References free_safe, struct_union_s::mem_head, struct_union_s::name, su_member_s::next, PROFILE, PROFILE_END, and struct_union_member_dealloc().
Referenced by struct_union_dealloc_list(), and struct_union_member_dealloc().
00276 { PROFILE(STRUCT_UNION_DEALLOC); 00277 00278 su_member* curr_mem; /* Pointer to current member entry to deallocate */ 00279 su_member* tmp_mem; /* Temporary pointer to current member to deallocate */ 00280 00281 if( su != NULL ) { 00282 00283 /* Deallocate the member list */ 00284 curr_mem = su->mem_head; 00285 while( curr_mem != NULL ) { 00286 tmp_mem = curr_mem; 00287 curr_mem = curr_mem->next; 00288 struct_union_member_dealloc( tmp_mem ); 00289 } 00290 00291 /* Deallocate the name */ 00292 free_safe( su->name, (strlen( su->name ) + 1) ); 00293 00294 /* Deallocate the struct/union itself */ 00295 free_safe( su, sizeof( su_member ) ); 00296 00297 } 00298 00299 PROFILE_END; 00300 00301 }
void struct_union_dealloc_list | ( | func_unit * | funit | ) |
Deallocates struct/union list from given functional unit.
Deallocates the entire list of struct/union structures in the given functional unit.
funit | Pointer to functional unit to remove struct/union list from |
References struct_union_s::next, PROFILE, PROFILE_END, struct_union_dealloc(), func_unit_s::su_head, and func_unit_s::su_tail.
00308 { PROFILE(STRUCT_UNION_DEALLOC_LIST); 00309 00310 struct_union* curr_su; /* Pointer to current struct/union to deallocate */ 00311 struct_union* tmp_su; /* Temporary pointer to current struct/union to deallocate */ 00312 00313 /* Iterate through each struct/union in the list */ 00314 curr_su = funit->su_head; 00315 while( curr_su != NULL ) { 00316 tmp_su = curr_su; 00317 curr_su = curr_su->next; 00318 struct_union_dealloc( tmp_su ); 00319 } 00320 00321 /* Clear the list for future use if necessary */ 00322 funit->su_head = funit->su_tail = NULL; 00323 00324 PROFILE_END; 00325 00326 }
static int struct_union_length | ( | struct_union * | su | ) | [static] |
Counts the number of stored struct/union members in the given struct/union.
su | Pointer to struct/union to count members of |
References struct_union_s::mem_head, su_member_s::next, PROFILE, and PROFILE_END.
Referenced by struct_union_add_member_enum(), struct_union_add_member_sig(), struct_union_add_member_struct_union(), struct_union_add_member_typedef(), and struct_union_add_member_void().
00036 { PROFILE(STRUCT_UNION_LENGTH); 00037 00038 su_member* curr; /* Pointer to current struct/union member */ 00039 int count = 0; /* Number of members counted */ 00040 00041 curr = su->mem_head; 00042 while( curr != NULL ) { 00043 count++; 00044 curr = curr->next; 00045 } 00046 00047 PROFILE_END; 00048 00049 return( count ); 00050 00051 }
static void struct_union_member_dealloc | ( | su_member * | mem | ) | [static] |
Deallocates all memory associated with the given struct/union member.
mem | Pointer to struct/union member to deallocate |
References su_member_s::ei, su_member_s::elem, enumerate_dealloc(), free_safe, PROFILE, PROFILE_END, su_member_s::sig, struct_union_dealloc(), su_member_s::su, SU_MEMTYPE_ENUM, SU_MEMTYPE_SIG, SU_MEMTYPE_SU, SU_MEMTYPE_VOID, su_member_s::type, and vsignal_dealloc().
Referenced by struct_union_dealloc().
00249 { PROFILE(STRUCT_UNION_MEMBER_DEALLOC); 00250 00251 if( mem != NULL ) { 00252 00253 switch( mem->type ) { 00254 case SU_MEMTYPE_VOID : break; 00255 case SU_MEMTYPE_SIG : vsignal_dealloc( mem->elem.sig ); break; 00256 //case SU_MEMTYPE_TYPEDEF : typedef_dealloc( mem->elem.tdi ); break; 00257 case SU_MEMTYPE_ENUM : enumerate_dealloc( mem->elem.ei ); break; 00258 case SU_MEMTYPE_SU : struct_union_dealloc( mem->elem.su ); break; 00259 default : assert( 0 ); break; 00260 } 00261 00262 /* Deallocate the member itself */ 00263 free_safe( mem, sizeof( su_member ) ); 00264 00265 } 00266 00267 PROFILE_END; 00268 00269 }