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

added tools to generate a JNI for firm. remove_cpp_commands.perl is

temporary, will be removed if a better version of crecoder is available

[r510]
parent 677f67f9
LIBNAME = libfirmjni.so
.PHONY: default all clean realclean depend
MEMBERS = Firm.m Firm.m Firm_common.m Dbginfo.m Ident.m Tv.m \
Type.m Entity.m Type_or_entity.m Tpop.m Mangle.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
OFILES = $(MEMBERS:.m=.o)
HFILES = $(MEMBERS:.m=.h)
all: lib
%.class: %.java
javac $<
%.h: %.class
javah $(<:.class=)
-cp Firm_0005fcommon.h Firm_common.h
-cp Type_0005for_0005fentity.h Type_or_entity.h
%.o: %.c %.h
gcc $(CPPFLAGS) -c $< -o $@
lib: $(HFILES) $(OFILES)
gcc -shared -fPIC -o $(LIBNAME) *.o /ben/goetz/proj/libfirm/i686/libfirm.a
clean:
# rm -f *.class $(JHFILES) *.o $(JCFILES) $(JOFILES) $(CLSFILES) $(JFILES)
realclean: clean
# rm -f *~ libfirmjni.a libfirmjni.so *.vcg
#!/bin/sh
# Project: FIRM
# File name: script/build_firm_jni
# Purpose: skript to build a java native interface for the public headers of firm.
# Author: Goetz Lindenmaier
# Modified by:
# Created: 30.10.2002
# CVS-ID: $Id$
# Copyright: (c) 2002 Universitt Karlsruhe
# Licence:
###############################################################################
# Set this variable to the directory which shall contain the JNI implementation
FIRM_JNI_DIR=/ben/goetz/proj/libfirm/firm-jni/
# Set these directories to point to a libfirm installation:
FIRM_INCLUDE_DIR=/ben/goetz/proj/libfirm/i686/include
FIRM_LIB_DIR=/ben/goetz/proj/libfirm/i686
FIRM_JNI_TOOLS_DIR=/ben/goetz/proj/libfirm/firm-jni/tools
# Set this directory to a directory with sufficient space.
WORK_DIR=/ben/goetz/proj/libfirm/firm-jni/tmp
# This is the list of firm headers a JNI interface is generated for
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"
###############################################################################
CURRENT_DIR=$PWD
SOURCE_DIR=sources
PUREC_DIR=purec
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
#
# 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.
cd $WORK_DIR
mkdir $PUREC_DIR
mkdir $SOURCE_DIR
for file in $FIRM_HEADERS; do
cp $FIRM_INCLUDE_DIR/$file $SOURCE_DIR
done;
cd $SOURCE_DIR
###############################################################################
# Remove C preprocessor commands. Overwrite the header files.
# This part should be removed if crecoder integrates the preprocessor.
rm -f firm_typedefs.h
for file in $FIRM_HEADERS; do
perl $REMOVE_CPP_COMMANDS $file
done;
for file in $FIRM_HEADERS; do
gcc -E -C -P $file -o ../$PUREC_DIR/$file
done;
cd ../$PUREC_DIR
###############################################################################
# Call crecoder to construct from each header a .java file specifying the
# java native interface. Further crecoder constructs an implementation of
# 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
for file in $FIRM_HEADERS; do
java crecoder/tools/jniBuilder/BuildJNI $file
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-sun/include/ -I/usr/public2/java/jdk1.3-sun/include/linux/ -I$FIRM_INCLUDE_DIR"
export LDFLAGS="-L$FIRM_LIB_DIR"
make -f $FIRM_JNI_TOOLS_DIR/Makefile
mv libfirmjni.so $FIRM_JNI_DIR
#mv *.java *.class $FIRM_JNI_DIR
#!/usr/local/bin/perl
#
# Take a C header file and remove all preprocessor commands.
# Wrap all typedefs with a preprocessor guard,
# add all possible typedefs in firm at the beginning of the file, also
# wrapped with a preprocessor guard
#
# Call
# perl remove_cpp_comands.perl <file>
# for a file with name <file>.h.
# open files
$infile = $ARGV[0];
open(IN, $infile);
@lines = <IN>;
close(IN);
$outfile = $infile;
open(OUT, ">$outfile");
$typedeffile = "firm_typedefs.h";
open(TDF, ">>$typedeffile");
#dump headers
print OUT "\n#include \"firm_typedefs.h\"\n\n";
#Unresolved preprocessor commands
print TDF "#define INLINE\n";
print TDF "#define FILE int *\n";
print TDF "#ifndef MYTYPEDEFS\n#define MYTYPEDEFS\n";
print TDF "typedef unsigned long size_t;\n";
#print TDF "typedef enum { false = 0, true = 1 } bool;\n"; geht nicht, false und true JAVA Schluesselwoerter
print TDF "typedef int bool;\n";
print TDF "#endif\n";
#to collect typedefs
$openbracket = 0;
$guardedtypedef = 0;
$scndlastline = "";
$lastline = "";
foreach $line (@lines) {
if (($line =~ /^\#/) ) {
# eat the line
$scndlastline = $lastline;
$lastline = $line;
} elsif ($openbracket == 1) {
print TDF "$line";
if ((index($line, "}") > -1)) {
$openbracket = 0;
if (($guardedtypedef == 1)) {
print TDF "#endif\n";
$guardedtypedef = 0;
}
}
$lastline = "";
} elsif ($line =~ /typedef/) {
# move the full typedef to firm_typedefs.h
if (($lastline =~ /^\#/) ) {
$guardedtypedef = 1;
print TDF "$scndlastline"; $scndlastline = "";
print TDF "$lastline"; $lastline = "";
}
print TDF "$line";
if ((index($line, "{") > -1)) {
$openbracket = 1;
} elsif (($guardedtypedef == 1)) {
print TDF "#endif\n";
$guardedtypedef = 0;
}
if ((index($line, "}") > -1)) {
$openbracket = 0;
if (($guardedtypedef == 1)) {
print TDF "#endif\n";
$guardedtypedef = 0;
}
}
} else {
print OUT "$line";
$scndlastline = $lastline;
$lastline = "";
}
}
close(TDF);
close(OUT);
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