Search in sources :

Example 1 with StructBitfieldInfo

use of com.oracle.svm.hosted.c.info.StructBitfieldInfo in project graal by oracle.

the class RawStructureLayoutPlanner method planLayout.

/**
 * Compute the offsets of each field.
 */
private void planLayout(RawStructureInfo info) {
    /* Inherit from the parent type. */
    int currentOffset = info.getParentInfo() != null ? info.getParentInfo().getSizeInfo().getProperty() : 0;
    List<StructFieldInfo> fields = new ArrayList<>();
    for (ElementInfo child : info.getChildren()) {
        if (child instanceof StructFieldInfo) {
            fields.add((StructFieldInfo) child);
        } else if (child instanceof StructBitfieldInfo) {
            throw UserError.abort("StructBitfield is currently not supported by RawStructures!");
        }
    }
    /*
         * Sort fields in field size descending order. Note that prior to this, the fields are
         * already sorted in alphabetical order.
         */
    fields.sort((f1, f2) -> f2.getSizeInfo().getProperty() - f1.getSizeInfo().getProperty());
    for (StructFieldInfo finfo : fields) {
        assert findParentFieldInfo(finfo, info.getParentInfo()) == null;
        int fieldSize = finfo.getSizeInfo().getProperty();
        currentOffset = alignOffset(currentOffset, fieldSize);
        assert currentOffset % fieldSize == 0;
        finfo.getOffsetInfo().setProperty(currentOffset);
        currentOffset += fieldSize;
    }
    info.getSizeInfo().setProperty(currentOffset);
    info.setPlanned();
}
Also used : ElementInfo(com.oracle.svm.hosted.c.info.ElementInfo) StructFieldInfo(com.oracle.svm.hosted.c.info.StructFieldInfo) ArrayList(java.util.ArrayList) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo)

Example 2 with StructBitfieldInfo

use of com.oracle.svm.hosted.c.info.StructBitfieldInfo in project graal by oracle.

the class SizeAndSignednessVerifier method visitAccessorInfo.

@Override
protected void visitAccessorInfo(AccessorInfo accessorInfo) {
    ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
    ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
    if (accessorInfo.getParent() instanceof StructBitfieldInfo) {
        StructBitfieldInfo bitfieldInfo = (StructBitfieldInfo) accessorInfo.getParent();
        switch(accessorInfo.getAccessorKind()) {
            case GETTER:
            case SETTER:
                checkSignedness(bitfieldInfo.isUnsigned(), returnType, method);
                break;
            default:
                assert false;
        }
    } else {
        SizableInfo sizableInfo = (SizableInfo) accessorInfo.getParent();
        switch(accessorInfo.getAccessorKind()) {
            case ADDRESS:
                assert nativeLibs.isPointerBase(returnType);
                break;
            case OFFSET:
                assert returnType.getJavaKind().isNumericInteger() || nativeLibs.isUnsigned(returnType);
                break;
            case GETTER:
                checkSizeAndSignedness(sizableInfo, returnType, method, true);
                break;
            case SETTER:
                assert returnType.getJavaKind() == JavaKind.Void;
                ResolvedJavaType valueType = (ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.valueParameterNumber(false), method.getDeclaringClass());
                checkSizeAndSignedness(sizableInfo, valueType, method, false);
                break;
        }
    }
}
Also used : SizableInfo(com.oracle.svm.hosted.c.info.SizableInfo) StructBitfieldInfo(com.oracle.svm.hosted.c.info.StructBitfieldInfo) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

StructBitfieldInfo (com.oracle.svm.hosted.c.info.StructBitfieldInfo)2 ElementInfo (com.oracle.svm.hosted.c.info.ElementInfo)1 SizableInfo (com.oracle.svm.hosted.c.info.SizableInfo)1 StructFieldInfo (com.oracle.svm.hosted.c.info.StructFieldInfo)1 ArrayList (java.util.ArrayList)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1