# UVM\_REG\_BLOCK from UVM\_REG

**URL:** <https://verificationacademy.com/forums/t/uvm-reg-block-from-uvm-reg/34476>\
**Category:** UVM\
**Tags:** UVM, uvm\_reg, RAL\
**Created:** [May 21, 2018, 5:58am UTC](https://verificationacademy.com/forums/t/uvm-reg-block-from-uvm-reg/34476 "2018-05-21T05:58:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nikhilsingla4u](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/n/2bfe46/32.png) [@nikhilsingla4u](https://verificationacademy.com/forums/u/nikhilsingla4u)\
**Post date:** [May 21, 2018, 5:58am UTC](https://verificationacademy.com/forums/t/uvm-reg-block-from-uvm-reg/34476/1 "2018-05-21T05:58:59Z")

</div>

I want a handle of uvm\_reg\_block in uvm\_reg as I want to write some different register from this reg\_block . I am providing the exact scenario below .  
**Reg\_block and Register declaration :**

class ral\_reg\_1 extends override\_reg; uvm\_reg\_field ID;

```
function new(string name = "ral_reg_1");
endfunction: new

```

virtual function void build();  
this.ID = uvm\_reg\_field::type\_id::create(“ID”,get\_full\_name());  
this.ID.configure(this, 32, 0, “RO”, 0, 8’h0, 0, 0, 1);  
endfunction: build

```
`uvm_object_utils(ral_reg_1)

```

endclass : ral\_reg\_1

class reg\_block\_1 extends uvm\_reg\_block;  
rand ral\_reg\_1 block\_1\_reg\_1;  
int is\_int;  
function new(string name = “reg\_block\_1”);  
super.new(name, build\_coverage(UVM\_NO\_COVERAGE));  
endfunction: new

virtual function void build();  
uvm\_config\_db#(int)::get(null,“”,“is\_int”, is\_int) ;  
this.block\_1\_reg\_1 = ral\_reg\_1::type\_id::create(“block\_1\_reg\_1”,get\_full\_name());  
this.block\_1\_reg\_1.configure(this, null, “”);  
this.block\_1\_reg\_1.build();  
endfunction : build

```
`uvm_object_utils(reg_block_1)

```

endclass : reg\_block\_1

Now I am extending uvm\_reg to override reg as I want different functionality when reg.write is called .I am showing example of integer , but I need multiple things from parent on basis of which reg.write will respond .Error location is in comments .  
**code :**  
  
class override\_reg extends uvm\_reg;

```
`uvm_object_utils(override_reg)
function new(string name = "override_reg");
	super.new(name, 32,build_coverage(UVM_NO_COVERAGE));
endfunction: new

```

task write(output uvm\_status\_e status,  
input uvm\_reg\_data\_t value,  
input uvm\_path\_e path = UVM\_DEFAULT\_PATH,  
input uvm\_reg\_map map = null,  
input uvm\_sequence\_base parent = null,  
input int prior = -1,  
input uvm\_object extension = null,  
input string fname = “”,  
input int lineno = 0);

// create an abstract transaction for this operation  
uvm\_reg\_item rw;  
uvm\_reg\_block reg\_blk,reg\_blk\_p,blks[$];  
$display(“Overidden”);  
XatomicX(1);

set(value);

rw = uvm\_reg\_item::type\_id::create(“write\_item”,get\_full\_name());  
rw.element = this;  
rw.element\_kind = UVM\_REG;  
rw.kind = UVM\_WRITE;  
rw.value[0] = value;  
rw.path = path;  
rw.map = map;  
rw.parent = parent;  
rw.prior = prior;  
rw.extension = extension;  
rw.fname = fname;  
rw.lineno = lineno;

do\_write(rw);  
reg\_blk = get\_parent();  
$display(“Overidden %s and indirect = %h”, reg\_blk.get\_name(),reg\_blk.is\_int); //Seeing error here , is\_int not found  
//I tried $cast also but same error , Is there any way to do this ? I don’t want to do typedef parent class and use handle of parent class , as I need to get it using get\_parent only ( parent keeps on changing)

status = rw.status;

XatomicX(0);

endtask  
endclass

Issue I have explained in comments .Please let me know how this can be achieved .

---

<div class="post-metadata">

**Author:** ![warnerrs](https://verificationacademy.com/forums/letter_avatar_proxy/v4/letter/w/858c86/32.png) [@warnerrs](https://verificationacademy.com/forums/u/warnerrs)\
**Post date:** [May 22, 2018, 3:14am UTC](https://verificationacademy.com/forums/t/uvm-reg-block-from-uvm-reg/34476/2 "2018-05-22T03:14:22Z")

</div>

_In reply to [nikhilverif](https://verificationacademy.com/forums/t/uvm-reg-block-from-uvm-reg/34476):_

> 

//I tried $cast also but same error , Is there any way to do this ? I don’t want to do typedef parent class and use handle of parent class , as I need to get it using get\_parent only ( parent keeps on changing)

For the code you show above, $cast’ing to reg\_block\_1 should work, but based on your comment I’m guessing you have multiple extensions of uvm\_reg\_block. In that case, $cast won’t work as you need a common type to cast to.

Before I suggest a solution, why are you doing this? What are you trying to accomplish? uvm\_reg is very opinionated about how you do things, and if you’re re-writing write() method it strikes me that there is probably a different way to accomplish your goal that is more in harmony with the architecture of uvm\_reg.

-Ryan
