Beispiel #1
0
bool CCallSpecial::isValid(Inst& inst)
{
    if (inst.args.size() < argArgOffset)
        return false;

    for (unsigned i = 0; i < numCalleeArgs; ++i) {
        Arg& arg = inst.args[i + calleeArgOffset];
        if (!arg.isGP())
            return false;
        switch (arg.kind()) {
        case Arg::Imm:
            if (is32Bit())
                break;
            return false;
        case Arg::Imm64:
            if (is64Bit())
                break;
            return false;
        case Arg::Tmp:
        case Arg::Addr:
        case Arg::Stack:
        case Arg::CallArg:
            break;
        default:
            return false;
        }
    }

    // Return args need to be exact.
    if (inst.args[returnGPArgOffset + 0] != Tmp(GPRInfo::returnValueGPR))
        return false;
    if (inst.args[returnGPArgOffset + 1] != Tmp(GPRInfo::returnValueGPR2))
        return false;
    if (inst.args[returnFPArgOffset + 0] != Tmp(FPRInfo::returnValueFPR))
        return false;

    for (unsigned i = argArgOffset; i < inst.args.size(); ++i) {
        if (!inst.args[i].isReg())
            return false;

        if (inst.args[i] == Tmp(scratchRegister))
            return false;
    }
    return true;
}
Beispiel #2
0
bool GCF::Message::encodeVariant(QDataStream& ds, const QVariant& value)
{
    QString typeName;

    if( value.isValid() )
    {
        typeName = QString(value.typeName());
        if( typeName.isEmpty() )
            return false;
    }
    else
        typeName = "Invalid";

    if( value.type() >= QVariant::UserType )
        return false;

    // Prepare the typename in-case of bool, char, int, double
    switch(value.type())
    {
    case QVariant::Int:
        typeName = is32Bit() ? "qint32" : "qint64";
        break;
    case QVariant::Char:
        typeName = "quint8";
        break;
    case QVariant::UInt:
        typeName = is32Bit() ? "quint32" : "quint64";
        break;
    default:
        break;
    }

    // Serialize value on to the byte array
    switch( value.type() )
    {
    case QVariant::Invalid:
        ds << typeName;
        ds << qint32(0);
        break;
    case QVariant::Bool:
        ds << typeName;
        ds << value.toBool();
        break;
    case QVariant::Char:
        ds << typeName;
        ds << value.toChar();
        break;
    case QVariant::Color:
        ds << typeName;
        ds << value.value<QColor>();
        break;
    case QVariant::Date:
        ds << typeName;
        ds << value.toDate();
        break;
    case QVariant::DateTime:
        ds << typeName;
        ds << value.toDateTime();
        break;
    case QVariant::Double:
        ds << typeName;
        ds << value.toDouble();
        break;
    case QVariant::Int:
        ds << typeName;
        if( is32Bit() )
            ds << (qint32)value.toInt();
        else
            ds << (qint64)value.toInt();
        break;
    case QVariant::Time:
        ds << typeName;
        ds << value.toTime();
        break;
    case QVariant::UInt:
        ds << typeName;
        if( is32Bit() )
            ds << (quint32)value.toUInt();
        else
            ds << (quint64)value.toUInt();
        break;
    case QVariant::String:
        ds << typeName;
        ds << value.toString();
        break;
    case QVariant::Pixmap:
        ds << typeName;
        ds << value.value<QPixmap>();
        break;
    case QVariant::ByteArray:
        ds << typeName;
        ds << value.toByteArray();
        break;
    case QVariant::BitArray:
        ds << typeName;
        ds << value.toBitArray();
        break;
    case QVariant::Image:
        ds << typeName;
        ds << value.value<QImage>();
        break;
    case QVariant::Url:
        ds << typeName;
        ds << value.toUrl();
        break;
    case QVariant::StringList:
        ds << typeName;
        ds << value.toStringList();
        break;
    case QVariant::SizePolicy:
        ds << typeName;
        ds << value.value<QSizePolicy>();
        break;
    case QVariant::SizeF:
        ds << typeName;
        ds << value.toSizeF();
        break;
    case QVariant::Size:
        ds << typeName;
        ds << value.toSize();
        break;
    case QVariant::RegExp:
        ds << typeName;
        ds << value.toRegExp();
        break;
    case QVariant::RectF:
        ds << typeName;
        ds << value.toRectF();
        break;
    case QVariant::Rect:
        ds << typeName;
        ds << value.toRect();
        break;
    case QVariant::Polygon:
        ds << typeName;
        ds << value.value<QPolygon>();
        break;
    case QVariant::PointF:
        ds << typeName;
        ds << value.toPointF();
        break;
    case QVariant::Point:
        ds << typeName;
        ds << value.toPoint();
        break;
    case QVariant::Matrix:
        ds << typeName;
        ds << value.value<QMatrix>();
        break;
    case QVariant::LineF:
        ds << typeName;
        ds << value.toLineF();
        break;
    case QVariant::Line:
        ds << typeName;
        ds << value.toLine();
        break;
    case QVariant::Brush:
        ds << typeName;
        ds << value.value<QBrush>();
        break;
    case QVariant::Bitmap:
        ds << typeName;
        ds << value.value<QBitmap>();
        break;
    case QVariant::Transform:
        ds << typeName;
        ds << value.value<QTransform>();
        break;
    default:
        // Other types will be supported shortly.
        // TODO: support user defined types.
        return false;
    }

    return true;
}
Beispiel #3
0
	int Instruction::approximateSize() const
	{
		const char *format = syntax->encoding;

		if(!format)
		{
			throw INTERNAL_ERROR;
		}

		int size = 0;

		while(*format)
		{
			switch((format[0] << 8) | format[1])
			{
			case LOCK_PRE:
			case CONST_PRE:
			case REPNE_PRE:
			case REP_PRE:
				size += 1;
				break;
			case OFF_PRE:
				if(!is32Bit())
				{
					size += 1;
				}
				break;
			case ADDR_PRE:
				if(!is32Bit())
				{
					size += 1;
				}
				break;
			case ADD_REG:
				break;
			case EFF_ADDR:
			case MOD_RM_0:
			case MOD_RM_1:
			case MOD_RM_2:
			case MOD_RM_3:
			case MOD_RM_4:
			case MOD_RM_5:
			case MOD_RM_6:
			case MOD_RM_7:
				size += 1;
				break;
			case DWORD_IMM:
			case DWORD_REL:
				size += 4;
				break;
			case WORD_IMM:
				size += 2;
				break;
			case BYTE_IMM:
			case BYTE_REL:
				size += 1;
				break;
			default:
				size += 1;
			}

			format += 2;

			if(*format == ' ')	
			{
				format++;
			}
			else if(*format == '\0')
			{
				break;
			}
			else
			{
				throw INTERNAL_ERROR;
			}
		}

		return size;
	}