struct_union.h File Reference

Contains functions for handling SystemVerilog structs/unions. More...

#include "defines.h"

Go to the source code of this file.

Functions

su_memberstruct_union_add_member_void (struct_union *su)
 Allocates, initializes and adds a new void member to the given struct/union.
su_memberstruct_union_add_member_sig (struct_union *su, vsignal *sig)
 Allocates, initializes and adds a new signal member to the given struct/union.
su_memberstruct_union_add_member_typedef (struct_union *su, typedef_item *tdi)
 Allocates, initializes and adds a new typedef member to the given struct/union.
su_memberstruct_union_add_member_enum (struct_union *su, enum_item *ei)
 Allocates, initializes and adds a new enum member to the given struct/union.
su_memberstruct_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_unionstruct_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.
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.

Detailed Description

Contains functions for handling SystemVerilog structs/unions.

Author:
Trevor Williams (phase1geo@gmail.com)
Date:
9/13/2007

Function Documentation

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.

Returns:
Returns a pointer to the newly allocated struct/union member.

Allocates, initializes and adds an 'enum' type struct/union member to the given struct/union.

Parameters:
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.

Returns:
Returns a pointer to the newly allocated struct/union member.

Allocates, initializes and adds a 'signal' type struct/union member to the given struct/union.

Parameters:
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.

Returns:
Returns a pointer to the newly allocated struct/union member.

Allocates, initializes and adds a 'struct/union' type struct/union member to the given struct/union.

Parameters:
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.

Returns:
Returns a pointer to the newly allocated struct/union member.

Allocates, initializes and adds a 'typedef' type struct/union member to the given struct/union.

Parameters:
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.

Returns:
Returns a pointer to the newly allocated struct/union member.

Allocates, initializes and adds a 'void' type struct/union member to the given struct/union.

Parameters:
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.

Returns:
Returns a pointer to the newly allocated struct/union.

Allocates, intializes and adds a new struct/union structure to the given functional unit's list of struct/union members.

Parameters:
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.

Parameters:
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.

Parameters:
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 }

Generated on Sun Nov 21 00:55:41 2010 for Covered by  doxygen 1.6.3