From 50839725367963cedbe62888735a765c26d70568 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Mon, 28 Apr 2025 19:34:40 -0400 Subject: [PATCH] Internals: Defer AstCast into V3LinkDot, in preparation for future parser --- src/V3Width.cpp | 6 ++++++ src/verilog.y | 3 +-- test_regress/t/t_cast_stream.py | 16 ++++++++++++++++ test_regress/t/t_cast_stream.v | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100755 test_regress/t/t_cast_stream.py create mode 100644 test_regress/t/t_cast_stream.v diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 521f60169..af85e2d28 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -2082,6 +2082,12 @@ class WidthVisitor final : public VNVisitor { nodep->replaceWith(newp); VL_DO_DANGLING(pushDeletep(nodep), nodep); userIterate(newp, m_vup); + } else if (AstNodeDType* const refp = VN_CAST(nodep->dtp(), NodeDType)) { + refp->unlinkFrBack(); + AstNode* const newp = new AstCast{nodep->fileline(), nodep->lhsp()->unlinkFrBack(), + VFlagChildDType{}, refp}; + nodep->replaceWith(newp); + VL_DO_DANGLING(pushDeletep(nodep), nodep); } else { nodep->v3warn(E_UNSUPPORTED, "Unsupported: Cast to " << nodep->dtp()->prettyTypeName()); diff --git a/src/verilog.y b/src/verilog.y index 455f90916..696659c06 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -5150,8 +5150,7 @@ expr: // IEEE: part of expression/constant_expression/ // // expanded from simple_type ps_type_identifier (part of simple_type) // // expanded from simple_type ps_parameter_identifier (part of simple_type) | packageClassScopeE idType yP_TICK '(' expr ')' - { $$ = new AstCast{$3, $5, VFlagChildDType{}, - new AstRefDType{$2, *$2, $1, nullptr}}; } + { $$ = new AstCastParse{$3, $5, new AstRefDType{$2, *$2, $1, nullptr}}; } // | yTYPE__ETC '(' exprOrDataType ')' yP_TICK '(' expr ')' { $$ = new AstCast{$1, $7, VFlagChildDType{}, diff --git a/test_regress/t/t_cast_stream.py b/test_regress/t/t_cast_stream.py new file mode 100755 index 000000000..147fe6faf --- /dev/null +++ b/test_regress/t/t_cast_stream.py @@ -0,0 +1,16 @@ +#!/usr/bin/env python3 +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2025 by Wilson Snyder. This program is free software; you +# can redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +import vltest_bootstrap + +test.scenarios('simulator') + +test.compile() + +test.passes() diff --git a/test_regress/t/t_cast_stream.v b/test_regress/t/t_cast_stream.v new file mode 100644 index 000000000..8ed483e0f --- /dev/null +++ b/test_regress/t/t_cast_stream.v @@ -0,0 +1,33 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2025 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +`define stop $stop +`define checkh(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0); + +typedef enum { + UVM_TLM_READ_COMMAND, + UVM_TLM_WRITE_COMMAND, + UVM_TLM_IGNORE_COMMAND +} uvm_tlm_command_e; + +module t(/*AUTOARG*/); + + initial begin + bit array[] = new [8]; + int unsigned m_length; + uvm_tlm_command_e m_command; + + m_length = 2; + array = '{0, 0, 0, 0, 0, 0, 1, 0}; + array = new [$bits(m_length)] (array); + m_command = uvm_tlm_command_e'({ << bit { array }}); + + `checkh(m_command, 'h40) + $write("*-* All Finished *-*\n"); + $finish; + end + +endmodule