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

📄 midtodemi.h

📁 SNL语言的编译器
💻 H
字号:
// midtodemi.h: interface for the Cmidtodemi class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_MIDTODEMI_H__A36B244F_152C_45A3_ACC6_9A222FD5CA59__INCLUDED_)
#define AFX_MIDTODEMI_H__A36B244F_152C_45A3_ACC6_9A222FD5CA59__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "global.h"



/* 程序指令指示器pc为7,指向当前指令存储位置		*
 * 程序指示器将使用寄存器数组中的第8个寄存器	*/
#define  pc 7	


/* 过程活动记录头指针指示器sp指向过程活动记录的头地址指针 */
#define  sp 6

/* 过程活动记录尾指针指示器top指向过程活动记录的尾地址指针 */
#define  top  5 

/* 过程活动记录sp到display表距离指示器displayOff */
#define  displayOff  4

/* 存储指示器mp指向用于临时变量存储的数据存储器顶端 */
#define  mp 3

#define  ac2 2      /* 第三累加器 */

#define  ac1 1		/* 第二累加器 */

#define  ac 0		/* 第一累加器 */



class Cmidtodemi : public Cglobal  
{
public:
	Cmidtodemi();
	virtual ~Cmidtodemi();

/*标号地址表*/
LabelAddr  *labelAddrT ;

/* TM指令当前生成代码写入地址 */
 int emitLoc ;

/* 用于在函数emitSkip,emitBackup,emitRestore	*
 * 中作为当前最高生成代码写入地址,初始为0		*/
 int highEmitLoc ;


/**************** 代码产生功能函数 *******************/

/* 该函数在代码文件code中写入指令的注释行,注释内容由c指定 */
void emitComment( char * c );

/************************************************************
 * 该函数产生一条只用寄存器操作数的TM指令,寄存器地址模式	*
 * op 为操作码												*
 * r  为目标寄存器											*
 * s  为第一寄存器											*
 * t  为第二寄存器											*
 * c  为要写入代码文件code的注释内容,						*
 *    当代码生成追踪标志TraceCode为TRUE时写入目标代码文件	*
 ************************************************************/
void emitRO( char *op, int r, int s, int t, char *c);

/************************************************************
 * 该函数产生一条寄存器-内存操作数的TM指令					*
 * op 为操作码												*
 * r  为目标寄存器											*
 * d  为偏移值												*
 * s  为基地址寄存器										*
 * c  为要写入代码文件code的注释内容,						*
 *    当代码生成追踪标志TraceCode为TRUE时写入目标代码文件	*
 ************************************************************/
void emitRM( char * op, int r, int d, int s, char *c);

/* 该函数略过参数howMany指定数量代码指令行,函数返回当前代码指令写入地址 */
int emitSkip( int howMany);

/* 该函数退回到由参数loc指明的上一个已经略过的代码指令写入地址 */
void emitBackup( int loc);

/* 该函数把当前代码写入地址恢复为当前未写入代码指令的最高地址 */
void emitRestore(void);

/************************************************************
 * 该函数在产生一条寄存器-内存操作数TM指令时,				*
 * 将一个绝对地址参数转换为pc相对地址参数					*
 * op 为操作码												*
 * r  为目标寄存器											*
 * a  为绝对存储器地址										*
 * c  为要写入代码文件code的注释内容,						*
 *    当追踪标志TraceCode为TRUE时写入						*
 ************************************************************/
void emitRM_Abs( char *op, int r, int a, char * c);




/*********目标代码生成函数声明***********/

void    codeGen(CodeFile  *midcode, char * destcode);

void	arithGen(CodeFile  *midcode);

void    operandGen(ArgRecord  *arg);

void	compaGen(CodeFile  *midcode);

void	aaddGen(CodeFile  *midcode);

void	readGen(CodeFile  *midcode);

void	writeGen(CodeFile  *midcode);

void	returnGen(CodeFile  *midcode);

void	assigGen(CodeFile  *midcode);

void	labelGen(CodeFile  *midcode);

void	jumpGen(CodeFile  *midcode , int i);

void	jump0Gen(CodeFile  *midcode);

void	valactGen(CodeFile  *midcode);

void	varactGen(CodeFile  *midcode);

void	callGen(CodeFile  *midcode);

void	pentryGen(CodeFile  *midcode);

void	endprocGen(CodeFile  *midcode);

void    FindAddr(ArgRecord  *arg );

void	FindSp(int varlevel);

void    mentryGen(CodeFile  *midcode,int savedLoc);
};

#endif // !defined(AFX_MIDTODEMI_H__A36B244F_152C_45A3_ACC6_9A222FD5CA59__INCLUDED_)

⌨️ 快捷键说明

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