From 30686d855044dcefab9f3359c091aea634666295 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 28 Nov 2020 12:43:13 -0500 Subject: [PATCH] Support passing of objects to functions --- src/V3Width.cpp | 1 + test_regress/t/t_class_new.v | 9 +++++++++ test_regress/t/t_class_static_method.v | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/V3Width.cpp b/src/V3Width.cpp index f4a35ce6d..af2a557c5 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -1789,6 +1789,7 @@ private: } } else if (nodep->isIO() && !(VN_IS(nodep->dtypeSkipRefp(), BasicDType) + || VN_IS(nodep->dtypeSkipRefp(), ClassRefDType) || VN_IS(nodep->dtypeSkipRefp(), NodeArrayDType) || VN_IS(nodep->dtypeSkipRefp(), NodeUOrStructDType))) { nodep->v3warn(E_UNSUPPORTED, diff --git a/test_regress/t/t_class_new.v b/test_regress/t/t_class_new.v index ba1506312..811693dc5 100644 --- a/test_regress/t/t_class_new.v +++ b/test_regress/t/t_class_new.v @@ -19,6 +19,11 @@ class ClsArg; function int geta; return imembera; endfunction + static function ClsArg create6; + ClsArg obj; + obj = new(6 - 1); + return obj; + endfunction endclass module t (/*AUTOARG*/); @@ -33,6 +38,10 @@ module t (/*AUTOARG*/); if (c2.imembera != 3) $stop; if (c2.geta() != 3) $stop; + c2 = ClsArg::create6(); + if (c2.imembera != 6) $stop; + if (c2.geta() != 6) $stop; + $write("*-* All Finished *-*\n"); $finish; end diff --git a/test_regress/t/t_class_static_method.v b/test_regress/t/t_class_static_method.v index 1d408aaef..5b518afb3 100644 --- a/test_regress/t/t_class_static_method.v +++ b/test_regress/t/t_class_static_method.v @@ -16,17 +16,34 @@ class Cls; if (x != 23) $stop; return 42; endfunction - endclass : Cls +class OCls; + int i; + static function OCls create(); + OCls o = new; + o.i = 42; + return o; + endfunction + static task test_obj(OCls o); + if (o.i != 42) $stop; + endtask +endclass + module t (/*AUTOARG*/); initial begin int x; + OCls oc; + Cls::static_task(16); x = Cls::static_function(23); $write("Static function result: %d\n", x); if (x != 42) $stop; + + oc = OCls::create(); + OCls::test_obj(oc); + $write("*-* All Finished *-*\n"); $finish; end