How to assign value to the function from different class with different enum

I have a common class common

class common;
    extern function bit get_type ( bit [1:0] xact_type );
endclass

function bit get_type ( bit [1:0] xact_type );
    `uvm_info(this.get_type_name(), $sformatf("Type is %h", xact_type), UVM_NONE)
endfunction

and Class A, B, C

class A
    typedef bit [1:0] {
        READ = 0,
        WRITE = 1
    } enum_a_type
    
    enum_a_type a_type;
    
    function void a;
        common.get_type(a_type);
    endfunction
endclass
class B
    typedef bit [1:0] {
        READ = 0,
        WRITE = 1
    } enum_b_type
    
    enum_b_type b_type;
    
    function void b;
        common.get_type(b_type);
    endfunction
endclass
class C
    typedef bit [1:0] {
        READ = 0,
        WRITE = 1
    } enum_c_type
    
    enum_c_type c_type;
    
    function void c;
        common.get_type(c_type);
    endfunction
endclass

And all are work fine, but I wanna print “Type is READ/WRITE” rather than “Type is 0/1”

I try to modify the class common

class common;
    typedef bit [1:0] {
        READ = 0,
        WRITE = 1
    } enum_common_type

    extern function bit get_type ( enum_common_type xact_type );
endclass

function bit get_type ( enum_common_type xact_type );
    `uvm_info(this.get_type_name(), $sformatf("Type is %s", xact_type), UVM_NONE)
endfunction

But it shows compile error:cannot assign a variable type to a value of type

I can’t modify class A, B, C, for it maintained by others.

Is there any method to do this ?

Thanks.

In reply to Jacky40210:

First I would tell the others that it is a bad practice declaring types inside a class. Put them in a sharable package.

You can cast to an enum type

   typedef bit [1:0] {
        READ = 0,
        WRITE = 1
    } enum_common_type
 function bit get_type ( bit [1:0] xact_type );
    enum_common_type xt = enum_common_type'(xact_type);
    `uvm_info(this.get_type_name(), $sformatf("Type is %h", xt.name()), UVM_NONE)
endfunction

In reply to dave_59:

Thanks Dave, it works.

And the

`uvm_info(this.get_type_name(), $sformatf("Type is %h", xt.name()), UVM_NONE)

should be

`uvm_info(this.get_type_name(), $sformatf("Type is %s", xt.name()), UVM_NONE)

Thank you

In reply to dave_59:

Hi Dave, I have one more question

I had tried the following

`uvm_info(this.get_type_name(), $sformatf("Type is %s", enum_common_type'(xact_type)), UVM_NONE)
`uvm_info(this.get_type_name(), $sformatf("Type is %s", xt), UVM_NONE)
`uvm_info(this.get_type_name(), $sformatf("Type is %s", xt.name()), UVM_NONE)

and I got the result

  1. Type is @#$% (garbled code)
  2. Type is WRITE
  3. Type is WRITE

May I know why is 1 not working?

Thank you

In reply to Jacky40210:

Both 1 & 2 should have the same result. You are trying to display a numeric value as an ASCII string. You are supposed to get whatever the ASCII representation of that numeric value.

In reply to dave_59:

I found that it’s tool issue

I change to another tool and got

  1. Type is @#$% (garbled code)
  2. Type is @#$% (garbled code)
  3. Type is WRITE

which is more reasonable.

Thank you