📄 verilog2c++.cc
字号:
ostr_ << '('; self->left()->callback( *this ); ostr_ << "<="; self->right()->callback( *this ); ostr_ << ')'; break; case Expression::GreaterEqual: ostr_ << '('; self->left()->callback( *this ); ostr_ << ">="; self->right()->callback( *this ); ostr_ << ')'; break; case Expression::CaseEquality: if( (typeid( *(self->right()) )==typeid( Number ))&& ((Number*)self->right())->isPartial() ) { ostr_ << "EmVer::CaseEquality"; ostr_ << '('; self->left()->callback( *this ); ostr_ << ','; ((Number*)self->right())->mask(); ostr_ << ','; ((Number*)self->right())->value(); } else { ostr_ << '('; self->left()->callback( *this ); ostr_ << "=="; self->right()->callback( *this ); ostr_ << ')'; } break; case Expression::CaseInequality: if( (typeid( *(self->right()) )==typeid( Number ))&& ((Number*)self->right())->isPartial() ) { ostr_ << "EmVer::CaseInequality"; ostr_ << '('; self->left()->callback( *this ); ostr_ << ','; ((Number*)self->right())->mask(); ostr_ << ','; ((Number*)self->right())->value(); } else { ostr_ << '('; self->left()->callback( *this ); ostr_ << "!="; self->right()->callback( *this ); ostr_ << ')'; } break; } } //////////////////////////////////// void trap(const Ternary* self) { ostr_ << '('; self->condition()->callback( *this ); ostr_ << " ? "; self->trueValue()->callback( *this ); ostr_ << " : "; self->falseValue()->callback( *this ); ostr_ << ')'; } //////////////////////////////////// void trap(const CallFunction* self) { // ostr_.form("f%08X(",self->net()); ostr_ << 'f' << (uint)self->net() << '('; vector<Expression*>::const_iterator i; for( i=self->parameter().begin();i!=self->parameter().end();++i ) { if( i!=self->parameter().begin() ) ostr_ << ","; (*i)->callback( *this ); } ostr_ << ")"; } }; //////////////////////////////////////////////////////////////////////// class LeftExpression : public Callback { bool comm_; ostream& ostr_; const set<const Net*>& flipflop_; unsigned int indent_; unsigned int cast_; public: LeftExpression(bool comm,ostream& ostr,const set<const Net*>& flipflop,unsigned int indent,unsigned int cast): comm_(comm), ostr_(ostr), flipflop_(flipflop), indent_(indent), cast_(cast) {} ~LeftExpression(){} void trap(const Number* self) { if( self->isPartial() ) std::cerr << " a partial number in this left value is failure profit. \n"; else if( self->width()>32 ) std::cerr << " a large number in this left number is failure profit. \n"; else ostr_ << self->calcConstant(); } void trap(const Identifier* self) { RightExpression re(comm_,ostr_,32); if( flipflop_.find( self->net() )!=flipflop_.end() ) { if( self->net()->isArray() ) { ostr_ << setw(indent_) << ""; // ostr_.form("d%08X =preproduct",self->net()); ostr_ << 'd' << (uint)self->net() << " =preproduct"; if( cast_!=self->net()->width() ) { ostr_<< '&'; printMask( ostr_,self->net()->width() ); } ostr_ << ";\n"; ostr_ << setw(indent_) << ""; // ostr_.form("a%08X",self->net()); ostr_ << 'a' << (uint)self->net(); ostr_ << " =("; self->idx()->callback( re ); ostr_ << '-' << self->net()->sa()->calcConstant(); ostr_ << ")%" << self->net()->depth() << ";\n"; ostr_ << setw(indent_) << ""; // ostr_.form("u%08X",self->net()); ostr_ << 'u' << (uint)self->net(); ostr_ << " =true;\n"; } else { if( self->idx()!=NULL ) { ostr_ << setw(indent_) << ""; ostr_ << "Assign("; // ostr_.form("d%08X",self->net()); ostr_ << 'd' << (uint)self->net(); ostr_ << ','; printMask( ostr_,self->net()->width(), self->idx()->calcConstant(), self->idx()->calcConstant() ); ostr_ << ','; ostr_ << self->idx()->calcConstant(); ostr_ << ",preproduct);\n"; ostr_ << setw(indent_) << ""; // ostr_.form("u%08X",self->net()); ostr_ << 'u' << (uint)self->net(); ostr_ << " =true;\n"; } else if( self->msb()!=NULL && self->lsb()!=NULL ) { ostr_ << setw(indent_) << ""; ostr_ << "Assign("; // ostr_.form("d%08X",self->net()); ostr_ << 'd' << (uint)self->net(); ostr_ << ','; printMask( ostr_,self->net()->width(), self->msb()->calcConstant(), self->lsb()->calcConstant() ); ostr_ << ','; ostr_ << self->lsb()->calcConstant(); ostr_ << ",preproduct);\n"; ostr_ << setw(indent_) << ""; // ostr_.form("u%08X",self->net()); ostr_ << 'u' << (uint)self->net(); ostr_ << " =true;\n"; } else { ostr_ << setw(indent_) << ""; // ostr_.form("d%08X =preproduct",self->net()); ostr_ << 'd' << (uint)self->net() << " =preproduct"; if( cast_!=self->net()->width() ) { ostr_<< '&'; printMask( ostr_,self->net()->width() ); } ostr_ << ";\n"; ostr_ << setw(indent_) << ""; // ostr_.form("u%08X",self->net()); ostr_ << 'u' << (uint)self->net(); ostr_ << " =true;\n"; } } } else if( self->net()->type()==Net::FUNCTION ) { ostr_ << setw(indent_) << ""; // ostr_.form("return preproduct",self->net()); ostr_ << "return preproduct"; if( cast_!=self->net()->width() ) { ostr_<< '&'; printMask( ostr_,self->net()->width() ); } ostr_ << ";\n"; } else { if( self->net()->isArray() ) { ostr_ << setw(indent_) << ""; // ostr_.form("n%08X",self->net()); ostr_ << 'n' << (uint)self->net(); ostr_ << '['; self->idx()->callback( re ); ostr_ << '-' << self->net()->sa()->calcConstant(); ostr_ << ']'; ostr_ << " =preproduct"; if( cast_!=self->net()->width() ) { ostr_<< '&'; printMask( ostr_,self->net()->width() ); } ostr_ << ";\n"; } else { if( self->idx()!=NULL ) { ostr_ << setw(indent_) << ""; ostr_ << "Assign("; // ostr_.form("n%08X",self->net()); ostr_ << 'n' << (uint)self->net(); ostr_ << ','; printMask( ostr_,self->net()->width(), self->idx()->calcConstant(), self->idx()->calcConstant() ); ostr_ << ','; ostr_ << self->idx()->calcConstant(); ostr_ << ",preproduct);\n"; } else if( self->msb()!=NULL && self->lsb()!=NULL ) { ostr_ << setw(indent_) << ""; ostr_ << "Assign("; // ostr_.form("n%08X",self->net()); ostr_ << 'n' << (uint)self->net(); ostr_ << ','; printMask( ostr_,self->net()->width(), self->msb()->calcConstant(), self->lsb()->calcConstant() ); ostr_ << ','; ostr_ << self->lsb()->calcConstant(); ostr_ << ",preproduct);\n"; } else { ostr_ << setw(indent_) << ""; // ostr_.form("n%08X =preproduct",self->net()); ostr_ << 'n' << (uint)self->net() << " =preproduct"; if( cast_!=self->net()->width() ) { ostr_<< '&'; printMask( ostr_,self->net()->width() ); } ostr_ << ";\n"; } } } } void trap(const Concat* self) { if( self->repeat()!=NULL ) std::cerr << " a repeat expression in this left value is failure profit. \n"; { vector<Expression*>::const_reverse_iterator i; for( i=self->list().rbegin();i!=self->list().rend();++i ) { (*i)->callback( *this ); if( (*i)!=self->list().front() ) ostr_ << setw(indent_) << "" << "preproduct >>=" << (*i)->width() << ";\n"; } } } void trap(const Event* self) { std::cerr << " a event expression in this left value is failure profit. \n"; } void trap(const Unary* self) { std::cerr << " a unary expression in this left value is failure profit. \n"; } void trap(const Binary* self) { std::cerr << " a binary expression in this left value is failure profit. \n"; } void trap(const Ternary* self) { std::cerr << " a ternary expression in this left value is failure profit. \n"; } void trap(const CallFunction* self) { std::cerr << " a call function expression in this left value is failure profit. \n"; } }; //////////////////////////////////////////////////////////////////////// class StatementSplice : public Callback { bool comm_; ostream& ostr_; const set<const Net*>& flipflop_; unsigned int indent_; public: StatementSplice(bool comm,ostream& ostr,const set<const Net*>& flipflop,unsigned int indent): comm_(comm), ostr_(ostr), flipflop_(flipflop), indent_(indent) {} ~StatementSplice(){} void trap(const EventStatement* self) { std::cerr << "a event statement in this handle is failure profit. \n"; } void trap(const Block* self) { ostr_ << setw(indent_) << "" << "{\n";indent_+=2; vector<Statement*>::const_iterator i; for( i=self->list().begin();i!=self->list().end();++i ) (*i)->callback( *this ); indent_-=2;ostr_ << setw(indent_) << "" << "}\n"; } void trap(const Condition* self) { RightExpression re(comm_,ostr_,32); ostr_ << setw(indent_) << "" << "if( "; self->expression()->callback( re ); ostr_ << " )\n"; indent_+=2; self->trueStatement()->callback( *this ); indent_-=2; if( self->falseStatement()!=NULL ) { ostr_ << setw(indent_) << "" << "else\n"; indent_+=2; self->falseStatement()->callback( *this ); indent_-=2; } } void trap(const Case* self) { RightExpression re(comm_,ostr_,32); ostr_ << setw(indent_) << "" << "{\n";indent_+=2; ostr_ << setw(indent_) << ""; printClass( ostr_,self->expression()->width() ); ostr_ << "preproduct ="; self->expression()->callback( re );// case pre-product ostr_ << ";\n"; vector<Case::Item*>::const_iterator i; for( i=self->items().begin();i!=self->items().end();++i ) { if( i!=self->items().begin() ) { ostr_ << setw(indent_) << "" << "else "; } else { ostr_ << setw(indent_) << ""; } if( !(*i)->expression().empty() ) { ostr_ << "if( "; vector<Expression*>::const_iterator ii; for( ii=(*i)->expression().begin();ii!=(*i)->expression().end();++ii ) { RightExpression re(comm_,ostr_,self->expression()->width()); if( ii!=(*i)->expression().begin() ) { ostr_ << "||" << std::endl; ostr_ << setw(indent_) << ""; if( i!=self->items().begin() ) ostr_ << " "; else ostr_ << " "; } { if( typeid( *(*ii) )==typeid( Number ) ) { if( ((Number*)(*ii))->isPartial() ) { ostr_ << "EmVer::CaseEquality(preproduct,"; (*ii)->callback( re ); ostr_ << ')'; } else { ostr_ << "(preproduct=="; (*ii)->callback( re ); ostr_ << ')'; } } else { ostr_ << "(preproduct=="; (*ii)->callback( re ); ostr_ << ')'; } } } ostr_ << " )\n"; } else ostr_ << "\n"; indent_+=2; ostr_ << setw(indent_) << "" << "{\n"; indent_+=2; (*i)->statement()->callback( *this ); indent_-=2; ostr_ << setw(indent_) << "" << "}\n"; indent_-=2; } indent_-=2;ostr_ << setw(indent_) << "" << "}\n"; } void trap(const Case::Item* self) { std::cerr << "a case-item statement in this callback is failure profit. \n"; } void trap(const Assign* self) { ostr_ << setw(indent_) << "" << "{\n";indent_+=2; RightExpression re(comm_,ostr_,self->leftValue()->width() ); LeftExpression le(comm_,ostr_,flipflop_,indent_, 32*((self->leftValue()->width() +31)/32) ); { ostr_ << setw(indent_) << ""; printClass( ostr_,self->leftValue()->width() ); ostr_ << "preproduct ="; self->rightValue()->callback( re ); ostr_ << ";\n"; self->leftValue()->callback( le ); } indent_-=2;ostr_ << setw(indent_) << "" << "}\n"; } }; //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// class Handle { const Statement* stat_; set<const Net*> left_; set<const Net*> right_; public: Handle(): stat_(NULL) {} ~Handle(){} Handle(const Statement* stat): stat_(stat) {} void setLeft(const set<const Net*>& l) { left_=l; } void setRight(const set<const Net*>& r) { right_=r; } const Statement* statement() const { return stat_; } const set<const Net*>& left() const { return left_; } const set<const Net*>& right() const { return right_; } }; //////////////////////////////////////////////////////////////////////// class Synchronous { const Net* net_; int type_; list<Handle> handle_; public: void dump(ostream &ostr) { list<Handle>::const_iterator i; for( i=handle_.begin();i!=handle_.end();++i ) (*i).statement()->toVerilog( ostr ,0 ); } ~Synchronous(){} Synchronous(): net_(NULL) {} Synchronous(const Net* net,int type): net_(net), type_(type) {} const Net* net() const { return net_; } int type() const { return type_; } list<Handle>& handle() { return handle_; } const list<Handle>& handle() const { return handle_; } }; //////////////////////////////////////////////////////////////////////// Module* top_; vector<Synchronous> sync_; Synchronous anysync_; set<const Net*> syncsrc_; set<const Net*> latch_; set<const Net*> flipflop_; multimap<const Net*,const Statement*> map_; // map<const Net*,const Assign*> constant_; //////////////////////////////////////////////////////////////////////// void _trace(const Net* net,int type,Synchronous& sync,int& curr,int& total) { total +=top_->process().size(); if( total==0 ) printProgress(std::cerr,100.0); else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -