Commit 95af0a8d authored by Götz Lindenmaier's avatar Götz Lindenmaier
Browse files

Fixed functionality for firm jni.

[r516]
parent 132d4be4
......@@ -15,6 +15,9 @@
/* Define if you have the <gmp.h> header file. */
#undef HAVE_GMP_H
/* Define if you have the <jni.h> header file. */
#undef HAVE_JNI_H
/* Define if you have the <math.h> header file. */
#undef HAVE_MATH_H
......
This diff is collapsed.
......@@ -37,7 +37,6 @@ else
fi])
AC_SUBST(enable_debug_libfirm)
AC_ARG_ENABLE(gcc_inline,
[ --enable-gcc_inline enable gcc inline C-extension],
[if test "$enableval" = yes; then
......@@ -67,6 +66,17 @@ fi],
AC_SUBST(enable_auto_documentation)
dnl set firm jni
dnl ------------
AC_ARG_ENABLE(firmjni,
[ --enable-firmjni check for tools necesarry to construct a java native interface for Firm],
[if test "$enableval"=yes; then
enable_firm_jni=yes
fi],
[enable_firm_jni=no])
AC_SUBST(enable_firm_jni)
dnl Checks for programs.
dnl ====================
......@@ -95,7 +105,7 @@ if test "$TAR" != "tar"; then
AC_MSG_ERROR(need tar for creating archives in distribution)
fi
dnl check wether ar can handle option -s
dnl check whether ar can handle option -s
dnl if not then ranlib is needed
dnl for simpliticity we use ranlib every time
......@@ -114,6 +124,21 @@ if test "$enable_auto_documentation" = yes; then
fi
fi
dnl check for availability of a jdk
dnl -------------------------------
if test "$enable_firm_jni" = yes; then
AC_CHECK_PROG(JAVAC, javac, "javac", "")
if test "$JAVAC" != "javac"; then
AC_MSG_ERROR(need java compiler javac to generate jni (IPD: module add jdk-1.3.1-sun))
fi
AC_CHECK_PROG(JAVAH, javah, "javah", "")
if test "$JAVAH" != "javah"; then
AC_MSG_ERROR(need javah to generate jni headers (IPD: module add jdk-1.3.1-sun))
fi
fi
dnl Checks for header files.
dnl ========================
......@@ -146,6 +171,16 @@ if test "$ac_obstack_headers" != yes; then
fi
dnl check for jni header files
if test "$enable_firm_jni" = yes; then
AC_CHECK_HEADERS(jni.h, ac_jni_headers="yes", ac_jni_headers="no")
if test "$ac_jni_headers" != yes; then
AC_MSG_ERROR(jni header file not found. (IPD: add -I/usr/public2/java/jdk1.3.1-sun/include/ -I/usr/public2/java/jdk1.3.1-sun/include/linux/ to CPPFLAGS))
fi
fi
dnl Checks for libraries.
dnl =====================
......
......@@ -6,10 +6,17 @@ srcdir = @srcdir@
topdir = ..
subdir = firmjni
libdir = @libdir@ # where to find libfirm.a and where to put libfirmjni.so
# The library implementing the JNI methods. This name is also
# known to the generator for the JNI interface and used in the
# static initializer.
LIBNAME = libfirmjni.so
# where to put libfirmjni.so
libdir = @libdir@
# where to put the directory firmjni containing the generated
# .java and .class files
#javadir = @javadir@ @@@ how to specify a dir in configure.in?
.PHONY: default all clean realclean depend
MEMBERS = Firm.m Firm.m Firm_common.m Dbginfo.m Ident.m Tv.m \
......@@ -17,12 +24,28 @@ MEMBERS = Firm.m Firm.m Firm_common.m Dbginfo.m Ident.m Tv.m \
Irprog.m Irgraph.m Irnode.m Irmode.m Irop.m Ircons.m Ircgcons.m \
Irflag.m Irvrfy.m Irdump.m Iropt.m Irgopt.m Ircgopt.m \
Irouts.m Irdom.m Irloop.m Cgana.m \
Irgwalk.m Irgmod.m Typewalk.m Typegmod.m
Irgmod.m Typegmod.m
# How to pass function pointers? Or how to obtain them?
# Irgwalk.m Typewalk.m
OFILES = $(MEMBERS:.m=.o)
HFILES = $(MEMBERS:.m=.h)
CLASSFILES = $(MEMBERS:.m=.class)
CPPFLAGS = -I$(top_srcdir)/ir/ir -I$(top_srcdir)/ir/common \
-I$(top_srcdir)/ir/ident -I$(top_srcdir)/ir/tr \
-I$(top_srcdir)/ir/tv -I$(top_srcdir)/ir/debug \
-I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@
LDFLAGS += $(topdir)
all: classfiles jni
# call the generator to make the implementation files
#impl:
# -sh build_firm_jni
all: jni
classfiles: $(CLASSFILES)
%.class: %.java
javac $<
......@@ -33,12 +56,14 @@ all: jni
%.o: %.c %.h
gcc $(CPPFLAGS) -c $< -o $@
jni: $(HFILES) $(OFILES) $(libdir)libfirm.a
gcc -shared -fPIC -o $(LIBNAME) *.o -L$(libdir) -lfirm
jni: $(HFILES) $(OFILES) # ../libfirm.a
gcc -shared -fPIC -o $(LIBNAME) *.o -lfirm -L..
install:
cp libfirmjni.so $(libdir)
# mkdir $(javadir)
# cp *.java @javadir@
# cp *.class @javadir@
clean:
rm -rf sources *.c *.h *.o
......
......@@ -4,10 +4,6 @@ Call
sh build_firm_jni
to generate a Java native interface for firm.
This script still contains various IPD specific settings,
e.g. oaths to the header files needed for JNI. This will be changed
at some point.
Generating the JNI requires various syntactic properties of the
header files that restrict legal C.
......@@ -16,7 +12,8 @@ from Idents (as idToStr). This will probably cause a segmentation
fault.
Some methods generated might not work yet. Please report this to
goetz@ipd.info.uni-karlsruhe.de
goetz@ipd.info.uni-karlsruhe.de. Do not use methods with function
pointers as arguments.
For now _all_ enumerators are generated into _all_ classes.
This results from deficiencies in the crecoder and will be removed
......
......@@ -15,22 +15,26 @@ srcdir=@srcdir@
topdir=..
subdir=firmjni
###############################################################################
# The directory which shall contain the JNI implementation after installation.
FIRM_JNI_DIR=./
# This is the list of firm headers a JNI interface is generated for
# If you change this list, also change the list in Makefile.in
# If you change this list, also change FRIM_PATH_HEADERS and the list
# in Makefile.in
FIRM_HEADERS="firm.h firm_common.h dbginfo.h ident.h tv.h
type.h entity.h type_or_entity.h tpop.h mangle.h
irprog.h irgraph.h irnode.h irmode.h irop.h ircons.h ircgcons.h
irflag.h irvrfy.h irdump.h iropt.h irgopt.h ircgopt.h
irouts.h irdom.h irloop.h cgana.h
irgwalk.h irgmod.h typewalk.h typegmod.h"
# These directories point to a libfirm installation:
FIRM_INCLUDE_DIR=@includedir@
FIRM_LIB_DIR=@libdir@
irgmod.h typegmod.h"
# How to pass function pointers? Therefore removed.
# irgwalk.h typewalk.h
FIRM_PATH_HEADERS="common/firm.h common/firm_common.h
debug/dbginfo.h ident/ident.h tv/tv.h
tr/type.h tr/entity.h tr/type_or_entity.h tr/tpop.h tr/mangle.h
ir/irprog.h ir/irgraph.h ir/irnode.h ir/irmode.h ir/irop.h
ir/ircons.h ir/ircgcons.h ir/irflag.h ir/irvrfy.h ir/irdump.h
ir/iropt.h ir/irgopt.h ir/ircgopt.h
ana/irouts.h ana/irdom.h ana/irloop.h ana/cgana.h
ir/irgmod.h tr/typegmod.h"
# The directory containing crecoder.jar and, for now,
# remove_cpp_comands.perl
......@@ -40,51 +44,11 @@ WORK_DIR=.
###############################################################################
CURRENT_DIR=$PWD
SOURCE_DIR=sources
MACHINE=`uname -m`
SYS_OS=`uname -s`
ARCH_DIR=$MACHINE-$SYS_OS
LOG_FILE=compile-log.txt
REMOVE_CPP_COMMANDS=$FIRM_JNI_TOOLS_DIR/remove_cpp_comands.perl
CRECODER=$FIRM_JNI_TOOLS_DIR/crecoder.jar
#
# shell initialization
#
source /afs/info.uni-karlsruhe.de/public/tools/Modules/init/sh
#
# flags
#
verbose=""
#
# set up directories
#
#rm -rf $WORK_DIR
#mkdir -p $WORK_DIR
cd $WORK_DIR
###############################################################################
analargs () {
while [ $# -gt 0 ]; do
case $1 in
--verbose) verbose="y";;
*) echo "Unknown option "$1;;
esac
shift
done
}
analargs $*
###############################################################################
###############################################################################
# Get all the necessary Firm headers.
......@@ -93,8 +57,8 @@ cd $WORK_DIR
rm -rf $SOURCE_DIR
mkdir $SOURCE_DIR
for file in $FIRM_HEADERS; do
cp $FIRM_INCLUDE_DIR/$file $SOURCE_DIR
for file in $FIRM_PATH_HEADERS; do
cp $top_srcdir/ir/$file $SOURCE_DIR
done;
###############################################################################
......@@ -119,9 +83,7 @@ done;
# the java native interface in C calling the real libfirm functions.
# For a file "file.h" files "File.java" and "File.c" are generated.
module add jdk-1.3.1-sun
export CLASSPATH=$FIRM_JNI_TOOLS_DIR/crecoder.jar:$CLASSPATH
#echo $CLASSPATH
for file in $FIRM_HEADERS; do
java crecoder/tools/jniBuilder/BuildJNI $file
done;
......@@ -129,14 +91,10 @@ done;
# Remove the C headers which are no more needed. They contain
# nonsense no C compiler ever should see ;-)
rm -f $FIRM_HEADERS
# Make the JNI Implementation
export CPPFLAGS="-I. -I/usr/public2/java/jdk1.3.1-sun/include/ -I/usr/public2/java/jdk1.3.1-sun/include/linux/ -I$FIRM_INCLUDE_DIR"
export LDFLAGS="-L$FIRM_LIB_DIR"
# javah renames these files. the jnibuilder doesn't anticipate this
# and generates #includes with the original names.
ln -s Firm_0005fcommon.h Firm_common.h
ln -s Type_0005for_0005fentity.h Type_or_entity.h
make -f Makefile
make
......@@ -5,6 +5,8 @@ import firmjni.*;
**
** Author: Goetz Lindenmaier
**
** $id$
**
** This is an example of how to use the JNI interface of Firm.
**
*/
......@@ -22,7 +24,6 @@ import firmjni.*;
**/
class Empty {
public static void main (String[] args) {
Firm firm = new Firm();
System.out.println("\nCreating an IR graph: EMPTY...");
......@@ -31,18 +32,17 @@ class Empty {
/** Build type information for the procedure. **/
/* FIRM was designed for oo languages where all methods beint to a class.
/* FIRM was designed for oo languages where all methods belong to a class.
* For imperative languages like C we view a file as a large class containing
* all functions in this file as methods.
* This clas is generated automatically.
*/
* This class is generated automatically. */
int owner = Irprog.getGlobType();
/* The type of the method */
int name = Ident.idFromStr("main", 4);
int proc_main = Type.newTypeMethod(name, 0, 0);
/* An entity representing the method. Owner of the entity is the global class
type mentioned above. */
/* An entity representing the method. Owner of the entity is the global
class type mentioned above. */
int ent = Entity.newEntity (owner, name, proc_main);
/** Build code for the procedure. **/
......
......@@ -5,27 +5,35 @@
# $Id$
#
top_srcdir := @top_srcdir@
top_srcdir = @top_srcdir@
srcdir = @srcdir@
topdir = ..
subdir := testprograms
subdir = testprograms
SOURCES := Makefile.in \
Empty.java
CLASSPATH += $srcdir
MYCLASSPATH = $(CLASSPATH):../..
LD_LIBRARY_PATH += $srcdir/firmjni
%.class: %.java
javac -d $CLASSPATH $<
%.class: $(top_srcdir)/firmjni/testprograms/%.java
javac -d . $<
all: empty
# bad hack ;-(
empty:
javac -classpath $(MYCLASSPATH) -d . @top_srcdir@/firmjni/testprograms/Empty.java
run: empty
java -cp $(MYCLASSPATH) Empty
all: %.class
clean:
-rm *.class
run: %.class
java $(<:.class=)
realclean: clean
-rm *.vcg
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment