2012-04-13 03:08:20 +02:00
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Break always into sensitivity block domains
|
|
|
|
|
//
|
2019-11-08 04:33:59 +01:00
|
|
|
// Code available from: https://verilator.org
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2022-01-01 14:26:40 +01:00
|
|
|
// Copyright 2003-2022 by Wilson Snyder. This program is free software; you
|
2020-03-21 16:24:24 +01:00
|
|
|
// can redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 23:07:57 +02:00
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2020-03-21 16:24:24 +01:00
|
|
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
2006-08-26 13:35:28 +02:00
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
2020-06-06 18:25:20 +02:00
|
|
|
// AstSenTree related utilities.
|
2006-08-26 13:35:28 +02:00
|
|
|
//*************************************************************************
|
2019-10-05 02:17:11 +02:00
|
|
|
|
2021-03-04 03:57:07 +01:00
|
|
|
#ifndef VERILATOR_V3SENTREE_H_
|
|
|
|
|
#define VERILATOR_V3SENTREE_H_
|
2006-08-26 13:35:28 +02:00
|
|
|
|
2006-12-18 20:20:45 +01:00
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
|
|
|
|
#include "V3Ast.h"
|
2021-05-21 02:41:46 +02:00
|
|
|
#include "V3Hasher.h"
|
2018-10-14 19:43:24 +02:00
|
|
|
|
2020-08-15 16:03:34 +02:00
|
|
|
#include <unordered_set>
|
2006-08-26 13:35:28 +02:00
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Collect SenTrees under the entire scope
|
|
|
|
|
// And provide functions to find/add a new one
|
|
|
|
|
|
2020-11-19 03:32:16 +01:00
|
|
|
class SenTreeFinder final {
|
2006-08-26 13:35:28 +02:00
|
|
|
private:
|
|
|
|
|
// STATE
|
2021-10-17 11:29:17 +02:00
|
|
|
AstTopScope* const m_topScopep; // Top scope to add global SenTrees to
|
2022-02-05 17:04:48 +01:00
|
|
|
std::unordered_set<VNRef<AstSenTree>> m_trees; // Set of global SenTrees
|
2009-01-21 22:56:50 +01:00
|
|
|
|
2020-06-06 18:25:20 +02:00
|
|
|
VL_UNCOPYABLE(SenTreeFinder);
|
2009-01-21 22:56:50 +01:00
|
|
|
|
2020-06-06 18:25:20 +02:00
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
2021-10-17 11:29:17 +02:00
|
|
|
SenTreeFinder()
|
2021-10-17 12:40:44 +02:00
|
|
|
: SenTreeFinder(v3Global.rootp()) {}
|
|
|
|
|
|
|
|
|
|
explicit SenTreeFinder(AstNetlist* netlistp)
|
|
|
|
|
: m_topScopep{netlistp->topScopep()} {
|
2021-10-17 11:29:17 +02:00
|
|
|
// Gather existing global SenTrees
|
2022-02-05 17:04:48 +01:00
|
|
|
for (AstSenTree* senTreep = m_topScopep->senTreesp(); senTreep;
|
|
|
|
|
senTreep = VN_AS(senTreep->nextp(), SenTree)) {
|
|
|
|
|
m_trees.emplace(*senTreep);
|
2021-10-17 11:29:17 +02:00
|
|
|
}
|
|
|
|
|
}
|
2020-04-04 14:31:14 +02:00
|
|
|
|
2006-08-26 13:35:28 +02:00
|
|
|
// METHODS
|
2021-10-17 12:40:44 +02:00
|
|
|
|
2022-02-05 17:04:48 +01:00
|
|
|
// Return a global AstSenTree equivalent to the given senTreep.
|
2021-10-17 12:40:44 +02:00
|
|
|
// If no such global AstSenTree exists create one and add it to the stored AstTopScope.
|
2020-06-06 18:25:20 +02:00
|
|
|
AstSenTree* getSenTree(AstSenTree* senTreep) {
|
2022-02-05 17:04:48 +01:00
|
|
|
auto it = m_trees.find(*senTreep);
|
|
|
|
|
// If match found, return it.
|
|
|
|
|
if (it != m_trees.end()) return &(*it).get();
|
|
|
|
|
|
|
|
|
|
// Not found, create a new one
|
|
|
|
|
AstSenTree* const newSenTreep = senTreep->cloneTree(false);
|
|
|
|
|
m_topScopep->addSenTreep(newSenTreep);
|
|
|
|
|
m_trees.emplace(*newSenTreep);
|
|
|
|
|
return newSenTreep;
|
2006-08-26 13:35:28 +02:00
|
|
|
}
|
2021-10-17 12:40:44 +02:00
|
|
|
|
|
|
|
|
// Return the global combinational AstSenTree.
|
|
|
|
|
// If no such global SenTree exists create one and add it to the stored AstTopScope.
|
|
|
|
|
AstSenTree* getComb() {
|
|
|
|
|
FileLine* const fl = m_topScopep->fileline();
|
|
|
|
|
AstSenTree* const combp = new AstSenTree{fl, new AstSenItem{fl, AstSenItem::Combo()}};
|
|
|
|
|
AstSenTree* const resultp = getSenTree(combp);
|
|
|
|
|
VL_DO_DANGLING(combp->deleteTree(), combp); // getSenTree clones, so can delete
|
|
|
|
|
return resultp;
|
|
|
|
|
}
|
2006-08-26 13:35:28 +02:00
|
|
|
};
|
|
|
|
|
|
2019-05-19 22:13:13 +02:00
|
|
|
#endif // Guard
|