aboutsummaryrefslogtreecommitdiff
path: root/bindings/java/src/c
diff options
context:
space:
mode:
Diffstat (limited to 'bindings/java/src/c')
-rw-r--r--bindings/java/src/c/Makefile.am39
-rw-r--r--bindings/java/src/c/com_galois_ppaml_tracer_Phase.c97
-rw-r--r--bindings/java/src/c/com_galois_ppaml_tracer_Tracer.c76
-rw-r--r--bindings/java/src/c/configure.ac58
-rw-r--r--bindings/java/src/c/pointer.h38
5 files changed, 308 insertions, 0 deletions
diff --git a/bindings/java/src/c/Makefile.am b/bindings/java/src/c/Makefile.am
new file mode 100644
index 0000000..c30a4cf
--- /dev/null
+++ b/bindings/java/src/c/Makefile.am
@@ -0,0 +1,39 @@
+# Makefile.am -- automake script for ppamltracer-java (JNI wrapper)
+# Copyright (C) 2013, 2014 Galois, Inc.
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# To contact Galois, complete the Web form at <http://corp.galois.com/contact/>
+# or write to Galois, Inc., 421 Southwest 6th Avenue, Suite 300, Portland,
+# Oregon, 97204-1622.
+
+ACLOCAL_AMFLAGS = -I m4
+
+lib_LTLIBRARIES = libppamltracer_java.la
+libppamltracer_java_la_SOURCES = \
+ $(srcdir)/com_galois_ppaml_tracer_Phase.c \
+ $(srcdir)/com_galois_ppaml_tracer_Phase.h \
+ $(srcdir)/com_galois_ppaml_tracer_Tracer.c \
+ $(srcdir)/com_galois_ppaml_tracer_Tracer.h \
+ $(srcdir)/pointer.h
+libppamltracer_java_la_CFLAGS = \
+ -std=c99 \
+ -Wall \
+ -Wextra \
+ -Wno-unused-parameter \
+ -pedantic \
+ -I@JAVA_HOME@/include
+libppamltracer_java_la_LDFLAGS = \
+ $(AM_LDFLAGS) \
+ -export-symbols-regex '^Java_'
diff --git a/bindings/java/src/c/com_galois_ppaml_tracer_Phase.c b/bindings/java/src/c/com_galois_ppaml_tracer_Phase.c
new file mode 100644
index 0000000..76f346b
--- /dev/null
+++ b/bindings/java/src/c/com_galois_ppaml_tracer_Phase.c
@@ -0,0 +1,97 @@
+/* com_galois_ppaml_tracer_Phase.c -- JNI wrapper for com.galois.ppaml.tracer.Phase
+ * Copyright (C) 2014 Galois, Inc.
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * To contact Galois, complete the Web form at
+ * <http://corp.galois.com/contact/> or write to Galois, Inc., 421 Southwest
+ * 6th Avenue, Suite 300, Portland, Oregon, 97204-1622. */
+
+#include <stdlib.h>
+
+#include <ppaml/tracer.h>
+
+#include <jni.h>
+#include <com_galois_ppaml_tracer_Phase.h>
+
+#include "pointer.h"
+
+JNIEXPORT
+jlong JNICALL Java_com_galois_ppaml_tracer_Phase_mallocPhase(
+ JNIEnv *const env,
+ jclass Phase)
+{
+ return jlong_of_pointer(malloc(sizeof(ppaml_phase_t)));
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Phase_ppaml_1phase_1init(
+ JNIEnv *const env,
+ jclass Phase,
+ jlong tracer,
+ jlong phase,
+ jstring name)
+{
+ jint r;
+ // Allocate memory.
+ const char *const cName = (*env)->GetStringUTFChars(env, name, NULL);
+ if (cName == NULL) {
+ r = -1;
+ goto done;
+ }
+ // Perform the operation.
+ r = ppaml_phase_init(
+ pointer_of_jlong(tracer),
+ pointer_of_jlong(phase),
+ cName);
+ // Clean up.
+done: (*env)->ReleaseStringUTFChars(env, name, cName);
+ return r;
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Phase_ppaml_1phase_1done(
+ JNIEnv *const env,
+ jclass Phase,
+ jlong phase)
+{
+ return ppaml_phase_done(pointer_of_jlong(phase));
+}
+
+JNIEXPORT
+void JNICALL Java_com_galois_ppaml_tracer_Phase_freePhase(
+ JNIEnv *const env,
+ jclass Phase,
+ jlong phase)
+{
+ free(pointer_of_jlong(phase));
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Phase_ppaml_1phase_1start(
+ JNIEnv *const env,
+ jclass Phase,
+ jlong phase)
+{
+ return ppaml_phase_start(pointer_of_jlong(phase));
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Phase_ppaml_1phase_1stop(
+ JNIEnv *const env,
+ jclass Phase,
+ jlong phase)
+{
+ return ppaml_phase_stop(pointer_of_jlong(phase));
+}
diff --git a/bindings/java/src/c/com_galois_ppaml_tracer_Tracer.c b/bindings/java/src/c/com_galois_ppaml_tracer_Tracer.c
new file mode 100644
index 0000000..2c23966
--- /dev/null
+++ b/bindings/java/src/c/com_galois_ppaml_tracer_Tracer.c
@@ -0,0 +1,76 @@
+/* com_galois_ppaml_tracer_Tracer.c -- JNI wrapper for com.galois.ppaml.tracer.Tracer
+ * Copyright (C) 2014 Galois, Inc.
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * To contact Galois, complete the Web form at
+ * <http://corp.galois.com/contact/> or write to Galois, Inc., 421 Southwest
+ * 6th Avenue, Suite 300, Portland, Oregon, 97204-1622. */
+
+#include <stdlib.h>
+
+#include <ppaml/tracer.h>
+
+#include <jni.h>
+#include <com_galois_ppaml_tracer_Tracer.h>
+
+#include "pointer.h"
+
+JNIEXPORT
+jlong JNICALL Java_com_galois_ppaml_tracer_Tracer_mallocTracer(
+ JNIEnv *const env,
+ jclass Tracer)
+{
+ return jlong_of_pointer(malloc(sizeof(ppaml_tracer_t)));
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Tracer_ppaml_1tracer_1init(
+ JNIEnv *const env,
+ jclass Tracer,
+ jlong tracer,
+ jstring reportNameBase)
+{
+ jint r;
+ // Allocate memory.
+ const char *const cReportNameBase =
+ (*env)->GetStringUTFChars(env, reportNameBase, NULL);
+ if (cReportNameBase == NULL) {
+ r = -1;
+ goto done;
+ }
+ // Perform the operation.
+ r = ppaml_tracer_init(pointer_of_jlong(tracer), cReportNameBase);
+ // Clean up.
+done: (*env)->ReleaseStringUTFChars(env, reportNameBase, cReportNameBase);
+ return r;
+}
+
+JNIEXPORT
+jint JNICALL Java_com_galois_ppaml_tracer_Tracer_ppaml_1tracer_1done(
+ JNIEnv *const env,
+ jclass Tracer,
+ jlong tracer)
+{
+ return ppaml_tracer_done(pointer_of_jlong(tracer));
+}
+
+JNIEXPORT
+void JNICALL Java_com_galois_ppaml_tracer_Tracer_freeTracer(
+ JNIEnv *const env,
+ jclass Tracer,
+ jlong tracer)
+{
+ free(pointer_of_jlong(tracer));
+}
diff --git a/bindings/java/src/c/configure.ac b/bindings/java/src/c/configure.ac
new file mode 100644
index 0000000..0d1556b
--- /dev/null
+++ b/bindings/java/src/c/configure.ac
@@ -0,0 +1,58 @@
+# configure.ac -- autoconf script for ppamltracer-java (JNI wrapper)
+# Copyright (C) 2013, 2014 Galois, Inc.
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free Software
+# Foundation, either version 3 of the License, or (at your option) any later
+# version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+# details.
+#
+# You should have received a copy of the GNU General Public License along with
+# this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# To contact Galois, complete the Web form at <http://corp.galois.com/contact/>
+# or write to Galois, Inc., 421 Southwest 6th Avenue, Suite 300, Portland,
+# Oregon, 97204-1622.
+
+# Fire up Autoconf.
+AC_PREREQ([2.69])
+AC_INIT([ppamltracer-java], [0.1.0], [bbarenblat@galois.com])
+
+# Fire up Automake.
+AM_INIT_AUTOMAKE([-Wall -Wno-gnu -Werror foreign no-dist-gzip dist-bzip2])
+AC_CONFIG_MACRO_DIR([m4])
+
+# Build quietly.
+m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
+
+# Build a C library.
+AC_PROG_CC
+AC_PROG_CC_C99
+# Automake 1.12 seems to require this, but automake 1.11 doesn't recognize it.
+m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
+LT_INIT
+
+# JNI
+AC_ARG_VAR([JAVA_HOME], [path to JDK installation])
+if test -z "$JAVA_HOME"; then
+ AC_MSG_ERROR([empty JAVA_HOME environment variable; please set it to the path to your JDK installation])
+fi
+AC_SUBST([JAVA_HOME])
+
+# ppamltracer
+AC_CHECK_HEADER([ppaml/tracer.h],
+ [],
+ [AC_MSG_ERROR([ppamltracer development headers are required (are they in C_INCLUDE_PATH?)])])
+AC_CHECK_LIB([ppamltracer], [ppaml_tracer_init],
+ [],
+ [AC_MSG_ERROR([libppamltracer is required (is it in LIBRARY_PATH?)])])
+
+# Generate Makefile.
+AC_CONFIG_FILES([Makefile])
+
+# All done.
+AC_OUTPUT
diff --git a/bindings/java/src/c/pointer.h b/bindings/java/src/c/pointer.h
new file mode 100644
index 0000000..123025d
--- /dev/null
+++ b/bindings/java/src/c/pointer.h
@@ -0,0 +1,38 @@
+/* pointer.h -- pointer <-> jlong casts
+ * Copyright (C) 2014 Galois, Inc.
+ *
+ * This library is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * To contact Galois, complete the Web form at
+ * <http://corp.galois.com/contact/> or write to Galois, Inc., 421 Southwest
+ * 6th Avenue, Suite 300, Portland, Oregon, 97204-1622. */
+
+#ifndef PPAML_TRACER_JAVA_POINTER_H
+#define PPAML_TRACER_JAVA_POINTER_H
+
+#include <stdint.h>
+
+#include <jni.h>
+
+inline void *pointer_of_jlong(const jlong value)
+{
+ return (void *)(intptr_t)value;
+}
+
+inline jlong jlong_of_pointer(void *const pointer)
+{
+ return (jlong)(intptr_t)pointer;
+}
+
+#endif