Jump to content

When is the MACROs executed?


Recommended Posts

hi,

macros are not executed - macros are expanded. lets take a simple example (created with DVT macro expand)

    `uvm_component_utils_begin(test)
     `uvm_field_int(cfg_field_set, UVM_DEFAULT)
     `uvm_field_int(cfg_field_notset, UVM_DEFAULT)
   `uvm_component_utils_end

get finally expanded into a typedef, some functions, a const type name

   typedef uvm_component_registry #(test,"test") type_id; 
  static function type_id get_type(); 
    return type_id::get(); 
  endfunction 
  virtual function uvm_object_wrapper get_object_type(); 
    return type_id::get(); 
  endfunction 

  const static string type_name = "test"; 
  virtual function string get_type_name (); 
    return type_name; 
  endfunction  

  function void __m_uvm_field_automation (uvm_object tmp_data__, 
                                    int what__, 
                                    string str__); 
  begin 
    test local_data__; /* Used for copy and compare */ 
    typedef test ___local_type____; 
    string string_aa_key; /* Used for associative array lookups */ 
    /* Type is verified by uvm_object::compare() */ 
    super.__m_uvm_field_automation(tmp_data__, what__, str__); 
    if(tmp_data__ != null) 
      /* Allow objects in same hierarchy to be copied/compared */ 
      if(!$cast(local_data__, tmp_data__)) return; 

 begin 
   case (what__) 
     UVM_CHECK_FIELDS: 
       begin 
         __m_uvm_status_container.do_field_check("cfg_field_set", this); 
       end 
     UVM_COPY: 
       begin 
         if(local_data__ == null) return; 
         if(!((UVM_DEFAULT)&UVM_NOCOPY)) cfg_field_set = local_data__.cfg_field_set; 
       end 
     UVM_COMPARE: 
       begin 
         if(local_data__ == null) return; 
         if(!((UVM_DEFAULT)&UVM_NOCOMPARE)) begin 
           if(cfg_field_set !== local_data__.cfg_field_set) begin 
              void'(__m_uvm_status_container.comparer.compare_field("cfg_field_set", cfg_field_set, local_data__.cfg_field_set, $bits(cfg_field_set))); 
              if(__m_uvm_status_container.comparer.result && (__m_uvm_status_container.comparer.show_max <= __m_uvm_status_container.comparer.result)) return; 
           end 
         end 
       end 
     UVM_PACK: 
       if(!((UVM_DEFAULT)&UVM_NOPACK)) begin 
         if($bits(cfg_field_set) <= 64) __m_uvm_status_container.packer.pack_field_int(cfg_field_set, $bits(cfg_field_set)); 
         else __m_uvm_status_container.packer.pack_field(cfg_field_set, $bits(cfg_field_set)); 
       end 
     UVM_UNPACK: 
       if(!((UVM_DEFAULT)&UVM_NOPACK)) begin 
         if($bits(cfg_field_set) <= 64) cfg_field_set =  __m_uvm_status_container.packer.unpack_field_int($bits(cfg_field_set)); 
         else cfg_field_set = __m_uvm_status_container.packer.unpack_field($bits(cfg_field_set)); 
       end 
     UVM_RECORD: 

 if(!((UVM_DEFAULT)&UVM_NORECORD)) begin 
   __m_uvm_status_container.recorder.record_field("cfg_field_set", cfg_field_set,  $bits(cfg_field_set), uvm_radix_enum'((UVM_DEFAULT)&(UVM_RADIX))); 
 end 
     UVM_PRINT: 
       if(!((UVM_DEFAULT)&UVM_NOPRINT)) begin 
         __m_uvm_status_container.printer.print_int("cfg_field_set", cfg_field_set, $bits(cfg_field_set), uvm_radix_enum'((UVM_DEFAULT)&UVM_RADIX)); 
       end 
     UVM_SETINT: 
       begin 
         bit matched; 
         __m_uvm_status_container.scope.set_arg("cfg_field_set"); 
         matched = uvm_is_match(str__, __m_uvm_status_container.scope.get()); 
         if(matched) begin 
           if((UVM_DEFAULT)&UVM_READONLY) begin 
             uvm_report_warning("RDONLY", $sformatf("Readonly argument match %s is ignored",  
                __m_uvm_status_container.get_full_scope_arg()), UVM_NONE); 
           end 
           else begin 
             if (__m_uvm_status_container.print_matches) 
                 uvm_report_info("STRMTC", {"set_int()", ": Matched string ", str__, " to field ", __m_uvm_status_container.get_full_scope_arg()}, UVM_LOW); 
             cfg_field_set = uvm_object::__m_uvm_status_container.bitstream; 
             uvm_object::__m_uvm_status_container.status = 1; 
           end 
         end 
         __m_uvm_status_container.scope.unset_arg("cfg_field_set"); 
       end 
   endcase 
 end

 begin 
   case (what__) 
     UVM_CHECK_FIELDS: 
       begin 
         __m_uvm_status_container.do_field_check("cfg_field_notset", this); 
       end 
     UVM_COPY: 
       begin 
         if(local_data__ == null) return; 
         if(!((UVM_DEFAULT)&UVM_NOCOPY)) cfg_field_notset = local_data__.cfg_field_notset; 
       end 
     UVM_COMPARE: 
       begin 
         if(local_data__ == null) return; 
         if(!((UVM_DEFAULT)&UVM_NOCOMPARE)) begin 
           if(cfg_field_notset !== local_data__.cfg_field_notset) begin 
              void'(__m_uvm_status_container.comparer.compare_field("cfg_field_notset", cfg_field_notset, local_data__.cfg_field_notset, $bits(cfg_field_notset))); 
              if(__m_uvm_status_container.comparer.result && (__m_uvm_status_container.comparer.show_max <= __m_uvm_status_container.comparer.result)) return; 
           end 
         end 
       end 
     UVM_PACK: 
       if(!((UVM_DEFAULT)&UVM_NOPACK)) begin 
         if($bits(cfg_field_notset) <= 64) __m_uvm_status_container.packer.pack_field_int(cfg_field_notset, $bits(cfg_field_notset)); 
         else __m_uvm_status_container.packer.pack_field(cfg_field_notset, $bits(cfg_field_notset)); 
       end 
     UVM_UNPACK: 
       if(!((UVM_DEFAULT)&UVM_NOPACK)) begin 
         if($bits(cfg_field_notset) <= 64) cfg_field_notset =  __m_uvm_status_container.packer.unpack_field_int($bits(cfg_field_notset)); 
         else cfg_field_notset = __m_uvm_status_container.packer.unpack_field($bits(cfg_field_notset)); 
       end 
     UVM_RECORD: 

 if(!((UVM_DEFAULT)&UVM_NORECORD)) begin 
   __m_uvm_status_container.recorder.record_field("cfg_field_notset", cfg_field_notset,  $bits(cfg_field_notset), uvm_radix_enum'((UVM_DEFAULT)&(UVM_RADIX))); 
 end 
     UVM_PRINT: 
       if(!((UVM_DEFAULT)&UVM_NOPRINT)) begin 
         __m_uvm_status_container.printer.print_int("cfg_field_notset", cfg_field_notset, $bits(cfg_field_notset), uvm_radix_enum'((UVM_DEFAULT)&UVM_RADIX)); 
       end 
     UVM_SETINT: 
       begin 
         bit matched; 
         __m_uvm_status_container.scope.set_arg("cfg_field_notset"); 
         matched = uvm_is_match(str__, __m_uvm_status_container.scope.get()); 
         if(matched) begin 
           if((UVM_DEFAULT)&UVM_READONLY) begin 
             uvm_report_warning("RDONLY", $sformatf("Readonly argument match %s is ignored",  
                __m_uvm_status_container.get_full_scope_arg()), UVM_NONE); 
           end 
           else begin 
             if (__m_uvm_status_container.print_matches) 
                 uvm_report_info("STRMTC", {"set_int()", ": Matched string ", str__, " to field ", __m_uvm_status_container.get_full_scope_arg()}, UVM_LOW); 
             cfg_field_notset = uvm_object::__m_uvm_status_container.bitstream; 
             uvm_object::__m_uvm_status_container.status = 1; 
           end 
         end 
         __m_uvm_status_container.scope.unset_arg("cfg_field_notset"); 
       end 
   endcase 
 end

    end 
  endfunction

Link to comment
Share on other sites

when are the codes exectured as follow in uvm_registry.svh:

local static this_type me = get();

// Function: get

//

// Returns the singleton instance of this type. Type-based factory operation

// depends on there being a single proxy instance for each registered type.

static function this_type get();

if (me == null) begin

uvm_factory f = uvm_factory::get();

me = new;

f.register(me);

end

return me;

endfunction

whether is it or not in line ' typedef uvm_component_registry #(test,"test") type_id; ' ?

Link to comment
Share on other sites

The specialization of any parametrized class, whether it is a typedef or the declaration of a class variable, creates the space for all static variables once the type exists. There is no need to construct an object of that class type; all the static variables of all class types are initialized at time 0 before any always or initial blocks execute. See section 8.24 of the 1800-2009 LRM

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...