Skip to content

Commit

Permalink
Register foreign calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Thihup committed May 27, 2024
1 parent 3d9c3fb commit ac0bc3d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 0 deletions.
18 changes: 18 additions & 0 deletions dev.thihup.jvisualg.ide/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<native.maven.plugin.version>0.9.12</native.maven.plugin.version>
<imageName>JVisualG</imageName>
<autoClose>false</autoClose>
<graalvm.version>24.0.1</graalvm.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -51,6 +52,17 @@
<artifactId>rsyntaxtextarea-antlr4-extension</artifactId>
<version>0.0.3</version>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<version>${graalvm.version}</version>
</dependency>
<dependency>
<groupId>org.graalvm.nativeimage</groupId>
<artifactId>svm</artifactId>
<version>${graalvm.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -83,6 +95,7 @@
<buildArgs>
<buildArg>--no-fallback</buildArg>
<buildArg>-H:+ForeignAPISupport</buildArg>
<buildArg>--features=dev.thihup.jvisualg.ide.NativeImageFeature</buildArg>
</buildArgs>
</configuration>
<executions>
Expand All @@ -108,6 +121,11 @@
<argument>${mainClass}</argument>
</arguments>
</configuration>
<executions>
<execution>
<id>java-agent</id>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dev.thihup.jvisualg.ide;

import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.hosted.RuntimeForeignAccess;

import java.lang.foreign.FunctionDescriptor;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.ValueLayout.JAVA_INT;

public class NativeImageFeature implements Feature {

@Override
public void duringSetup(DuringSetupAccess access) {
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(ADDRESS, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_FLOAT, JAVA_FLOAT, JAVA_FLOAT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_FLOAT, ADDRESS, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_FLOAT, JAVA_FLOAT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS));

}
}
1 change: 1 addition & 0 deletions dev.thihup.jvisualg.ide/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
requires org.antlr.antlr4.runtime;
requires rsyntaxtextarea.antlr4.extension;
requires java.desktop;
requires org.graalvm.nativeimage;

exports dev.thihup.jvisualg.ide to org.fife.RSyntaxTextArea;
}

0 comments on commit ac0bc3d

Please sign in to comment.