error: cannot convert 'bool' to 'svLogic*' in assignment

2.7k Views Asked by At

We are working on the system verilog DPI calls. While compiling the C++ file we are getting the errors like this:

error: cannot convert 'bool' to 'svLogic*' in assignment

Here svLogic is 4-state variable.

The VCS simulator has predefined function in DirectC method vc_putScalar, where vc_putScalar is "Passes the value of a scalar reg or bit to a vc_handle by reference". The vc_handle is input or output variable in function. With VCS we could use: vc_putScalar(mem_req_rdy, mm->req_cmd_ready());

We are working on Modelsim questa simulator so DirectC will not work. We are tiring to modify the vc_putScalar into w.r.t of DPI IEEE Std 1800-2012 standards. We changed the predefined function logic into this: mem_req_rdy = mm->req_cmd_ready(); Here mem_req_rdy is svLogic and req_cmd_ready is bool.

4

There are 4 best solutions below

0
On BEST ANSWER

Given that you had:

vc_putScalar(mem_req_rdy, mm->req_cmd_ready());

I am guessing that mem_req_rdy is of pointer type svLogic* (since from the name of the function vc_putScalar, it seems that it intends to change the value held in mem_req_rdy). So you need to dereference the pointer as in the following statement:

*mem_req_rdy = mm->req_cmd_ready();
0
On

error: cannot convert 'bool' to 'svLogic*' in assignment

svLogic seems to be a pointer. You cannot assign a bool value to a pointer variable.

TYPE* p = /* initialized somehow */;
bool b = /* initialized somehow */;
p = b;  // YOU CANNOT DO THAT
2
On

You may want to re-think your DPI interface. Does your C code really need to deal with 4-state logic?

In many cases, no access routines are needed to access arguments passed between the two languages. This is always true is the passing types are C-compatible (int, byte,string, and unpacked arrays and structs of these types).

For example this DirectC example

SV:
extern "C" void foo(input bit A, output bit B);
C:
void foo(vc_handle A, vc_handle B)
{ vc_scalar value;
  value = vc_getSalar(A);
 vc_putScalar(B,value);
}

translates to this DPI code

SV:
import "DPI-C" void foo(input bit A, output bit B);
C:
void foo(svBit A, svBit *B)
{ svBit value;
  value = A;
 *B = value;
}

We strongly recommend that Questa DPI users use the vlog -dpiheader filename.h, switch and then their C code should #include that file. Then the compiler will catch any mismatches in the syntax of argument handling.

0
On

svLogic is a typedef of unsiged char, see IEEE Std 1800-2012 § H.10.1.1 Scalars of type bit and logic

For a bool to svLogic conversion you need a function, not a direct assignment. If the bool value is true, then the svLogic should be assigned to sv_1. If the bool value is falue, then the svLogic should be assigned to sv_0.

Something like this should work:

mem_req_rdy = mm->req_cmd_ready() ? sv_1 : sv_0;