Search in sources :

Example 1 with OpenCLFunction

use of de.mirkosertic.bytecoder.api.opencl.OpenCLFunction 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());
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BytecodeAnnotation(de.mirkosertic.bytecoder.core.BytecodeAnnotation) BytecodeResolvedMethods(de.mirkosertic.bytecoder.core.BytecodeResolvedMethods) BytecodeMethodSignature(de.mirkosertic.bytecoder.core.BytecodeMethodSignature) BytecodeMethod(de.mirkosertic.bytecoder.core.BytecodeMethod) DoubleValue(de.mirkosertic.bytecoder.ssa.DoubleValue) Value(de.mirkosertic.bytecoder.ssa.Value) IntegerValue(de.mirkosertic.bytecoder.ssa.IntegerValue) LongValue(de.mirkosertic.bytecoder.ssa.LongValue) FloatValue(de.mirkosertic.bytecoder.ssa.FloatValue) OpenCLFunction(de.mirkosertic.bytecoder.api.opencl.OpenCLFunction) BytecodeLinkedClass(de.mirkosertic.bytecoder.core.BytecodeLinkedClass)

Aggregations

OpenCLFunction (de.mirkosertic.bytecoder.api.opencl.OpenCLFunction)1 BytecodeAnnotation (de.mirkosertic.bytecoder.core.BytecodeAnnotation)1 BytecodeLinkedClass (de.mirkosertic.bytecoder.core.BytecodeLinkedClass)1 BytecodeMethod (de.mirkosertic.bytecoder.core.BytecodeMethod)1 BytecodeMethodSignature (de.mirkosertic.bytecoder.core.BytecodeMethodSignature)1 BytecodeResolvedMethods (de.mirkosertic.bytecoder.core.BytecodeResolvedMethods)1 DoubleValue (de.mirkosertic.bytecoder.ssa.DoubleValue)1 FloatValue (de.mirkosertic.bytecoder.ssa.FloatValue)1 IntegerValue (de.mirkosertic.bytecoder.ssa.IntegerValue)1 LongValue (de.mirkosertic.bytecoder.ssa.LongValue)1 Value (de.mirkosertic.bytecoder.ssa.Value)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1