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

📄 txt.c

📁 这是一个同样来自贝尔实验室的和UNIX有着渊源的操作系统, 其简洁的设计和实现易于我们学习和理解
💻 C
📖 第 1 页 / 共 2 页
字号:
				a = AMOVFD;			break;		case TFLOAT:			a = AMOVDF;			if(ft == TFLOAT)				a = AMOVF;			break;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:		case TSHORT:		case TUSHORT:		case TCHAR:		case TUCHAR:			if(fproundflg) {				/* convert f, t */				regalloc(&nod, f, Z);				gins(AMOVDW, f, &nod);				if(ft == TFLOAT)					p->as = AMOVFW;				gins(AMOVW, &nod, t);				regfree(&nod);				gins(AMOVW, t, t);				return;			}			regalloc(&nod1, &regnode, Z);			regalloc(&nod2, &regnode, Z);			/* movw fcr, rx */			gins(AMOVW, Z, &nod1);			p->from.type = D_FCREG;			p->from.reg = 31;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			/* or $3, rx, ry */			gins(AOR, nodconst(3), &nod2);			p->reg = nod1.reg;			/* xor $2, ry */			gins(AXOR, nodconst(2), &nod2);			/* movw ry, fcr */			gins(AMOVW, &nod2, Z);			p->to.type = D_FCREG;			p->to.reg = 31;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			/* convert f, t */			regalloc(&nod, f, Z);			gins(AMOVDW, f, &nod);			if(ft == TFLOAT)				p->as = AMOVFW;			gins(AMOVW, &nod, t);			regfree(&nod);			gins(AMOVW, t, t);			/* movw rx, fcr */			gins(AMOVW, &nod1, Z);			p->to.type = D_FCREG;			p->to.reg = 31;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			/* nop */			gins(ANOR, nodconst(0), nodconst(0));			p->to.type = D_REG;			p->to.reg = 0;			regfree(&nod1);			regfree(&nod2);			return;		}		break;	case TINT:	case TUINT:	case TLONG:	case TULONG:	case TIND:		switch(tt) {		case TDOUBLE:		case TVLONG:			gins(AMOVW, f, t);			gins(AMOVWD, t, t);			if(ft == TULONG || ft == TUINT) {				regalloc(&nod, t, Z);				gins(ACMPGED, t, Z);				p->reg = FREGZERO;				gins(ABFPT, Z, Z);				p1 = p;				gins(AMOVD, nodfconst(4294967296.), &nod);				gins(AADDD, &nod, t);				patch(p1, pc);				regfree(&nod);			}			return;		case TFLOAT:			gins(AMOVW, f, t);			gins(AMOVWF, t, t);			if(ft == TULONG || ft == TUINT) {				regalloc(&nod, t, Z);				gins(ACMPGEF, t, Z);				p->reg = FREGZERO;				gins(ABFPT, Z, Z);				p1 = p;				gins(AMOVF, nodfconst(4294967296.), &nod);				gins(AADDF, &nod, t);				patch(p1, pc);				regfree(&nod);			}			return;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:		case TSHORT:		case TUSHORT:		case TCHAR:		case TUCHAR:			a = AMOVW;			break;		}		break;	case TSHORT:		switch(tt) {		case TDOUBLE:		case TVLONG:			regalloc(&nod, f, Z);			gins(AMOVH, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWD, t, t);			regfree(&nod);			return;		case TFLOAT:			regalloc(&nod, f, Z);			gins(AMOVH, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWF, t, t);			regfree(&nod);			return;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:			a = AMOVH;			break;		case TSHORT:		case TUSHORT:		case TCHAR:		case TUCHAR:			a = AMOVW;			break;		}		break;	case TUSHORT:		switch(tt) {		case TDOUBLE:		case TVLONG:			regalloc(&nod, f, Z);			gins(AMOVHU, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWD, t, t);			regfree(&nod);			return;		case TFLOAT:			regalloc(&nod, f, Z);			gins(AMOVHU, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWF, t, t);			regfree(&nod);			return;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:			a = AMOVHU;			break;		case TSHORT:		case TUSHORT:		case TCHAR:		case TUCHAR:			a = AMOVW;			break;		}		break;	case TCHAR:		switch(tt) {		case TDOUBLE:		case TVLONG:			regalloc(&nod, f, Z);			gins(AMOVB, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWD, t, t);			regfree(&nod);			return;		case TFLOAT:			regalloc(&nod, f, Z);			gins(AMOVB, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWF, t, t);			regfree(&nod);			return;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:		case TSHORT:		case TUSHORT:			a = AMOVB;			break;		case TCHAR:		case TUCHAR:			a = AMOVW;			break;		}		break;	case TUCHAR:		switch(tt) {		case TDOUBLE:		case TVLONG:			regalloc(&nod, f, Z);			gins(AMOVBU, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWD, t, t);			regfree(&nod);			return;		case TFLOAT:			regalloc(&nod, f, Z);			gins(AMOVBU, f, &nod);			gins(AMOVW, &nod, t);			gins(AMOVWF, t, t);			regfree(&nod);			return;		case TINT:		case TUINT:		case TLONG:		case TULONG:		case TIND:		case TSHORT:		case TUSHORT:			a = AMOVBU;			break;		case TCHAR:		case TUCHAR:			a = AMOVW;			break;		}		break;	}	if(a == AGOK)		diag(Z, "bad opcode in gmove %T -> %T", f->type, t->type);	if(a == AMOVW || a == AMOVF || a == AMOVD)	if(samaddr(f, t))		return;	gins(a, f, t);}voidgins(int a, Node *f, Node *t){	nextpc();	p->as = a;	if(f != Z)		naddr(f, &p->from);	if(t != Z)		naddr(t, &p->to);	if(debug['g'])		print("%P\n", p);}voidgopcode(int o, Node *f1, Node *f2, Node *t){	int a, et;	Adr ta;	et = TLONG;	if(f1 != Z && f1->type != T)		et = f1->type->etype;	a = AGOK;	switch(o) {	case OAS:		gmove(f1, t);		return;	case OASADD:	case OADD:		a = AADDU;		if(et == TFLOAT)			a = AADDF;		else		if(et == TDOUBLE || et == TVLONG)			a = AADDD;		break;	case OASSUB:	case OSUB:		a = ASUBU;		if(et == TFLOAT)			a = ASUBF;		else		if(et == TDOUBLE || et == TVLONG)			a = ASUBD;		break;	case OASOR:	case OOR:		a = AOR;		break;	case OASAND:	case OAND:		a = AAND;		break;	case OASXOR:	case OXOR:		a = AXOR;		break;	case OASLSHR:	case OLSHR:		a = ASRL;		break;	case OASASHR:	case OASHR:		a = ASRA;		break;	case OASASHL:	case OASHL:		a = ASLL;		break;	case OFUNC:		a = AJAL;		break;	case OCOND:		a = ASGTU;		break;	case OCOMMA:		a = ASGT;		break;	case OASMUL:	case OMUL:		if(et == TFLOAT) {			a = AMULF;			break;		} else		if(et == TDOUBLE || et == TVLONG) {			a = AMULD;			break;		}		a = AMUL;		goto muldiv;	case OASDIV:	case ODIV:		if(et == TFLOAT) {			a = ADIVF;			break;		} else		if(et == TDOUBLE || et == TVLONG) {			a = ADIVD;			break;		}		a = ADIV;		goto muldiv;	case OASMOD:	case OMOD:		a = ADIV;		o = OMOD;		goto muldiv;	case OASLMUL:	case OLMUL:		a = AMULU;		goto muldiv;	case OASLMOD:	case OLMOD:		a = ADIVU;		o = OMOD;		goto muldiv;	case OASLDIV:	case OLDIV:		a = ADIVU;		goto muldiv;	muldiv:		nextpc();		naddr(f1, &p->from);		if(f2 == Z)			raddr(t, p);		else			raddr(f2, p);		p->as = a;		if(debug['g'])			print("%P\n", p);		nextpc();		p->as = AMOVW;		a = D_LO;		if(o == OMOD)			a = D_HI;		p->from.type = a;		naddr(t, &p->to);		if(debug['g'])			print("%P\n", p);		return;	case OEQ:		if(!typefd[et]) {			a = ABEQ;			break;		}	case ONE:		if(!typefd[et]) {			a = ABNE;			break;		}	case OLT:	case OLE:	case OGE:	case OGT:		if(typefd[et]) {			nextpc();			if(et == TFLOAT) {				a = ACMPGTF;				if(o == OEQ || o == ONE)					a = ACMPEQF;				else				if(o == OLT || o == OGE)					a = ACMPGEF;			} else {				a = ACMPGTD;				if(o == OEQ || o == ONE)					a = ACMPEQD;				else				if(o == OLT || o == OGE)					a = ACMPGED;			}			p->as = a;			naddr(f1, &p->from);			raddr(f2, p);			if(debug['g'])				print("%P\n", p);			nextpc();			a = ABFPF;			if(o == OEQ || o == OGE || o == OGT)				a = ABFPT;			p->as = a;			if(debug['g'])				print("%P\n", p);			return;		}		if(vconst(f1) == 0 || vconst(f2) == 0) {			if(vconst(f1) == 0) {				o = invrel[relindex(o)];				f1 = f2;			}			switch(o) {			case OLT:				a = ABLTZ;				break;			case OLE:				a = ABLEZ;				break;			case OGE:				a = ABGEZ;				break;			case OGT:				a = ABGTZ;				break;			}			f2 = Z;			break;		}	case OLO:	case OLS:	case OHS:	case OHI:		nextpc();		if(o == OLE || o == OGT || o == OLS || o == OHI) {			naddr(f1, &p->from);			raddr(f2, p);		} else {			naddr(f2, &p->from);			raddr(f1, p);		}		naddr(&regnode, &p->to);		p->to.reg = tmpreg();		a = ASGT;		if(o == OLO || o == OLS || o == OHS || o == OHI)			a = ASGTU;		p->as = a;		if(debug['g'])			print("%P\n", p);		nextpc();		naddr(&regnode, &p->from);		p->from.reg = tmpreg();		a = ABEQ;		if(o == OLT || o == OGT || o == OLO || o == OHI)			a = ABNE;		p->as = a;		if(debug['g'])			print("%P\n", p);		return;	}	if(a == AGOK)		diag(Z, "bad in gopcode %O", o);	nextpc();	p->as = a;	if(f1 != Z)		naddr(f1, &p->from);	if(f2 != Z) {		naddr(f2, &ta);		p->reg = ta.reg;		if(ta.type == D_CONST && ta.offset == 0)			p->reg = REGZERO;	}	if(t != Z)		naddr(t, &p->to);	if(debug['g'])		print("%P\n", p);}intsamaddr(Node *f, Node *t){	if(f->op != t->op)		return 0;	switch(f->op) {	case OREGISTER:		if(f->reg != t->reg)			break;		return 1;	}	return 0;}voidgbranch(int o){	int a;	a = AGOK;	switch(o) {	case ORETURN:		a = ARET;		break;	case OGOTO:		a = AJMP;		break;	}	nextpc();	if(a == AGOK) {		diag(Z, "bad in gbranch %O",  o);		nextpc();	}	p->as = a;}voidpatch(Prog *op, long pc){	op->to.offset = pc;	op->to.type = D_BRANCH;}voidgpseudo(int a, Sym *s, Node *n){	nextpc();	p->as = a;	p->from.type = D_OREG;	p->from.sym = s;	p->reg = (profileflg ? 0 : NOPROF);	p->from.name = D_EXTERN;	if(s->class == CSTATIC)		p->from.name = D_STATIC;	naddr(n, &p->to);	if(a == ADATA || a == AGLOBL)		pc--;}intsconst(Node *n){	vlong vv;	if(n->op == OCONST) {		if(!typefd[n->type->etype]) {			vv = n->vconst;			if(vv >= (vlong)(-32766) && vv < (vlong)32766)				return 1;		}	}	return 0;}intsval(long v){	if(v >= -32766L && v < 32766L)		return 1;	return 0;}longexreg(Type *t){	long o;	if(typechlp[t->etype]) {		if(exregoffset <= 16)			return 0;		o = exregoffset;		exregoffset--;		return o;	}	if(typefd[t->etype]) {		if(exfregoffset <= 16)			return 0;		o = exfregoffset + NREG;		exfregoffset--;		return o;	}	return 0;}schar	ewidth[NTYPE] ={	-1,		/* [TXXX] */	SZ_CHAR,	/* [TCHAR] */	SZ_CHAR,	/* [TUCHAR] */	SZ_SHORT,	/* [TSHORT] */	SZ_SHORT,	/* [TUSHORT] */	SZ_INT,		/* [TINT] */	SZ_INT,		/* [TUINT] */	SZ_LONG,	/* [TLONG] */	SZ_LONG,	/* [TULONG] */	SZ_VLONG,	/* [TVLONG] */	SZ_VLONG,	/* [TUVLONG] */	SZ_FLOAT,	/* [TFLOAT] */	SZ_DOUBLE,	/* [TDOUBLE] */	SZ_IND,		/* [TIND] */	0,		/* [TFUNC] */	-1,		/* [TARRAY] */	0,		/* [TVOID] */	-1,		/* [TSTRUCT] */	-1,		/* [TUNION] */	SZ_INT,		/* [TENUM] */};long	ncast[NTYPE] ={	0,				/* [TXXX] */	BCHAR|BUCHAR,			/* [TCHAR] */	BCHAR|BUCHAR,			/* [TUCHAR] */	BSHORT|BUSHORT,			/* [TSHORT] */	BSHORT|BUSHORT,			/* [TUSHORT] */	BINT|BUINT|BLONG|BULONG|BIND,	/* [TINT] */	BINT|BUINT|BLONG|BULONG|BIND,	/* [TUINT] */	BINT|BUINT|BLONG|BULONG|BIND,	/* [TLONG] */	BINT|BUINT|BLONG|BULONG|BIND,	/* [TULONG] */	BVLONG|BUVLONG,			/* [TVLONG] */	BVLONG|BUVLONG,			/* [TUVLONG] */	BFLOAT,				/* [TFLOAT] */	BDOUBLE,			/* [TDOUBLE] */	BLONG|BULONG|BIND,		/* [TIND] */	0,				/* [TFUNC] */	0,				/* [TARRAY] */	0,				/* [TVOID] */	BSTRUCT,			/* [TSTRUCT] */	BUNION,				/* [TUNION] */	0,				/* [TENUM] */};

⌨️ 快捷键说明

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