⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 verilog.hh

📁 将Verilog代码转换成C++代码的软件
💻 HH
📖 第 1 页 / 共 3 页
字号:
/* * Copyright (c) 2000-2002 moe * *    This source code is free software; you can redistribute it *    and/or modify it in source code form under the terms of the GNU *    General Public License as published by the Free Software *    Foundation; either version 2 of the License, or (at your option) *    any later version. * *    This program 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. * *    You should have received a copy of the GNU General Public License *    along with this program; if not, write to the Free Software *    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */#ifndef __VERILOG_HH#define __VERILOG_HH#include <stdint.h>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <string>#include <iostream>#include <iomanip>#include <typeinfo>#include <set>#include <map>#include <list>#include <vector>using namespace std;extern int verilog_parse();extern FILE*  verilog_input;extern string verilog_file;extern string verilog_comment;namespace moe{  class Verilog;}extern moe::Verilog* source_;namespace moe{  ////////////////////////////////////////////////////////////////////////  class Verilog  {    public:    class LineInfo    {      string       file_;      unsigned int line_;    public:      LineInfo():	line_(0)      {}            void setFile(const string& name){ file_=name; }      void setLine(unsigned int line) { line_=line; }      const string& file() const { return file_; }      unsigned int  line() const { return line_; }            string getInfo() const      {	char buf[16];	snprintf(buf,sizeof(buf),"%u",line_);	return (file_ + " : " + buf);      }    };    class Callback;    ////////////////////////////////////////////////////////////////////////    class Module;    class Net;    ////////////////////////////////////////////////////////////////////////    class Expression    {    public:      virtual ~Expression(){}      virtual bool isConstant() const { return false; }      virtual uint64_t calcConstant() const { return 0; }      virtual unsigned int width() const { return 0; }      virtual void link(const map<string,Net*>& net,Module* mod) {}      virtual const Net* net() const { return NULL; }            virtual Expression* clone(const string& hname) const { return NULL; }      virtual Expression* clone() const { return NULL; }      virtual void chain(set<const Net*>& ev) const {}      virtual void chain(set<const Expression*>& ev) const { ev.insert((Expression*)this); }      virtual void toXML(std::ostream& ostr) const {}      virtual void toVerilog(std::ostream& ostr) const {}      enum      {	ArithmeticAdd,	ArithmeticMinus,	ArithmeticMultiply,	ArithmeticDivide,	ArithmeticModulus,	ArithmeticLeftShift,	ArithmeticRightShift,	ArithmeticPower,	LeftShift,	RightShift,		LessThan,	GreaterThan,	LessEqual,	GreaterEqual,	CaseEquality,	CaseInequality,		LogicalNegation,	LogicalAND,	LogicalOR,	LogicalEquality,	LogicalInequality,		BitwiseAND,	BitwiseOR,	BitwiseNOR,	BitwiseNXOR,	BitwiseXOR,	BitwiseNegation,		ReductionAND,	ReductionNAND,	ReductionNOR,	ReductionNXOR,	ReductionXOR,	ReductionOR,	CastUnsigned,	CastSigned      };      virtual void callback(Callback& cb) const{}    };    ////////////////////////////////////////////////////////////////////////    class Number : public Expression    {      string text_;      string bitset_;      string value_;      string mask_;      unsigned int width_;    public:      Number():      width_(0)      {}      Number(const char* text);      virtual ~Number(){}      const string& text() const { return text_; }      const string& bitset() const { return bitset_; }      unsigned int width() const { return width_; }      bool isConstant() const { return true; }      bool isPartial() const;      const string& value() const { return value_; }      const string& mask() const { return mask_; }      uint64_t calcConstant() const;      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const { return new Number(*this); }      Expression* clone() const { return new Number(*this); }      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Identifier : public Expression    {      string      name_;      Expression* msb_;      Expression* lsb_;      Expression* idx_;      Net*        net_;    public:      Identifier(const char* name,		 Expression* msb=NULL,Expression* lsb=NULL,		 Expression* idx=NULL):	name_(name),	msb_(msb),lsb_(lsb),	idx_(idx),	net_(NULL)      {}      Identifier():	msb_(NULL),lsb_(NULL),	idx_(NULL),	net_(NULL)      {}      virtual ~Identifier();      const string& name() const { return name_; }      const Expression* msb() const { return msb_; }      const Expression* lsb() const { return lsb_; }      const Expression* idx() const { return idx_; }      bool isPartial() const;      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      unsigned int width() const;      void link(const map<string,Net*>& net,Module* mod);      const Net* net() const { return net_; }      void setNet(Net* net) { net_=net; }      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Concat : public Expression    {      Expression*         repeat_;      vector<Expression*> list_;    public:      Concat(const vector<Expression*>& l):	repeat_(NULL),	list_(l)      {}      Concat(Expression* r,const vector<Expression*>& l):	repeat_(r),	list_(l)      {}      Concat():	repeat_(NULL)      {}      virtual ~Concat();      const Expression* repeat() const { return repeat_; }      const vector<Expression*>& list() const { return list_; }      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      unsigned int width() const;      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Event : public Expression    {      int         type_;      Expression* expr_;    public:      enum      {	ANYEDGE,	POSEDGE,	NEGEDGE,	POSITIVE      };      Event(int t,Expression* e):	type_(t),	expr_(e)      {}      Event():	expr_(NULL)      {}      virtual ~Event();      int         type() const { return type_; }      Expression* expression() const { return expr_; }      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      unsigned int width() const { return 0; }      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Unary : public Expression    {      /*	ArithmeticMinus	BitwiseNegation	LogicalNegation	ReductionAND	ReductionOR	ReductionXOR	ReductionNAND	ReductionNOR	ReductionNXOR	CastSigned	CastUnsigned       */      int         op_;      Expression* expr_;    public:      Unary(int o,Expression* e):	op_(o),	expr_(e)      {}      Unary():	expr_(NULL)      {}      virtual ~Unary();      int operation() const { return op_; }      const Expression* value() const { return expr_; }      unsigned int width() const;      bool isConstant() const { return expr_->isConstant(); }      uint64_t calcConstant() const;      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      const char* opToken() const;      const char* opName() const;      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Binary : public Expression    {      int         op_;      Expression* left_;      Expression* right_;    public:      Binary(int o,Expression* l,Expression* r):	op_(o),	left_(l),	right_(r)      {}      Binary():	left_(NULL),	right_(NULL)      {}      virtual ~Binary();      int operation() const { return op_; }      const Expression* left() const { return left_; }      const Expression* right() const { return right_; }      unsigned int width() const;      bool isConstant() const { return (left_->isConstant()&&right_->isConstant()); }      uint64_t calcConstant() const;      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      const char* opToken() const;      const char* opName() const;      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Ternary : public Expression    {      Expression* expr_;      Expression* true_;      Expression* false_;    public:      Ternary(Expression* e,Expression* t,Expression* f):	expr_(e),	true_(t),	false_(f)      {}      Ternary():	expr_(NULL),	true_(NULL),	false_(NULL)      {}      virtual ~Ternary();      const Expression* condition() const { return expr_; }      const Expression* trueValue() const { return true_; }      const Expression* falseValue() const { return false_; }            unsigned int width() const { return (false_!=NULL) ? max( true_->width(),false_->width() ) : true_->width() ; }      virtual bool isConstant() const{}      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    class Function;    ////////////////////////////////////////////////////////////////////////    class CallFunction : public Expression    {      string              name_;      vector<Expression*> parms_;      Function*           func_;      Net*                net_;    public:      CallFunction(const char* n,const vector<Expression*> &p):	name_(n),	parms_(p),	func_(NULL),	net_(NULL)      {}      CallFunction():	func_(NULL),	net_(NULL)      {}      virtual ~CallFunction();      const string name() const { return name_; }      const vector<Expression*>& parameter() const { return parms_; }      const Function* function() const { return func_; }      const Net* net() const { return net_; }      void toXML(std::ostream& ostr) const;      void toVerilog(std::ostream& ostr) const;      unsigned int width() const { return net_->width(); }      void link(const map<string,Net*>& net,Module* mod);      Expression* clone(const string& hname) const;      Expression* clone() const;      void chain(set<const Net*>& ev) const;      void chain(set<const Expression*>& ev) const;      void callback(Callback& cb) const;    };    ////////////////////////////////////////////////////////////////////////    class Net    {    public:      class nrm_      {      public:	char* name;	Expression* start;	Expression* end;	int   type;	nrm_():	  name(NULL)	{}	~nrm_()	{	  delete name;	  delete start;	  delete end;	}      };      int    type_;      int    interface_;      bool   sign_;            Expression* msb_;      Expression* lsb_;      Expression* sa_;      Expression* ea_;      bool constant_;      string name_;    public:      enum      {	IMPLICIT,	WIRE,	TRI,	TRI1,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -