2008-06-10 01:25:10 +00:00
|
|
|
|
// -*- C++ -*-
|
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
|
|
|
|
//
|
|
|
|
|
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
|
|
|
|
|
//
|
|
|
|
|
//*************************************************************************
|
|
|
|
|
//
|
2009-01-02 16:47:39 +00:00
|
|
|
|
// Copyright 2003-2009 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>
|
|
|
|
|
|
|
|
|
|
#include "V3Global.h"
|
|
|
|
|
#include "V3Ast.h"
|
|
|
|
|
|
|
|
|
|
//######################################################################
|
|
|
|
|
// Collect SenTrees under the entire scope
|
|
|
|
|
// And provide functions to find/add a new one
|
|
|
|
|
|
|
|
|
|
class SenTreeFinder : public AstNVisitor {
|
|
|
|
|
private:
|
|
|
|
|
// STATE
|
|
|
|
|
AstTopScope* m_topscopep; // Top scope to add statement to
|
|
|
|
|
vector<AstSenTree*> m_treesp; // List of sensitive blocks, for folding
|
2009-01-21 21:56:50 +00:00
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
// VISITORS
|
2009-01-21 21:56:50 +00:00
|
|
|
|
static int debug() {
|
|
|
|
|
static int level = -1;
|
|
|
|
|
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
|
|
|
|
|
return level;
|
|
|
|
|
}
|
|
|
|
|
|
2006-08-26 11:35:28 +00:00
|
|
|
|
virtual void visit(AstModule* nodep, AstNUser*) {
|
|
|
|
|
// Only do the top
|
|
|
|
|
if (nodep->isTop()) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstTopScope* nodep, AstNUser*) {
|
|
|
|
|
m_topscopep = nodep;
|
|
|
|
|
nodep->iterateChildren(*this);
|
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
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstScope* nodep, AstNUser*) {
|
|
|
|
|
// But no SenTrees under TopScope's scope
|
|
|
|
|
}
|
|
|
|
|
// Memorize existing block names
|
|
|
|
|
virtual void visit(AstActive* nodep, AstNUser*) {
|
|
|
|
|
// Don't grab SenTrees under Actives, only those that are global (under Scope directly)
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
virtual void visit(AstSenTree* nodep, AstNUser*) {
|
|
|
|
|
m_treesp.push_back(nodep);
|
|
|
|
|
}
|
|
|
|
|
// Empty visitors, speed things up
|
|
|
|
|
virtual void visit(AstNodeStmt* nodep, AstNUser*) { }
|
|
|
|
|
virtual void visit(AstNode* nodep, AstNUser*) {
|
|
|
|
|
nodep->iterateChildren(*this);
|
|
|
|
|
}
|
|
|
|
|
// METHODS
|
|
|
|
|
public:
|
|
|
|
|
void clear() {
|
2008-06-10 01:25:10 +00:00
|
|
|
|
m_topscopep = NULL;
|
2006-08-26 11:35:28 +00:00
|
|
|
|
m_treesp.clear();
|
|
|
|
|
}
|
|
|
|
|
AstSenTree* getSenTree(FileLine* fl, AstSenTree* sensesp) {
|
|
|
|
|
// Return a global sentree that matches given sense list.
|
|
|
|
|
// Not the fastest, but there tend to be few clocks
|
|
|
|
|
AstSenTree* treep = NULL;
|
|
|
|
|
//sensesp->dumpTree(cout," Lookingfor: ");
|
|
|
|
|
for (vector<AstSenTree*>::iterator it = m_treesp.begin(); it!=m_treesp.end(); ++it) {
|
|
|
|
|
treep = *it;
|
|
|
|
|
if (treep) { // Not deleted
|
|
|
|
|
if (treep->sameTree(sensesp)) {
|
|
|
|
|
UINFO(8," Found SBLOCK "<<treep<<endl);
|
|
|
|
|
goto found;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
treep = NULL;
|
|
|
|
|
}
|
|
|
|
|
found:
|
|
|
|
|
// 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);
|
|
|
|
|
m_treesp.push_back(treep);
|
|
|
|
|
// Note blocks may have also been added above in the Active visitor
|
|
|
|
|
}
|
|
|
|
|
return treep;
|
|
|
|
|
}
|
|
|
|
|
public:
|
|
|
|
|
// CONSTUCTORS
|
|
|
|
|
SenTreeFinder() {
|
|
|
|
|
clear();
|
|
|
|
|
}
|
|
|
|
|
virtual ~SenTreeFinder() {}
|
|
|
|
|
void main(AstTopScope* nodep) {
|
|
|
|
|
nodep->accept(*this);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif // Guard
|