use of com.oracle.svm.hosted.c.info.SizableInfo in project graal by oracle.
the class CInterfaceInvocationPlugin method replaceAccessor.
private boolean replaceAccessor(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, AccessorInfo accessorInfo, int displacement) {
StructuredGraph graph = b.getGraph();
SizableInfo sizableInfo = (SizableInfo) accessorInfo.getParent();
int elementSize = sizableInfo.getSizeInfo().getProperty();
boolean isUnsigned = sizableInfo.isUnsigned();
assert args.length == accessorInfo.parameterCount(true);
ValueNode base = args[accessorInfo.baseParameterNumber(true)];
switch(accessorInfo.getAccessorKind()) {
case ADDRESS:
{
ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
b.addPush(pushKind(method), address);
return true;
}
case GETTER:
{
JavaKind resultKind = wordTypes.asKind(b.getInvokeReturnType());
JavaKind readKind = kindFromSize(elementSize, resultKind);
if (readKind == JavaKind.Object) {
assert resultKind == JavaKind.Object;
} else if (readKind.getBitCount() > resultKind.getBitCount() && !readKind.isNumericFloat() && resultKind != JavaKind.Boolean) {
readKind = resultKind;
}
ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
Stamp stamp;
if (readKind == JavaKind.Object) {
stamp = b.getInvokeReturnStamp(null).getTrustedStamp();
} else if (readKind == JavaKind.Float || readKind == JavaKind.Double) {
stamp = StampFactory.forKind(readKind);
} else {
stamp = StampFactory.forInteger(readKind.getBitCount());
}
ValueNode read = readOp(b, address, locationIdentity, stamp, accessorInfo);
ValueNode adapted = adaptPrimitiveType(graph, read, readKind, resultKind == JavaKind.Boolean ? resultKind : resultKind.getStackKind(), isUnsigned);
b.push(pushKind(method), adapted);
return true;
}
case SETTER:
{
ValueNode value = args[accessorInfo.valueParameterNumber(true)];
JavaKind valueKind = value.getStackKind();
JavaKind writeKind = kindFromSize(elementSize, valueKind);
ValueNode address = makeAddress(graph, args, accessorInfo, base, displacement, elementSize);
LocationIdentity locationIdentity = makeLocationIdentity(b, method, args, accessorInfo);
ValueNode adaptedValue = adaptPrimitiveType(graph, value, valueKind, writeKind, isUnsigned);
writeOp(b, address, locationIdentity, adaptedValue, accessorInfo);
return true;
}
default:
throw shouldNotReachHere();
}
}
use of com.oracle.svm.hosted.c.info.SizableInfo 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