|
| 1 | +// Generated by jextract |
| 2 | + |
| 3 | +package myscalalib_bindings; |
| 4 | + |
| 5 | +import java.lang.invoke.*; |
| 6 | +import java.lang.foreign.*; |
| 7 | +import java.nio.ByteOrder; |
| 8 | +import java.util.*; |
| 9 | +import java.util.function.*; |
| 10 | +import java.util.stream.*; |
| 11 | + |
| 12 | +import static java.lang.foreign.ValueLayout.*; |
| 13 | +import static java.lang.foreign.MemoryLayout.PathElement.*; |
| 14 | + |
| 15 | +public class interface_h { |
| 16 | + |
| 17 | + interface_h() { |
| 18 | + // Should not be called directly |
| 19 | + } |
| 20 | + |
| 21 | + static final Arena LIBRARY_ARENA = Arena.ofAuto(); |
| 22 | + static final boolean TRACE_DOWNCALLS = Boolean.getBoolean("jextract.trace.downcalls"); |
| 23 | + |
| 24 | + static void traceDowncall(String name, Object... args) { |
| 25 | + String traceArgs = Arrays.stream(args) |
| 26 | + .map(Object::toString) |
| 27 | + .collect(Collectors.joining(", ")); |
| 28 | + System.out.printf("%s(%s)\n", name, traceArgs); |
| 29 | + } |
| 30 | + |
| 31 | + static MemorySegment findOrThrow(String symbol) { |
| 32 | + return SYMBOL_LOOKUP.find(symbol) |
| 33 | + .orElseThrow(() -> new UnsatisfiedLinkError("unresolved symbol: " + symbol)); |
| 34 | + } |
| 35 | + |
| 36 | + static MethodHandle upcallHandle(Class<?> fi, String name, FunctionDescriptor fdesc) { |
| 37 | + try { |
| 38 | + return MethodHandles.lookup().findVirtual(fi, name, fdesc.toMethodType()); |
| 39 | + } catch (ReflectiveOperationException ex) { |
| 40 | + throw new AssertionError(ex); |
| 41 | + } |
| 42 | + } |
| 43 | + |
| 44 | + static MemoryLayout align(MemoryLayout layout, long align) { |
| 45 | + return switch (layout) { |
| 46 | + case PaddingLayout p -> p; |
| 47 | + case ValueLayout v -> v.withByteAlignment(align); |
| 48 | + case GroupLayout g -> { |
| 49 | + MemoryLayout[] alignedMembers = g.memberLayouts().stream() |
| 50 | + .map(m -> align(m, align)).toArray(MemoryLayout[]::new); |
| 51 | + yield g instanceof StructLayout ? |
| 52 | + MemoryLayout.structLayout(alignedMembers) : MemoryLayout.unionLayout(alignedMembers); |
| 53 | + } |
| 54 | + case SequenceLayout s -> MemoryLayout.sequenceLayout(s.elementCount(), align(s.elementLayout(), align)); |
| 55 | + }; |
| 56 | + } |
| 57 | + |
| 58 | + static final SymbolLookup SYMBOL_LOOKUP = SymbolLookup.loaderLookup() |
| 59 | + .or(Linker.nativeLinker().defaultLookup()); |
| 60 | + |
| 61 | + public static final ValueLayout.OfBoolean C_BOOL = ValueLayout.JAVA_BOOLEAN; |
| 62 | + public static final ValueLayout.OfByte C_CHAR = ValueLayout.JAVA_BYTE; |
| 63 | + public static final ValueLayout.OfShort C_SHORT = ValueLayout.JAVA_SHORT; |
| 64 | + public static final ValueLayout.OfInt C_INT = ValueLayout.JAVA_INT; |
| 65 | + public static final ValueLayout.OfLong C_LONG_LONG = ValueLayout.JAVA_LONG; |
| 66 | + public static final ValueLayout.OfFloat C_FLOAT = ValueLayout.JAVA_FLOAT; |
| 67 | + public static final ValueLayout.OfDouble C_DOUBLE = ValueLayout.JAVA_DOUBLE; |
| 68 | + public static final AddressLayout C_POINTER = ValueLayout.ADDRESS |
| 69 | + .withTargetLayout(MemoryLayout.sequenceLayout(java.lang.Long.MAX_VALUE, JAVA_BYTE)); |
| 70 | + public static final ValueLayout.OfLong C_LONG = ValueLayout.JAVA_LONG; |
| 71 | + private static final int MULTIPLY = (int)1L; |
| 72 | + /** |
| 73 | + * {@snippet lang=c : |
| 74 | + * enum <anonymous>.MULTIPLY = 1 |
| 75 | + * } |
| 76 | + */ |
| 77 | + public static int MULTIPLY() { |
| 78 | + return MULTIPLY; |
| 79 | + } |
| 80 | + private static final int ADD = (int)2L; |
| 81 | + /** |
| 82 | + * {@snippet lang=c : |
| 83 | + * enum <anonymous>.ADD = 2 |
| 84 | + * } |
| 85 | + */ |
| 86 | + public static int ADD() { |
| 87 | + return ADD; |
| 88 | + } |
| 89 | + |
| 90 | + private static class myscalalib_run { |
| 91 | + public static final FunctionDescriptor DESC = FunctionDescriptor.of( |
| 92 | + interface_h.C_FLOAT, |
| 93 | + interface_h.C_POINTER, |
| 94 | + interface_h.C_FLOAT, |
| 95 | + interface_h.C_FLOAT |
| 96 | + ); |
| 97 | + |
| 98 | + public static final MemorySegment ADDR = interface_h.findOrThrow("myscalalib_run"); |
| 99 | + |
| 100 | + public static final MethodHandle HANDLE = Linker.nativeLinker().downcallHandle(ADDR, DESC); |
| 101 | + } |
| 102 | + |
| 103 | + /** |
| 104 | + * Function descriptor for: |
| 105 | + * {@snippet lang=c : |
| 106 | + * extern float myscalalib_run(myscalalib_config *config, float left, float right) |
| 107 | + * } |
| 108 | + */ |
| 109 | + public static FunctionDescriptor myscalalib_run$descriptor() { |
| 110 | + return myscalalib_run.DESC; |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * Downcall method handle for: |
| 115 | + * {@snippet lang=c : |
| 116 | + * extern float myscalalib_run(myscalalib_config *config, float left, float right) |
| 117 | + * } |
| 118 | + */ |
| 119 | + public static MethodHandle myscalalib_run$handle() { |
| 120 | + return myscalalib_run.HANDLE; |
| 121 | + } |
| 122 | + |
| 123 | + /** |
| 124 | + * Address for: |
| 125 | + * {@snippet lang=c : |
| 126 | + * extern float myscalalib_run(myscalalib_config *config, float left, float right) |
| 127 | + * } |
| 128 | + */ |
| 129 | + public static MemorySegment myscalalib_run$address() { |
| 130 | + return myscalalib_run.ADDR; |
| 131 | + } |
| 132 | + |
| 133 | + /** |
| 134 | + * {@snippet lang=c : |
| 135 | + * extern float myscalalib_run(myscalalib_config *config, float left, float right) |
| 136 | + * } |
| 137 | + */ |
| 138 | + public static float myscalalib_run(MemorySegment config, float left, float right) { |
| 139 | + var mh$ = myscalalib_run.HANDLE; |
| 140 | + try { |
| 141 | + if (TRACE_DOWNCALLS) { |
| 142 | + traceDowncall("myscalalib_run", config, left, right); |
| 143 | + } |
| 144 | + return (float)mh$.invokeExact(config, left, right); |
| 145 | + } catch (Throwable ex$) { |
| 146 | + throw new AssertionError("should not reach here", ex$); |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | + |
0 commit comments