Files
lucisv/crates/vlog_formatter/tests/cases/dpi_export.cases
T
lucioandClaude Fable 5 ee0faa2e18 Modport method prototypes, unnamed DPI formals, and the const ref comment gap
TODO section 30 (coverage_gaps M13, corrected).
A modport port may be a method prototype - import task drive(int x),
export function int get() - parsed by Parser::parse_tf_header, the
one header parse parse_function_decl and parse_task_decl now
destructure, printed by Fmt::tf_header, bound as Target::InScope
(IEEE 1800-2017 25.5: a modport names a member of its own interface)
with the formals declared in a scope of their own; one prototype per
import/export group, the LRM's comma list still a clean error
(recorded narrowing). A DPI import's formals may be unnamed
(35.5.5) behind parse_tf_ports(allow_unnamed), the empty-name
convention documented on TfArg::name, every other caller unchanged
and a non-DPI unnamed formal still an error at its position. M13's
const half was misfiled - const ref already parsed - but the probe
found the unowned gap in const /*c*/ ref, now TfArg::after_const.
Proof: 3 223 tests / 48 binaries, corpus 814/820, 4 807 corpus +
opentitan files byte-identical to 0.33.0 (zero population), QA's
adversarial probes and consumer audit of the possibly-empty names.

docs/features/interface-dpi-arms/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-09-03 02:27:24 -07:00

320 lines
8.7 KiB
Plaintext

# a DPI import split across lines collapses onto one when it fits
# corpus/ibex/dv/cs_registers/env/env_dpi.sv:7
package p;
import "DPI-C"
function void env_final();
endpackage
----
package p;
import "DPI-C" function void env_final();
endpackage
====
# a DPI import's argument list breaks like any other, one per line
# corpus/ibex/dv/cs_registers/reg_driver/reg_dpi.sv:8
package p;
import "DPI-C"
function void monitor_tick (
input string name,
input bit rst_n,
input bit [1:0] csr_op,
input bit [11:0] csr_addr,
input bit [31:0] csr_wdata,
input bit [31:0] csr_rdata);
endpackage
----
package p;
import "DPI-C" function void monitor_tick(
input string name,
input bit rst_n,
input bit [1:0] csr_op,
input bit [11:0] csr_addr,
input bit [31:0] csr_wdata,
input bit [31:0] csr_rdata
);
endpackage
====
# a DPI import with no port list at all, returning `chandle`
# corpus/ibex/dv/verilator/simple_system_cosim/ibex_simple_system_cosim_checker.sv:29
module m;
import "DPI-C" function chandle get_spike_cosim;
endmodule
----
module m;
import "DPI-C" function chandle get_spike_cosim;
endmodule
====
# `context` keeps its place, and packed multi-dimensional argument types survive
# corpus/ibex/vendor/lowrisc_ip/ip/prim/dv/prim_ascon/ascon_model_dpi/ascon_model_dpi_pkg.sv:8
package p;
import "DPI-C" context function void c_dpi_ascon_round(
input bit[4:0][7:0][7:0] data_i,
input bit[7:0] round_i,
output bit[4:0][7:0][7:0] data_o
);
endpackage
----
package p;
import "DPI-C" context function void c_dpi_ascon_round(
input bit [4:0][7:0][7:0] data_i,
input bit [7:0] round_i,
output bit [4:0][7:0][7:0] data_o
);
endpackage
====
# arguments without a direction keyword, and an unsized unpacked dimension
# corpus/ibex/vendor/lowrisc_ip/ip/prim/dv/prim_present/crypto_dpi_present/crypto_dpi_present_pkg.sv:12
package p;
import "DPI-C" function chandle c_dpi_present_mk(int unsigned key_size,
bit [127:0] key);
import "DPI-C" context function void c_dpi_aead_encrypt(output byte unsigned ct[],
input byte unsigned msg[]);
endpackage
----
package p;
import "DPI-C" function chandle c_dpi_present_mk(int unsigned key_size, bit [127:0] key);
import "DPI-C" context function void c_dpi_aead_encrypt(
output byte unsigned ct [],
input byte unsigned msg []
);
endpackage
====
# `longint unsigned` returns and arguments
# corpus/ibex/vendor/lowrisc_ip/ip/prim/dv/prim_prince/crypto_dpi_prince/crypto_dpi_prince_pkg.sv:14
package p;
import "DPI-C" context function longint c_dpi_prince_encrypt(
input longint unsigned data,
input int unsigned num_half_rounds
);
endpackage
----
package p;
import "DPI-C" context function longint c_dpi_prince_encrypt(
input longint unsigned data,
input int unsigned num_half_rounds
);
endpackage
====
# a `pure` DPI import, and a DPI-imported task
package p;
import "DPI-C" pure function int clog2( input int x );
import "DPI-C" context task tick(input int cycles);
endpackage
----
package p;
import "DPI-C" pure function int clog2(input int x);
import "DPI-C" context task tick(input int cycles);
endpackage
====
# the `c_identifier =` linkage-name spelling, on an import and on an export
package p;
import "DPI-C" my_c_name=function void f(input int x);
import "DPI-C" context other_name = task t();
export "DPI-C" exported_c_name = function f;
endpackage
----
package p;
import "DPI-C" my_c_name = function void f(input int x);
import "DPI-C" context other_name = task t();
export "DPI-C" exported_c_name = function f;
endpackage
====
# a DPI export next to the function it names
# corpus/ibex/examples/simple_system/rtl/ibex_simple_system.sv:369
module m;
export "DPI-C" function mhpmcounter_num;
function automatic int unsigned mhpmcounter_num();
return 0;
endfunction
endmodule
----
module m;
export "DPI-C" function mhpmcounter_num;
function automatic int unsigned mhpmcounter_num();
return 0;
endfunction
endmodule
====
# a DPI export inside a generate block, under a directive
# corpus/ibex/rtl/ibex_if_stage.sv:378
module m;
if (1) begin : g
`ifndef SYNTHESIS
export "DPI-C" function simutil_get_scramble_key;
export "DPI-C" task simutil_tick;
`endif
end
endmodule
----
module m;
if (1) begin : g
`ifndef SYNTHESIS
export "DPI-C" function simutil_get_scramble_key;
export "DPI-C" task simutil_tick;
`endif
end
endmodule
====
# a wildcard package re-export
# corpus/ibex/dv/uvm/core_ibex/common/ibex_mem_intf_agent/ibex_mem_intf_agent_pkg.sv:28
package p;
export ibex_mem_intf_pkg::* ;
endpackage
----
package p;
export ibex_mem_intf_pkg::*;
endpackage
====
# a package re-export naming individual items
# corpus/ibex/vendor/lowrisc_ip/dv/sv/csr_utils/csr_utils_pkg.sv:10
package p;
import dv_base_reg_pkg::*;
export dv_base_reg_pkg::csr_field_t,dv_base_reg_pkg::decode_csr_or_field;
endpackage
----
package p;
import dv_base_reg_pkg::*;
export dv_base_reg_pkg::csr_field_t, dv_base_reg_pkg::decode_csr_or_field;
endpackage
====
# `export *::*;` — the LRM's re-export-everything form (no corpus hits)
package p;
export * :: *;
endpackage
----
package p;
export *::*;
endpackage
====
# comments cling to a DPI import: leading, trailing, and inside the arg list
package p;
// what it does
import "DPI-C" function void f( // opens
input int a, // first
// about b
input int b /* before comma */,
input int c
); // done
endpackage
----
package p;
// what it does
import "DPI-C" function void f(
// opens
input int a, // first
// about b
input int b /* before comma */,
input int c
); // done
endpackage
====
# a DPI import and a DPI export inside a `verilog_format: off` fence stay byte-exact
package p;
// verilog_format: off
import "DPI-C" function void f( input int a );
export "DPI-C" function f;
export p2::*;
// verilog_format: on
import "DPI-C" function void g();
endpackage
----
package p;
// verilog_format: off
import "DPI-C" function void f( input int a );
export "DPI-C" function f;
export p2::*;
// verilog_format: on
import "DPI-C" function void g();
endpackage
====
# the header fits at exactly 100 columns and breaks at 101
package p;
import "DPI-C" context function void aaaaaaaaaaaaaaaaaaaaaaaaaa(input int bbbbbbbbb, int ccccccc);
import "DPI-C" context function void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(input int bbbbbbbbb, int ccccccc);
endpackage
----
package p;
import "DPI-C" context function void aaaaaaaaaaaaaaaaaaaaaaaaaa(input int bbbbbbbbb, int ccccccc);
import "DPI-C" context function void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(
input int bbbbbbbbb,
int ccccccc
);
endpackage
====
# an ordinary package import is untouched by the DPI spelling next to it
package p;
import q::*;
import "DPI-C" function void f();
import r::t , s::u;
endpackage
----
package p;
import q::*;
import "DPI-C" function void f();
import r::t, s::u;
endpackage
====
# DPI imports and exports inside a class body
class c;
import "DPI-C" function int c_get(input int i);
export "DPI-C" function sv_put;
function void sv_put(int v);
endfunction
endclass
----
class c;
import "DPI-C" function int c_get(input int i);
export "DPI-C" function sv_put;
function void sv_put(int v);
endfunction
endclass
====
# at compilation-unit scope, outside any package or module
import "DPI-C" function void f(input int a);
export "DPI-C" function g;
export p::*;
----
import "DPI-C" function void f(input int a);
export "DPI-C" function g;
export p::*;
====
====
# an imported prototype's formals may name only their types
# IEEE 1800-2017 35.5.5
package p;
import "DPI-C" function int f(int, chandle);
import "DPI-C" function void g(input int, logic [7:0], int named);
import "DPI-C" context task t(chandle);
endpackage
----
package p;
import "DPI-C" function int f(int, chandle);
import "DPI-C" function void g(input int, logic [7:0], int named);
import "DPI-C" context task t(chandle);
endpackage
====
# a comment where an unnamed formal's name would have been
package p;
import "DPI-C" function int h(int /*why*/, chandle /*and why*/);
endpackage
----
package p;
import "DPI-C" function int h(int /*why*/, chandle /*and why*/);
endpackage
====
# an unnamed formal list long enough to break, one per line
package p;
import "DPI-C" function int a_very_long_imported_function_name(int, chandle, longint unsigned, logic [31:0]);
endpackage
----
package p;
import "DPI-C" function int a_very_long_imported_function_name(
int,
chandle,
longint unsigned,
logic [31:0]
);
endpackage