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

📄 scoreboarddlg.cpp

📁 用VC实现的模拟指令发射流程的计分排算法实现
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// scoreboardDlg.cpp : implementation file
//

#include "stdafx.h"
#include "scoreboard.h"
#include "scoreboardDlg.h"
#include "myfile.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
void readcode();
struct Instruction{
	char* op;     //operation code;
	char* dest;   //the destination operand
	char* sour1;  //the first source operand
	char* sour2;  //the second soruce operand
    int   stage;  //register instruction current stage
	int   lasttime;//indaicates the next instrucion's location
	int	  exe_time;//the execuse time
	
} instruction[5];
struct StatusTable{
	bool busy;
	char*  op;
	char*  fi;
	char*  fj;
	char*  fk;
	int    qj;
	int    qk;
	bool   rj;
	bool   rk;
}statustable[Num_FU];

struct Floatreg{
	char * fi;
	int  num;
}floatreg[Num_Floatreg];


char clock1[5];
char *code[Num_instr_set]={"LD","MULTD","ADDD","SUBD","DIVD"};		
//the resulttable to record the float register where is it 
int resulttable[Num_Floatreg+1];


//void readcode();

bool CScoreboardDlg::testfinished()
{
	bool finished=false;
	int count=0;
	for(int i=0;i<Num_Instruc;i++){
		if(instruction[i].stage==WB)
			count++;
	}
	if(count==Num_Instruc)
		finished=true;
	return finished;
}
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoreboardDlg dialog

CScoreboardDlg::CScoreboardDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CScoreboardDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CScoreboardDlg)
	
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CScoreboardDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CScoreboardDlg)
	DDX_Control(pDX, FU_LIST1, m_function);
	DDX_Control(pDX, Register_LIST2, m_register);
	DDX_Control(pDX, Instatus_LIST2, m_instatus);
	DDX_Control(pDX, Instruc_LIST1, m_instruction);
	DDX_Text(pDX, IDC_EDIT2, m_inttime);
	DDX_Text(pDX, IDC_EDIT3, m_addtime);
	DDX_Text(pDX, IDC_EDIT4, m_multime);
	DDX_Text(pDX, IDC_EDIT5, m_divtime);
	DDX_Text(pDX, IDC_EDIT1, m_clock);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CScoreboardDlg, CDialog)
	//{{AFX_MSG_MAP(CScoreboardDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_open, Onopen)
	ON_COMMAND(ID_runauto, runauto)
	ON_COMMAND(ID_steprun, steprun)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_COMMAND(ID_MENUITEM32775, OnMenuitem32775)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CScoreboardDlg message handlers

BOOL CScoreboardDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	CFrameWnd::LoadFrame;

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);// Set small icon
		
	
    Start=false;
	stepinto=false;
	stepflag=false;
	clockcnt=0;
	m_clock=0;
	m_inttime=1;UpdateData(FALSE);
	m_addtime=2;UpdateData(FALSE);
	m_multime=10;UpdateData(FALSE);
	m_divtime=40;UpdateData(FALSE);

	initial();
	// TODO: Add extra initialization here
	//m_instruction.InsertColumn(0,"ID",LVCFMT_CENTER,45);
    m_instruction.InsertColumn(0,"指令",LVCFMT_CENTER,50);
    m_instruction.InsertColumn(1,"目的",LVCFMT_CENTER,50);
	m_instruction.InsertColumn(2,"源J",LVCFMT_CENTER,50);
	m_instruction.InsertColumn(3,"源K",LVCFMT_CENTER,50);

	m_instatus.InsertColumn(0,"ID",LVCFMT_CENTER,45);
	m_instatus.InsertColumn(1,"IS",LVCFMT_CENTER,45);
	m_instatus.InsertColumn(2,"RO",LVCFMT_CENTER,45);
	m_instatus.InsertColumn(3,"EX",LVCFMT_CENTER,45);
	m_instatus.InsertColumn(4,"WB",LVCFMT_CENTER,45);

	m_function.InsertColumn(0,"FU",LVCFMT_CENTER,50);
	m_function.InsertColumn(1,"busy",LVCFMT_CENTER,45);
	m_function.InsertColumn(2,"OP",LVCFMT_CENTER,45);
	m_function.InsertColumn(3,"Fi",LVCFMT_CENTER,40);
	m_function.InsertColumn(4,"Fj",LVCFMT_CENTER,40);
	m_function.InsertColumn(5,"Fk",LVCFMT_CENTER,40);
	m_function.InsertColumn(6,"Qj",LVCFMT_CENTER,50);
	m_function.InsertColumn(7,"Qk",LVCFMT_CENTER,50);
	m_function.InsertColumn(8,"Rj",LVCFMT_CENTER,45);
	m_function.InsertColumn(9,"Rk",LVCFMT_CENTER,45);

	m_function.InsertItem(0,"int");
    m_function.InsertItem(1,"mul");
    m_function.InsertItem(2,"add");
    m_function.InsertItem(3,"div");

	m_register.InsertColumn(0,"F0",LVCFMT_CENTER,45);
	m_register.InsertColumn(1,"F1",LVCFMT_CENTER,45);
	m_register.InsertColumn(2,"F2",LVCFMT_CENTER,45);
	m_register.InsertColumn(3,"F3",LVCFMT_CENTER,45);
	m_register.InsertColumn(4,"F4",LVCFMT_CENTER,45);
	m_register.InsertColumn(5,"F5",LVCFMT_CENTER,45);
	m_register.InsertColumn(6,"F6",LVCFMT_CENTER,45);
	m_register.InsertColumn(7,"F7",LVCFMT_CENTER,45);
    //m_register.SetItemText(1,0,"ok!");
	char display[40];
    /*for(int i=0;i<Num_Instruc;i++){
	   
	   m_instatus.InsertItem(i,::itoa(i,display,10));
	   
	}*/
   m_register.InsertItem(0,::itoa(0,display,10));
	for(int num=0;num<=10;num++)
	{
		m_register.SetItemText(0,num,_T("-1"));
	}
	
	return TRUE;  // return TRUE  unless you set the focus to a control

	

	
}

void CScoreboardDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CScoreboardDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CScoreboardDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CScoreboardDlg::Onopen() 
{
	// TODO: Add your command handler code here
	TCHAR* szSelections = NULL;

	CFileDialog FileDlg(true,"s",NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT|
 		                OFN_ALLOWMULTISELECT,"scoreboard Files(*.s) |*.s|All Files(*.*) |*.*||",NULL);

    szSelections = new TCHAR[1000];
 	memset(szSelections,NULL,1000);
 	FileDlg.m_ofn.lpstrFile=szSelections;
 	FileDlg.m_ofn.nMaxFile = 1000;
	FileDlg.m_ofn.lpstrTitle = "please choose the source code ";
	if (FileDlg.DoModal()==IDOK)
	{
      PathName=FileDlg.GetPathName();
	}
	MessageBox(PathName);
    readcode();
	char display[40];
	int i;
	for(i=0;i<Num_Instruc;i++){
	m_instruction.InsertItem(i,::itoa(i,display,10));
	m_instruction.SetItemText(i,0,instruction[i].op);
	m_instruction.SetItemText(i,1,instruction[i].dest);
	m_instruction.SetItemText(i,2,instruction[i].sour1);
	m_instruction.SetItemText(i,3,instruction[i].sour2);
	
	} 	

}


int	CScoreboardDlg::determtime(char *str)
{
	int fu_unit=get_fu_number(str);//str point to the instruction's op field
	int time=0;
	switch (fu_unit)
	{
	case Int:	time=m_inttime;
		break;
	case Mult:	time=m_multime;
		break;
	case Addd:	time=m_addtime;
		break;
	case Divd:	 time=m_divtime;
		break;
	default:	time=0;
		break;
	}
	return	time;
}



void CScoreboardDlg::decode(char* str,struct Instruction *instr)
{
//	char ch;
	(*instr).op=new char[10];
	strcpy((*instr).op,"\0");
	(*instr).dest=new char[10];
	strcpy((*instr).dest,"\0");
	(*instr).sour1=new char[10];
	strcpy((*instr).sour1,"\0");
	(*instr).sour2=new char[10];
	strcpy((*instr).sour2,"\0");
	(*instr).stage=BEG;
	(*instr).lasttime=-1;
	(*instr).exe_time=0;

	char *temp=new char[10];
	int index=0;
	int i_temp=0,i_str=0,i_instr=0;
	while(str[i_str]!='\0'){
		if((str[i_str]!=9))			
			temp[i_temp++]=str[i_str++];
		else{
			i_str++;
			temp[i_temp]='\0';
			switch (index++){
			case 0:
				strcpy((*instr).op,temp);
				(*instr).exe_time=determtime(temp);
				break;
			case 1:
				strcpy((*instr).dest,temp);
				break;
			case 2:
				strcpy((*instr).sour1,temp);
				break;
			case 3:
				strcpy((*instr).sour2,temp);
				break;
			}
			i_temp=0;
		}
			
	}

}

void CScoreboardDlg::readcode()
{
	ifstream infile("code.s");
	if(!infile){
		MessageBox("open code file error!\n");
	}
	char* str=new char[100];	//to store a line
	char* remark=new char[100];	//to store the remark 
	int num=0;	//index opsition of a line 
	int num_instr=0;	//index the instruction array
	char ch;	//register the char 
	while(infile.get(ch)){
		if((ch!='\n')){
			if(ch==' ')
				continue;
			if(ch==',')
				ch=9;
			str[num++]=ch;	//make str only contain TAB as the interval;
		}else{
			str[num++]=9;	//add a \tab key;
			str[num]='\0';
			decode(str,&instruction[num_instr]);
			num_instr++;
			if(num_instr>Num_Instruc)
				return;
			num=0;		
		}	//a line have been sucessfully readed;
	}
}



void CScoreboardDlg::initial()
{
	for(int i=0;i<Num_Floatreg+1;i++)
		resulttable[i]=-1;

	for( i=0;i<Num_FU;i++)//initial the statustable array
	{
		statustable[i].busy=false;
		statustable[i].op=NULL;
		statustable[i].fi=NULL;
		statustable[i].fj=NULL;
		statustable[i].fk=NULL;
		statustable[i].qj=-1;
		statustable[i].qk=-1;
		statustable[i].rj=true;
		statustable[i].rk=true;
	}

	//initial the map of floatregister and number
	floatreg[0].fi="F0";floatreg[0].num=0; 
	floatreg[1].fi="F1";floatreg[1].num=1; 

⌨️ 快捷键说明

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