2023-10-07 05:18:26 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Cleanup stage in V3Width
|
|
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2025-01-01 14:30:25 +01:00
|
|
|
// Copyright 2003-2025 by Wilson Snyder. This program is free software; you
|
2023-10-07 05:18:26 +02:00
|
|
|
// 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
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#ifndef VERILATOR_V3WIDTHREMOVE_H_
|
|
|
|
|
#define VERILATOR_V3WIDTHREMOVE_H_
|
|
|
|
|
|
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3Error.h"
|
|
|
|
|
|
|
|
|
|
// clang-format off
|
|
|
|
|
#ifndef VERILATOR_V3WIDTH_CPP_
|
|
|
|
|
# error "V3WidthRemove for V3Width internal use only"
|
|
|
|
|
#endif
|
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
class WidthRemoveVisitor final : public VNVisitor {
|
|
|
|
|
// METHODS
|
|
|
|
|
VL_DEFINE_DEBUG_FUNCTIONS;
|
|
|
|
|
|
|
|
|
|
void replaceWithSignedVersion(AstNode* nodep, AstNode* newp) {
|
2025-05-23 02:29:32 +02:00
|
|
|
UINFO(6, " Replace " << nodep << " w/ " << newp);
|
2025-05-05 12:31:06 +02:00
|
|
|
nodep->replaceWithKeepDType(newp);
|
2023-10-07 05:18:26 +02:00
|
|
|
VL_DO_DANGLING(pushDeletep(nodep), nodep);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// VISITORS
|
|
|
|
|
void visit(AstSigned* nodep) override {
|
|
|
|
|
VL_DO_DANGLING(replaceWithSignedVersion(nodep, nodep->lhsp()->unlinkFrBack()), nodep);
|
|
|
|
|
}
|
|
|
|
|
void visit(AstUnsigned* nodep) override {
|
|
|
|
|
VL_DO_DANGLING(replaceWithSignedVersion(nodep, nodep->lhsp()->unlinkFrBack()), nodep);
|
|
|
|
|
}
|
|
|
|
|
void visit(AstNode* nodep) override { iterateChildren(nodep); }
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
|
WidthRemoveVisitor() = default;
|
|
|
|
|
~WidthRemoveVisitor() override = default;
|
|
|
|
|
AstNode* mainAcceptEdit(AstNode* nodep) { return iterateSubtreeReturnEdits(nodep); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
|
|
|
|
#endif // Guard
|