VMM OpenSource - sv/std_lib/vmm_data_macros_utils.sv

sv/std_lib/vmm_data_macros_utils.sv expanded source

00001 // 
00002 // -------------------------------------------------------------
00003 //    Copyright 2004-2008 Synopsys, Inc.
00004 //    All Rights Reserved Worldwide
00005 // 
00006 //    Licensed under the Apache License, Version 2.0 (the
00007 //    "License"); you may not use this file except in
00008 //    compliance with the License.  You may obtain a copy of
00009 //    the License at
00010 // 
00011 //        http://www.apache.org/licenses/LICENSE-2.0
00012 // 
00013 //    Unless required by applicable law or agreed to in
00014 //    writing, software distributed under the License is
00015 //    distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
00016 //    CONDITIONS OF ANY KIND, either express or implied.  See
00017 //    the License for the specific language governing
00018 //    permissions and limitations under the License.
00019 // -------------------------------------------------------------
00020 // 
00021 
00022 
00023 `define vmm_data_member_scalar_count(__name,__count) \
00024  \
00025 	   __count = $bits(__name)/8; \
00026 	   if ($bits(__name)%8 ) __count++; 
00027 
00028 
00029 `define vmm_data_member_scalar_pack(__pack,__maxbits,__count,__offset) \
00030  \
00031            if (__pack.size() < __offset+__count) \
00032               __pack = new [__offset+__count] (__pack); \
00033    	   for (int i=0; i < __count; i++) begin \
00034 	      __pack[__offset+i] = __maxbits[i*8 +: 8]; \
00035 	   end 
00036 
00037 
00038 `define vmm_data_member_scalar_unpack(__unpack,__maxbits,__count,__offset) \
00039  \
00040    	   for (int i=0; i < __count; i++) begin \
00041 	       __maxbits[i*8 +: 8] = __unpack[__offset+i]; \
00042 	   end 
00043 
00044 
00045 `define vmm_data_member_scalar_packint(__pack,__index,__st,__endian) \
00046  \
00047         if (__pack.size() < __st+4) \
00048             __pack = new [__st+4] (__pack); \
00049 	if ( __endian) begin \
00050            {__pack[__st],__pack[__st+1],__pack[__st+2],__pack[__st+3]} = __index; \
00051 	end \
00052 	else begin \
00053            {__pack[__st+3],__pack[__st+2],__pack[__st+1],__pack[__st]} = __index; \
00054 	end
00055 
00056 
00057 `define vmm_data_member_scalar_unpackint(__unpack,__index,__st,__endian) \
00058  \
00059 	if ( __endian) begin \
00060            __index = {__unpack[__st],__unpack[__st+1],__unpack[__st+2],__unpack[__st+3]}; \
00061 	end \
00062 	else begin \
00063            __index = {__unpack[__st+3],__unpack[__st+2],__unpack[__st+1],__unpack[__st]}; \
00064 	end
00065 
00066 
00067 `define vmm_data_member_update_offset(__offset,__count) \
00068  \
00069 	 __offset = __offset + __count;
00070 
00071 
00072 `define vmm_data_member_enum_set_name(__name,__stemp,__index) \
00073  \
00074 	  if ( __stemp == __name.name()) begin \
00075                    __name = __name; \
00076                    __index =0; \
00077           end \
00078 	  else begin \
00079               while ( __stemp != __name.name()) begin \
00080                    __name = __name.next(); \
00081                    if ( __index > __name.num() ) \
00082                        break; \
00083                    __index++; \
00084                end \
00085            end