Compare commits

...
15 Commits
47 changed files with 1192 additions and 560 deletions
+10
View File
@@ -3,6 +3,16 @@ Revision history for Verilator
The contributors that suggested a given feature are shown in []. [by ...]
indicates the contributor was also the author of the fix; Thanks!
* Verilator 3.713 2009/08/04
** Support constant function calls for parameters. [many!]
*** Support SystemVerilog "logic", bug101. [by Alex Duller]
*** Name SYMRSVDWORD error, and allow disabling it, bug103. [Gary Thomas]
**** Fix escaped preprocessor identifiers, bug106. [Nimrod Gileadi]
* Verilator 3.712 2009/07/14
** Patching SystemC is no longer required to trace sc_bvs.
+44 -8
View File
@@ -1144,8 +1144,8 @@ including function call-like preprocessor defines.
Verilator supports ==? and !=? operators, $bits, $countones, $error,
$fatal, $info, $isunknown, $onehot, $onehot0, $warning, always_comb,
always_ff, always_latch, do-while, final, priority case/if, and unique
case/if.
always_ff, always_latch, do-while, final, logic, priority case/if, and
unique case/if.
It also supports .name and .* interconnection.
@@ -1965,6 +1965,13 @@ example:
Ignoring this warning may make Verilator simulations differ from other
simulators.
=item SYMRSVDWORD
Error that a symbol matches a C++ reserved word and using this as a symbol
name would result in odd C compiler errors. You may disable this error
message as you would disable warnings, but the symbol will be renamed by
Verilator to avoid the conflict.
=item TASKNSVAR
Error when a call to a task or function has a output from that task tied to
@@ -2241,26 +2248,55 @@ untarred directory.
In your top level C code, call Verilated::traceEverOn(true). Then create a
SpTraceVcdC object, and in your main loop call "trace_object->dump(time)"
every time step, and finally call "trace_object->close()". For an example,
see the call to SpTraceVcdC in the test_c/sim_main.cpp file of the
distribution.
see below and the test_c/sim_main.cpp file of the distribution.
You also need to compile SpTraceVcdC.cpp and add it to your link. This is
done for you if using the Verilator --exe flag.
#include "SpTraceVcdC.cpp"
...
int main(int argc, char **argv, char **env) {
...
Verilated::traceEverOn(true);
SpTraceVcdCFile* tfp = new SpTraceVcdCFile;
topp->trace (tfp, 99);
tfp->open ("obj_dir/t_trace_ena_cc/simx.vcd");
...
while (sc_time_stamp() < sim_time && !Verilated::gotFinish()) {
main_time += #;
tfp->dump (main_time);
}
tfp->close();
}
=item How do I generate waveforms (traces) in SystemC/SystemPerl?
Add the --trace switch to Verilator, and make sure the SystemPerl package
is installed.
In your top level C sc_main code, call Verilated::traceEverOn(true). Then
create a SpTraceFile object as you would create a normal SystemC trace
file. For an example, see the call to SpTraceFile in the
test_sp/sc_main.cpp file of the distribution.
In your top level C sc_main code, include SpTraceVcd.h. Then call
Verilated::traceEverOn(true). Then create a SpTraceFile object as you
would create a normal SystemC trace file. For an example, see the call to
SpTraceFile in the test_sp/sc_main.cpp file of the distribution, and below.
Alternatively you may use the C++ trace mechanism described in the previous
question, however the timescale and timeprecision will not inherited from
your SystemC settings.
#include "SpTraceVcd.cpp"
...
int main(int argc, char **argv, char **env) {
...
Verilated::traceEverOn(true);
SpTraceVcdFile* tfp = new SpTraceVcdFile;
topp->trace (tfp, 99);
tfp->open ("obj_dir/t_trace_ena_cc/simx.vcd");
...
sc_start(1);
...
tfp->close();
}
=item How do I view waveforms (traces)?
Verilator makes standard VCD (Value Change Dump) files. They are viewable
+51 -51
View File
@@ -41,10 +41,10 @@ public:
// enum en {...};
// const char* ascii() const {...};
enum en m_e;
inline AstType () {};
inline AstType (en _e) : m_e(_e) {};
explicit inline AstType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstType () {}
inline AstType (en _e) : m_e(_e) {}
explicit inline AstType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (AstType lhs, AstType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstType lhs, AstType::en rhs) { return (lhs.m_e == rhs); }
@@ -64,10 +64,10 @@ public:
PUBLIC_TASK
};
enum en m_e;
inline AstPragmaType () {};
inline AstPragmaType (en _e) : m_e(_e) {};
explicit inline AstPragmaType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstPragmaType () {}
inline AstPragmaType (en _e) : m_e(_e) {}
explicit inline AstPragmaType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (AstPragmaType lhs, AstPragmaType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstPragmaType lhs, AstPragmaType::en rhs) { return (lhs.m_e == rhs); }
@@ -87,10 +87,10 @@ public:
TRACE_CHANGE_SUB
};
enum en m_e;
inline AstCFuncType () {};
inline AstCFuncType (en _e) : m_e(_e) {};
explicit inline AstCFuncType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstCFuncType () {}
inline AstCFuncType (en _e) : m_e(_e) {}
explicit inline AstCFuncType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
// METHODS
bool isTrace() const { return (m_e==TRACE_INIT || m_e==TRACE_INIT_SUB
|| m_e==TRACE_FULL || m_e==TRACE_FULL_SUB
@@ -155,10 +155,10 @@ public:
};
return names[m_e];
};
inline AstEdgeType () {};
inline AstEdgeType (en _e) : m_e(_e) {};
explicit inline AstEdgeType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstEdgeType () {}
inline AstEdgeType (en _e) : m_e(_e) {}
explicit inline AstEdgeType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (AstEdgeType lhs, AstEdgeType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstEdgeType lhs, AstEdgeType::en rhs) { return (lhs.m_e == rhs); }
@@ -188,10 +188,10 @@ public:
};
return names[m_e];
};
inline AstAttrType () {};
inline AstAttrType (en _e) : m_e(_e) {};
explicit inline AstAttrType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstAttrType () {}
inline AstAttrType (en _e) : m_e(_e) {}
explicit inline AstAttrType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (AstAttrType lhs, AstAttrType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstAttrType lhs, AstAttrType::en rhs) { return (lhs.m_e == rhs); }
@@ -223,17 +223,17 @@ public:
XTEMP
};
enum en m_e;
inline AstVarType () {};
inline AstVarType (en _e) : m_e(_e) {};
explicit inline AstVarType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstVarType () {}
inline AstVarType (en _e) : m_e(_e) {}
explicit inline AstVarType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
static const char* names[] = {
"?","GPARAM","LPARAM","GENVAR",
"INTEGER","INPUT","OUTPUT","INOUT",
"SUPPLY0","SUPPLY1","WIRE","IMPLICIT","REG","TRIWIRE","PORT",
"BLOCKTEMP","MODULETEMP","STMTTEMP","XTEMP"};
return names[m_e];};
return names[m_e]; }
};
inline bool operator== (AstVarType lhs, AstVarType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstVarType lhs, AstVarType::en rhs) { return (lhs.m_e == rhs); }
@@ -252,10 +252,10 @@ public:
};
enum en m_e;
// CONSTRUCTOR - note defaults to *UNKNOWN*
inline AstBranchPred () : m_e(UNKNOWN) {};
inline AstBranchPred (en _e) : m_e(_e) {};
explicit inline AstBranchPred (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstBranchPred () : m_e(UNKNOWN) {}
inline AstBranchPred (en _e) : m_e(_e) {}
explicit inline AstBranchPred (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
AstBranchPred invert() const {
if (m_e==UNLIKELY) return LIKELY;
else if (m_e==LIKELY) return UNLIKELY;
@@ -264,7 +264,7 @@ public:
const char* ascii() const {
static const char* names[] = {
"","VL_LIKELY","VL_UNLIKELY"};
return names[m_e];};
return names[m_e]; }
};
inline bool operator== (AstBranchPred lhs, AstBranchPred rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstBranchPred lhs, AstBranchPred::en rhs) { return (lhs.m_e == rhs); }
@@ -281,10 +281,10 @@ public:
CASEZ
};
enum en m_e;
inline AstCaseType () {};
inline AstCaseType (en _e) : m_e(_e) {};
explicit inline AstCaseType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstCaseType () {}
inline AstCaseType (en _e) : m_e(_e) {}
explicit inline AstCaseType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (AstCaseType lhs, AstCaseType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstCaseType lhs, AstCaseType::en rhs) { return (lhs.m_e == rhs); }
@@ -303,16 +303,16 @@ public:
FATAL
};
enum en m_e;
inline AstDisplayType () {};
inline AstDisplayType (en _e) : m_e(_e) {};
explicit inline AstDisplayType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstDisplayType () {}
inline AstDisplayType (en _e) : m_e(_e) {}
explicit inline AstDisplayType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
bool addNewline() const { return m_e!=WRITE; }
bool needScopeTracking() const { return m_e!=DISPLAY && m_e!=WRITE; }
const char* ascii() const {
static const char* names[] = {
"display","write","info","error","warning","fatal"};
return names[m_e];};
return names[m_e]; }
};
inline bool operator== (AstDisplayType lhs, AstDisplayType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstDisplayType lhs, AstDisplayType::en rhs) { return (lhs.m_e == rhs); }
@@ -331,14 +331,14 @@ public:
_ENUM_END
};
enum en m_e;
inline AstParseRefExp() : m_e(NONE) {};
inline AstParseRefExp (en _e) : m_e(_e) {};
explicit inline AstParseRefExp (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline AstParseRefExp() : m_e(NONE) {}
inline AstParseRefExp (en _e) : m_e(_e) {}
explicit inline AstParseRefExp (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
static const char* names[] = {
"","VAR_MEM","VAR_ANY","TASK","FUNC"};
return names[m_e];};
return names[m_e]; }
};
inline bool operator== (AstParseRefExp lhs, AstParseRefExp rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (AstParseRefExp lhs, AstParseRefExp::en rhs) { return (lhs.m_e == rhs); }
@@ -520,9 +520,9 @@ public:
uint32_t depth() const { return (m_both >> 24) & 255; }
uint32_t hshval() const { return m_both & M24; }
// OPERATORS
inline bool operator== (const V3Hash& rh) const { return m_both==rh.m_both; };
inline bool operator!= (const V3Hash& rh) const { return m_both!=rh.m_both; };
inline bool operator< (const V3Hash& rh) const { return m_both<rh.m_both; };
inline bool operator== (const V3Hash& rh) const { return m_both==rh.m_both; }
inline bool operator!= (const V3Hash& rh) const { return m_both!=rh.m_both; }
inline bool operator< (const V3Hash& rh) const { return m_both<rh.m_both; }
// CREATORS
class Illegal {}; // for creator type-overload selection
class FullValue {}; // for creator type-overload selection
@@ -669,6 +669,7 @@ public:
// ACCESSORS
virtual string name() const { return ""; }
virtual void name(const string& name) { this->v3fatalSrc("name() called on object without name() method"); }
virtual string verilogKwd() const { return ""; }
string shortName() const; // Name with __PVT__ removed for concatenating scopes
static string dedotName(const string& namein); // Name with dots removed
@@ -980,7 +981,6 @@ struct AstNodeFor : public AstNodeStmt {
AstNode* incsp() const { return op3p()->castNode(); } // op3= increment statements
AstNode* bodysp() const { return op4p()->castNode(); } // op4= body of loop
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual int instrCount() const { return instrCountBranch(); }
virtual V3Hash sameHash() const { return V3Hash(); }
virtual bool same(AstNode* samep) const { return true; }
@@ -1059,7 +1059,7 @@ public:
virtual int instrCount() const { return widthInstrs(); }
virtual void cloneRelink();
virtual string name() const { return m_name; } // * = Var name
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
bool lvalue() const { return m_lvalue; }
void lvalue(bool lval) { m_lvalue=lval; } // Avoid using this; Set in constructor
AstVar* varp() const { return m_varp; } // [After Link] Pointer to variable
@@ -1136,7 +1136,7 @@ public:
virtual bool maybePointedTo() const { return true; }
// {AstFunc only} op1 = Range output variable
// op3 = Statements/Ports/Vars
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
AstNode* stmtsp() const { return op3p()->castNode(); } // op1 = List of statements
void addStmtsp(AstNode* nodep) { addOp3p(nodep); }
void taskPublic(bool flag) { m_taskPublic=flag; }
@@ -1169,7 +1169,7 @@ public:
void inlinedDots(const string& flag) { m_inlinedDots = flag; }
AstNodeFTask* taskp() const { return m_taskp; } // [After Link] Pointer to variable
void taskp(AstNodeFTask* taskp) { m_taskp=taskp; }
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
void dotted(const string& name) { m_dotted = name; }
// op1 = namep
AstNode* namep() const { return op1p(); }
+17 -26
View File
@@ -251,13 +251,6 @@ private:
m_trace=false;
}
public:
AstVar(FileLine* fl, AstVarType type, const string& name)
:AstNode(fl)
, m_name(name) {
init();
combineType(type);
width(msb()-lsb()+1,0);
}
AstVar(FileLine* fl, AstVarType type, const string& name, AstRange* rangep, AstRange* arrayp=NULL)
:AstNode(fl)
, m_name(name) {
@@ -277,7 +270,7 @@ public:
if (examplep->arraysp()) {
setOp2p(examplep->arraysp()->cloneTree(true));
}
width(msb()-lsb()+1,0);
width(examplep->width(), examplep->widthMin());
}
ASTNODE_NODE_FUNCS(Var, VAR)
virtual void dump(ostream& str);
@@ -315,7 +308,7 @@ public:
void funcReturn(bool flag) { m_funcReturn = flag; }
void trace(bool flag) { m_trace=flag; }
// METHODS
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
bool isInput() const { return m_input; }
bool isOutput() const { return m_output; }
bool isInOnly() const { return m_input && !m_output; }
@@ -432,7 +425,7 @@ public:
virtual bool broken() const;
virtual bool maybePointedTo() const { return true; }
virtual string name() const { return m_name; } // * = Scope name
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
string nameDotless() const;
string nameVlSym() const { return (((string)"vlSymsp->") + nameDotless()); }
AstModule* modp() const { return m_modp; }
@@ -572,7 +565,7 @@ public:
virtual void dump(ostream& str);
virtual bool broken() const { return (m_modVarp && !m_modVarp->brokeExists()); }
virtual string name() const { return m_name; } // * = Pin name, ""=go by number
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
bool dotStar() const { return name() == ".*"; } // Special fake name for .* connections until linked
int pinNum() const { return m_pinNum; }
void exprp(AstNode* nodep) { addOp1p(nodep); }
@@ -612,7 +605,7 @@ public:
void addStmtp(AstNode* nodep) { addOp2p(nodep); }
void addActivep(AstNode* nodep) { addOp3p(nodep); }
// ACCESSORS
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
string origName() const { return m_origName; }
bool inLibrary() const { return m_inLibrary; }
void inLibrary(bool flag) { m_inLibrary = flag; }
@@ -649,7 +642,7 @@ public:
virtual bool maybePointedTo() const { return true; }
// ACCESSORS
virtual string name() const { return m_name; } // * = Cell name
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
string origName() const { return m_origName; } // * = Original name
void origName(const string& name) { m_origName = name; }
string modName() const { return m_modName; } // * = Instance name
@@ -679,7 +672,7 @@ public:
// ACCESSORS
virtual string name() const { return m_name; } // * = Cell name
string origModName() const { return m_origModName; } // * = modp()->origName() before inlining
void name(const string& name) { m_name = name; }
virtual void name(const string& name) { m_name = name; }
};
struct AstPort : public AstNode {
@@ -714,7 +707,7 @@ public:
}
ASTNODE_NODE_FUNCS(Begin, BEGIN)
virtual string name() const { return m_name; } // * = Block name
void name(const string& flag) { m_name=flag; }
virtual void name(const string& name) { m_name = name; }
// op1 = Statements
AstNode* stmtsp() const { return op1p()->castNode(); } // op1 = List of statements
void addStmtp(AstNode* nodep) { addOp1p(nodep); }
@@ -942,7 +935,7 @@ struct AstAssign : public AstNodeAssign {
}
ASTNODE_NODE_FUNCS(Assign, ASSIGN)
virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssign(this->fileline(), lhsp, rhsp); }
virtual string verilogKwd() const { return "="; };
virtual string verilogKwd() const { return "="; }
};
struct AstAssignAlias : public AstNodeAssign {
@@ -961,7 +954,7 @@ struct AstAssignDly : public AstNodeAssign {
ASTNODE_NODE_FUNCS(AssignDly, ASSIGNDLY)
virtual AstNode* cloneType(AstNode* lhsp, AstNode* rhsp) { return new AstAssignDly(this->fileline(), lhsp, rhsp); }
virtual bool isGateOptimizable() const { return false; }
virtual string verilogKwd() const { return "<="; };
virtual string verilogKwd() const { return "<="; }
};
struct AstAssignW : public AstNodeAssign {
@@ -1249,7 +1242,7 @@ struct AstFClose : public AstNodeStmt {
setNOp2p(filep);
}
ASTNODE_NODE_FUNCS(FClose, FCLOSE)
virtual string verilogKwd() const { return "$fclose"; };
virtual string verilogKwd() const { return "$fclose"; }
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual bool isSplittable() const { return false; }
@@ -1269,7 +1262,7 @@ struct AstFOpen : public AstNodeStmt {
setOp3p(modep);
}
ASTNODE_NODE_FUNCS(FOpen, FOPEN)
virtual string verilogKwd() const { return "$fclose"; };
virtual string verilogKwd() const { return "$fclose"; }
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual bool isSplittable() const { return false; }
@@ -1290,7 +1283,7 @@ struct AstFFlush : public AstNodeStmt {
setNOp2p(filep);
}
ASTNODE_NODE_FUNCS(FFlush, FFLUSH)
virtual string verilogKwd() const { return "$fflush"; };
virtual string verilogKwd() const { return "$fflush"; }
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual bool isSplittable() const { return false; }
@@ -1378,7 +1371,7 @@ public:
setOp1p(filenamep); setOp2p(memp); setNOp3p(lsbp); setNOp4p(msbp);
}
ASTNODE_NODE_FUNCS(ReadMem, READMEM)
virtual string verilogKwd() const { return (isHex()?"$readmemh":"$readmemb"); };
virtual string verilogKwd() const { return (isHex()?"$readmemh":"$readmemb"); }
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual bool isSplittable() const { return false; }
@@ -1417,8 +1410,7 @@ struct AstRepeat : public AstNodeStmt {
ASTNODE_NODE_FUNCS(Repeat, REPEAT)
AstNode* countp() const { return op2p()->castNode(); } // op2= condition to continue
AstNode* bodysp() const { return op3p()->castNode(); } // op3= body of loop
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual bool isGateOptimizable() const { return false; } // Not releavant - converted to FOR
virtual int instrCount() const { return instrCountBranch(); }
virtual V3Hash sameHash() const { return V3Hash(); }
virtual bool same(AstNode* samep) const { return true; }
@@ -1436,7 +1428,6 @@ struct AstWhile : public AstNodeStmt {
void addPrecondsp(AstNode* newp) { addOp1p(newp); }
void addBodysp(AstNode* newp) { addOp3p(newp); }
virtual bool isGateOptimizable() const { return false; }
virtual bool isPredictOptimizable() const { return false; }
virtual int instrCount() const { return instrCountBranch(); }
virtual V3Hash sameHash() const { return V3Hash(); }
virtual bool same(AstNode* samep) const { return true; }
@@ -2636,7 +2627,7 @@ public:
virtual string name() const { return m_name; } // * = Var name
virtual V3Hash sameHash() const { return V3Hash(name()); }
virtual bool same(AstNode* samep) const { return samep->name() == name(); }
void name(const string& flag) { m_name = flag; }
virtual void name(const string& name) { m_name = name; }
AstNode* propp() const { return op1p(); } // op1 = property
AstSenTree* sentreep() const { return op2p()->castSenTree(); } // op2 = clock domain
void sentreep(AstSenTree* sentreep) { addOp2p(sentreep); } // op2 = clock domain
@@ -2818,7 +2809,7 @@ public:
&& (rtnTypeVoid()==samep->castCFunc()->rtnTypeVoid())
&& (argTypes()==samep->castCFunc()->argTypes())); }
//
void name(const string& flag) { m_name = flag; }
virtual void name(const string& name) { m_name = name; }
AstScope* scopep() const { return m_scopep; }
void scopep(AstScope* nodep) { m_scopep = nodep; }
string rtnTypeVoid() const { return ((m_rtnType=="") ? "void" : m_rtnType); }
+1 -1
View File
@@ -86,7 +86,7 @@ private:
if (varp->width()!=1) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
string newvarname = ((string)"__Vclklast__"+vscp->scopep()->nameDotless()+"__"+varp->shortName());
AstVar* newvarp
= new AstVar (vscp->fileline(), AstVarType::MODULETEMP, newvarname); // No range; 1 bit.
= new AstVar (vscp->fileline(), AstVarType::MODULETEMP, newvarname, NULL, NULL); // No range; 1 bit.
newvarp->width(1,1);
m_modp->addStmtp(newvarp);
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
+37 -5
View File
@@ -39,6 +39,7 @@
#include "V3Ast.h"
#include "V3Width.h"
#include "V3Signed.h"
#include "V3Simulate.h"
//######################################################################
// Utilities
@@ -827,6 +828,26 @@ private:
if (debug()>=9) newp->dumpTree(cout," _new: ");
}
void replaceWithSimulation(AstNode* nodep) {
SimulateVisitor simvis;
// Run it - may be unoptimizable due to large for loop, etc
simvis.mainParamEmulate(nodep);
if (!simvis.optimizable()) {
AstNode* errorp = simvis.whyNotNodep(); if (!errorp) errorp = nodep;
nodep->v3error("Expecting expression to be constant, but can't determine constant for "
<<nodep->prettyTypeName()<<endl
<<V3Error::msgPrefix()<<errorp->fileline()<<"... Location of non-constant "
<<errorp->prettyTypeName()<<": "<<simvis.whyNotMessage());
replaceZero(nodep); nodep=NULL;
} else {
// Fetch the result
V3Number* outnump = simvis.fetchNumberNull(nodep);
if (!outnump) nodep->v3fatalSrc("No number returned from simulation");
// Replace it
replaceNum(nodep,*outnump); nodep=NULL;
}
}
//----------------------------------------
// VISITORS
@@ -1420,6 +1441,13 @@ private:
}
}
virtual void visit(AstFuncRef* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (m_params) { // Only parameters force us to do constant function call propagation
replaceWithSimulation(nodep);
}
}
virtual void visit(AstWhile* nodep, AstNUser*) {
nodep->iterateChildren(*this);
if (nodep->condp()->isZero()) {
@@ -1708,12 +1736,16 @@ public:
void V3Const::constifyParam(AstNode* nodep) {
//if (debug()>0) nodep->dumpTree(cout," forceConPRE : ");
if (!nodep->width()) {
V3Width::widthParams(nodep);
V3Signed::signedParams(nodep);
}
V3Width::widthSignedIfNotAlready(nodep); // Make sure we've sized everything first
ConstVisitor visitor (true,false,false,false);
visitor.main(nodep);
if (AstVar* varp=nodep->castVar()) {
// If a var wants to be constified, it's really a param, and
// we want the value to be constant. We aren't passed just the
// init value because we need widthing above to handle the var's type.
if (varp->initp()) visitor.main(varp->initp());
} else {
visitor.main(nodep);
}
// Because we do edits, nodep links may get trashed and core dump this.
//if (debug()>0) nodep->dumpTree(cout," forceConDONE: ");
}
+6 -6
View File
@@ -43,7 +43,7 @@ public:
V3OutCFile(const string& filename) : V3OutFile(filename) {
resetPrivate();
}
virtual ~V3OutCFile() {};
virtual ~V3OutCFile() {}
virtual void putsCellDecl(const string& classname, const string& cellname) {
this->printf("%-19s\t%s;\n",
(classname + "*").c_str(),cellname.c_str());
@@ -66,7 +66,7 @@ public:
class V3OutScFile : public V3OutCFile {
public:
V3OutScFile(const string& filename) : V3OutCFile(filename) {}
virtual ~V3OutScFile() {};
virtual ~V3OutScFile() {}
virtual void putsHeader() { puts("// Verilated -*- SystemC -*-\n"); }
virtual void putsIntTopInclude() {
puts("#include \"systemc.h\"\n");
@@ -77,7 +77,7 @@ public:
class V3OutSpFile : public V3OutCFile {
public:
V3OutSpFile(const string& filename) : V3OutCFile(filename) {}
virtual ~V3OutSpFile() {};
virtual ~V3OutSpFile() {}
virtual void putsHeader() { puts("// Verilated -*- SystemC -*-\n"); }
virtual void putsIntTopInclude() {
puts("#include \"systemperl.h\"\n");
@@ -88,14 +88,14 @@ public:
class V3OutVFile : public V3OutFile {
public:
V3OutVFile(const string& filename) : V3OutFile(filename) {}
virtual ~V3OutVFile() {};
virtual ~V3OutVFile() {}
virtual void putsHeader() { puts("// Verilated -*- Verilog -*-\n"); }
};
class V3OutMkFile : public V3OutFile {
public:
V3OutMkFile(const string& filename) : V3OutFile(filename) {}
virtual ~V3OutMkFile() {};
virtual ~V3OutMkFile() {}
virtual void putsHeader() { puts("# Verilated -*- Makefile -*-\n"); }
// No automatic indentation yet.
void puts(const char* strg) { putsNoTracking(strg); }
@@ -110,7 +110,7 @@ public:
// STATE
V3OutCFile* m_ofp;
// METHODS
V3OutCFile* ofp() const { return m_ofp; };
V3OutCFile* ofp() const { return m_ofp; }
void puts(const string& str) { ofp()->puts(str); }
void putbs(const string& str) { ofp()->putbs(str); }
void putsQuoted(const string& str) { ofp()->putsQuoted(str); }
+3 -1
View File
@@ -65,7 +65,9 @@ class EmitCSyms : EmitCBaseVisitor {
if (nodep->name() != "") {
string rsvd = m_words.isKeyword(nodep->name());
if (rsvd != "") {
nodep->v3error("Unsupported: "+rsvd+": "<<nodep->name());
// Generally V3Name should find all of these and throw SYMRSVDWORD.
// We'll still check here because the compiler errors resulting if we miss this warning are SO nasty
nodep->v3error("Symbol matching "+rsvd+" reserved word reached emitter, should have hit SYMRSVDWORD: '"<<nodep->name()<<"'");
}
}
}
+1 -1
View File
@@ -461,7 +461,7 @@ class EmitVFileVisitor : public EmitVBaseVisitor {
// MEMBERS
V3OutFile* m_ofp;
// METHODS
V3OutFile* ofp() const { return m_ofp; };
V3OutFile* ofp() const { return m_ofp; }
void puts(const string& str) { ofp()->puts(str); }
void putbs(const string& str) { ofp()->putbs(str); }
void putsNoTracking(const string& str) { ofp()->putsNoTracking(str); }
+2 -2
View File
@@ -46,7 +46,7 @@ bool V3Error::s_describedWarnings = false;
bool V3Error::s_pretendError[V3ErrorCode::MAX];
struct v3errorIniter {
v3errorIniter() { V3Error::init(); };
v3errorIniter() { V3Error::init(); }
};
v3errorIniter v3errorInit;
@@ -358,7 +358,7 @@ void V3Error::v3errorEnd (ostringstream& sstr) {
// If first warning is not the user's fault (internal/unsupported) then give the website
// Not later warnings, as a internal may be caused by an earlier problem
if (s_tellManual == 0) {
if (s_errorCode==V3ErrorCode::FATALSRC
if (s_errorCode.mentionManual()
|| sstr.str().find("Unsupported") != string::npos) {
s_tellManual = 1;
} else {
+14 -10
View File
@@ -59,6 +59,7 @@ public:
CMPCONST, // Comparison is constant due to limited range
COMBDLY, // Combinatorial delayed assignment
STMTDLY, // Delayed statement
SYMRSVDWORD, // Symbol is Reserved Word
GENCLK, // Generated Clock
IMPERFECTSCH, // Imperfect schedule (disabled by default)
IMPLICIT, // Implicit wire
@@ -77,11 +78,11 @@ public:
// ***Add new elements below also***
};
enum en m_e;
inline V3ErrorCode () {};
inline V3ErrorCode (en _e) : m_e(_e) {};
inline V3ErrorCode () {}
inline V3ErrorCode (en _e) : m_e(_e) {}
V3ErrorCode (const char* msgp); // Matching code or ERROR
explicit inline V3ErrorCode (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
explicit inline V3ErrorCode (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
const char* ascii() const {
const char* names[] = {
// Leading spaces indicate it can't be disabled.
@@ -94,21 +95,24 @@ public:
" FIRST_WARN",
"BLKANDNBLK",
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CMPCONST",
"COMBDLY", "STMTDLY", "GENCLK", "IMPERFECTSCH", "IMPLICIT", "IMPURE",
"COMBDLY", "STMTDLY", "SYMRSVDWORD", "GENCLK", "IMPERFECTSCH", "IMPLICIT", "IMPURE",
"MULTIDRIVEN", "REDEFMACRO",
"UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNSIGNED", "UNUSED",
"VARHIDDEN", "WIDTH", "WIDTHCONCAT",
" MAX"
};
return names[m_e];
};
}
// Warnings that default to off
bool defaultsOff() const { return ( m_e==IMPERFECTSCH );};
bool defaultsOff() const { return ( m_e==IMPERFECTSCH ); }
// Warnings that warn about nasty side effects
bool dangerous() const { return ( m_e==COMBDLY );};
bool dangerous() const { return ( m_e==COMBDLY ); }
// Warnings we'll present to the user as errors
// Later -Werror- options may make more of these.
bool pretendError() const { return ( m_e==BLKANDNBLK || m_e==IMPURE); };
bool pretendError() const { return ( m_e==BLKANDNBLK || m_e==IMPURE || m_e==SYMRSVDWORD); }
// Warnings to mention manual
bool mentionManual() const { return ( m_e==FATALSRC || pretendError() ); }
// Warnings that are lint only
bool lintError() const { return ( m_e==CASEINCOMPLETE || m_e==CASEOVERLAP
|| m_e==CASEWITHX || m_e==CASEX
@@ -116,7 +120,7 @@ public:
|| m_e==IMPLICIT
|| m_e==UNDRIVEN || m_e==UNSIGNED
|| m_e==UNUSED || m_e==VARHIDDEN
|| m_e==WIDTH); };
|| m_e==WIDTH); }
};
inline bool operator== (V3ErrorCode lhs, V3ErrorCode rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (V3ErrorCode lhs, V3ErrorCode::en rhs) { return (lhs.m_e == rhs); }
+1 -1
View File
@@ -62,7 +62,7 @@ class V3FileDependImp {
}
}
}
bool operator<(const DependFile& rhs) const { return filename()<rhs.filename(); };
bool operator<(const DependFile& rhs) const { return filename()<rhs.filename(); }
};
// MEMBERS
+1 -1
View File
@@ -123,7 +123,7 @@ public:
bool exceededWidth() const { return m_column > WIDTH; }
bool tokenStart(const char* cp, const char* cmp);
bool tokenEnd(const char* cp);
void indentInc() { m_indentLevel += INDBLK; };
void indentInc() { m_indentLevel += INDBLK; }
void indentDec() {
m_indentLevel -= INDBLK;
UASSERT(m_indentLevel>=0, ": "<<m_filename<<": Underflow of indentation\n");
+1 -1
View File
@@ -156,7 +156,7 @@ private:
if (!forrefp->varp()) {
if (!noWarn) forrefp->v3warn(IMPLICIT,"Signal definition not found, creating implicitly: "<<forrefp->prettyName());
AstVar* newp = new AstVar (forrefp->fileline(), AstVarType::WIRE,
forrefp->name());
forrefp->name(), NULL, NULL); // width 1
newp->trace(m_modp->modTrace());
m_modp->addStmtp(newp);
// Link it to signal list
+1 -1
View File
@@ -69,7 +69,7 @@ protected:
};
uint32_t m_flags;
VarFlags(AstNode* nodep) { m_flags = nodep->user2(); }
void setNodeFlags(AstNode* nodep) { nodep->user2(m_flags); };
void setNodeFlags(AstNode* nodep) { nodep->user2(m_flags); }
};
};
+27 -22
View File
@@ -34,6 +34,7 @@
#include "V3Global.h"
#include "V3Name.h"
#include "V3Ast.h"
#include "V3LanguageWords.h"
//######################################################################
// Name state, as a visitor of each AstNode
@@ -45,14 +46,11 @@ private:
// AstCell::user1() -> bool. Set true if already processed
// AstScope::user1() -> bool. Set true if already processed
// AstVar::user1() -> bool. Set true if already processed
//
// AstCell::user2() -> bool. Set true if was privitized
// AstVar::user2() -> bool. Set true if was privitized
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
// STATE
AstModule* m_modp;
V3LanguageWords m_words; // Reserved word detector
// METHODS
static int debug() {
@@ -61,6 +59,23 @@ private:
return level;
}
void rename(AstNode* nodep, bool addPvt) {
if (!nodep->user1()) { // Not already done
if (addPvt) {
string newname = (string)"__PVT__"+nodep->name();
nodep->name(newname);
} else {
string rsvd = m_words.isKeyword(nodep->name());
if (rsvd != "") {
nodep->v3warn(SYMRSVDWORD,"Symbol matches "+rsvd+": '"<<nodep->name()<<"'");
string newname = (string)"__SYM__"+nodep->name();
nodep->name(newname);
}
}
nodep->user1(1);
}
}
// VISITORS
virtual void visit(AstModule* nodep, AstNUser*) {
m_modp = nodep;
@@ -70,16 +85,13 @@ private:
// Add __PVT__ to names of local signals
virtual void visit(AstVar* nodep, AstNUser*) {
// Don't iterate... Don't need temps for RANGES under the Var.
if (!nodep->user1()
&& !m_modp->isTop()
&& !nodep->isSigPublic()
&& !nodep->isTemp()) { // Don't bother to rename internal signals
// Change the name to something private...
string newname = (string)"__PVT__"+nodep->name();
nodep->name(newname);
nodep->user1(1);
nodep->user2(1);
}
rename(nodep, (!m_modp->isTop()
&& !nodep->isSigPublic()
&& !nodep->isTemp())); // Don't bother to rename internal signals
}
virtual void visit(AstCFunc* nodep, AstNUser*) {
nodep->iterateChildren(*this);
rename(nodep, false);
}
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (nodep->varp()) {
@@ -88,14 +100,7 @@ private:
}
}
virtual void visit(AstCell* nodep, AstNUser*) {
if (!nodep->user1()
&& !nodep->modp()->modPublic()) {
// Change the name to something private...
string newname = (string)"__PVT__"+nodep->name();
nodep->name(newname);
nodep->user1(1);
nodep->user2(1);
}
rename(nodep, !nodep->modp()->modPublic());
nodep->iterateChildren(*this);
}
virtual void visit(AstScope* nodep, AstNUser*) {
+1 -1
View File
@@ -108,7 +108,7 @@ public:
class VerilogString {}; // for creator type-overload selection
// CONSTRUCTORS
V3Number(FileLine* fileline) { init(fileline, 1); }
V3Number(FileLine* fileline, int width) { init(fileline, width); }; // 0=unsized
V3Number(FileLine* fileline, int width) { init(fileline, width); } // 0=unsized
V3Number(FileLine* fileline, int width, uint32_t value) { init(fileline, width); m_value[0]=value; }
V3Number(FileLine* fileline, const char* source); // Create from a verilog 32'hxxxx number.
V3Number(VerilogString, FileLine* fileline, const string& vvalue);
+4 -4
View File
@@ -60,11 +60,11 @@ public:
bool legal() const { return m_e != ERROR; }
//
enum en m_e;
inline V3LangCode () : m_e(ERROR) {};
inline V3LangCode (en _e) : m_e(_e) {};
inline V3LangCode () : m_e(ERROR) {}
inline V3LangCode (en _e) : m_e(_e) {}
V3LangCode (const char* textp); // Return matching code or ERROR
explicit inline V3LangCode (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
explicit inline V3LangCode (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
//######################################################################
+5 -5
View File
@@ -103,12 +103,12 @@ struct OrderVEdgeType {
};
return names[m_e];
};
}
enum en m_e;
inline OrderVEdgeType () {};
inline OrderVEdgeType (en _e) : m_e(_e) {};
explicit inline OrderVEdgeType (int _e) : m_e(static_cast<en>(_e)) {};
operator en () const { return m_e; };
inline OrderVEdgeType () {}
inline OrderVEdgeType (en _e) : m_e(_e) {}
explicit inline OrderVEdgeType (int _e) : m_e(static_cast<en>(_e)) {}
operator en () const { return m_e; }
};
inline bool operator== (OrderVEdgeType lhs, OrderVEdgeType rhs) { return (lhs.m_e == rhs.m_e); }
inline bool operator== (OrderVEdgeType lhs, OrderVEdgeType::en rhs) { return (lhs.m_e == rhs); }
+8
View File
@@ -127,6 +127,14 @@ private:
}
virtual void visit(AstCell* nodep, AstNUser*);
// Make sure all parameters are constantified
virtual void visit(AstVar* nodep, AstNUser*) {
if (nodep->isParam()) {
if (!nodep->hasSimpleInit()) { nodep->v3fatalSrc("Parameter without initial value"); }
V3Const::constifyParam(nodep); // The variable, not just the var->init()
}
}
// Generate Statements
virtual void visit(AstGenerate* nodep, AstNUser*) {
if (debug()>=9) nodep->dumpTree(cout,"-genin: ");
+1 -1
View File
@@ -69,7 +69,7 @@ wsn [ \t\f]
crnl [\r]*[\n]
quote [\"]
backslash [\\]
symb [a-zA-Z_][a-zA-Z0-9_$]*
symb ([a-zA-Z_][a-zA-Z0-9_$]*|\\[^ \t\f\r\n]+)
drop [\032]
psl [p]sl
+1 -1
View File
@@ -83,7 +83,7 @@ protected:
};
public:
static V3PreProc* createPreProc(FileLine* fileline);
virtual ~V3PreProc() {};
virtual ~V3PreProc() {}
};
#endif // Guard
+1 -1
View File
@@ -103,7 +103,7 @@ public: // But for internal use only
}
// Return next token, for bison, since bison isn't class based, use a global THIS
static int yylex() { return s_readp->yylexThis(); };
static int yylex() { return s_readp->yylexThis(); }
static FileLine* fileline() { return s_readp->m_fileline; }
static AstNetlist* rootp() { return s_readp->m_rootp; }
static FileLine* copyOrSameFileLine() { return s_readp->fileline()->copyOrSameFileLine(); }
+599
View File
@@ -0,0 +1,599 @@
// -*- C++ -*-
//*************************************************************************
// DESCRIPTION: Verilator: Simulate code to determine output values/variables
//
// Code available from: http://www.veripool.org/verilator
//
// AUTHORS: Wilson Snyder with Paul Wasson, Duane Gabli
//
//*************************************************************************
//
// Copyright 2003-2009 by Wilson Snyder. 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.
//
// 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.
//
//*************************************************************************
//
// void example_usage() {
// SimulateVisitor simvis (false, false);
// simvis.clear();
// // Set all inputs to the constant
// for (deque<AstVarScope*>::iterator it = m_inVarps.begin(); it!=m_inVarps.end(); ++it) {
// simvis.newNumber(invscp, #);
// }
// // Simulate
// simvis.main(nodep);
// // Read outputs
// for (deque<AstVarScope*>::iterator it = m_outVarps.begin(); it!=m_outVarps.end(); ++it) {
// V3Number* outnump = simvis.fetchOutNumberNull(outvscp);
//
//*************************************************************************
#ifndef _V3SIMULATE_H_
#define _V3SIMULATE_H_ 1
#include "config_build.h"
#include "verilatedos.h"
#include "V3Error.h"
#include "V3Ast.h"
#include "V3Width.h"
//============================================================================
//######################################################################
// Simulate class functions
class SimulateVisitor : public AstNVisitor {
// Simulate a node tree, returning value of variables
// Two major operating modes:
// Test the tree to see if it is conformant
// Given a set of input values, find the output values
// Both are done in this same visitor to reduce risk; if a visitor
// is missing, we will simply not apply the optimization, rather then bomb.
private:
// NODE STATE
// Cleared on each always/assignw
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
// Checking:
// AstVarScope::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue
// Simulating:
// AstVarScope::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments)
// AstVarScope::user2() -> V3Number*. Output value of variable (delayed assignments)
enum VarUsage { VU_NONE=0, VU_LV=1, VU_RV=2, VU_LVDLY=4 };
// STATE
// Major mode
bool m_checkOnly; ///< Checking only (no simulation) mode
bool m_scoped; ///< Running with AstVarScopes instead of AstVars
bool m_params; ///< Doing parameter propagation
// Checking:
string m_whyNotOptimizable; ///< String explaining why not optimizable or NULL to optimize
AstNode* m_whyNotNodep; ///< First node not optimizable
bool m_anyAssignDly; ///< True if found a delayed assignment
bool m_anyAssignComb; ///< True if found a non-delayed assignment
bool m_inDlyAssign; ///< Under delayed assignment
int m_instrCount; ///< Number of nodes
int m_dataCount; ///< Bytes of data
// Simulating:
deque<V3Number*> m_numFreeps; ///< List of all numbers free and not in use
deque<V3Number*> m_numAllps; ///< List of all numbers free and in use
// Note level 8&9 include debugging each simulation value
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
// Checking METHODS
public:
/// Call other-this function on all new var references
virtual void varRefCb(AstVarRef* nodep) {}
void clearOptimizable(AstNode* nodep/*null ok*/, const string& why) {
// Something bad found. optimizable() will return false,
// and fetchNumber should not be called or it may assert.
if (!m_whyNotNodep) {
m_whyNotNodep = nodep;
if (debug()>=5) {
UINFO(0,"Clear optimizable: "<<why);
if (nodep) cout<<": "<<nodep;
cout<<endl;
}
m_whyNotOptimizable = why;
}
}
inline bool optimizable() const { return m_whyNotNodep==NULL; }
string whyNotMessage() const { return m_whyNotOptimizable; }
AstNode* whyNotNodep() const { return m_whyNotNodep; }
bool isAssignDly() const { return m_anyAssignDly; }
int instrCount() const { return m_instrCount; }
int dataCount() const { return m_dataCount; }
// Simulation METHODS
private:
V3Number* allocNumber(AstNode* nodep, uint32_t value) {
// Save time - kept a list of allocated but unused V3Numbers
// It would be more efficient to do this by size, but the extra accounting
// slows things down more than we gain.
V3Number* nump;
if (!m_numFreeps.empty()) {
//UINFO(7,"Num Reuse "<<nodep->width()<<endl);
nump = m_numFreeps.back(); m_numFreeps.pop_back();
nump->width(nodep->width());
nump->fileline(nodep->fileline());
nump->setLong(value); // We do support more than 32 bit numbers, just valuep=0 in that case
} else {
//UINFO(7,"Num New "<<nodep->width()<<endl);
nump = new V3Number (nodep->fileline(), nodep->width(), value);
m_numAllps.push_back(nump);
}
return nump;
}
public:
V3Number* newNumber(AstNode* nodep, uint32_t value=0) {
// Set a constant value for this node
if (!nodep->user3p()) {
V3Number* nump = allocNumber(nodep, value);
setNumber(nodep, nump);
return nump;
} else {
return (fetchNumber(nodep));
}
}
V3Number* newOutNumber(AstNode* nodep, uint32_t value=0) {
// Set a constant value for this node
if (!nodep->user2p()) {
V3Number* nump = allocNumber(nodep, value);
setOutNumber(nodep, nump);
return nump;
} else {
return (fetchOutNumber(nodep));
}
}
V3Number* fetchNumberNull(AstNode* nodep) {
return ((V3Number*)nodep->user3p());
}
V3Number* fetchOutNumberNull(AstNode* nodep) {
return ((V3Number*)nodep->user2p());
}
V3Number* fetchNumber(AstNode* nodep) {
V3Number* nump = fetchNumberNull(nodep);
if (!nump) nodep->v3fatalSrc("No value found for node.");
//UINFO(9," fetch num "<<*nump<<" on "<<nodep<<endl);
return nump;
}
V3Number* fetchOutNumber(AstNode* nodep) {
V3Number* nump = fetchOutNumberNull(nodep);
if (!nump) nodep->v3fatalSrc("No value found for node.");
return nump;
}
private:
inline void setNumber(AstNode* nodep, const V3Number* nump) {
UINFO(9," set num "<<*nump<<" on "<<nodep<<endl);
nodep->user3p((AstNUser*)nump);
}
inline void setOutNumber(AstNode* nodep, const V3Number* nump) {
UINFO(9," set num "<<*nump<<" on "<<nodep<<endl);
nodep->user2p((AstNUser*)nump);
}
void checkNodeInfo(AstNode* nodep) {
if (m_checkOnly) {
m_instrCount += nodep->instrCount();
m_dataCount += nodep->width();
}
if (!nodep->isPredictOptimizable()) {
//UINFO(9," !predictopt "<<nodep<<endl);
clearOptimizable(nodep,"Isn't predictable");
}
}
void badNodeType(AstNode* nodep) {
// Call for default node types, or other node types we don't know how to handle
checkNodeInfo(nodep);
if (optimizable()) {
// Hmm, what is this then?
// In production code, we'll just not optimize. It should be fixed though.
clearOptimizable(nodep, "Unknown node type, perhaps missing visitor in SimulateVisitor");
#ifdef VL_DEBUG
UINFO(0,"Unknown node type in SimulateVisitor: "<<nodep->prettyTypeName()<<endl);
#endif
}
}
AstNode* varOrScope(AstVarRef* nodep) {
AstNode* vscp;
if (m_scoped) vscp = nodep->varScopep();
else vscp = nodep->varp();
if (!vscp) nodep->v3fatalSrc("Not linked");
return vscp;
}
int unrollCount() {
return m_params ? v3Global.opt.unrollCount()*16
: v3Global.opt.unrollCount();
}
// VISITORS
virtual void visit(AstAlways* nodep, AstNUser*) {
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
}
virtual void visit(AstSenTree* nodep, AstNUser*) {
// Sensitivities aren't inputs per se; we'll keep our tree under the same sens.
}
virtual void visit(AstVarRef* nodep, AstNUser*) {
if (!optimizable()) return; // Accelerate
AstNode* vscp = varOrScope(nodep);
// We can't have non-delayed assignments with same value on LHS and RHS
// as we don't figure out variable ordering.
// Delayed is OK though, as we'll decode the next state separately.
if (nodep->varp()->arraysp()) clearOptimizable(nodep,"Array references");
if (nodep->lvalue()) {
if (m_inDlyAssign) {
if (!(vscp->user1() & VU_LVDLY)) {
vscp->user1( vscp->user1() | VU_LVDLY);
if (m_checkOnly) varRefCb (nodep);
}
} else { // nondly asn
if (!(vscp->user1() & VU_LV)) {
if (!m_params && (vscp->user1() & VU_RV)) clearOptimizable(nodep,"Var read & write");
vscp->user1( vscp->user1() | VU_LV);
if (m_checkOnly) varRefCb (nodep);
}
}
} else {
if (!(vscp->user1() & VU_RV)) {
if (!m_params && (vscp->user1() & VU_LV)) clearOptimizable(nodep,"Var write & read");
vscp->user1( vscp->user1() | VU_RV);
if (m_checkOnly) varRefCb (nodep);
}
}
if (!m_checkOnly && optimizable()) { // simulating
if (nodep->lvalue()) {
nodep->v3fatalSrc("LHS varref should be handled in AstAssign visitor.");
} else {
// Return simulation value - copy by reference instead of value for speed
V3Number* nump = fetchNumberNull(vscp);
if (!nump) {
if (m_params) {
clearOptimizable(nodep,"Language violation: reference to non-function-local variable");
} else {
nodep->v3fatalSrc("Variable value should have been set before any visitor called.");
}
nump = allocNumber(nodep, 0); // Any value; just so recover from error
}
setNumber(nodep, nump);
}
}
}
virtual void visit(AstVarXRef* nodep, AstNUser*) {
if (m_scoped) { badNodeType(nodep); return; }
else { clearOptimizable(nodep,"Language violation: Dotted hierarchical references not allowed in constant functions"); }
}
virtual void visit(AstNodeFTask* nodep, AstNUser*) {
if (!m_params) { badNodeType(nodep); return; }
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
}
virtual void visit(AstNodeIf* nodep, AstNUser*) {
UINFO(5," IF "<<nodep<<endl);
checkNodeInfo(nodep);
if (m_checkOnly) {
nodep->iterateChildren(*this);
} else {
nodep->condp()->iterateAndNext(*this);
if (optimizable()) {
if (fetchNumber(nodep->condp())->isNeqZero()) {
nodep->ifsp()->iterateAndNext(*this);
} else {
nodep->elsesp()->iterateAndNext(*this);
}
}
}
}
virtual void visit(AstConst* nodep, AstNUser*) {
checkNodeInfo(nodep);
if (!m_checkOnly && optimizable()) {
setNumber(nodep, &(nodep->num()));
}
}
virtual void visit(AstNodeUniop* nodep, AstNUser*) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
if (!m_checkOnly && optimizable()) {
nodep->numberOperate(*newNumber(nodep), *fetchNumber(nodep->lhsp()));
}
}
virtual void visit(AstNodeBiop* nodep, AstNUser*) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
if (!m_checkOnly && optimizable()) {
nodep->numberOperate(*newNumber(nodep), *fetchNumber(nodep->lhsp()), *fetchNumber(nodep->rhsp()));
}
}
virtual void visit(AstNodeTriop* nodep, AstNUser*) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
if (!m_checkOnly && optimizable()) {
nodep->numberOperate(*newNumber(nodep),
*fetchNumber(nodep->lhsp()),
*fetchNumber(nodep->rhsp()),
*fetchNumber(nodep->thsp()));
}
}
virtual void visit(AstNodeCond* nodep, AstNUser*) {
// We could use above visit(AstNodeTriop), but it's slower even O(n^2) to evaluate
// both sides when we really only need to evaluate one side.
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
if (m_checkOnly) {
nodep->iterateChildren(*this);
} else {
nodep->condp()->accept(*this);
if (optimizable()) {
if (fetchNumber(nodep->condp())->isNeqZero()) {
nodep->expr1p()->accept(*this);
newNumber(nodep)->opAssign(*fetchNumber(nodep->expr1p()));
} else {
nodep->expr2p()->accept(*this);
newNumber(nodep)->opAssign(*fetchNumber(nodep->expr2p()));
}
}
}
}
virtual void visit(AstNodeAssign* nodep, AstNUser*) {
if (!optimizable()) return; // Accelerate
if (nodep->castAssignDly()) {
if (m_anyAssignComb) clearOptimizable(nodep, "Mix of dly/non dly assigns");
m_anyAssignDly = true;
m_inDlyAssign = true;
} else {
if (m_anyAssignDly) clearOptimizable(nodep, "Mix of dly/non dly assigns");
m_anyAssignComb = true;
}
if (!nodep->lhsp()->castVarRef()) {
clearOptimizable(nodep, "LHS isn't simple variable");
}
else if (m_checkOnly) {
nodep->iterateChildren(*this);
}
else if (optimizable()) {
nodep->rhsp()->iterateAndNext(*this);
if (optimizable()) {
AstNode* vscp = varOrScope(nodep->lhsp()->castVarRef());
// Copy by value, not reference, as we don't want a=a+1 to get right results
if (nodep->castAssignDly()) {
// Don't do setNumber, as value isn't yet visible to following statements
newOutNumber(vscp)->opAssign(*fetchNumber(nodep->rhsp()));
} else {
newNumber(vscp)->opAssign(*fetchNumber(nodep->rhsp()));
newOutNumber(vscp)->opAssign(*fetchNumber(nodep->rhsp()));
}
}
}
m_inDlyAssign = false;
}
virtual void visit(AstBegin* nodep, AstNUser*) {
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
}
virtual void visit(AstNodeCase* nodep, AstNUser*) {
UINFO(5," CASE "<<nodep<<endl);
checkNodeInfo(nodep);
if (m_checkOnly) {
nodep->iterateChildren(*this);
} else if (optimizable()) {
nodep->exprp()->iterateAndNext(*this);
bool hit = false;
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
if (!itemp->isDefault()) {
for (AstNode* ep = itemp->condsp(); ep; ep=ep->nextp()) {
if (hit) break;
ep->iterateAndNext(*this);
if (optimizable()) {
V3Number match (nodep->fileline(), 1);
match.opEq(*fetchNumber(nodep->exprp()), *fetchNumber(ep));
if (match.isNeqZero()) {
itemp->bodysp()->iterateAndNext(*this);
hit = true;
}
}
}
}
}
// Else default match
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=itemp->nextp()->castCaseItem()) {
if (hit) break;
if (!hit && itemp->isDefault()) {
itemp->bodysp()->iterateAndNext(*this);
hit = true;
}
}
}
}
virtual void visit(AstCaseItem* nodep, AstNUser*) {
// Real handling is in AstNodeCase
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
}
virtual void visit(AstComment*, AstNUser*) {}
virtual void visit(AstStop* nodep, AstNUser*) {
if (m_params) { // This message seems better than an obscure $stop
// The spec says $stop is just ignored, it seems evil to ignore assertions
clearOptimizable(nodep,"$stop executed during function constification; maybe indicates assertion firing");
}
checkNodeInfo(nodep);
}
virtual void visit(AstNodeFor* nodep, AstNUser*) {
// Doing lots of Whiles is slow, so only for parameters
UINFO(5," FOR "<<nodep<<endl);
if (!m_params) { badNodeType(nodep); return; }
checkNodeInfo(nodep);
if (m_checkOnly) {
nodep->iterateChildren(*this);
} else if (optimizable()) {
int loops = 0;
nodep->initsp()->iterateAndNext(*this);
while (1) {
UINFO(5," FOR-ITER "<<nodep<<endl);
nodep->condp()->iterateAndNext(*this);
if (!optimizable()) break;
if (!fetchNumber(nodep->condp())->isNeqZero()) {
break;
}
nodep->bodysp()->iterateAndNext(*this);
nodep->incsp()->iterateAndNext(*this);
if (loops++ > unrollCount()*16) {
clearOptimizable(nodep, "Loop unrolling took too long; probably this is an infinite loop, or set --unroll-count above "+cvtToStr(unrollCount()));
break;
}
}
}
}
virtual void visit(AstWhile* nodep, AstNUser*) {
// Doing lots of Whiles is slow, so only for parameters
UINFO(5," WHILE "<<nodep<<endl);
if (!m_params) { badNodeType(nodep); return; }
checkNodeInfo(nodep);
if (m_checkOnly) {
nodep->iterateChildren(*this);
} else if (optimizable()) {
int loops = 0;
while (1) {
UINFO(5," WHILE-ITER "<<nodep<<endl);
nodep->precondsp()->iterateAndNext(*this);
nodep->condp()->iterateAndNext(*this);
if (!optimizable()) break;
if (!fetchNumber(nodep->condp())->isNeqZero()) {
break;
}
nodep->bodysp()->iterateAndNext(*this);
if (loops++ > unrollCount()*16) {
clearOptimizable(nodep, "Loop unrolling took too long; probably this is an infinite loop, or set --unroll-count above "+cvtToStr(unrollCount()));
break;
}
}
}
}
virtual void visit(AstFuncRef* nodep, AstNUser*) {
UINFO(5," FUNCREF "<<nodep<<endl);
if (!m_params) { badNodeType(nodep); return; }
AstFunc* funcp = nodep->taskp()->castFunc(); if (!funcp) nodep->v3fatalSrc("Not linked");
V3Width::widthSignedIfNotAlready(funcp); // Make sure we've sized the function
// Apply function call values to function
// Note we'd need a stack if we allowed recursive functions!
AstNode* pinp = nodep->pinsp(); AstNode* nextpinp = NULL;
for (AstNode* stmtp = funcp->stmtsp(); stmtp; pinp=nextpinp, stmtp=stmtp->nextp()) {
if (AstVar* portp = stmtp->castVar()) {
if (portp->isIO()) {
if (pinp==NULL) {
nodep->v3error("Too few arguments in function call");
} else {
nextpinp = pinp->nextp();
if (portp->isOutput()) {
clearOptimizable(portp,"Language violation: Outputs not allowed in constant functions");
return;
}
// Evaluate pin value
pinp->accept(*this);
// Apply value to the function
if (!m_checkOnly && optimizable()) {
newNumber(stmtp)->opAssign(*fetchNumber(pinp));
}
}
}
}
}
// Evaluate the function
funcp->accept(*this);
if (!m_checkOnly && optimizable()) {
// Grab return value from output variable
newNumber(nodep)->opAssign(*fetchNumber(funcp->fvarp()));
}
}
virtual void visit(AstVar* nodep, AstNUser*) {
if (!m_params) { badNodeType(nodep); return; }
}
// default
// These types are definately not reducable
// AstCoverInc, AstNodePli, AstArraySel, AstStop, AstFinish,
// AstRand, AstTime, AstUCFunc, AstCCall, AstCStmt, AstUCStmt
virtual void visit(AstNode* nodep, AstNUser*) {
badNodeType(nodep);
}
public:
// CONSTRUCTORS
SimulateVisitor() {
setMode(false,false,false);
clear(); // We reuse this structure in the main loop, so put initializers inside clear()
}
void setMode(bool scoped, bool checkOnly, bool params) {
m_checkOnly = checkOnly;
m_scoped = scoped;
m_params = params;
}
void clear() {
m_whyNotOptimizable = "";
m_whyNotNodep = NULL;
m_anyAssignComb = false;
m_anyAssignDly = false;
m_inDlyAssign = false;
m_instrCount = 0;
m_dataCount = 0;
AstNode::user1ClearTree(); // user1p() used on entire tree
AstNode::user2ClearTree(); // user2p() used on entire tree
AstNode::user3ClearTree(); // user3p() used on entire tree
// Move all allocated numbers to the free pool
m_numFreeps = m_numAllps;
}
void mainTableCheck (AstNode* nodep) {
setMode(true/*scoped*/,true/*checking*/, false/*params*/);
nodep->accept(*this);
}
void mainTableEmulate (AstNode* nodep) {
setMode(true/*scoped*/,false/*checking*/, false/*params*/);
nodep->accept(*this);
}
void mainParamEmulate (AstNode* nodep) {
setMode(false/*scoped*/,false/*checking*/, true/*params*/);
nodep->accept(*this);
}
virtual ~SimulateVisitor() {
for (deque<V3Number*>::iterator it = m_numAllps.begin(); it != m_numAllps.end(); ++it) {
delete (*it);
}
m_numFreeps.clear();
m_numAllps.clear();
}
};
#endif // Guard
+8 -8
View File
@@ -34,19 +34,19 @@ class V3Double0 {
double m_d; ///< Count of occurrences/ value
public:
// METHODS
V3Double0() : m_d(0) {};
V3Double0() : m_d(0) {}
~V3Double0() {}
// Implicit conversion operators:
inline V3Double0 (const vluint64_t v) : m_d(v) { };
inline operator double () const { return m_d; };
inline V3Double0 (const vluint64_t v) : m_d(v) { }
inline operator double () const { return m_d; }
// Explicit operators:
inline V3Double0& operator++() { ++m_d; return *this; }; // prefix
inline V3Double0 operator++(int) { V3Double0 old=*this; m_d++; return old; }; // postfix
inline V3Double0& operator= (const double v) { m_d = v; return *this; };
inline V3Double0& operator+=(const double v) { m_d += v; return *this; };
inline V3Double0& operator-=(const double v) { m_d -= v; return *this; };
inline V3Double0& operator++() { ++m_d; return *this; } // prefix
inline V3Double0 operator++(int) { V3Double0 old=*this; m_d++; return old; } // postfix
inline V3Double0& operator= (const double v) { m_d = v; return *this; }
inline V3Double0& operator+=(const double v) { m_d += v; return *this; }
inline V3Double0& operator-=(const double v) { m_d -= v; return *this; }
};
//============================================================================
+26 -352
View File
@@ -36,6 +36,7 @@
#include "V3Global.h"
#include "V3Table.h"
#include "V3Simulate.h"
#include "V3Stats.h"
#include "V3Ast.h"
@@ -48,365 +49,31 @@ static const double TABLE_TOTAL_BYTES = 64*1024*1024; // 64MB is close to max me
static const double TABLE_SPACE_TIME_MULT = 8; // Worth 8 bytes of data to replace a instruction
static const int TABLE_MIN_NODE_COUNT = 32; // If < 32 instructions, not worth the effort
//######################################################################
class TableVisitor;
//######################################################################
class TableBaseVisitor : public AstNVisitor {
public:
// Note level 8&9 include debugging each simulation value
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
};
//######################################################################
class TableSimulateVisitor : public TableBaseVisitor {
// Simulate a node tree, returning value of variables
// Two major operating modes:
// Test the tree to see if it is conformant
// Given a set of input values, find the output values
// Both are done in this same visitor to reduce risk; if a visitor
// is missing, we will simply not apply the optimization, rather then bomb.
private:
// NODE STATE
// Cleared on each always/assignw
// Checking:
// AstVarScope::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue
// Simulating:
// AstVarScope::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments)
// AstVarScope::user4() -> V3Number*. Output value of variable (delayed assignments)
enum VarUsage { VU_NONE=0, VU_LV=1, VU_RV=2, VU_LVDLY=4 };
// STATE
bool m_checking; ///< Checking vs. simulation mode
// Checking:
class TableSimulateVisitor : public SimulateVisitor {
// MEMBERS
TableVisitor* m_cbthis; ///< Class for callback
const char* m_whyNotOptimizable; ///< String explaining why not optimizable or NULL to optimize
bool m_anyAssignDly; ///< True if found a delayed assignment
bool m_anyAssignComb; ///< True if found a non-delayed assignment
bool m_inDlyAssign; ///< Under delayed assignment
int m_instrCount; ///< Number of nodes
int m_dataCount; ///< Bytes of data
// Simulating:
deque<V3Number*> m_numFreeps; ///< List of all numbers free and not in use
deque<V3Number*> m_numAllps; ///< List of all numbers free and in use
// Checking METHODS
public:
void varRefCb(AstVarRef* nodep); ///< Call other-this function on all new var references
void clearOptimizable(AstNode* nodep/*null ok*/, const char* why) {
if (!m_whyNotOptimizable) {
if (debug()>=5) {
UINFO(0,"Clear optimizable: "<<why);
if (nodep) cout<<": "<<nodep;
cout<<endl;
}
m_whyNotOptimizable = why;
}
}
bool optimizable() const { return m_whyNotOptimizable==NULL; }
bool isAssignDly() const { return m_anyAssignDly; }
int instrCount() const { return m_instrCount; }
int dataCount() const { return m_dataCount; }
// Simulation METHODS
private:
V3Number* allocNumber(AstNode* nodep, uint32_t value) {
// Save time - kept a list of allocated but unused V3Numbers
// It would be more efficient to do this by size, but the extra accounting
// slows things down more than we gain.
V3Number* nump;
if (!m_numFreeps.empty()) {
//UINFO(7,"Num Reuse "<<nodep->width()<<endl);
nump = m_numFreeps.back(); m_numFreeps.pop_back();
nump->width(nodep->width());
nump->fileline(nodep->fileline());
nump->setLong(value); // We do support more than 32 bit numbers, just valuep=0 in that case
} else {
//UINFO(7,"Num New "<<nodep->width()<<endl);
nump = new V3Number (nodep->fileline(), nodep->width(), value);
m_numAllps.push_back(nump);
}
return nump;
}
public:
V3Number* newNumber(AstNode* nodep, uint32_t value=0) {
// Set a constant value for this node
if (!nodep->user3p()) {
V3Number* nump = allocNumber(nodep, value);
setNumber(nodep, nump);
}
return (fetchNumber(nodep));
}
V3Number* newOutNumber(AstNode* nodep, uint32_t value=0) {
// Set a constant value for this node
if (!nodep->user4p()) {
V3Number* nump = allocNumber(nodep, value);
setOutNumber(nodep, nump);
}
return (fetchOutNumber(nodep));
}
V3Number* fetchNumberNull(AstNode* nodep) {
return ((V3Number*)nodep->user3p());
}
V3Number* fetchOutNumberNull(AstNode* nodep) {
return ((V3Number*)nodep->user4p());
}
V3Number* fetchNumber(AstNode* nodep) {
V3Number* nump = fetchNumberNull(nodep);
if (!nump) nodep->v3fatalSrc("No value found for node.");
return nump;
}
V3Number* fetchOutNumber(AstNode* nodep) {
V3Number* nump = fetchOutNumberNull(nodep);
if (!nump) nodep->v3fatalSrc("No value found for node.");
return nump;
}
private:
void setNumber(AstNode* nodep, const V3Number* nump) {
UINFO(9," set num "<<*nump<<" on "<<nodep<<endl);
nodep->user3p((AstNUser*)nump);
}
void setOutNumber(AstNode* nodep, const V3Number* nump) {
UINFO(9," set num "<<*nump<<" on "<<nodep<<endl);
nodep->user4p((AstNUser*)nump);
}
void checkNodeInfo(AstNode* nodep) {
m_instrCount += nodep->instrCount();
m_dataCount += nodep->width();
if (!nodep->isPredictOptimizable()) {
//UINFO(9," !predictopt "<<nodep<<endl);
clearOptimizable(nodep,"!predictOptimzable");
}
}
// VISITORS
virtual void visit(AstAlways* nodep, AstNUser*) {
if (m_checking) checkNodeInfo(nodep);
nodep->iterateChildren(*this);
}
virtual void visit(AstSenTree* nodep, AstNUser*) {
// Sensitivities aren't inputs per se; we'll keep our tree under the same sens.
}
virtual void visit(AstVarRef* nodep, AstNUser*) {
AstVarScope* vscp = nodep->varScopep();
if (!vscp) nodep->v3fatalSrc("Not linked");
if (m_checking) {
if (m_checking && !optimizable()) return; // Accelerate
// We can't have non-delayed assignments with same value on LHS and RHS
// as we don't figure out variable ordering.
// Delayed is OK though, as we'll decode the next state separately.
if (nodep->varp()->arraysp()) clearOptimizable(nodep,"Array references");
if (nodep->lvalue()) {
if (m_inDlyAssign) {
if (!(vscp->user1() & VU_LVDLY)) {
vscp->user1( vscp->user1() | VU_LVDLY);
varRefCb (nodep);
}
} else { // nondly asn
if (!(vscp->user1() & VU_LV)) {
if (vscp->user1() & VU_RV) clearOptimizable(nodep,"Var read & write");
vscp->user1( vscp->user1() | VU_LV);
varRefCb (nodep);
}
}
} else {
if (!(vscp->user1() & VU_RV)) {
if (vscp->user1() & VU_LV) clearOptimizable(nodep,"Var write & read");
vscp->user1( vscp->user1() | VU_RV);
varRefCb (nodep);
}
}
}
else { // simulating
if (nodep->lvalue()) {
nodep->v3fatalSrc("LHS varref should be handled in AstAssign visitor.");
} else {
// Return simulation value
V3Number* nump = fetchNumberNull(vscp);
if (!nump) nodep->v3fatalSrc("Variable value should have been set before any visitor called.");
setNumber(nodep, nump);
}
}
}
virtual void visit(AstNodeIf* nodep, AstNUser*) {
if (m_checking) {
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
} else {
nodep->condp()->iterateAndNext(*this);
if (fetchNumber(nodep->condp())->isNeqZero()) {
nodep->ifsp()->iterateAndNext(*this);
} else {
nodep->elsesp()->iterateAndNext(*this);
}
}
}
virtual void visit(AstConst* nodep, AstNUser*) {
if (m_checking) {
checkNodeInfo(nodep);
} else {
setNumber(nodep, &(nodep->num()));
}
}
virtual void visit(AstNodeUniop* nodep, AstNUser*) {
if (m_checking) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
} else {
nodep->iterateChildren(*this);
nodep->numberOperate(*newNumber(nodep), *fetchNumber(nodep->lhsp()));
}
}
virtual void visit(AstNodeBiop* nodep, AstNUser*) {
if (m_checking) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
} else {
nodep->iterateChildren(*this);
nodep->numberOperate(*newNumber(nodep), *fetchNumber(nodep->lhsp()), *fetchNumber(nodep->rhsp()));
}
}
virtual void visit(AstNodeTriop* nodep, AstNUser*) {
if (m_checking) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
} else {
nodep->iterateChildren(*this);
nodep->numberOperate(*newNumber(nodep),
*fetchNumber(nodep->lhsp()),
*fetchNumber(nodep->rhsp()),
*fetchNumber(nodep->thsp()));
}
}
virtual void visit(AstNodeCond* nodep, AstNUser*) {
// We could use above visit(AstNodeTriop), but it's slower even O(n^2) to evaluate
// both sides when we really only need to evaluate one side.
if (m_checking) {
if (!optimizable()) return; // Accelerate
checkNodeInfo(nodep);
nodep->iterateChildren(*this);
} else {
nodep->condp()->accept(*this);
if (fetchNumber(nodep->condp())->isNeqZero()) {
nodep->expr1p()->accept(*this);
newNumber(nodep)->opAssign(*fetchNumber(nodep->expr1p()));
} else {
nodep->expr2p()->accept(*this);
newNumber(nodep)->opAssign(*fetchNumber(nodep->expr2p()));
}
}
}
virtual void visit(AstNodeAssign* nodep, AstNUser*) {
if (m_checking) {
if (!optimizable()) return; // Accelerate
if (nodep->castAssignDly()) {
if (m_anyAssignComb) clearOptimizable(nodep, "Mix of dly/non dly assigns");
m_anyAssignDly = true;
m_inDlyAssign = true;
} else {
if (m_anyAssignDly) clearOptimizable(nodep, "Mix of dly/non dly assigns");
m_anyAssignComb = true;
}
nodep->iterateChildren(*this);
}
if (!nodep->lhsp()->castVarRef()) {
clearOptimizable(nodep, "LHS isn't simple variable");
}
else if (!m_checking) {
nodep->rhsp()->iterateAndNext(*this);
AstVarScope* vscp = nodep->lhsp()->castVarRef()->varScopep();
if (nodep->castAssignDly()) {
// Don't do setNumber, as value isn't yet visible to following statements
setOutNumber(vscp, fetchNumber(nodep->rhsp()));
} else {
setNumber(vscp, fetchNumber(nodep->rhsp()));
setOutNumber(vscp, fetchNumber(nodep->rhsp()));
}
}
m_inDlyAssign = false;
}
virtual void visit(AstComment*, AstNUser*) {}
// default
// These types are definately not reducable
// AstCoverInc, AstNodePli, AstArraySel, AstStop, AstFinish,
// AstRand, AstTime, AstUCFunc, AstCCall, AstCStmt, AstUCStmt
// In theory, we could follow the loop, but might be slow
// AstFor, AstWhile
virtual void visit(AstNode* nodep, AstNUser*) {
if (m_checking) {
checkNodeInfo(nodep);
if (optimizable()) {
// Hmm, what is this then?
// In production code, we'll just not optimize. It should be fixed though.
clearOptimizable(nodep, "Unknown node type, perhaps missing visitor in TableSimulateVisitor");
#ifdef VL_DEBUG
UINFO(0,"Unknown node type in TableSimulateVisitor: "<<nodep->prettyTypeName()<<endl);
#endif
}
} else { // simulating
nodep->v3fatalSrc("Optimizable should have been cleared in check step, and never reach simulation.");
}
}
public:
virtual void varRefCb(AstVarRef* nodep); ///< Call other-this function on all new var references
// CONSTRUCTORS
TableSimulateVisitor(TableVisitor* cbthis, bool checking) {
TableSimulateVisitor(TableVisitor* cbthis) {
m_cbthis = cbthis;
m_checking = checking;
clear(); // We reuse this structure in the main loop, so put initializers inside clear()
}
void clear() {
m_whyNotOptimizable = NULL;
m_anyAssignComb = false;
m_anyAssignDly = false;
m_inDlyAssign = false;
m_instrCount = 0;
m_dataCount = 0;
AstNode::user1ClearTree(); // user1p() used on entire tree
AstNode::user3ClearTree(); // user3p() used on entire tree
AstNode::user4ClearTree(); // user4p() used on entire tree
// Move all allocated numbers to the free pool
m_numFreeps = m_numAllps;
}
void main (AstNode* nodep) {
nodep->accept(*this);
}
virtual ~TableSimulateVisitor() {
for (deque<V3Number*>::iterator it = m_numAllps.begin(); it != m_numAllps.end(); ++it) {
delete (*it);
}
m_numFreeps.clear();
m_numAllps.clear();
}
virtual ~TableSimulateVisitor() {}
};
//######################################################################
// Table class functions
class TableVisitor : public TableBaseVisitor {
class TableVisitor : public AstNVisitor {
private:
// NODE STATE
// Cleared on each always/assignw
AstUser1InUse m_inuser1;
AstUser2InUse m_inuser2;
AstUser3InUse m_inuser3;
AstUser4InUse m_inuser4;
// STATE
double m_totalBytes; // Total bytes in tables created
@@ -432,6 +99,12 @@ private:
deque<AstVarScope*> m_tableVarps; // Table being created
// METHODS
static int debug() {
static int level = -1;
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__);
return level;
}
bool treeTest(AstAlways* nodep) {
// Process alw/assign tree
m_inWidth = 0;
@@ -441,8 +114,8 @@ private:
m_outNotSet.clear();
// Collect stats
TableSimulateVisitor chkvis (this, true);
chkvis.main(nodep);
TableSimulateVisitor chkvis (this);
chkvis.mainTableCheck(nodep);
m_assignDly = chkvis.isAssignDly();
// Also sets m_inWidth
// Also sets m_outWidth
@@ -458,19 +131,19 @@ private:
double bytesPerInst = 4;
double time = (chkvis.instrCount()*bytesPerInst + chkvis.dataCount()) + 1; // +1 so won't div by zero
if (chkvis.instrCount() < TABLE_MIN_NODE_COUNT) {
chkvis.clearOptimizable(nodep,"Too few nodes involved");
chkvis.clearOptimizable(nodep,"Table has too few nodes involved");
}
if (space > TABLE_MAX_BYTES) {
chkvis.clearOptimizable(nodep,"Too much space");
chkvis.clearOptimizable(nodep,"Table takes too much space");
}
if (space > time * TABLE_SPACE_TIME_MULT) {
chkvis.clearOptimizable(nodep,"Bad tradeoff");
chkvis.clearOptimizable(nodep,"Table has bad tradeoff");
}
if (m_totalBytes > TABLE_TOTAL_BYTES) {
chkvis.clearOptimizable(nodep,"Out of memory");
chkvis.clearOptimizable(nodep,"Table out of memory");
}
if (!m_outWidth || !m_inWidth) {
chkvis.clearOptimizable(nodep,"No I/O");
chkvis.clearOptimizable(nodep,"Table has no outputs");
}
UINFO(4, " Test: Opt="<<(chkvis.optimizable()?"OK":"NO")
<<", Instrs="<<chkvis.instrCount()<<" Data="<<chkvis.dataCount()
@@ -599,7 +272,7 @@ private:
m_outNotSet.push_back(false);
}
uint32_t inValueNextInitArray=0;
TableSimulateVisitor simvis (this, false);
TableSimulateVisitor simvis (this);
for (uint32_t inValue=0; inValue <= VL_MASK_I(m_inWidth); inValue++) {
// Make a new simulation structure so we can set new input values
UINFO(8," Simulating "<<hex<<inValue<<endl);
@@ -621,7 +294,8 @@ private:
}
// Simulate
simvis.main(nodep);
simvis.mainTableEmulate(nodep);
if (!simvis.optimizable()) simvis.whyNotNodep()->v3fatalSrc("Optimizable cleared, even though earlier test run said not: "<<simvis.whyNotMessage());
// If a output changed, add it to table
int outnum = 0;
+17 -4
View File
@@ -52,6 +52,7 @@
#include "V3Global.h"
#include "V3Width.h"
#include "V3Signed.h"
#include "V3Number.h"
#include "V3Const.h"
@@ -66,7 +67,7 @@
int m_minWidth; // Minimum width, for (2+2), it's 2 bits, for 32'2+32'2 it's 32 bits
Stage m_stage; // If true, report errors
public:
WidthVP(int width, int minWidth, Stage stage) : m_width(width), m_minWidth(minWidth), m_stage(stage) {};
WidthVP(int width, int minWidth, Stage stage) : m_width(width), m_minWidth(minWidth), m_stage(stage) {}
int width() const { return m_width; }
int widthMin() const { return m_minWidth?m_minWidth:m_width; }
bool prelim() const { return m_stage&1; }
@@ -442,6 +443,8 @@ private:
virtual void visit(AstVar* nodep, AstNUser* vup) {
//if (debug()) nodep->dumpTree(cout," InitPre: ");
// Must have deterministic constant width
// We can't skip this step when width()!=0, as creating a AstVar
// with non-constant range gets size 1, not size 0.
int width=1; int mwidth=1;
nodep->arraysp()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p());
if (nodep->rangep()) {
@@ -457,8 +460,11 @@ private:
}
if (nodep->initp()) {
nodep->initp()->iterateAndNext(*this,WidthVP(width,0,BOTH).p());
if (nodep->isParam() && !nodep->rangep()) {
if (nodep->initp()->widthSized()) {
if (nodep->isParam()) {
if (nodep->rangep()) {
// Parameters need to preserve widthMin from the value, not get a constant size
mwidth = nodep->initp()->widthMin();
} else if (nodep->initp()->widthSized()) {
width = mwidth = nodep->initp()->width();
} else {
if (nodep->initp()->width()>32) nodep->initp()->v3warn(WIDTH,"Assigning >32 bit to unranged parameter (defaults to 32 bits)\n");
@@ -847,7 +853,7 @@ public:
m_taskDepth = 0;
m_cellRangep = NULL;
m_casep = NULL;
nodep->accept(*this);
nodep->accept(*this, WidthVP(ANYSIZE,0,BOTH).p());
}
virtual ~WidthVisitor() {}
};
@@ -1192,6 +1198,13 @@ void V3Width::widthParams(AstNode* nodep) {
WidthVisitor visitor (nodep, true);
}
void V3Width::widthSignedIfNotAlready(AstNode* nodep) {
if (!nodep->width()) {
V3Width::widthParams(nodep);
V3Signed::signedParams(nodep);
}
}
void V3Width::widthCommit(AstNode* nodep) {
UINFO(2,__FUNCTION__<<": "<<endl);
WidthCommitVisitor visitor (nodep);
+1
View File
@@ -34,6 +34,7 @@ public:
static void width(AstNetlist* nodep);
// Smaller step... Only do a single node for parameter propagation
static void widthParams(AstNode* nodep);
static void widthSignedIfNotAlready(AstNode* nodep);
// Final step... Mark all widths as equal
static void widthCommit(AstNode* nodep);
};
+1 -1
View File
@@ -25,7 +25,7 @@
//**********************************************************************
//**** Version and host name
#define DTVERSION "Verilator 3.712 2009/07/14"
#define DTVERSION "Verilator 3.713 2009/08/04"
//**********************************************************************
//**** Functions
+1 -1
View File
@@ -358,6 +358,7 @@ escid \\[^ \t\f\r\n]+
"endproperty" { FL; return yENDPROPERTY; }
"final" { FL; return yFINAL; }
"iff" { FL; return yIFF; }
"logic" { FL; return yLOGIC; }
"priority" { FL; return yPRIORITY; }
"static" { FL; return ySTATIC; }
"timeprecision" { FL; return yTIMEPRECISION; }
@@ -407,7 +408,6 @@ escid \\[^ \t\f\r\n]+
"join_any" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"join_none" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"local" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"logic" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"longint" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"matches" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
"modport" { yyerrorf("Unsupported: SystemVerilog 2005 reserved word not implemented: %s",yytext); }
+2
View File
@@ -246,6 +246,7 @@ class AstSenTree;
%token<fileline> yGENVAR "genvar"
%token<fileline> yIF "if"
%token<fileline> yIFF "iff"
%token<fileline> yLOGIC "logic"
%token<fileline> yINITIAL "initial"
%token<fileline> yINOUT "inout"
%token<fileline> yINPUT "input"
@@ -823,6 +824,7 @@ data_type<rangep>: // ==IEEE: data_type
data_typeNoRef<rangep>: // ==IEEE: data_type, excluding class_type etc references
yINTEGER { VARDECL(INTEGER); $$ = new AstRange($1,31,0); $$->isSigned(true); }
| yREG signingE rangeListE { VARDECL(REG); $$ = $3; }
| yLOGIC signingE rangeListE { VARDECL(REG); $$ = $3; }
//UNSUP: above instead of integer_type
//
//UNSUP integer_type signingE regArRangeE { UNSUP }
+1 -1
View File
@@ -87,7 +87,7 @@ module Test (/*AUTOARG*/
// merge the output values into the result vector.
input clk;
input [31:0] in;
input [31:0] in;
output reg [31:0] out;
always @(posedge clk) begin
+3
View File
@@ -8,6 +8,9 @@ module t;
`ifndef GOT_DEF2
$write("%%Error: NO GOT_DEF2\n"); $stop;
`endif
`ifndef GOT_DEF3
$write("%%Error: NO GOT_DEF3\n"); $stop;
`endif
`ifdef NON_DEF
$write("%%Error: NON_DEF\n"); $stop;
`endif
+2
View File
@@ -1,2 +1,4 @@
// Test that environment substitutions work
-f $VERILATOR_ROOT/test_regress/t/t_flag_f__2.vc
// Env var with .v file
$VERILATOR_ROOT/test_regress/t/t_flag_f__3.v
+1
View File
@@ -0,0 +1 @@
`define GOT_DEF3 1
@@ -8,12 +8,11 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di
# Version 2.0.
compile (
fails=>$Self->{v3},
expect=>
'%Error: t/t_var_bad_rsvd.v:\d+: Unsupported: C\+\+ common word: bool
%Error: t/t_var_bad_rsvd.v:\d+: Unsupported: C\+\+ reserved word: switch
%Error: Exiting due to.*',
);
execute (
check_finished=>1,
);
ok(1);
1;
@@ -3,15 +3,12 @@
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2003 by Wilson Snyder.
module t_loop (/*AUTOARG*/
// Outputs
passed,
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
output passed; reg passed; initial passed = 0;
reg [7:0] cyc; initial cyc=0;
reg [31:0] loops;
@@ -53,8 +50,8 @@ module t_loop (/*AUTOARG*/
end
if (loops !== 100000) $stop;
//
$write("[%0t] t_loop: Passed\n",$time);
passed <= 1'b1;
$write("*-* All Finished *-*\n");
$finish;
end
end
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. 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.
compile (
);
execute (
check_finished=>1,
);
ok(1);
1;
+72
View File
@@ -0,0 +1,72 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2009 by Wilson Snyder.
module t;
localparam P4 = f_add(P3,1);
localparam P8 = f_add2(P3,P3,f_add(1,1));
localparam P5 = f_while(7);
localparam P16 = f_for(P4);
localparam P18 = f_case(P4);
localparam P3 = 3;
initial begin
`ifdef TEST_VERBOSE
$display("P5=%0d P8=%0d P16=%0d P18=%0d",P5,P8,P16,P18);
`endif
if (P3 !== 3) $stop;
if (P4 !== 4) $stop;
if (P5 !== 5) $stop;
if (P8 !== 8) $stop;
if (P16 !== 16) $stop;
if (P18 !== 18) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
function integer f_add(input [31:0] a, input [31:0] b);
f_add = a+b;
endfunction
// Speced ok: function called from function
function integer f_add2(input [31:0] a, input [31:0] b, input [31:0] c);
f_add2 = f_add(a,b)+c;
endfunction
// Speced ok: local variables
function integer f_for(input [31:0] a);
integer i;
integer times;
begin
times = 1;
for (i=0; i<a; i=i+1) times = times*2;
f_for = times;
end
endfunction
function integer f_while(input [31:0] a);
integer i;
begin
i=0;
begin : named
f_while = 1;
end : named
while (i<=a) begin
if (i[0]) f_while = f_while + 1;
i = i + 1;
end
end
endfunction
// Speced ok: local variables
function integer f_case(input [31:0] a);
case(a)
32'd1: f_case = 1;
32'd0, 32'd4: f_case = 18;
32'd1234: begin $display("never get here"); $stop; end
default: f_case = 99;
endcase
endfunction
endmodule
+28
View File
@@ -0,0 +1,28 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. 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.
compile (
v_flags2 => ["--lint-only"],
fails=>1,
expect=>
q{%Error: t/t_func_const_bad.v:\d+: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_output'
%Error: t/t_func_const_bad.v:\d+: ... Location of non-constant VAR 'o': Language violation: Outputs not allowed in constant functions
%Error: t/t_func_const_bad.v:\d+: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_dotted'
%Error: t/t_func_const_bad.v:\d+: ... Location of non-constant VARXREF 'EIGHT': Language violation: Dotted hierarchical references not allowed in constant functions
%Error: t/t_func_const_bad.v:\d+: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_nonparam'
%Error: t/t_func_const_bad.v:\d+: ... Location of non-constant VARREF 'modvar': Language violation: reference to non-function-local variable
%Error: t/t_func_const_bad.v:\d+: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_infinite'
%Error: t/t_func_const_bad.v:\d+: ... Location of non-constant WHILE: Loop unrolling took too long; probably this is an infinite loop, or set --unroll-count above 1024
%Error: t/t_func_const_bad.v:\d+: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_stop'
%Error: t/t_func_const_bad.v:\d+: ... Location of non-constant STOP: .stop executed during function constification; maybe indicates assertion firing
%Error: Exiting due to.*},
);
ok(1);
1;
+48
View File
@@ -0,0 +1,48 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2009 by Wilson Snyder.
module t;
// Speced ignored: system calls. I think this is nasty, so we error instead.
// Speced Illegal: inout/output/ref not allowed
localparam B1 = f_bad_output(1,2);
function integer f_bad_output(input [31:0] a, output [31:0] o);
f_bad_output = 0;
endfunction
// Speced Illegal: void
// Speced Illegal: dotted
localparam EIGHT = 8;
localparam B2 = f_bad_dotted(2);
function integer f_bad_dotted(input [31:0] a);
f_bad_dotted = t.EIGHT;
endfunction
// Speced Illegal: ref to non-local var
integer modvar;
localparam B3 = f_bad_nonparam(3);
function integer f_bad_nonparam(input [31:0] a);
f_bad_nonparam = modvar;
endfunction
// Speced Illegal: needs constant function itself
// Our own - infinite loop
localparam B4 = f_bad_infinite(3);
function integer f_bad_infinite(input [31:0] a);
while (1) begin
f_bad_infinite = 0;
end
endfunction
// Our own - stop
localparam BSTOP = f_bad_stop(3);
function integer f_bad_stop(input [31:0] a);
$stop;
endfunction
endmodule
+14 -8
View File
@@ -18,19 +18,21 @@ module t (/*AUTOARG*/
/*AUTOWIRE*/
// Beginning of automatic wires (for undeclared instantiated-module outputs)
wire [2:0] pos; // From test of Test.v
wire [2:0] pos1; // From test of Test.v
wire [2:0] pos2; // From test of Test.v
// End of automatics
Test test (
// Outputs
.pos (pos[2:0]),
.pos1 (pos1[2:0]),
.pos2 (pos2[2:0]),
/*AUTOINST*/
// Inputs
.clk (clk),
.rst_n (rst_n));
// Aggregate outputs into a single result vector
wire [63:0] result = {61'h0, pos};
wire [63:0] result = {61'h0, pos1};
// What checksum will we end up with
`define EXPECTED_SUM 64'h039ea4d039c2e70b
@@ -54,6 +56,7 @@ module t (/*AUTOARG*/
rst_n <= ~1'b1;
end
else if (cyc<90) begin
if (pos1 !== pos2) $stop;
end
else if (cyc==99) begin
$write("[%0t] cyc==%0d crc=%x sum=%x\n",$time, cyc, crc, sum);
@@ -69,11 +72,12 @@ endmodule
module Test
#(parameter SAMPLE_WIDTH = 5 )
(
`ifdef verilator // UNSUPPORTED
output reg [$clog2(SAMPLE_WIDTH)-1:0] pos,
`ifdef verilator // Some simulators don't support clog2
output reg [$clog2(SAMPLE_WIDTH)-1:0] pos1,
`else
output reg [log2(SAMPLE_WIDTH-1)-1:0] pos,
output reg [log2(SAMPLE_WIDTH-1)-1:0] pos1,
`endif
output reg [log2(SAMPLE_WIDTH-1)-1:0] pos2,
// System
input clk,
input rst_n
@@ -88,9 +92,11 @@ module Test
always @ (posedge clk or negedge rst_n)
if (!rst_n) begin
pos <= 0;
pos1 <= 0;
pos2 <= 0;
end
else begin
pos <= pos + 1;
pos1 <= pos1 + 1;
pos2 <= pos2 + 1;
end
endmodule
+3 -1
View File
@@ -36,8 +36,10 @@ module t (/*AUTOARG*/
endmodule
module m1;
localparam PAR1MINUS1 = PAR1DUP-2-1;
localparam PAR1DUP = PAR1+2; // Check we propagate parameters properly
parameter PAR1 = 0;
m2 #(PAR1-1) m2 ();
m2 #(PAR1MINUS1) m2 ();
endmodule
module m2;
-18
View File
@@ -1,18 +0,0 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2005 by Wilson Snyder.
module t (/*AUTOARG*/
// Inputs
bool
);
input bool; // BAD
reg vector; // OK, as not public
reg switch /*verilator public*/; // Bad
initial $stop;
endmodule
+18
View File
@@ -0,0 +1,18 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003 by Wilson Snyder. 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.
compile (
);
execute (
check_finished=>1,
);
ok(1);
1;
+83
View File
@@ -0,0 +1,83 @@
// DESCRIPTION: Verilator: Verilog Test module
//
// This file ONLY is placed into the Public Domain, for any use,
// without warranty, 2009 by Wilson Snyder.
module t (/*AUTOARG*/
// Inputs
clk
);
input clk;
integer cyc=0;
// Test that we can actually use the logic keyword without an error popping up
//reg [63:0] crc;
logic [63:0] crc;
reg [63:0] sum;
// Take CRC data and apply to testblock inputs
wire [31:0] in = crc[31:0];
/*AUTOWIRE*/
// Beginning of automatic wires (for undeclared instantiated-module outputs)
wire [31:0] out; // From test of Test.v
// End of automatics
Test test (/*AUTOINST*/
// Outputs
.out (out[31:0]),
// Inputs
.clk (clk),
.in (in[31:0]));
// Aggregate outputs into a single result vector
wire [63:0] result = {32'h0, out};
// Test loop
always @ (posedge clk) begin
`ifdef TEST_VERBOSE
$write("[%0t] cyc==%0d crc=%x result=%x\n",$time, cyc, crc, result);
`endif
cyc <= cyc + 1;
crc <= {crc[62:0], crc[63]^crc[2]^crc[0]};
sum <= result ^ {sum[62:0],sum[63]^sum[2]^sum[0]};
if (cyc==0) begin
// Setup
crc <= 64'h5aef0c8d_d70a4497;
sum <= 64'h0;
end
else if (cyc<10) begin
sum <= 64'h0;
end
else if (cyc<90) begin
end
else if (cyc==99) begin
$write("[%0t] cyc==%0d crc=%x sum=%x\n",$time, cyc, crc, sum);
if (crc !== 64'hc77bb9b3784ea091) $stop;
// What checksum will we end up with (above print should match)
`define EXPECTED_SUM 64'h4afe43fb79d7b71e
if (sum !== `EXPECTED_SUM) $stop;
$write("*-* All Finished *-*\n");
$finish;
end
end
endmodule
module Test (/*AUTOARG*/
// Outputs
out,
// Inputs
clk, in
);
input clk;
input [31:0] in;
output reg [31:0] out;
always @(posedge clk) begin
out <= in;
end
endmodule
+1 -5
View File
@@ -80,11 +80,7 @@ module t (/*AUTOARG*/
// Inputs
.clk (clk),
.fastclk (fastclk));
t_loop tloop
(.passed (passedv[15]),
/*AUTOINST*/
// Inputs
.clk (clk));
assign passedv[15] = 1'b1;
assign passedv[16] = 1'b1;
assign passedv[17] = 1'b1;
assign passedv[18] = 1'b1;