Beispiel #1
0
AstExpression Cast(Type ty, AstExpression expr)
{
	int scode = TypeCode(expr->ty);
	int dcode = TypeCode(ty);
	
	if (dcode == V)
	{
		return CastExpression(ty, expr);
	}

	if (scode < F4 && dcode < F4 && scode / 2 == dcode / 2)
	{
		expr->ty = ty;
		return expr;
	}

	if (scode < I4)
	{
		expr = CastExpression(T(INT), expr);
		scode = I4;
	}
	if (scode != dcode)
	{
		if (dcode < I4)
		{
			expr = CastExpression(T(INT), expr);
		}
		expr = CastExpression(ty, expr);
	}
	return expr;
}
Beispiel #2
0
void DefineValue(Type ty, union value val)
{
	int tcode = TypeCode(ty);

	switch (tcode)
	{
	case I1: case U1:
		Print(".byte\t%d\n", val.i[0] & 0xff);
		break;

	case I2: case U2:
		Print(".word\t%d\n", val.i[0] & 0xffff);
		break;

	case I4: case U4:
		Print(".long\t%d\n", val.i[0]);
		break;

	case F4:
		Print(".long\t%d\n", *(unsigned *)&val.f );
		break;

	case F8:
		{
			unsigned *p = (unsigned *)&val.d;
			Print(".long\t%d\n.long\t%d\n", p[0], p[1]);
			break;
		}

	default:
		assert(0);
	}
}
Beispiel #3
0
void DefineValue(Type ty, union value val)
{
	int tcode = TypeCode(ty);

	switch (tcode)
	{
	case I1: case U1:
		Print("BYTE\t0%xH\n", val.i[0] & 0xff);
		break;

	case I2: case U2:
		Print("WORD\t0%xH\n", val.i[0] & 0xffff);
		break;

	case I4: case U4:
		Print("DWORD\t0%xH\n", val.i[0]);
		break;

	case F4:
		Print("DWORD\t0%xH\n", *(unsigned *)&val.f );
		break;

	case F8:
		{
			unsigned *p = (unsigned *)&val.d;
			Print("DWORD\t0%xH, 0%xH\n", p[0], p[1]);
			break;
		}

	default:
		assert(0);
	}
}
Beispiel #4
0
void FieldValue::print(std::ostream& out) const {
    data->print(out);
    out << TypeCode(typeOctet) << '(';
    if (data->convertsToString()) out << data->getString();
    else if (data->convertsToInt()) out << data->getInt();
    else data->print(out);
    out << ')';
}
Beispiel #5
0
void CRuleType::Dump(CString & oDump, uint32 nLevel) const
{
	CRuleType::DumpLevel(oDump, nLevel);
	if(TypeCode() == ARF_OBJECT)
		oDump += "object ";
	oDump += m_oName;
	oDump += ";\n";
}
status_t
BAffineTransform::Unflatten(type_code code, const void* _buffer, ssize_t size)
{
    if (_buffer == NULL || size < FlattenedSize() || code != TypeCode())
        return B_BAD_VALUE;

    const double* buffer = reinterpret_cast<const double*>(_buffer);

    sx = buffer[0];
    shy = buffer[1];
    shx = buffer[2];
    sy = buffer[3];
    tx = buffer[4];
    ty = buffer[5];

    return B_OK;
}
Beispiel #7
0
static void PeepHole(BBlock bb)
{
	IRInst inst = bb->insth.next;
	IRInst ninst;

	while (inst != &bb->insth)
	{
		ninst = inst->next;
		if ((inst->opcode == CALL || (inst->opcode >= EXTI1 && inst->opcode <= CVTF8U4)) && 
		    ninst->opcode == MOV && inst->opds[0] == ninst->opds[1])
		{
			inst->opds[0]->ref -= 2;
			inst->opds[0] = ninst->opds[0];
			inst->next = ninst->next;
			ninst->next->prev = inst;
			bb->ninst--;
			if (ninst->opds[0]->kind == SK_Temp)
				DefineTemp(ninst->opds[0], inst->opcode, (Symbol)inst, NULL);
		}
		else if ((inst->opcode == MOV || inst->opcode == IMOV) && inst->opds[1]->kind == SK_Temp)
		{
			ValueDef def = AsVar(inst->opds[1])->def;
			IRInst p;

			if (def->op == MOV)
			{
				while (def != NULL)
				{
					p = (IRInst)def->src1;
					p->opds[0]->ref--;
					inst->opds[0]->ref++;
					p->opds[0] = inst->opds[0];
					p->opcode = inst->opcode;
					def = def->link;
				}
				inst->opds[0]->ref--;
				inst->opds[1]->ref--;
				inst->prev->next = inst->next;
				inst->next->prev = inst->prev;
			}
		}
		else if ((inst->opcode == ADD || inst->opcode == SUB) && ninst->opcode == MOV &&
		         inst->opds[0] == ninst->opds[1] && inst->opds[1] == ninst->opds[0] &&
		         inst->opds[2]->kind == SK_Constant)
		{
			int tcode = TypeCode(inst->ty);
			if ((tcode == F4 && inst->opds[2]->val.f == 1.0f) ||
			    (tcode == F8 && inst->opds[2]->val.d == 1.0)  ||
			    (inst->opds[2]->val.i[0] == 1))
			{
				inst->opds[0]->ref -= 2;
				inst->opds[1]->ref--;
				inst->opds[2]->ref--;
				inst->opcode = inst->opcode == ADD ? INC : DEC;
				inst->opds[0] = inst->opds[1];
				inst->opds[1] = inst->opds[2] = NULL;
				inst->next = ninst->next;
				ninst->next->prev = inst;
			}
		}
		inst = inst->next;
	}
}