Exemple #1
0
static Symbol GetRegInternal(int width)
{
	int i, endr;
	Symbol *regs;

	switch (width)
	{
	case 1:
		endr = EDX;
		regs = X86ByteRegs;
		break;

	case 2:
		endr = EDI;
		regs = X86WordRegs;
		break;

	case 4:
		endr = EDI;
		regs = X86Regs;
		break;
	}

	i = FindEmptyReg(endr);
	if (i == NO_REG)
	{
		i = SelectSpillReg(endr);
		SpillReg(X86Regs[i]);
	}
	UsedRegs |= 1 << i;

	return regs[i];
}
Exemple #2
0
void ClearRegs(void)
{
	int i;

	for (i = EAX; i <= EDI; ++i)
	{
		if (X86Regs[i])
			SpillReg(X86Regs[i]);
	}
}
Exemple #3
0
void Reg::ClearRegs()
{
	int i;

	for (i = EAX; i <= EDI; i++)
	{
		if (Regs[i])
			SpillReg(Regs[i]);
	}
}
Exemple #4
0
Symbol Reg::GetRegInternal()
{
	int i;

	// 尝试找到一个还没有使用的寄存器,若返回不等于-1,代表存在
	i = FindEmptyReg();
	// 若没有空余的寄存器
	if (i == NO_REG)
	{
		i = SelectSpillReg();
		SpillReg(Regs[i]);
	}

	UsedRegs |= 1 << i;	//设置标志位

	return Regs[i];
}
Exemple #5
0
void Compiler::EmitAssign(IRInst inst)
{
	switch (OP)
	{
		case $ADD:
		case $SUB:

			AllocateReg(inst, 1);
			AllocateReg(inst, 2);
			AllocateReg(inst, 0);
			//char name[40];
			//sprintf(name, "%s", SRC1->reg->name.c_str());
			//PutString(name);


			if (DST->reg != SRC1->reg)
			{
				Move(DST, SRC1);
			}
			if (OP == $ADD) PutASMCode(X86_ADDI4, inst->opds);
			if (OP == $SUB) PutASMCode(X86_SUBI4, inst->opds);
			break;

		case $MUL:
		case $DIV:
			if (SRC1->reg == Regs[EAX])
			{
				SpillReg(Regs[EAX]);
			}
			else
			{
				Symbol sym = Regs[EAX]->link;

				if (sym != NULL && sym->ref > 0) {
					Symbol reg = GetRegInternal();
					SpillReg(Regs[EAX]);

					Move(reg, Regs[EAX]);
					sym->reg = reg;
					reg->link = sym;
				}
				else {
					SpillReg(Regs[EAX]);
				}

				Move(Regs[EAX], SRC1);
			}
			// SpillReg(Regs[EDX]);
			// 将SRC1扩展后放在EAX与EDX
			UsedRegs = 1 << EAX ;
			if (SRC2->kind == SK_Constant)
			{
				Symbol reg = GetRegInternal();

				Move(reg, SRC2);
				SRC2 = reg;
			}
			else
			{
				AllocateReg(inst, 2);
			}

			if (OP == $MUL) PutASMCode(X86_MULI4, inst->opds);
			if (OP == $DIV) PutASMCode(X86_DIVI4, inst->opds);

			DST->link = Regs[EAX]->link;
			Regs[EAX]->link = DST;
			DST->reg = Regs[EAX];
			break;

		default:
			break;
	}

	if (DST) DST->ref--;
	if (SRC1) SRC1->ref--;
	if (SRC2) SRC2->ref--;
}