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

Added support for debug callback. Not generated by crecoder, files

as handimplemented sources are linked into libfirmjni.so

[r849]
parent e49a1ac2
/**
* @file firmjni/Dbginfo.cc
*
*
*
* @author Goetz Lindenmaier
* CVS-ID: $Id$
* Copyright (c) 2003 University of Karlsruhe
* Created: 26.2.2003
* Project: Recoder frontend for libfirm
*
*
*/
#include "Dbginfo.h"
#include <firm.h>
#include "dbginfo.h"
#include <stdio.h>
static jmethodID pair_id;
static jmethodID sets_id;
static JNIEnv *my_env_jni_;
static jclass my_cls_jni_;
static void
my_dbg_info_merge_pair(ir_node *nw, ir_node *old, dbg_action info) {
if (pair_id) {
(*my_env_jni_)->CallStaticVoidMethod(my_env_jni_, my_cls_jni_, pair_id, nw, old, info);
}
}
static void
my_dbg_info_merge_sets(ir_node **new_nodes, int n_new_nodes,
ir_node **old_nodes, int n_old_nodes,
dbg_action info) {
if (sets_id) {
/* Convert argument arrays to java arrays. */
jintArray j_new_nodes = (*my_env_jni_)->NewIntArray(my_env_jni_, n_new_nodes);
jintArray j_old_nodes = (*my_env_jni_)->NewIntArray(my_env_jni_, n_old_nodes);
if (j_new_nodes)
(*my_env_jni_)->SetIntArrayRegion(my_env_jni_, j_new_nodes, 0, n_new_nodes, (jint *)new_nodes);
if (j_old_nodes)
(*my_env_jni_)->SetIntArrayRegion(my_env_jni_, j_old_nodes, 0, n_old_nodes, (jint *)old_nodes);
(*my_env_jni_)->CallStaticVoidMethod(my_env_jni_, my_cls_jni_, sets_id, j_new_nodes, j_old_nodes, info);
}
}
void Java_firmjni_Dbginfo_dbgInit (JNIEnv *env_jni_, jclass cls_jni_) {
pair_id = (*env_jni_)->GetStaticMethodID(env_jni_, cls_jni_, "myJavaDbgInfoMergePair", "(III)V");
sets_id = (*env_jni_)->GetStaticMethodID(env_jni_, cls_jni_, "myJavaDbgInfoMergeSets", "([I[II)V");
my_env_jni_ = env_jni_;
my_cls_jni_ = cls_jni_;
dbg_init(&my_dbg_info_merge_pair, &my_dbg_info_merge_sets);
}
package firmjni;
/**
* @(#)Mydbginfo.java
*
* @author Goetz Lindenmaier
* CVS-ID: $Id$
* Copyright (c) 2003 University of Karlsruhe
* All rights reserved.
* Use is subject to license terms.
* Created: 26.2.2003
* Project: Recoder frontend for libfirm
*
* Please report bugs with a detailed description to
* goetz@ipd.info.uni-karlsruhe.de
*/
import firmjni.*;
public class Dbginfo {
// Set env var LD_LIBRARY_PATH accordingly.
static {
System.loadLibrary("firmjni");
}
public static native void dbgInit ();
public static void myJavaDbgInfoMergePair(int new_node, int old_node, int info) {
System.out.println("new Node " + Irnode.getIrnNodeNr(new_node));
System.out.println("old Node " + Irnode.getIrnNodeNr(old_node));
}
public static void myJavaDbgInfoMergeSets(int new_nodes[], int old_nodes[], int info) {
System.out.print("new Nodes: ");
for (int i = 0; i < new_nodes.length; i++)
System.out.print(Irnode.getIrnNodeNr(new_nodes[i]) + ", ");
System.out.print("\nold Nodes: ");
for (int i = 0; i < old_nodes.length; i++)
System.out.print(Irnode.getIrnNodeNr(old_nodes[i]) + ", ");
System.out.println("");
}
}
......@@ -33,13 +33,13 @@ 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@ \
-D_SIZE_T_
-I$(top_srcdir)/ir/ana -I$(top_srcdir)/ir/st @CPPFLAGS@
LDFLAGS += $(topdir)
FIRM_HEADERS=$(notdir $(FIRM_PATH_HEADERS))
MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
MEMBERS += $(IMPL_MEMBERS)
# How to pass function pointers? Therefore removed.
# irgwalk.h typewalk.h
......@@ -48,7 +48,7 @@ MEMBERS=$(subst .h,.m,$(shell echo $(FIRM_HEADERS)|$(SHELL_TOUPPER)))
# Irgwalk.m Typewalk.m
#
FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
debug/dbginfo.h ident/ident.h tv/tv.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 \
......@@ -57,6 +57,9 @@ FIRM_PATH_HEADERS=common/firm.h common/firm_common.h \
ir/irgmod.h tr/typegmod.h
FIRM_SOURCE_DIR_HEADERS=$(addprefix $(SOURCE_DIR)/,$(FIRM_HEADERS))
# hand implemented members
IMPL_MEMBERS = Dbginfo.m
# The directory containing crecoder.jar and, for now,
# remove_cpp_comands.perl
FIRM_JNI_TOOLS_DIR=$(top_srcdir)/tools
......@@ -76,7 +79,7 @@ classfiles: $(CLASSFILES)
javafiles: $(JAVAFILES)
%.class: %.java
javac $<
javac -classpath .. $<
# javah renames these files. the jnibuilder doesn't anticipate this
# and generates #includes with the original names.
......@@ -88,6 +91,12 @@ Type_or_entity.h: Type_or_entity.class
ln -sf Type_0005for_0005fentity.h Type_or_entity.h
javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
Dbginfo.java:
cp $(srcdir)/Dbginfo.java .
cp $(srcdir)/Dbginfo.c .
%.h: %.class
javah -classpath $(topdir) -o $@ $(PACKAGENAME).$(<:.class=)
......@@ -147,5 +156,8 @@ $(FIRM_HEADERS):$(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
H_FROM_JAVA=$(subst .java,.h,$(shell echo $@|$(SHELL_TOLOWER)))
%.java: $(FIRM_HEADERS)
%.java: $(FIRM_SOURCE_DIR_HEADERS) $(SOURCE_DIR)/firm_typedefs.h
gcc $(CPPFLAGS) -E -C -P $(SOURCE_DIR)/$(H_FROM_JAVA) -o $(H_FROM_JAVA)
env CLASSPATH=$(FIRM_JNI_TOOLS_DIR)/crecoder.jar:$$CLASSPATH java crecoder/tools/jniBuilder/BuildJNI $(H_FROM_JAVA);\
rm $(H_FROM_JAVA);
# remove the patched header so that further compilation finds the proper firm headers
......@@ -29,8 +29,9 @@ class IfElseExample {
System.out.println("\nCreating an IR graph: IfElseExample...");
/* init library: Java did not support the callback, so ALWAYS use 0 here */
/* init library */
Firm.initFirm(0);
Dbginfo.dbgInit();
/** Build type information for the compilation unit. **/
......
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