2020-08-15 15:43:53 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Plan for Hierarchical Verilation
|
|
|
|
|
//
|
|
|
|
|
// Code available from: https://verilator.org
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2026-01-27 02:24:34 +01:00
|
|
|
// 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-FileCopyrightText: 2003-2026 Wilson Snyder
|
2023-01-21 02:42:30 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2020-08-15 15:43:53 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_V3HIERBLOCK_H_
|
|
|
|
|
#define VERILATOR_V3HIERBLOCK_H_
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
#include "verilatedos.h"
|
|
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
#include "V3Ast.h"
|
|
|
|
|
#include "V3Graph.h"
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
2022-01-08 18:01:39 +01:00
|
|
|
#include <unordered_map>
|
2020-11-26 02:57:30 +01:00
|
|
|
#include <unordered_set>
|
2022-08-05 11:56:57 +02:00
|
|
|
#include <utility>
|
2020-08-15 15:43:53 +02:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
class AstNetlist;
|
2022-01-08 17:18:23 +01:00
|
|
|
class AstNodeModule;
|
2024-08-21 11:30:59 +02:00
|
|
|
class AstParamTypeDType;
|
2020-08-15 15:43:53 +02:00
|
|
|
class AstVar;
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
class V3HierGraph final : public V3Graph {
|
2020-08-15 15:43:53 +02:00
|
|
|
public:
|
2025-10-09 21:41:23 +02:00
|
|
|
V3HierGraph() = default;
|
|
|
|
|
~V3HierGraph() = default;
|
|
|
|
|
VL_UNCOPYABLE(V3HierGraph);
|
|
|
|
|
VL_UNMOVABLE(V3HierGraph);
|
2024-08-21 11:30:59 +02:00
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
// Write command line arguments to .f files for child Verilation run
|
|
|
|
|
void writeCommandArgsFiles(bool forMkJson) const VL_MT_DISABLED;
|
|
|
|
|
void writeParametersFiles() const VL_MT_DISABLED;
|
|
|
|
|
static string topCommandArgsFilename(bool forMkJson) VL_MT_DISABLED;
|
2024-08-21 11:30:59 +02:00
|
|
|
};
|
|
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
class V3HierBlock final : public V3GraphVertex {
|
|
|
|
|
VL_RTTI_IMPL(V3HierBlock, V3GraphVertex)
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
// TYPES
|
|
|
|
|
// Parameter name, stringified value
|
2024-08-21 11:30:59 +02:00
|
|
|
using StrGParam = std::pair<string, string>;
|
|
|
|
|
using StrGParams = std::vector<StrGParam>;
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
// MEMBERS
|
2025-10-09 21:41:23 +02:00
|
|
|
const AstModule* const m_modp; // Hierarchical block module
|
|
|
|
|
// Value parameters that are overridden by #(.param(value)) syntax.
|
|
|
|
|
const std::vector<AstVar*> m_params;
|
|
|
|
|
// Types parameters that are overridden by #(.param(value)) syntax.
|
|
|
|
|
const std::vector<AstParamTypeDType*> m_typeParams;
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
// METHODS
|
2025-10-09 21:41:23 +02:00
|
|
|
static StrGParams stringifyParams(const std::vector<AstVar*>& params,
|
2024-08-21 11:30:59 +02:00
|
|
|
bool forGOption) VL_MT_DISABLED;
|
2020-08-15 15:43:53 +02:00
|
|
|
|
|
|
|
|
public:
|
2025-10-09 21:41:23 +02:00
|
|
|
// CONSTRUCTORs
|
|
|
|
|
V3HierBlock(V3HierGraph* graphp, const AstModule* modp, const std::vector<AstVar*>& params,
|
|
|
|
|
const std::vector<AstParamTypeDType*>& typeParams)
|
|
|
|
|
: V3GraphVertex{graphp}
|
|
|
|
|
, m_modp{modp}
|
|
|
|
|
, m_params{params}
|
|
|
|
|
, m_typeParams{typeParams} {}
|
2025-09-09 23:39:44 +02:00
|
|
|
~V3HierBlock() VL_MT_DISABLED = default;
|
2025-10-09 21:41:23 +02:00
|
|
|
VL_UNCOPYABLE(V3HierBlock);
|
|
|
|
|
VL_UNMOVABLE(V3HierBlock);
|
2020-08-15 15:43:53 +02:00
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
const AstModule* modp() const { return m_modp; }
|
2020-08-15 15:43:53 +02:00
|
|
|
|
2025-10-08 15:40:17 +02:00
|
|
|
// For emitting Makefile and build definition JSON
|
|
|
|
|
VStringList commandArgs(bool forMkJson) const VL_MT_DISABLED;
|
2025-09-28 02:51:37 +02:00
|
|
|
VStringList hierBlockArgs() const VL_MT_DISABLED;
|
2023-09-25 04:12:23 +02:00
|
|
|
string hierPrefix() const VL_MT_DISABLED;
|
2024-07-14 15:34:54 +02:00
|
|
|
string hierSomeFilename(bool withDir, const char* prefix,
|
|
|
|
|
const char* suffix) const VL_MT_DISABLED;
|
|
|
|
|
string hierWrapperFilename(bool withDir) const VL_MT_DISABLED;
|
|
|
|
|
string hierMkFilename(bool withDir) const VL_MT_DISABLED;
|
|
|
|
|
string hierLibFilename(bool withDir) const VL_MT_DISABLED;
|
|
|
|
|
string hierGeneratedFilenames(bool withDir) const VL_MT_DISABLED;
|
2020-09-19 01:13:49 +02:00
|
|
|
// Returns the original HDL file if it is not included in v3Global.opt.vFiles().
|
2023-09-25 04:12:23 +02:00
|
|
|
string vFileIfNecessary() const VL_MT_DISABLED;
|
2022-12-03 00:46:38 +01:00
|
|
|
// Write command line arguments to .f file for this hierarchical block
|
2025-10-08 15:40:17 +02:00
|
|
|
void writeCommandArgsFile(bool forMkJson) const VL_MT_DISABLED;
|
2024-08-21 11:30:59 +02:00
|
|
|
void writeParametersFile() const VL_MT_DISABLED;
|
2025-10-08 15:40:17 +02:00
|
|
|
string commandArgsFilename(bool forMkJson) const VL_MT_DISABLED;
|
2024-08-21 11:30:59 +02:00
|
|
|
string typeParametersFilename() const VL_MT_DISABLED;
|
2025-10-09 21:41:23 +02:00
|
|
|
|
|
|
|
|
// For Graphviz dumps only
|
|
|
|
|
std::string name() const override { return m_modp->prettyNameQ(); }
|
|
|
|
|
std::string dotShape() const override { return "box"; }
|
2020-08-15 15:43:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
2025-10-09 21:41:23 +02:00
|
|
|
// Pass to create hierarcical block graph
|
2020-08-15 15:43:53 +02:00
|
|
|
|
2025-10-09 21:41:23 +02:00
|
|
|
class V3Hierarchical final {
|
2020-08-15 15:43:53 +02:00
|
|
|
public:
|
2025-10-09 21:41:23 +02:00
|
|
|
static void createGraph(AstNetlist* nodep) VL_MT_DISABLED;
|
2020-08-15 15:43:53 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // guard
|