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();
}
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;
}
}
}
Aggregations