Add regression tests for binding task/function arguments by name

Check that binding task and function arguments by name works as expected.
Also check that is works for the various variations of invoking a class
constructor.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
This commit is contained in:
Lars-Peter Clausen 2022-12-31 19:02:01 -08:00
parent f6a51bc9db
commit 250c456f94
80 changed files with 1009 additions and 0 deletions

View File

@ -0,0 +1,25 @@
// Check that binding task arguments by name is supported.
module test;
class B;
integer val;
function new(integer a, integer b);
val = a + b * 10;
endfunction
endclass
class C extends B(.b(2), .a(1));
endclass
initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,26 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.
module test;
class B;
integer val;
function new(integer a, integer b, integer c);
val = a + b * 10 + c * 100;
endfunction
endclass
class C extends B(1, .c(3), .b(2));
endclass
initial begin
C c;
c = new;
if (c.val == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,27 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.
module test;
class B;
integer val;
function new(integer a, integer b = 2);
val = a + b * 10;
endfunction
endclass
class C extends B(.a(1), .b());
endclass
initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B(.b(2), .c(1)); // This should fail. `c` is not an arugment
// of the base constructor.
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B(.a(1), .a(2)); // This should fail. `a` is provided twice
// as a named argument.
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B(1, .a(2)); // This should fail. `a` is provided both as a
// positional and named argument.
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B(.a(2), 1); // This should fail. Positional arguments must
// precede named arguments.
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,20 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.
module test;
class B;
function new(integer a);
$display("FAILED");
endfunction
endclass
class C extends B(.a()); // This should fail. `a` has no default value.
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,28 @@
// Check that binding task arguments by name is supported.
module test;
class B;
integer val;
function new(integer a, integer b);
val = a + b * 10;
endfunction
endclass
class C extends B;
function new;
super.new(.b(2), .a(1));
endfunction
endclass
initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,29 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.
module test;
class B;
integer val;
function new(integer a, integer b, integer c);
val = a + b * 10 + c * 100;
endfunction
endclass
class C extends B;
function new;
super.new(1, .c(3), .b(2));
endfunction
endclass
initial begin
C c;
c = new;
if (c.val == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,30 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.
module test;
class B;
integer val;
function new(integer a, integer b = 2);
val = a + b * 10;
endfunction
endclass
class C extends B;
function new;
super.new(.a(1), .b());
endfunction
endclass
initial begin
C c;
c = new;
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B;
function new;
super.new(.b(2), .c(1)); // This should fail. `c` is not an arugment of
// the base constructor.
endfunction
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B;
function new;
super.new(.a(1), .a(2)); // This should fail. `a` is provided twice as a
// named argument.
endfunction
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,24 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B;
function new;
super.new(1, .a(2)); // This should fail. `a` is provided both as a
// positional and named argument.
endfunction
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,24 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.
module test;
class B;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
class C extends B;
function new;
super.new(.a(2), 1); // This should fail. Positional arguments must
// precede named arguments.
endfunction
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,23 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.
module test;
class B;
function new(integer a);
$display("FAILED");
endfunction
endclass
class C extends B;
function new;
super.new(.a()); // This should fail. `a` has no default value.
endfunction
endclass
initial begin
C c;
c = new;
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that binding task arguments by name is supported.
module test;
function integer f(integer a, integer b);
return a + b * 10;
endfunction
initial begin
integer x;
x = f(.b(2), .a(1));
if (x == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,20 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.
module test;
function integer f(integer a, integer b, integer c);
return a + b * 10 + c * 100;
endfunction
initial begin
integer x;
x = f(1, .c(3), .b(2));
if (x == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,21 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.
module test;
function integer f(integer a, integer b = 2);
return a + b * 10;
endfunction
initial begin
integer x;
x = f(.a(1), .b());
if (x == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,15 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist
module test;
function f(integer a, integer b);
$display("FAILED");
endfunction
initial begin
integer x;
x = f(.b(2), .c(1)); // This should fail. `c` is not an arugment of `f`.
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.
module test;
function f(integer a, integer b);
$display("FAILED");
endfunction
initial begin
integer x;
x = f(.a(1), .a(2)); // This should fail. `a` is provided twice as a named
// argument.
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.
module test;
function f(integer a, integer b);
$display("FAILED");
endfunction
initial begin
integer x;
x = f(1, .a(2)); // This should fail. `a` is provided both as a positional
// and named argument.
end
endmodule

View File

@ -0,0 +1,16 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.
module test;
function f(integer a, integer b);
$display("FAILED");
endfunction
initial begin
integer x;
x = f(.a(2), 1); // This should fail. Positional arguments must precede
// named arguments.
end
endmodule

View File

@ -0,0 +1,15 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.
module test;
function f(integer a);
$display("FAILED");
endfunction
initial begin
integer x;
x = f(.a()); // This should fail. `a` has no default value.
end
endmodule

View File

@ -0,0 +1,22 @@
// Check that binding task arguments by name is supported.
module test;
class C;
integer val;
function new(integer a, integer b);
val = a + b * 10;
endfunction
endclass
initial begin
C c;
c = new(.b(2), .a(1));
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,23 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.
module test;
class C;
integer val;
function new(integer a, integer b, integer c);
val = a + b * 10 + c * 100;
endfunction
endclass
initial begin
C c;
c = new(1, .c(3), .b(2));
if (c.val == 321) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,24 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.
module test;
class C;
integer val;
function new(integer a, integer b = 2);
val = a + b * 10;
endfunction
endclass
initial begin
C c;
c = new(.a(1), .b());
if (c.val == 21) begin
$display("PASSED");
end else begin
$display("FAILED");
end
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist
module test;
class C;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
initial begin
C c;
c = new(.b(2), .c(1)); // This should fail. `c` is not an arugment of the
// constructor.
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.
module test;
class C;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
initial begin
C c;
c = new(.a(1), .a(2)); // This should fail. `a` is provided twice as a named
// argument.
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.
module test;
class C;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
initial begin
C c;
c = new(1, .a(2)); // This should fail. `a` is provided both as a positional
// and named argument.
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that an error is reported trying to provide a positional argument to a
// function after a named argument.
module test;
class C;
function new(integer a, integer b);
$display("FAILED");
endfunction
endclass
initial begin
C c;
c = new(.a(2), 1); // This should fail. Positional arguments must precede
// named arguments.
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.
module test;
class C;
function new(integer a);
$display("FAILED");
endfunction
endclass
initial begin
C c;
c = new(.a()); // This should fail. `a` has no default value.
end
endmodule

View File

@ -0,0 +1,17 @@
// Check that binding task arguments by name is supported.
module test;
task t(integer a, integer b);
if (a == 1 && b == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
initial begin
t(.b(2), .a(1));
end
endmodule

View File

@ -0,0 +1,18 @@
// Check that binding task arguments by name is supported and that a mix of
// positional and named arguments is supported.
module test;
task t(integer a, integer b, integer c);
if (a == 1 && b == 2 && c == 3) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
initial begin
t(1, .c(3), .b(2));
end
endmodule

View File

@ -0,0 +1,19 @@
// Check that binding task arguments by name is supported and that an empty
// value can be bound to the name, in which case the default argument value
// should be used.
module test;
task t(integer a, integer b = 2);
if (a == 1 && b == 2) begin
$display("PASSED");
end else begin
$display("FAILED");
end
endtask
initial begin
t(.a(1), .b());
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that an error is reported when trying to bind an argument by nae that
// does not exist
module test;
task t(integer a, integer b);
$display("FAILED");
endtask
initial begin
t(.b(2), .c(1));
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that an error is reported when trying to bind the same argument by name
// multiple times.
module test;
task t(integer a, integer b);
$display("FAILED");
endtask
initial begin
t(.a(1), .a(2));
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that an error is reported when trying to bind an argument by name that
// is also provided as a positional argument.
module test;
task t(integer a, integer b);
$display("FAILED");
endtask
initial begin
t(1, .a(2));
end
endmodule

View File

@ -0,0 +1,15 @@
// Check that an error is reported trying to provide a positional argument to a
// task after a named argument.
module test;
task t(integer a, integer b);
$display("FAILED");
endtask
initial begin
t(.a(2), 1); // This should fail. Positional arguments must precede
// named arguments.
end
endmodule

View File

@ -0,0 +1,14 @@
// Check that an error is reported when binding an empty value to an argument by
// name and the argument does not have a default value.
module test;
task t(integer a);
$display("FAILED");
endtask
initial begin
t(.a()); // This should fail. `a` has no default value.
end
endmodule

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_base1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_base2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_base3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_base_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_base_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_base_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_base_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_base_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_chained1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_chained2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_chained3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_chained_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_chained_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_chained_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_chained_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_chained_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_func1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_func2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_func3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_func_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_func_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_func_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_func_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_func_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_new1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_new2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_new3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_new_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_new_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_new_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_new_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_new_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_task1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_task2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "normal",
"source" : "sv_named_arg_task3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_task_fail1.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_task_fail2.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_task_fail3.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_task_fail4.v",
"iverilog-args" : [ "-g2005-sv" ]
}

View File

@ -0,0 +1,5 @@
{
"type" : "CE",
"source" : "sv_named_arg_task_fail5.v",
"iverilog-args" : [ "-g2005-sv" ]
}