use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.
the class OpenCLWriter method printInvokeStatic.
private void printInvokeStatic(InvokeStaticMethodExpression aValue) {
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aValue.getClassName());
BytecodeResolvedMethods theMethods = theLinkedClass.resolvedMethods();
AtomicBoolean theFound = new AtomicBoolean(false);
theMethods.stream().forEach(aMethodMapsEntry -> {
BytecodeMethod theMethod = aMethodMapsEntry.getValue();
if (Objects.equals(theMethod.getName().stringValue(), aValue.getMethodName()) && theMethod.getSignature().metchesExactlyTo(aValue.getSignature())) {
BytecodeAnnotation theAnnotation = theMethod.getAttributes().getAnnotationByType(OpenCLFunction.class.getName());
if (theAnnotation == null) {
throw new IllegalArgumentException("Annotation @OpenCLFunction required for static method " + aValue.getMethodName());
}
String theMethodName = theAnnotation.getElementValueByName("value").stringValue();
BytecodeMethodSignature theSignature = aValue.getSignature();
print(theMethodName);
print("(");
List<Value> theArguments = aValue.incomingDataFlows();
for (int i = 0; i < theArguments.size(); i++) {
if (i > 0) {
print(",");
}
if (!theSignature.getArguments()[i].isPrimitive()) {
print("*");
}
printValue(theArguments.get(i));
}
print(")");
theFound.set(true);
}
});
if (!theFound.get()) {
throw new IllegalArgumentException("Not supported method : " + aValue.getMethodName());
}
}
use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.
the class OpenCLWriter method printGetFieldValue.
private void printGetFieldValue(GetFieldExpression aValue) {
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
if (theLinkedClass == kernelClass) {
print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
} else {
Value theValue = aValue.incomingDataFlows().get(0);
if (theValue instanceof Variable && ((Variable) theValue).isSynthetic()) {
print(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
} else {
printValue(theValue);
printInstanceFieldReference(aValue.getField());
}
}
}
use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeInstanceOfValue.
private void writeInstanceOfValue(InstanceOfExpression aValue) {
BytecodeLinkedClass theClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getType().getConstant()));
print("(call $INSTANCEOF_CHECK ");
writeValue(aValue.incomingDataFlows().get(0));
print(" (i32.const ");
print(theClass.getUniqueId());
println("))");
}
use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeGetStaticValue.
private void writeGetStaticValue(GetStaticExpression aValue) {
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
WASMMemoryLayouter.MemoryLayout theLayout = memoryLayouter.layoutFor(BytecodeObjectTypeRef.fromUtf8Constant(aValue.getField().getClassIndex().getClassConstant().getConstant()));
int theMemoryOffset = theLayout.offsetForClassMember(aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue());
String theFieldName = aValue.getField().getNameAndTypeIndex().getNameAndType().getNameIndex().getName().stringValue();
BytecodeResolvedFields theStaticFields = theLinkedClass.resolvedFields();
BytecodeResolvedFields.FieldEntry theField = theStaticFields.fieldByName(theFieldName);
if (!theField.getValue().getAccessFlags().isStatic()) {
throw new IllegalStateException("Field " + theFieldName + " is not static!");
}
String theClassName = WASMWriterUtils.toClassName(aValue.getField().getClassIndex().getClassConstant());
switch(TypeRef.toType(theField.getValue().getTypeRef()).resolve()) {
case DOUBLE:
case FLOAT:
{
print("(f32.load offset=");
break;
}
default:
{
print("(i32.load offset=");
break;
}
}
print(theMemoryOffset);
println();
WASMSSAWriter theChild = withDeeperIndent();
theChild.print("(get_global $");
theChild.print(theClassName);
theChild.println("__runtimeClass)");
println(")");
}
use of de.mirkosertic.bytecoder.core.BytecodeLinkedClass in project Bytecoder by mirkosertic.
the class WASMSSAWriter method writeClassReferenceValue.
private void writeClassReferenceValue(ClassReferenceValue aValue) {
print("(get_global $");
BytecodeLinkedClass theLinkedClass = linkerContext.resolveClass(aValue.getType());
print(WASMWriterUtils.toClassName(theLinkedClass.getClassName()));
print("__runtimeClass)");
}
Aggregations