Skip to content

Calling tasks with string valued arguments #25

Closed
@penguali

Description

@penguali

Hi Matthew,

I am currently trying to call SystemVerilog task from Python, which takes a string argument.
The task is defined under the InitiatorImpl class as follows:

virtual task print_arg(output int unsigned retval, input string argument);
    $display(The argument is %s", argument);
endtask

On the Python API side, I have defined the following async function:

@hif.imp
async def print_arg(self, argument : str) -> ct.c_uint32:
        pass

The task inside hdl_call_if_api is defined under the invokeTask as follows:

"print_arg": begin
                int unsigned __retval;
                string __argument = pyhdl_if::string(pyhdl_if::PyTuple_GetItem(args, 0));
                print_arg(
                    __retval, 
                    __argument);
                retval = pyhdl_if::PyLong_FromLong(__retval);

This is causing the following error:

Illegal syntax for a package reference name (string)

As an alternative I tried packing the string on SV's side as a bit array, thus changing pyhdl_if::string to pyhdl_if::PyLong_AsLong and adjusting the types in all classes.

This allowed me to run the test without a problem, however, the string is not passed properly.
Do you have any suggestions on how I could pass the strings correctly?

I appreciate the help.
Ali

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions