Internals: new() support code, and misc stuff.

This commit is contained in:
Wilson Snyder 2019-12-24 12:47:27 -05:00
parent 40a847d613
commit f540dead79
4 changed files with 26 additions and 8 deletions

View File

@ -6707,10 +6707,11 @@ public:
class AstCMath : public AstNodeMath { class AstCMath : public AstNodeMath {
private: private:
bool m_cleanOut; bool m_cleanOut;
bool m_pure; // Pure optimizable
public: public:
// Emit C textual math function (like AstUCFunc) // Emit C textual math function (like AstUCFunc)
AstCMath(FileLine* fl, AstNode* exprsp) AstCMath(FileLine* fl, AstNode* exprsp)
: AstNodeMath(fl), m_cleanOut(true) { : AstNodeMath(fl), m_cleanOut(true), m_pure(false) {
addOp1p(exprsp); addOp1p(exprsp);
dtypeFrom(exprsp); dtypeFrom(exprsp);
} }
@ -6720,8 +6721,8 @@ public:
if (setwidth) { dtypeSetLogicSized(setwidth, AstNumeric::UNSIGNED); } if (setwidth) { dtypeSetLogicSized(setwidth, AstNumeric::UNSIGNED); }
} }
ASTNODE_NODE_FUNCS(CMath) ASTNODE_NODE_FUNCS(CMath)
virtual bool isGateOptimizable() const { return false; } virtual bool isGateOptimizable() const { return m_pure; }
virtual bool isPredictOptimizable() const { return false; } virtual bool isPredictOptimizable() const { return m_pure; }
virtual bool cleanOut() const { return m_cleanOut; } virtual bool cleanOut() const { return m_cleanOut; }
virtual string emitVerilog() { V3ERROR_NA; return ""; } // Implemented specially virtual string emitVerilog() { V3ERROR_NA; return ""; } // Implemented specially
virtual string emitC() { V3ERROR_NA; return ""; } virtual string emitC() { V3ERROR_NA; return ""; }
@ -6729,9 +6730,10 @@ public:
virtual bool same(const AstNode* samep) const { return true; } virtual bool same(const AstNode* samep) const { return true; }
void addBodysp(AstNode* nodep) { addNOp1p(nodep); } void addBodysp(AstNode* nodep) { addNOp1p(nodep); }
AstNode* bodysp() const { return op1p(); } // op1 = expressions to print AstNode* bodysp() const { return op1p(); } // op1 = expressions to print
bool pure() const { return m_pure; }
void pure(bool flag) { m_pure = flag; }
}; };
class AstCReset : public AstNodeStmt { class AstCReset : public AstNodeStmt {
// Reset variable at startup // Reset variable at startup
public: public:

View File

@ -88,6 +88,7 @@ private:
if (!nodep->user2() && nodep->hasDType()) { if (!nodep->user2() && nodep->hasDType()) {
if (VN_IS(nodep, Var) || VN_IS(nodep, NodeDType) // Don't want to change variable widths! if (VN_IS(nodep, Var) || VN_IS(nodep, NodeDType) // Don't want to change variable widths!
|| VN_IS(nodep->dtypep()->skipRefp(), AssocArrayDType) // Or arrays || VN_IS(nodep->dtypep()->skipRefp(), AssocArrayDType) // Or arrays
|| VN_IS(nodep->dtypep()->skipRefp(), ClassRefDType)
|| VN_IS(nodep->dtypep()->skipRefp(), QueueDType) || VN_IS(nodep->dtypep()->skipRefp(), QueueDType)
|| VN_IS(nodep->dtypep()->skipRefp(), UnpackArrayDType) || VN_IS(nodep->dtypep()->skipRefp(), UnpackArrayDType)
|| VN_IS(nodep->dtypep()->skipRefp(), VoidDType)) { || VN_IS(nodep->dtypep()->skipRefp(), VoidDType)) {

View File

@ -714,6 +714,11 @@ public:
iterateAndNextNull(nodep->expr2p()); puts(")"); iterateAndNextNull(nodep->expr2p()); puts(")");
} }
} }
virtual void visit(AstNew* nodep) {
puts("std::make_shared<" + nodep->dtypep()->nameProtect() + ">(");
iterateChildren(nodep);
puts(")");
}
virtual void visit(AstSel* nodep) { virtual void visit(AstSel* nodep) {
// Note ASSIGN checks for this on a LHS // Note ASSIGN checks for this on a LHS
emitOpName(nodep, nodep->emitC(), nodep->fromp(), nodep->lsbp(), nodep->thsp()); emitOpName(nodep, nodep->emitC(), nodep->fromp(), nodep->lsbp(), nodep->thsp());
@ -2736,21 +2741,19 @@ void EmitCImp::emitInt(AstNodeModule* modp) {
ofp()->putsPrivate(false); // public: ofp()->putsPrivate(false); // public:
puts("void "+protect("__Vserialize")+"(VerilatedSerialize& os);\n"); puts("void "+protect("__Vserialize")+"(VerilatedSerialize& os);\n");
puts("void "+protect("__Vdeserialize")+"(VerilatedDeserialize& os);\n"); puts("void "+protect("__Vdeserialize")+"(VerilatedDeserialize& os);\n");
puts("\n");
} }
puts("} VL_ATTR_ALIGNED(128);\n"); puts("} VL_ATTR_ALIGNED(128);\n");
puts("\n");
// Save/restore // Save/restore
if (v3Global.opt.savable() && modp->isTop()) { if (v3Global.opt.savable() && modp->isTop()) {
puts("inline VerilatedSerialize& operator<<(VerilatedSerialize& os, " puts("\n");
puts("inline VerilatedSerialize& operator<<(VerilatedSerialize& os, "
+modClassName(modp)+"& rhs) {\n" +modClassName(modp)+"& rhs) {\n"
"Verilated::quiesce(); rhs."+protect("__Vserialize")+"(os); return os; }\n"); "Verilated::quiesce(); rhs."+protect("__Vserialize")+"(os); return os; }\n");
puts("inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, " puts("inline VerilatedDeserialize& operator>>(VerilatedDeserialize& os, "
+modClassName(modp)+"& rhs) {\n" +modClassName(modp)+"& rhs) {\n"
"Verilated::quiesce(); rhs."+protect("__Vdeserialize")+"(os); return os; }\n"); "Verilated::quiesce(); rhs."+protect("__Vdeserialize")+"(os); return os; }\n");
puts("\n");
} }
// finish up h-file // finish up h-file

View File

@ -2239,6 +2239,18 @@ private:
} }
} }
virtual void visit(AstNew* nodep) {
if (nodep->didWidthAndSet()) return;
userIterateChildren(nodep, WidthVP(SELF, BOTH).p());
AstClassRefDType* refp = VN_CAST(m_vup->dtypeNullp(), ClassRefDType);
if (!refp) { // e.g. int a = new;
if (refp) UINFO(1, "Got refp "<<refp<<endl);
nodep->v3error("new() not expected in this context");
return;
}
nodep->dtypep(refp);
}
virtual void visit(AstPattern* nodep) { virtual void visit(AstPattern* nodep) {
if (nodep->didWidthAndSet()) return; if (nodep->didWidthAndSet()) return;
UINFO(9,"PATTERN "<<nodep<<endl); UINFO(9,"PATTERN "<<nodep<<endl);