Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion annotations/it/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,16 @@
<description>Integration tests for the Chicory annotations</description>

<dependencies>
<!-- Dummy dependencies to force the order -->
<!-- Dummy dependencies to force reactor ordering -->
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>annotations-processor</artifactId>
</dependency>
<!-- Needed for reactor ordering: plugin-only-exports IT uses the compiler plugin -->
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory-compiler-maven-plugin</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasi</artifactId>
Expand All @@ -34,6 +39,7 @@
<configuration>
<ignoredUnusedDeclaredDependencies combine.children="append">
<dependency>com.dylibso.chicory:annotations-processor</dependency>
<dependency>com.dylibso.chicory:chicory-compiler-maven-plugin</dependency>
<dependency>com.dylibso.chicory:wasi</dependency>
</ignoredUnusedDeclaredDependencies>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=test
97 changes: 97 additions & 0 deletions annotations/it/src/it/plugin-only-exports/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>

<modelVersion>4.0.0</modelVersion>
<groupId>com.dylibso.chicory</groupId>

<artifactId>plugin-only-exports-chicory-it</artifactId>
<version>0.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.release>@maven.compiler.release@</maven.compiler.release>
</properties>

<dependencies>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>runtime</artifactId>
<version>@project.version@</version>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm-corpus</artifactId>
<version>@project.version@</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>@junit.version@</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>@junit.version@</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory-compiler-maven-plugin</artifactId>
<version>@project.version@</version>
<executions>
<execution>
<id>compile-all-exports</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<name>chicory.test.AllExportsModule</name>
<wasmFile>src/test/resources/all-exports.wat.wasm</wasmFile>
<moduleInterface>chicory.test.AllExportsWrapper</moduleInterface>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>@maven-compiler-plugin.version@</version>
<configuration>
<release>${maven.compiler.release}</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>@maven-resources-plugin.version@</version>
<executions>
<execution>
<id>copy-resources</id>
<goals>
<goal>copy-resources</goal>
</goals>
<phase>validate</phase>
<configuration>
<outputDirectory>${basedir}/src/test/resources</outputDirectory>
<resources>
<resource>
<directory>@basedir@/../../wasm-corpus/src/main/resources/compiled</directory>
<includes>
<include>all-exports.wat.wasm</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package chicory.test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import com.dylibso.chicory.runtime.Instance;
import com.dylibso.chicory.wasm.types.Value;
import org.junit.jupiter.api.Test;

class PluginOnlyExportsTest {

@Test
public void exportsModuleWithPluginOnly() {
// Use the compiled module generated by the maven plugin
var instance =
Instance.builder(AllExportsModule.load())
.withMachineFactory(AllExportsModule::create)
.build();

// Use the _ModuleExports generated by the plugin via moduleInterface
var exports = new AllExportsWrapper_ModuleExports(instance);

// Assert
assertEquals(exports.glob1().getValue(), exports.get1());
assertEquals(exports.glob2().getValue(), exports.get2());
assertEquals(Value.longToFloat(exports.glob3().getValue()), exports.get3());
assertEquals(Value.longToDouble(exports.glob4().getValue()), exports.get4());
assertEquals(exports.glob1().getValue() + 5, exports.get5(5));
assertEquals(exports.glob2().getValue() + 6, exports.get6(6));
assertEquals(Value.longToFloat(exports.glob3().getValue()) + 7.0f, exports.get7(7.0f));
assertEquals(Value.longToDouble(exports.glob4().getValue()) + 8.0d, exports.get8(8.0d));
assertEquals(46, exports.get9(1, 2L, 3.0f, 4.0d));
var multiReturn = exports.get10(1, 2L, 3.0f, 4.0d);
assertEquals(47, multiReturn[0]);
assertEquals(48, multiReturn[1]);
assertNotNull(exports.mem());
assertNotNull(exports.tab());
}
}
4 changes: 4 additions & 0 deletions annotations/processor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
<groupId>com.dylibso.chicory</groupId>
<artifactId>annotations</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>codegen</artifactId>
</dependency>
<dependency>
<groupId>com.dylibso.chicory</groupId>
<artifactId>wasm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
package com.dylibso.chicory.annotations.processor;

import static com.github.javaparser.printer.configuration.DefaultPrinterConfiguration.ConfigOption.COLUMN_ALIGN_PARAMETERS;

import com.dylibso.chicory.codegen.CodegenUtils;
import com.github.javaparser.printer.DefaultPrettyPrinter;
import com.github.javaparser.printer.configuration.DefaultConfigurationOption;
import com.github.javaparser.printer.configuration.DefaultPrinterConfiguration;
import java.util.Locale;
import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Filer;
import javax.lang.model.SourceVersion;
Expand Down Expand Up @@ -43,30 +39,15 @@ static PackageElement getPackageName(Element element) {
}

static String camelCaseToSnakeCase(String name) {
return name.replaceAll("([a-z])([A-Z]+)", "$1_$2").toLowerCase(Locale.ROOT);
return CodegenUtils.camelCaseToSnakeCase(name);
}

static String snakeCaseToCamelCase(String name, boolean className) {
var sb = new StringBuilder();
var toUppercase = className;
for (int i = 0; i < name.length(); i++) {
var c = name.charAt(i);
if ((c == '_' || c == '-' || !Character.isJavaIdentifierPart(c)) && i != 0) {
toUppercase = true;
} else if (toUppercase) {
sb.append(Character.toUpperCase(c));
toUppercase = false;
} else {
sb.append(c);
}
}
return sb.toString();
return CodegenUtils.snakeCaseToCamelCase(name, className);
}

static DefaultPrettyPrinter printer() {
return new DefaultPrettyPrinter(
new DefaultPrinterConfiguration()
.addOption(new DefaultConfigurationOption(COLUMN_ALIGN_PARAMETERS, true)));
return CodegenUtils.printer();
}

static final class AbortProcessingException extends RuntimeException {}
Expand Down
Loading