MikePopoloski / slang

SystemVerilog compiler and language services
MIT License
550 stars 117 forks source link

Support unsized arrays as DPI argument types #520

Closed MikePopoloski closed 1 year ago

MikePopoloski commented 1 year ago

This has been added.

jrudess commented 1 year ago

Seeing some type mismatches errors for this.

slangtest97.sv:10:34: error: value of type 'dynamic array of byte' cannot be assigned to type 'unpacked array [] of byte'
        P::write_buf("file.txt", write_buffer);
                                 ^~~~~~~~~~~~
package P;
    import "DPI-C" context function int write_buf(string outfile, byte write_buf[]);
endpackage

class C;
    function main();
        int rc;
        byte write_buffer[];

        P::write_buf("file.txt", write_buffer);
    endfunction
endclass
MikePopoloski commented 1 year ago

Ah, I did not realize dynamic arrays were still allowed here, but upon closer reading of the LRM they're only disallowed in DPI exports, not imports. I will fix.

MikePopoloski commented 1 year ago

Should be fixed now.

jrudess commented 1 year ago

Ah, interesting -- I'll need to go through the LRM more. I didn't include the read_buff function in the first example because I assumed it was just the same issue. At least VCS/Questa are compiling the following code, but I've only tested runtime sim functionality in VCS.

slangtest98.sv:10:40: error: value of type 'unpacked array [] of byte' cannot be assigned to type 'dynamic array of byte'
        rc = P::read_buf("input.data", read_buffer);
                                       ^~~~~~~~~~~
package P;
    import "DPI-C" context function int read_buf(string outfile, output byte buffer[]);
endpackage

class C;
    function main();
        int rc;
        byte read_buffer[];

        rc = P::read_buf("input.data", read_buffer);
    endfunction
endclass
MikePopoloski commented 1 year ago

Yeah, I overlooked output parameter handling. The conversion goes in the opposite direction.

MikePopoloski commented 1 year ago

Should be fixed for output args.