From 2f2f416bea72bd72b4ee731ba8982570274fa437 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 2 Dec 2009 19:32:41 -0500 Subject: [PATCH] Fix auto-indentation of AstCStmts - again --- src/V3AstNodes.h | 24 ++++++++++++++++-------- src/V3Clock.cpp | 5 ++--- src/V3Descope.cpp | 4 ++-- src/V3EmitC.cpp | 6 +++++- src/V3Life.cpp | 6 ++++++ src/Verilator.cpp | 3 ++- test_regress/driver.pl | 4 +++- 7 files changed, 36 insertions(+), 16 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 8f28a46f4..078982b48 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -2939,9 +2939,14 @@ struct AstPslBool : public AstNode { // Text based nodes struct AstText : public AstNodeText { - AstText(FileLine* fl, const string& textp) - : AstNodeText(fl, textp) {} +private: + bool m_tracking; // When emit, it's ok to parse the string to do indentation +public: + AstText(FileLine* fl, const string& textp, bool tracking=false) + : AstNodeText(fl, textp), m_tracking(tracking) {} ASTNODE_NODE_FUNCS(Text, TEXT) + void tracking(bool flag) { m_tracking = flag; } + bool tracking() const { return m_tracking; } }; struct AstScCtor : public AstNodeText { @@ -3208,22 +3213,25 @@ public: }; struct AstCMath : public AstNodeMath { +private: + bool m_cleanOut; +public: // Emit C textual math function (like AstUCFunc) AstCMath(FileLine* fl, AstNode* exprsp) - : AstNodeMath(fl) { + : AstNodeMath(fl), m_cleanOut(true) { addOp1p(exprsp); widthSignedFrom(exprsp); } - AstCMath(FileLine* fl, const string& textStmt, int setwidth) - : AstNodeMath(fl) { - addNOp1p(new AstText(fl, textStmt)); + AstCMath(FileLine* fl, const string& textStmt, int setwidth, bool cleanOut=true) + : AstNodeMath(fl), m_cleanOut(cleanOut) { + addNOp1p(new AstText(fl, textStmt, true)); if (setwidth) { width(setwidth,setwidth); } } ASTNODE_NODE_FUNCS(CMath, CMATH) AstNode* bodysp() const { return op1p()->castNode(); } // op1= expressions to print virtual bool isGateOptimizable() const { return false; } virtual bool isPredictOptimizable() const { return false; } - virtual bool cleanOut() { return true; } + virtual bool cleanOut() { return m_cleanOut; } virtual string emitVerilog() { V3ERROR_NA; return ""; } // Implemented specially virtual string emitC() { V3ERROR_NA; return ""; } virtual V3Hash sameHash() const { return V3Hash(); } @@ -3239,7 +3247,7 @@ struct AstCStmt : public AstNodeStmt { } AstCStmt(FileLine* fl, const string& textStmt) : AstNodeStmt(fl) { - addNOp1p(new AstText(fl, textStmt)); + addNOp1p(new AstText(fl, textStmt, true)); } ASTNODE_NODE_FUNCS(CStmt, CSTMT) AstNode* bodysp() const { return op1p()->castNode(); } // op1= expressions to print diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index 7ff4fb7b2..3104c6bcb 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -232,9 +232,8 @@ private: funcp->slow(true); funcp->isStatic(false); funcp->entryPoint(true); - funcp->addInitsp( - new AstCStmt(nodep->fileline(), - " "+EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n")); + funcp->addInitsp(new AstCStmt(nodep->fileline(), + EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n")); funcp->addInitsp(new AstCStmt(nodep->fileline(), EmitCBaseVisitor::symTopAssign()+"\n")); m_scopep->addActivep(funcp); m_finalFuncp = funcp; diff --git a/src/V3Descope.cpp b/src/V3Descope.cpp index 0cb9ee4dc..6c6474b99 100644 --- a/src/V3Descope.cpp +++ b/src/V3Descope.cpp @@ -121,7 +121,7 @@ private: newfuncp->isStatic(false); newfuncp->addInitsp( new AstCStmt(newfuncp->fileline(), - " "+EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n")); + EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n")); newfuncp->addInitsp(new AstCStmt(newfuncp->fileline(), EmitCBaseVisitor::symTopAssign()+"\n")); topFuncp->addNextHere(newfuncp); // In the body, call each function if it matches the given scope @@ -224,7 +224,7 @@ private: if (m_needThis) { nodep->v3fatalSrc("old code"); // Really we should have more node types for backend optimization of this stuff - string text = " "+v3Global.opt.modPrefix() + "_" + m_modp->name() + string text = v3Global.opt.modPrefix() + "_" + m_modp->name() +"* thisp = &("+m_scopep->nameVlSym()+");\n"; nodep->addInitsp(new AstCStmt(nodep->fileline(), text)); } diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index aafa5d574..0b94174a0 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -412,7 +412,11 @@ public: puts(",\"\");\n"); } virtual void visit(AstText* nodep, AstNUser*) { - ofp()->putsNoTracking(nodep->text()); + if (nodep->tracking()) { + puts(nodep->text()); + } else { + ofp()->putsNoTracking(nodep->text()); + } } virtual void visit(AstCStmt* nodep, AstNUser*) { putbs(""); diff --git a/src/V3Life.cpp b/src/V3Life.cpp index 56cc985d3..e27f5c759 100644 --- a/src/V3Life.cpp +++ b/src/V3Life.cpp @@ -136,6 +136,12 @@ class LifeBlock { LifeBlock* m_aboveLifep; // Upper life, or NULL LifeState* m_statep; // Current global state + static int debug() { + static int level = -1; + if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__); + return level; + } + public: LifeBlock(LifeBlock* aboveLifep, LifeState* statep) { m_aboveLifep = aboveLifep; // Null if top diff --git a/src/Verilator.cpp b/src/Verilator.cpp index b76d42aff..7b2bca4cc 100644 --- a/src/Verilator.cpp +++ b/src/Verilator.cpp @@ -285,7 +285,8 @@ void process () { // Push constants across variables and remove redundant assignments V3Const::constifyAll(v3Global.rootp()); - //v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("const.tree")); + v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("const.tree")); + if (v3Global.opt.oLife()) { V3Life::lifeAll(v3Global.rootp()); v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("life.tree")); diff --git a/test_regress/driver.pl b/test_regress/driver.pl index 6a54b2d7e..3c95786f7 100755 --- a/test_regress/driver.pl +++ b/test_regress/driver.pl @@ -356,7 +356,9 @@ sub read_status { use vars qw($VAR1); local $VAR1; require $filename or die "%Error: $! $filename,"; - %{$self} = %{$VAR1}; + if ($VAR1) { + %{$self} = %{$VAR1}; + } } #----------------------------------------------------------------------