Function returns 1 only if all reg_fields in a uvm_reg are "RO"

Hi ,

I am currently writing a function which returns 1 only when all fields within a uvm_reg are RO . So if I have combination of fields like “RW” , “RO” , etc the function should return 0 .


function bit ONLY_RO ( uvm_field fld[$] ) ; // fld Contains all uvm_fields within a uvm_reg ( Obtained via get_fields( ) method ) 

  foreach( fld[i] )
  begin
     // if ( ! fld[i].get_access inside {"RO"} ) // [QA] Compilation Error !!
   if ( fld[i].get_access inside { "RW" , "W1C" , "WO" }  // [QB]
   begin
    return 0 ;
   end  
end
   return 1 ;
endfunction


[QA] get_access returns a string so using ! is illegal . Any alternative ?
[QB] This is what I am going for now , but this code is subject to access of the project . I want a generic code so that if I have a new access policy ( apart from RW or W1C or WO ) the logic should still work .

In reply to MICRO_91:

[AA] ! has higher precedence than inside. So you can write

 !(fld[i].get_access inside {"RO"} )

You can simplify this to

function bit ONLY_RO ( uvm_field fld[$] ) ;
  return fld.and(field) with (field.get_access inside {"RO"});
ebnfunction

[AB] Not exactly sure what you mean, but you can put the access codes in an array

string policy[] = { "RW" , "W1C" , "WO" }
...
filed..get_access inside {policy}