2012-04-13 01:08:20 +00:00
|
|
|
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//*************************************************************************
|
|
|
|
|
// DESCRIPTION: Verilator: Break always into sensitivity block domains
|
|
|
|
|
//
|
2008-04-25 12:14:27 +00:00
|
|
|
|
// Code available from: http://www.veripool.org/verilator
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2018-01-02 23:05:06 +00:00
|
|
|
|
// Copyright 2003-2018 by Wilson Snyder. This program is free software; you can
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// redistribute it and/or modify it under the terms of either the GNU
|
2009-05-04 21:07:57 +00:00
|
|
|
|
// Lesser General Public License Version 3 or the Perl Artistic License
|
|
|
|
|
// Version 2.0.
|
2006-08-26 11:35:28 +00:00
|
|
|
|
//
|
|
|
|
|
// Verilator is distributed in the hope that it will be useful,
|
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
// V3Block's Transformations:
|
2008-06-10 01:25:10 +00:00
|
|
|
|
//
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Note this can be called multiple times.
|
|
|
|
|
// Create a IBLOCK(initial), SBLOCK(combo)
|
|
|
|
|
// ALWAYS: Remove any-edges from sense list
|
|
|
|
|
// If no POS/NEG in senselist, Fold into SBLOCK(combo)
|
|
|
|
|
// Else fold into SBLOCK(sequent).
|
|
|
|
|
// OPTIMIZE: When support async clocks, fold into that block if possible
|
|
|
|
|
// INITIAL: Move into IBLOCK
|
|
|
|
|
// WIRE: Move into SBLOCK(combo)
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
|
|
|
|
|
#ifndef _V3SENTREE_H_
|
|
|
|
|
#define _V3SENTREE_H_
|
|
|
|
|
|
2006-12-18 19:20:45 +00:00
|
|
|
|
#include "config_build.h"
|
|
|
|
|
#include "verilatedos.h"
|
2008-06-30 17:11:25 +00:00
|
|
|
|
#include <cstdio>
|
|
|
|
|
#include <cstdarg>
|
2006-08-26 11:35:28 +00:00
|
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <map>
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <vector>
|
2018-06-12 02:05:45 +00:00
|
|
|
|
#include VL_INCLUDE_UNORDERED_SET
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Ast.h"
|
2018-06-12 02:05:45 +00:00
|
|
|
|
#include "V3Hashed.h"
|
2006-08-26 11:35:28 +00:00
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Collect SenTrees under the entire scope
|
|
|
|
|
// And provide functions to find/add a new one
|
|
|
|
|
|
2018-06-12 02:05:45 +00:00
|
|
|
|
class SenTreeSet {
|
|
|
|
|
// Hash table of sensitive blocks.
|
|
|
|
|
private:
|
|
|
|
|
// TYPES
|
|
|
|
|
class HashSenTree {
|
|
|
|
|
public:
|
|
|
|
|
HashSenTree() {}
|
|
|
|
|
size_t operator() (const AstSenTree* kp) const {
|
|
|
|
|
return V3Hashed::uncachedHash(kp).fullValue();
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
VL_UNCOPYABLE(HashSenTree);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class EqSenTree {
|
|
|
|
|
public:
|
|
|
|
|
EqSenTree() {}
|
|
|
|
|
bool operator() (const AstSenTree* ap, const AstSenTree* bp) const {
|
|
|
|
|
return ap->sameTree(bp);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
VL_UNCOPYABLE(EqSenTree);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// MEMBERS
|
|
|
|
|
typedef vl_unordered_set<AstSenTree*, HashSenTree, EqSenTree> Set;
|
|
|
|
|
Set m_trees; // Set of sensitive blocks, for folding.
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
// CONSTRUCTORS
|
|
|
|
|
SenTreeSet() {}
|
|
|
|
|
|
|
|
|
|
// METHODS
|
|
|
|
|
void add(AstSenTree* nodep) { m_trees.insert(nodep); }
|
|
|
|
|
AstSenTree* find(AstSenTree* likep) {
|
|
|
|
|
AstSenTree* resultp = NULL;
|
|
|
|
|
Set::iterator it = m_trees.find(likep);
|
|
|
|
|
if (it != m_trees.end()) {
|
|
|
|
|
resultp = *it;
|
|
|
|
|
}
|
|
|
|
|
return resultp;
|
|
|
|
|
}
|
|
|
|
|
void clear() { m_trees.clear(); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
VL_UNCOPYABLE(SenTreeSet);
|
|
|
|
|
};
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
class SenTreeFinder : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// STATE
|
2018-06-12 02:05:45 +00:00
|
|
|
|
AstTopScope* m_topscopep; // Top scope to add statement to
|
|
|
|
|
SenTreeSet m_trees; // Set of sensitive blocks, for folding
|
2009-01-21 21:56:50 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// VISITORS
|
2018-05-14 10:50:47 +00:00
|
|
|
|
VL_DEBUG_FUNC; // Declare debug()
|
2009-01-21 21:56:50 +00:00
|
|
|
|
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeModule* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Only do the top
|
|
|
|
|
if (nodep->isTop()) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstTopScope* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_topscopep = nodep;
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2008-11-20 12:55:54 +00:00
|
|
|
|
// Don't clear topscopep, the namer persists beyond this visit
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstScope* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// But no SenTrees under TopScope's scope
|
|
|
|
|
}
|
|
|
|
|
// Memorize existing block names
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstActive* nodep) {
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Don't grab SenTrees under Actives, only those that are global (under Scope directly)
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
2018-06-12 02:05:45 +00:00
|
|
|
|
virtual void visit(AstSenTree* nodep) { m_trees.add(nodep); }
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Empty visitors, speed things up
|
2016-11-27 13:11:38 +00:00
|
|
|
|
virtual void visit(AstNodeStmt* nodep) { }
|
|
|
|
|
virtual void visit(AstNode* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterateChildren(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
// METHODS
|
|
|
|
|
public:
|
|
|
|
|
void clear() {
|
2008-06-10 01:25:10 +00:00
|
|
|
|
m_topscopep = NULL;
|
2018-06-12 02:05:45 +00:00
|
|
|
|
m_trees.clear();
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
AstSenTree* getSenTree(FileLine* fl, AstSenTree* sensesp) {
|
|
|
|
|
// Return a global sentree that matches given sense list.
|
2018-06-12 02:05:45 +00:00
|
|
|
|
AstSenTree* treep = m_trees.find(sensesp);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Not found, form a new one
|
|
|
|
|
if (!treep) {
|
|
|
|
|
UASSERT(m_topscopep,"Never called main()");
|
2008-11-20 01:15:05 +00:00
|
|
|
|
treep = sensesp->cloneTree(false);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_topscopep->addStmtsp(treep);
|
|
|
|
|
UINFO(8," New SENTREE "<<treep<<endl);
|
2018-06-12 02:05:45 +00:00
|
|
|
|
m_trees.add(treep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// Note blocks may have also been added above in the Active visitor
|
|
|
|
|
}
|
|
|
|
|
return treep;
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
|
|
|
|
SenTreeFinder() {
|
|
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
virtual ~SenTreeFinder() {}
|
|
|
|
|
void main(AstTopScope* nodep) {
|
2018-05-11 00:55:37 +00:00
|
|
|
|
iterate(nodep);
|
2006-08-26 11:35:28 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // Guard
|