use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.
the class SizeAndSignednessVerifier method visitEnumValueInfo.
@Override
protected void visitEnumValueInfo(EnumValueInfo valueInfo) {
ResolvedJavaMethod method = (ResolvedJavaMethod) valueInfo.getAnnotatedElement();
ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
EnumInfo enumInfo = (EnumInfo) valueInfo.getParent();
for (ElementInfo info : enumInfo.getChildren()) {
if (info instanceof EnumConstantInfo) {
EnumConstantInfo constantInfo = (EnumConstantInfo) info;
checkSizeAndSignedness(constantInfo, returnType, method, true);
}
}
}
use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.
the class CEntryPointCallStubMethod method adaptParameterTypes.
private EnumInfo[] adaptParameterTypes(HostedProviders providers, NativeLibraries nativeLibraries, HostedGraphKit kit, JavaType[] parameterTypes, JavaType[] parameterLoadTypes, Purpose purpose) {
EnumInfo[] parameterEnumInfos = null;
for (int i = 0; i < parameterTypes.length; i++) {
if (!parameterTypes[i].getJavaKind().isPrimitive() && !providers.getWordTypes().isWord(parameterTypes[i])) {
ElementInfo typeInfo = nativeLibraries.findElementInfo(parameterTypes[i]);
if (typeInfo instanceof EnumInfo) {
UserError.guarantee(typeInfo.getChildren().stream().anyMatch(EnumLookupInfo.class::isInstance), "Enum class " + parameterTypes[i].toJavaName() + " needs a method that is annotated with @" + CEnumLookup.class + " because it is used as a parameter of an entry point method: " + targetMethod.format("%H.%n(%p)"));
if (parameterEnumInfos == null) {
parameterEnumInfos = new EnumInfo[parameterTypes.length];
}
parameterEnumInfos[i] = (EnumInfo) typeInfo;
parameterLoadTypes[i] = providers.getMetaAccess().lookupJavaType(cEnumParameterKind.toJavaClass());
final int parameterIndex = i;
FrameState initialState = kit.getGraph().start().stateAfter();
Iterator<ValueNode> matchingNodes = initialState.values().filter(node -> ((ParameterNode) node).index() == parameterIndex).iterator();
ValueNode parameterNode = matchingNodes.next();
assert !matchingNodes.hasNext() && parameterNode.usages().filter(n -> n != initialState).isEmpty();
parameterNode.setStamp(StampFactory.forKind(cEnumParameterKind));
} else if (purpose != Purpose.ANALYSIS) {
// for analysis test cases: abort only during compilation
throw UserError.abort("Entry point method parameter types are restricted to primitive types, word types and enumerations (@" + CEnum.class.getSimpleName() + "): " + targetMethod.format("%H.%n(%p)"));
}
}
}
return parameterEnumInfos;
}
use of com.oracle.svm.hosted.c.info.ElementInfo in project graal by oracle.
the class NativeLibraries method findElementInfo.
public ElementInfo findElementInfo(Object e) {
Object element = unwrap(e);
ElementInfo result = elementToInfo.get(element);
if (result == null && element instanceof ResolvedJavaType && ((ResolvedJavaType) element).getInterfaces().length == 1) {
result = findElementInfo(((ResolvedJavaType) element).getInterfaces()[0]);
}
return result;
}
use of com.oracle.svm.hosted.c.info.ElementInfo 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.ElementInfo in project graal by oracle.
the class JNIJavaCallWrapperMethod method getJNIValueOffsetOf.
private StructFieldInfo getJNIValueOffsetOf(ResolvedJavaType jniValueType, JavaKind kind) {
String name = String.valueOf(kind.isObject() ? 'l' : Character.toLowerCase(kind.getTypeChar()));
StructInfo structInfo = (StructInfo) nativeLibs.findElementInfo(jniValueType);
for (ElementInfo elementInfo : structInfo.getChildren()) {
if (elementInfo instanceof StructFieldInfo) {
StructFieldInfo fieldInfo = (StructFieldInfo) elementInfo;
if (name.equals(fieldInfo.getName())) {
return fieldInfo;
}
}
}
throw VMError.shouldNotReachHere();
}
Aggregations