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

📄 simulator.cpp

📁 类似vc的集成开发环境
💻 CPP
📖 第 1 页 / 共 3 页
字号:
			prunlinepre=pselend;
//	if(in(code[pc].sourceline)==2)
//		return;

		}
		}while((pc!=-1)&&(!in(code[pc].sourceline)));
	}


//	pselstart.y=gotoline;
//	pselstart.x=gotorow;




}

void simulator::StepInto()
{
	CMDIFrameWnd *nowframe = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;
	//活动子窗口指针
	CMDIChildWnd *nowchild = nowframe->MDIGetActive();

	//获得当前活动视图
	CCrystalTextView* m_pexpandview=NULL;	
	m_pexpandview=(CCrystalTextView*)nowchild->GetActiveView();

	if(m_pexpandview==NULL)
		return;
	CPoint pselend;
	int i_curpc=0;
	if(pc!=-1)
	{
		

		StepOne();
/*			if((pc==-1)&&(i_pcpre>=(cx-1)))
			{
				
				pselend.y=code[i_pcpre].sourceline;
				pselend.x=0;
				m_pexpandview->SetCursorPos(pselend);
				//编辑控件光标所在行 
				m_pexpandview->OnToggleBookmark(0);
				return;

			}

	int i_curpc;
	if (pc=-1)
		i_curpc=i_pcpre;
	else
		i_curpc=pc;
*/
		if(	pc!=-1)
		{
	pselend.y=code[pc].sourceline;
	pselend.x=0;
    m_pexpandview->SetCursorPos(pselend);
	 //编辑控件光标所在行 
	m_pexpandview->OnToggleBookmark(0);
	prunlinepre=pselend;
//	if(in(code[pc].sourceline)==2)
//		return;
		}
	}


}

void simulator::StepOver()           
{
	int k;
	if(pc!=-1)
	{
		k=subflag;
	

		StepOne();
		while(k!=subflag)
		{
			StepOne();
		}

	}

}

void simulator::StepOut()
{
	int k;
	if(pc!=-1)
	{
		if(subflag>0)
		{
			k=subflag-1;
			while(k!=subflag)
			{
	

				StepOne();
			}
		}
		else
		{
			StepOne();
		}
	}
			

}

int simulator::StepOne()

//执行在C02源程序中一行程序所编译出的三元式代码

{
	int PcLine;
	PcLine=code[pc].sourceline;
	do{

		SimRun(1);

	
	}while(code[pc].sourceline==PcLine);
//	i_pcpre=code[pc].sourceline;
 
	CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;	
/*	CListCtrl* m_list=(CListCtrl*)&(m_pmainFrame->m_wndWatchBar.m_viarable);

	m_list->GetItemText(m_nItem,m_nSubItem,ch_sel,100);
	if(ch_sel!=NULL)
		str_sel=ch_sel;
   m_list->SetItemText(m_nItem,1,ch_sel);
   int n_count=m_list->GetItemCount();
   CString str_new=_T(" ");
   m_list->InsertItem(n_count,str_new);*/

	m_pmainFrame->m_wndWatchBar.UpDatePC(pc);
	UpdateReg();
	return 1;
}

int simulator::in(int n)

//**该函数功能是在断点链表中查找值为n的断
//**点是否存在,如果存在则返回1否则返回0

{
	struct Breakpoint *p1;
	p1=BreakpointList->next;
	while(p1!=NULL)
	{
		if(p1->value==n)
			return 1;
		p1=p1->next;
	}
	
	return 0;
	

}

void simulator::get_varinfor()

//**该函数主要功能是把C02语言中的变量定义信息读入变量信息表
//**wholevar(全局变量信息表)和PartVar(局部变量信息表)中
//
//
{
	char buf[30];
	int line_len;
	int j,i;
	int m;
	
	struct table *p1,*p2;

	i=0;
	line_len=0;
	m=0;
	sub_count=0;
	wholevar=new table;
	wholevar->next=NULL;

	FVarInfor.get(buf,30);
	FVarInfor.get();

	line_len=strlen(buf);

	buf[line_len]='\n';

	while(buf[i]!='\n')
	{
		m=10*m+buf[i]-'0';
		i++;
	}

	p2=wholevar;
	for( j=0;j<m;j++)
	{
		i=0;
		line_len=0;
		p1=new table;

		FVarInfor.get(buf,30);
		FVarInfor.get();

		line_len=strlen(buf);

		buf[line_len]='\n';

		p1->name=new char[15];
		while(buf[i]!=' ')
		{
			p1->name[i]=buf[i];
			i++;
		}
		p1->name[i]=0;

		while(buf[i]==' ')
			i++;

		p1->size=0;
		while(buf[i]!=' ')
		{
			p1->size=10*p1->size+buf[i]-'0';
			i++;
		}

		while(buf[i]==' ')
			i++;

		p1->adr=0;
		while(buf[i]!='\n')
		{
			p1->adr=10*p1->adr+(int)buf[i]-'0';
			i++;
		}

		p1->next=NULL;
		p2->next=p1;
		p2=p1;
	}
	p1=wholevar;
	wholevar=wholevar->next;
	delete p1;

	while(!FVarInfor.eof())
	{
		i=0;
		line_len=0;
		
		FVarInfor.get(buf,30);
		FVarInfor.get();

		line_len=strlen(buf);

		if(line_len>2)
		{
			buf[line_len]='\n';

			PartVar[sub_count].amount=0;
			while(buf[i]!=' ')
			{
				PartVar[sub_count].amount=10*PartVar[sub_count].amount+(int)buf[i]-'0';
				i++;
			}
			
			while(buf[i]==' ')
				i++;
			
			PartVar[sub_count].startaddr=0;
			while(buf[i]!=' ')
			{
				PartVar[sub_count].startaddr=10*PartVar[sub_count].startaddr+(int)buf[i]-'0';
				i++;
			}
	
			while(buf[i]==' ')
				i++;
			PartVar[sub_count].overaddr=0;
			while(buf[i]!='\n')
			{
				PartVar[sub_count].overaddr=10*PartVar[sub_count].overaddr+(int)buf[i]-'0';
				i++;
			}

			PartVar[sub_count].var=new table;
			p2=PartVar[sub_count].var;
			p2->next=NULL;
	
			
			for( j=0;j<PartVar[sub_count].amount;j++)
			{
				i=0;
				line_len=0;
				p1=new table;

				FVarInfor.get(buf,30);
				FVarInfor.get();

				line_len=strlen(buf);

				buf[line_len]='\n';

				p1->name=new char[15];
				while(buf[i]!=' ')
				{
					p1->name[i]=buf[i];
					i++;
				}
				p1->name[i]=0;

				while(buf[i]==' ')
				i++;

				p1->size=0;
				while(buf[i]!=' ')
				{
					p1->size=10*p1->size+buf[i]-'0';
					i++;
				}

				while(buf[i]==' ')
					i++;

				p1->adr=0;
				while(buf[i]!='\n')
				{
					p1->adr=10*p1->adr+(int)buf[i]-'0';
					i++;
				}

				p1->next=NULL;
				p2->next=p1;
				p2=p1;
			}

			p1=PartVar[sub_count].var;
			PartVar[sub_count].var=PartVar[sub_count].var->next;
			delete p1;

			sub_count++;
		}
				
	}

}

int simulator::inquire(char *name)

//**该函数实现用户输入变量名,可以查询出变量在内存中存贮的位置。
//**返回查询变量的绝对地址,如果要查询的变量是长整型变量,
//**则返回低16位绝对地址,高16位为返回值减1。

{
	int i;
	int BackValue;
	struct table *p1;
	i=0;
	while(pc>PartVar[i].overaddr)
		i++;
	p1=PartVar[i].var;
	while((p1!=NULL)&&(strcmp(name,p1->name)!=0))
		p1=p1->next;
	if(p1==NULL)
	{
		p1=wholevar;
		while((p1!=NULL)&&(strcmp(name,p1->name)!=0))
			p1=p1->next;
		if(p1==NULL)
		{
			InquireVarType=0;
			BackValue=-1;
		}
		else
		{
			if(p1->size==2)
			{
				InquireVarType=2;
				BackValue=cpu.ra[0]+p1->adr;
			}
			else
			{
				InquireVarType=1;
				BackValue=cpu.ra[0]+p1->adr;
			}
		}
	}
	else
	{
		if(p1->size==2)
		{
			InquireVarType=2;
			BackValue=cpu.ra[1]+p1->adr;
		}
		else
		{
			InquireVarType=1;
			BackValue=cpu.ra[1]+p1->adr;
		}
	}

	return BackValue;

}

int simulator::InquireRegister(char *RegisterName)

//该函数的主要功能是实现对用户所输入的寄存器名称进行查找;
//并且返回该寄存器的值,如果寄存器返回值为-10,这证明用户
//的输入有错误

{
	int k;
	int RegisterValue;
	//存贮所要查找的寄存器值寄存器

	k=cpu.rsp/4;
	if(strcmp(RegisterName,"ra[0]")==0)
	{
		RegisterValue=cpu.ra[0];
	}
	else
		if(strcmp(RegisterName,"ra[1]")==0)
		{
			RegisterValue=cpu.ra[1];
		}
		else
			if(strcmp(RegisterName,"ra[2]")==0)
			{
				RegisterValue=cpu.ra[2];
			}
			else
				if(strcmp(RegisterName,"rd[0]")==0)
				{
					k=4*k+1;
					if((k>cpu.rsp)&&(k>4))
						k-=4;

					RegisterValue=cpu.memony[k];
				}   
				else
					if(strcmp(RegisterName,"rd[1]")==0)
					{
						k=4*k+2;
						if((k>cpu.rsp)&&(k>4))
							k-=4;

						RegisterValue=cpu.memony[k];
					}
					else
						if(strcmp(RegisterName,"rd[2]")==0)
						{
							k=4*k+3;
							if((k>cpu.rsp)&&(k>4))
								k-=4;
							RegisterValue=cpu.memony[k];
						}
						else
							if(strcmp(RegisterName,"rd[3]")==0)
							{
								RegisterValue=cpu.memony[4*k];
							}
							else
								if(strcmp(RegisterName,"rsp")==0)
								{
									RegisterValue=cpu.rsp;
								}
								else
									if(strcmp(RegisterName,"rhp")==0)
									{
										RegisterValue=cpu.rhp;
									}
									else
										RegisterValue=-10;
					
	return RegisterValue;
}


int simulator::upvar(int i_sel,char * name)
{
	int VarAddr;
	CString str_var=_T(""),str_varhigh=_T(""),str_name=_T("");

	str_name=name;
    str_name.TrimLeft();
	str_name.TrimRight();
//	name=str_name;

	if(str_name.Find("[")!=-1)
	{
		if(str_name.Find("]")==0)
			return 0;
		int i=0,j=0;
		i=str_name.Find("[");
		j=str_name.Find("]");
		CString str_ident=_T("");
		CString str_num=_T("");
		str_ident=str_name.Left(i);
		if(j-1<i+1)
			return 0;
		str_num=str_name.Mid(i+1,j-i-1);
		int n_namelength=str_ident.GetLength();
		strcpy(name, T2A(str_ident.GetBuffer(n_namelength)));
		VarAddr=inquire(name);
		int i_arrayindex=0;
		
		n_namelength=str_num.GetLength();
//		char * c_num;
		strcpy(name, T2A(str_num.GetBuffer(n_namelength)));
		for(int ii=0;ii<n_namelength;ii++)
		{
			i_arrayindex=10*i_arrayindex+(int)name[ii]-'0';
			ii++;
		}
		VarAddr=VarAddr+i_arrayindex;
		if(InquireVarType==0)
		{
			return 0;
		}
		else
			if(InquireVarType==1)
			{
//					cout<<"var "<<name<<" value is  "<<cpu.memony[VarAddr]<<endl;
			str_var.Format("%d", cpu.memony[VarAddr]); 
			}
			else
			{
//					cout<<"var "<<name<<" value is  "<<cpu.memony[VarAddr-1]<<cpu.memony[VarAddr]<<endl;
			//str_varhigh.Format("%d", cpu.memony[VarAddr-1]); 
			str_var.Format("%d", cpu.memony[VarAddr-1]*REG_BIT+cpu.memony[VarAddr]);
			
			//str_var=str_varhigh+str_var;
			}
//			delete name;			
		CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;	
		
		m_pmainFrame->m_wndWatchBar.UpDateVar(i_sel,str_var);
		return 1;
	}
	else
	{
	int n_namelength=str_name.GetLength();
	strcpy(name, T2A(str_name.GetBuffer(n_namelength)));
//	name=new char[15];
//	cin>>name;

	VarAddr=inquire(name);
	if(InquireVarType==0)
	{
		return 0;
	}
	else
		if(InquireVarType==1)
			{
//					cout<<"var "<<name<<" value is  "<<cpu.memony[VarAddr]<<endl;
			str_var.Format("%d", cpu.memony[VarAddr]); 
			}
		else
			{
//					cout<<"var "<<name<<" value is  "<<cpu.memony[VarAddr-1]<<cpu.memony[VarAddr]<<endl;
			str_var.Format("%d", cpu.memony[VarAddr-1]*REG_BIT+cpu.memony[VarAddr]);
			}
//			delete name;			
	CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;	

    m_pmainFrame->m_wndWatchBar.UpDateVar(i_sel,str_var);
	return 1;
	}
}

int simulator::UpdateReg()
{
	CString str_add=_T(""),str_value=_T("");
	int k;
	//存贮所要查找的寄存器值寄存器
//	int RegisterValue;

	k=cpu.rsp/4;
	str_value.Format("%d",cpu.ra[0]);
	str_add=str_add+"ra[0]  "+str_value+"\n";
	str_value.Format("%d",cpu.ra[1]);
	str_add=str_add+"ra[1]  "+str_value+"\n";
	str_value.Format("%d",cpu.ra[2]);
	str_add=str_add+"ra[2]  "+str_value+"\n";
	k=4*k+1;
	if((k>cpu.rsp)&&(k>4))
		k-=4;
	str_value.Format("%d",cpu.memony[k]);
	str_add=str_add+"rd[0]  "+str_value+"\n";

	k++;
	str_value.Format("%d",cpu.memony[k]);
	str_add=str_add+"rd[1]  "+str_value+"\n";
	k++;
	str_value.Format("%d",cpu.memony[k]);
	str_add=str_add+"rd[2]  "+str_value+"\n";
	k++;
	str_value.Format("%d",cpu.memony[k]);
	str_add=str_add+"rd[3]  "+str_value+"\n";
	str_value.Format("%d",cpu.rsp);
	str_add=str_add+"rsp    "+str_value+"\n";
	str_value.Format("%d",cpu.rhp);
    str_add=str_add+"rhp    "+str_value;




	CMainFrame *m_pmainFrame = (CMainFrame*)AfxGetApp()->m_pMainWnd;	
    m_pmainFrame->m_regbar.p_VarEdit.SetWindowText(str_add);

	return 1;
}

⌨️ 快捷键说明

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