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

📄 mywindow.cpp

📁 將Verilog設計轉成VHDL設計的程式
💻 CPP
字号:
#include "mywindow.h"#include <qapplication.h>#include <qstring.h>#include <qfiledialog.h>#include <qfile.h>#include <qtextstream.h>#include <string.h>#include <stdlib.h>#include <stddef.h>#include <unistd.h>#include <sys/types.h>#include <sys/wait.h>#include "mydebug.h"MyWindow::MyWindow(QWidget *parent, const char *name ) : QWidget(parent,name){	setMinimumSize(380,200);	quit = new QPushButton( "Quit", this, "quit" );	connect( quit, SIGNAL(clicked()), qApp, SLOT(quit()) );	open = new QPushButton( "Open", this, "open" );	connect( open, SIGNAL(clicked()), this, SLOT(_open()) );	toVHDL = new QPushButton( "toVHDL", this, "toVHDL" );	connect( toVHDL, SIGNAL(clicked()), this, SLOT(_toVHDL()) );	debug = new QPushButton( "Debug", this, "debug" );	connect( debug, SIGNAL(clicked()), this, SLOT(_debug()) );	toVHDL->setEnabled(FALSE);	debug->setEnabled(FALSE);	verilog= new QMultiLineEdit(this,"verilog");	verilog->setReadOnly(TRUE);		vhdl= new QMultiLineEdit(this,"vhdl");	connect( vhdl, SIGNAL(textChanged()), this, SLOT(_textChanged()) );}MyWindow::~MyWindow(){}void MyWindow::resizeEvent( QResizeEvent * ){	int w=width();	quit->setGeometry( w-80,10, 70, 30 );	verilog->setGeometry(5,45,w/2-10,height()-50);	vhdl->setGeometry(w/2+5,45,w/2-10,height()-50);}void MyWindow::init(){	int w=width();	open->setGeometry(10,10,70,30);	toVHDL->setGeometry(90,10,70,30);	debug->setGeometry(170,10,70,30);	quit->setGeometry( w-80,10, 70, 30 );	verilog->setGeometry(5,45,w/2-10,height()-50);	vhdl->setGeometry(w/2+5,45,w/2-10,height()-50);}void MyWindow::onOpen(){	QString fileName = QFileDialog::getOpenFileName();	if (!fileName.isNull());}void MyWindow::_open(){	QString fileName = QFileDialog::getOpenFileName();	if (fileName.isNull())return;	v_file=(char*)calloc(fileName.length()+1,sizeof(char));	strcpy(v_file,(const char*)fileName);	verilog->setAutoUpdate( FALSE );	verilog->clear();		/*FILE *f=fopen(v_file,"r");	char buf[500];	int read=500;	while(read==500)	{		read=fread(buf,sizeof(char),500,f);		buf[read]='\0';		verilog->append(buf);	}	fclose(f);	*/		QFile f( fileName );	if ( !f.open( IO_ReadOnly ) )		return;	QTextStream t(&f);	while ( !t.eof() ) {		QString s = t.readLine();		verilog->append( s );	}	f.close();	verilog->setAutoUpdate( TRUE );	verilog->repaint();	toVHDL->setEnabled(TRUE);	toVHDL->setText("toVHDL");}void MyWindow::_toVHDL(){	if(strcasecmp(toVHDL->text(),"toVHDL")==0){ 	QString fileName = QFileDialog::getSaveFileName();	if (fileName.isNull())return;	o_file=(char*)calloc(fileName.length()+1,sizeof(char));	strcpy(o_file,(const char*)fileName);		//fprintf(stderr,"unu\n%s , %s",v_file,o_file);		//un core dump de toata frumusetea	//execute(v_file,o_file,"debug.v2vhdl");		//fprintf(stderr,"doi\n");		int status;	pid_t pid;	pid = fork ();	if (pid == 0)	{	/* This is the child process. */		execl ("../../parser/lexp", "../../parser/lexp", v_file, o_file, NULL);		_exit (EXIT_FAILURE);	}	else if (pid < 0)	/* The fork failed.  Report failure.  */		status = -1;	else	/* This is the parent process.  Wait for the child to complete.  */		if (waitpid (pid, &status, 0) != pid)			status = -1;		vhdl->setAutoUpdate( FALSE );	vhdl->clear();		QFile f( fileName );	if ( !f.open( IO_ReadOnly ) )		return;	QTextStream t(&f);	while ( !t.eof() ) {		QString s = t.readLine();		vhdl->append( s );	}	f.close();	vhdl->setAutoUpdate( TRUE );	vhdl->repaint();	toVHDL->setText("toVHDL");	debug->setEnabled(TRUE);	}	else if(strcasecmp(toVHDL->text(),"Save")==0){		QString text=vhdl->text();		FILE *fp;		if (text.isNull())return;		fp=fopen(o_file,"w");		fwrite((const char*)text,text.length(),sizeof(char),fp);		fclose(fp);		toVHDL->setText("Saved");	}}void MyWindow::_textChanged(){	toVHDL->setText("Save");}void MyWindow::_debug(){	MyDebug *_w=new MyDebug(NULL,"debug window");	_w->show();}

⌨️ 快捷键说明

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