Fix auto-indentation of AstCStmts - again

This commit is contained in:
Wilson Snyder 2009-12-02 19:32:41 -05:00
parent 1da07a3b86
commit 2f2f416bea
7 changed files with 36 additions and 16 deletions

View File

@ -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

View File

@ -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;

View File

@ -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));
}

View File

@ -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("");

View File

@ -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

View File

@ -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"));

View File

@ -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};
}
}
#----------------------------------------------------------------------