Commit e04a16fb by Anthony Green

Initial revision

From-SVN: r22299
parent fc08e329
# Top level makefile fragment for the GNU compiler for the Java(TM)
# language.
# Copyright (C) 1996, 1998 Free Software Foundation, Inc.
#This file is part of GNU CC.
#GNU CC 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 2, or (at your option)
#any later version.
#GNU CC 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 GNU CC; see the file COPYING. If not, write to
#the Free Software Foundation, 59 Temple Place - Suite 330,
#Boston, MA 02111-1307, USA.
#Java and all Java-based marks are trademarks or registered trademarks
#of Sun Microsystems, Inc. in the United States and other countries.
#The Free Software Foundation is independent of Sun Microsystems, Inc.
# This file provides the language dependent support in the main Makefile.
# Each language makefile fragment must provide the following targets:
#
# foo.all.build, foo.all.cross, foo.start.encap, foo.rest.encap,
# foo.info, foo.dvi,
# foo.install-normal, foo.install-common, foo.install-info, foo.install-man,
# foo.uninstall, foo.distdir,
# foo.mostlyclean, foo.clean, foo.distclean, foo.extraclean,
# foo.maintainer-clean, foo.stage1, foo.stage2, foo.stage3, foo.stage4
#
# where `foo' is the name of the language.
#
# It should also provide rules for:
#
# - making any compiler driver (eg: g++)
# - the compiler proper (eg: jc1)
# - define the names for selecting the language in LANGUAGES.
# Extra flags to pass to recursive makes.
JAVA_FLAGS_TO_PASS = \
"JAVA_FOR_BUILD=$(JAVA_FOR_BUILD)" \
"JAVAFLAGS=$(JAVAFLAGS)" \
"JAVA_FOR_TARGET=$(JAVA_FOR_TARGET)"
# Actual names to use when installing a native compiler.
JAVA_INSTALL_NAME = `t='$(program_transform_name)'; echo gcj | sed $$t`
# Actual names to use when installing a cross-compiler.
JAVA_CROSS_NAME = `t='$(program_transform_cross_name)'; echo gcj | sed $$t`
# Define the names for selecting java in LANGUAGES.
java: jc1$(exeext) $(GCJ)$(exeext) jvgenmain$(exeext) gcjh$(exeext)
# Define the name of target independant tools to be installed in $(bindir)
# Names are subject to changes
JAVA_TARGET_INDEPENDENT_BIN_TOOLS = gcjh jv-scan jcf-dump
# Tell GNU make to ignore these if they exist.
.PHONY: java
GCJ = gcj
# Remember to keep this list in sync with JAVA_OBJS in Makefile.in!!!
#
JAVA_SRCS = $(srcdir)/java/parse.y $(srcdir)/java/class.c \
$(srcdir)/java/decl.c $(srcdir)/java/expr.c $(srcdir)/java/constants.c \
$(srcdir)/java/lang.c $(srcdir)/java/typeck.c $(srcdir)/java/except.c \
$(srcdir)/java/verify.c $(srcdir)/java/zextract.c $(srcdir)/java/jcf-io.c \
$(srcdir)/java/jcf-parse.c $(srcdir)/java/mangle.c \
$(srcdir)/java/jcf-write.c $(srcdir)/java/buffer.c
jc1$(exeext): $(P) $(JAVA_SRCS) $(LIBDEPS) stamp-objlist
cd java; $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) ../jc1$(exeext)
$(GCJ).c: $(srcdir)/gcc.c
-rm -f $@
$(LN_S) $(srcdir)/gcc.c $@
jvspec.o: $(srcdir)/java/jvspec.c
$(CC) -c -DWITH_THREAD_$(GCC_THREAD_FILE) \
$(ALL_CFLAGS) $(ALL_CPPFLAGS) \
$(INCLUDES) $(srcdir)/java/jvspec.c
# N.B.: This is a copy of the gcc.o rule, with -DLANG_SPECIFIC_DRIVER added.
# It'd be nice if we could find an easier way to do this---rather than have
# to track changes to the toplevel gcc Makefile as well.
# We depend on $(GCJ).c last, to make it obvious where it came from.
$(GCJ).o: $(CONFIG_H) multilib.h config.status $(lang_specs_files) $(GCJ).c \
system.h
$(CC) $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
$(DRIVER_DEFINES) \
-DLANG_SPECIFIC_DRIVER \
-c $(GCJ).c
# Create the compiler driver for $(GCJ).
$(GCJ)$(exeext): $(GCJ).o jvspec.o version.o choose-temp.o\
pexecute.o prefix.o mkstemp.o $(LIBDEPS) $(EXTRA_GCC_OBJS)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ $(GCJ).o jvspec.o prefix.o \
version.o choose-temp.o pexecute.o mkstemp.o $(EXTRA_GCC_OBJS) $(LIBS)
# Create a version of the $(GCJ) driver which calls the cross-compiler.
$(GCJ)-cross$(exeext): $(GCJ)$(exeext)
-rm -f $(GCJ)-cross$(exeext)
cp $(GCJ)$(exeext) $(GCJ)-cross$(exeext)
# Dependencies here must be kept in sync with dependencies in Makefile.in.
jvgenmain$(exeext): $(srcdir)/java/jvgenmain.c $(srcdir)/java/mangle.c \
$(OBSTACK)
cd java && $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) ../jvgenmain$(exeext)
# This must be kept in sync with dependencies in Makefile.in.
GCJH_SOURCES = $(srcdir)/java/gjavah.c $(srcdir)/java/jcf-io.c \
$(srcdir)/java/zextract.c $(srcdir)/java/jcf-reader.c \
$(srcdir)/java/jcf.h $(srcdir)/java/javaop.h \
$(srcdir)/java/javaop.def
gcjh$(exeext): $(GCJH_SOURCES)
cd java && $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) ../gcjh$(exeext)
# Build hooks:
java.all.build: $(GCJ)$(exeext) jvgenmain$(exeext) gcjh$(exeext)
java.all.cross: $(GCJ)-cross$(exeext) jvgenmain$(exeext) gcjh$(exeext)
java.start.encap: $(GCJ)$(exeext)
java.rest.encap: jvgenmain$(exeext) gcjh$(exeext)
java.info:
# Install hooks:
# jc1, gcj, jvgenmain, and gcjh are installed elsewhere as part
# of $(COMPILERS).
# Nothing to do here.
java.install-normal:
java.install-common:
-if [ -f $(GCJ)$(exeext) ]; then \
if [ -f $(GCJ)-cross$(exeext) ]; then \
rm -f $(bindir)/$(JAVA_CROSS_NAME)$(exeext); \
$(INSTALL_PROGRAM) $(GCJ)-cross$(exeext) $(bindir)/$(JAVA_CROSS_NAME)$(exeext); \
chmod a+x $(bindir)/$(JAVA_CROSS_NAME)$(exeext); \
else \
rm -f $(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
$(INSTALL_PROGRAM) $(GCJ)$(exeext) $(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
chmod a+x $(bindir)/$(JAVA_INSTALL_NAME)$(exeext); \
fi ; \
fi ; \
for tool in $(JAVA_TARGET_INDEPENDENT_BIN_TOOLS); do \
if [ -f $$tool$(exeext) ]; then \
rm -f $(bindir)/$$tool$(exeext); \
$(INSTALL_PROGRAM) $$tool$(exeext) $(bindir)/$$tool$(exeext); \
chmod a+x $(bindir)/$$tool$(exeext); \
fi ; \
done
java.install-man:
java.uninstall:
-rm -rf $(bindir)/$(JAVA_INSTALL_NAME)$(exeext)
-rm -rf $(bindir)/$(JAVA_CROSS_NAME)$(exeext)
java.install-info:
# Clean hooks:
# A lot of the ancillary files are deleted by the main makefile.
# We just have to delete files specific to us.
java.mostlyclean:
-rm -f java/*$(objext) $(DEMANGLER_PROG)
java.clean:
java.distclean:
-rm -f java/config.status java/Makefile
-rm -f java/parse.output
java.extraclean:
java.maintainer-clean:
-rm -f java/parse.h
# Stage hooks:
# The main makefile has already created stage?/java.
java.stage1:
-mv java/*$(objext) stage1/java
java.stage2:
-mv java/*$(objext) stage2/java
java.stage3:
-mv java/*$(objext) stage3/java
java.stage4:
-mv java/*$(objext) stage4/java
# Maintenance hooks:
# This target creates the files that can be rebuilt, but go in the
# distribution anyway. It then copies the files to the distdir directory.
java.distdir:
mkdir tmp/java
cd java ; $(MAKE) $(FLAGS_TO_PASS) $(JAVA_FLAGS_TO_PASS) parse.c hash.h
cd java; \
for file in *[0-9a-zA-Z+]; do \
ln $$file ../tmp/java >/dev/null 2>&1 || cp $$file ../tmp/java; \
done
# Makefile for GNU compiler for the Java(TM) language.
# Copyright (C) 1987, 88, 90-4, 1995, 1998 Free Software Foundation, Inc.
#This file is part of GNU CC.
#GNU CC 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 2, or (at your option)
#any later version.
#GNU CC 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 GNU CC; see the file COPYING. If not, write to
#the Free Software Foundation, 59 Temple Place - Suite 330,
#Boston, MA 02111-1307, USA.
#Java and all Java-based marks are trademarks or registered trademarks
#of Sun Microsystems, Inc. in the United States and other countries.
#The Free Software Foundation is independent of Sun Microsystems, Inc.
# The makefile built from this file lives in the language subdirectory.
# Its purpose is to provide support for:
#
# 1) recursion where necessary, and only then (building .o's), and
# 2) building and debugging cc1 from the language subdirectory, and
# 3) nothing else.
#
# The parent makefile handles all other chores, with help from the
# language makefile fragment, of course.
#
# The targets for external use are:
# all, TAGS, ???mostlyclean, ???clean.
# Suppress smart makes who think they know how to automake Yacc files
.y.c:
# Variables that exist for you to override.
# See below for how to change them for certain systems.
ALLOCA =
# Various ways of specifying flags for compilations:
# CFLAGS is for the user to override to, e.g., do a bootstrap with -O2.
# BOOT_CFLAGS is the value of CFLAGS to pass
# to the stage2 and stage3 compilations
# XCFLAGS is used for most compilations but not when using the GCC just built.
XCFLAGS =
CFLAGS = -g
BOOT_CFLAGS = -O $(CFLAGS)
# These exists to be overridden by the x-* and t-* files, respectively.
X_CFLAGS =
T_CFLAGS =
X_CPPFLAGS =
T_CPPFLAGS =
CC = @CC@
BISON = `if [ -f ../../bison/bison ] ; then echo ../../bison/bison -L $(srcdir)/../../bison/ ; else echo bison ; fi`
BISONFLAGS =
JAVABISONFLAGS = --name-prefix=java_
LEX = `if [ -f ../../flex/flex ] ; then echo ../../flex/flex ; else echo flex ; fi`
LEXFLAGS =
AR = ar
AR_FLAGS = rc
SHELL = /bin/sh
MAKEINFO = makeinfo
TEXI2DVI = texi2dvi
# Define this as & to perform parallel make on a Sequent.
# Note that this has some bugs, and it seems currently necessary
# to compile all the gen* files first by hand to avoid erroneous results.
P =
# This is used in the definition of SUBDIR_USE_ALLOCA.
# ??? Perhaps it would be better if it just looked for *gcc*.
OLDCC = cc
# This is used instead of ALL_CFLAGS when compiling with GCC_FOR_TARGET.
# It omits XCFLAGS, and specifies -B./.
# It also specifies -B$(tooldir)/ to find as and ld for a cross compiler.
GCC_CFLAGS=$(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS)
# Tools to use when building a cross-compiler.
# These are used because `configure' appends `cross-make'
# to the makefile when making a cross-compiler.
# We don't use cross-make. Instead we use the tools
# from the build tree, if they are available.
# program_transform_name and objdir are set by configure.in.
program_transform_name =
objdir = .
+target=@target@
+xmake_file=@dep_host_xmake_file@
+tmake_file=@dep_tmake_file@
#version=`sed -e 's/.*\"\([^ \"]*\)[ \"].*/\1/' < $(srcdir)/version.c`
#mainversion=`sed -e 's/.*\"\([0-9]*\.[0-9]*\).*/\1/' < $(srcdir)/version.c`
# Directory where sources are, from where we are.
srcdir = @srcdir@
VPATH = @srcdir@
# Additional system libraries to link with.
CLIB=
# Change this to a null string if obstacks are installed in the
# system library.
OBSTACK=obstack.o
# Choose the real default target.
ALL=all
# End of variables for you to override.
# Definition of `all' is here so that new rules inserted by sed
# do not specify the default target.
all: all.indirect
# This tells GNU Make version 3 not to put all variables in the environment.
.NOEXPORT:
# sed inserts variable overrides after the following line.
####target overrides
@target_overrides@
####host overrides
@host_overrides@
####cross overrides
@cross_overrides@
####build overrides
@build_overrides@
####site overrides
# Now figure out from those variables how to compile and link.
all.indirect: Makefile ../jc1$(exeext) ../jcf-dump$(exeext) \
../jvgenmain$(exeext) ../gcjh$(exeext) ../jv-scan$(exeext)
# IN_GCC tells obstack.h that we are using gcc's <stddef.h> file.
INTERNAL_CFLAGS = $(CROSS) -DIN_GCC @extra_c_flags@
# This is the variable actually used when we compile.
ALL_CFLAGS = $(INTERNAL_CFLAGS) $(X_CFLAGS) $(T_CFLAGS) $(CFLAGS) $(XCFLAGS)
# Likewise.
ALL_CPPFLAGS = $(CPPFLAGS) $(X_CPPFLAGS) $(T_CPPFLAGS)
# Even if ALLOCA is set, don't use it if compiling with GCC.
SUBDIR_OBSTACK = `if [ x$(OBSTACK) != x ]; then echo ../$(OBSTACK); else true; fi`
SUBDIR_USE_ALLOCA = `case "${CC}" in "${OLDCC}") if [ x$(ALLOCA) != x ]; then echo ../$(ALLOCA); else true; fi ;; esac`
SUBDIR_MALLOC = `if [ x$(MALLOC) != x ]; then echo ../$(MALLOC); else true; fi`
# How to link with both our special library facilities
# and the system's installed libraries.
LIBS = $(SUBDIR_OBSTACK) $(SUBDIR_USE_ALLOCA) $(SUBDIR_MALLOC) $(CLIB)
# Specify the directories to be searched for header files.
# Both . and srcdir are used, in that order,
# so that tm.h and config.h will be found in the compilation
# subdirectory rather than in the source directory.
INCLUDES = -I. -I.. -I$(srcdir) -I$(srcdir)/.. -I$(srcdir)/../config
# Always use -I$(srcdir)/config when compiling.
.c.o:
$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) $<
# This tells GNU make version 3 not to export all the variables
# defined in this file into the environment.
.NOEXPORT:
# Lists of files for various purposes.
# Language-specific object files for Gcc/Java:
# Remember to keep this list in sync with JAVA_SRCS in Make-lang.in!!!
#
JAVA_OBJS = parse.o class.o decl.o expr.o constants.o lang.o typeck.o \
except.o verify.o zextract.o jcf-io.o jcf-parse.o mangle.o jcf-write.o \
buffer.o
JAVA_OBJS_LITE = parse-scan.o jv-scan.o
# Language-independent object files.
OBJS = `cat ../stamp-objlist`
OBJDEPS = ../stamp-objlist
compiler: ../jc1$(exeext) ../jv-scan$(exeext)
../jc1$(exeext): $(P) $(JAVA_OBJS) $(OBJDEPS) $(LIBDEPS)
rm -f ../jc1$(exeext)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
$(JAVA_OBJS) $(OBJS) $(LIBS)
../jv-scan$(exeext): $(P) $(JAVA_OBJS_LITE) $(OBJDEPS) $(LIBDEPS)
rm -f ../jv-scan$(exeext)
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ \
$(JAVA_OBJS_LITE) $(LIBS)
../jcf-dump$(exeext): jcf-dump.o jcf-io.o zextract.o
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ jcf-dump.o jcf-io.o zextract.o
# Dependencies here must be kept in sync with dependencies in Make-lang.in.
../jvgenmain$(exeext): jvgenmain.o mangle.o
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ jvgenmain.o mangle.o ../obstack.o
../gcjh$(exeext): gjavah.o jcf-io.o zextract.o
$(CC) $(ALL_CFLAGS) $(LDFLAGS) -o $@ gjavah.o jcf-io.o zextract.o
Makefile: $(srcdir)/Makefile.in $(srcdir)/../configure
cd ..; $(SHELL) config.status
native: config.status ../jc1$(exeext)
# Compiling object files from source files.
PARSE_H = $(srcdir)/parse.h
PARSE_C = $(srcdir)/parse.c
PARSE_SCAN_C = $(srcdir)/parse-scan.c
$(PARSE_H): $(PARSE_C)
$(PARSE_C): $(srcdir)/parse.y $(srcdir)/lex.c $(PARSE_H) $(srcdir)/lex.h
$(BISON) -t -v $(BISONFLAGS) $(JAVABISONFLAGS) -o $(PARSE_C) \
$(srcdir)/parse.y
$(PARSE_SCAN_C): $(srcdir)/parse-scan.y $(srcdir)/lex.c $(PARSE_H) \
$(srcdir)/lex.h
$(BISON) -t -v $(BISONFLAGS) -o $(PARSE_SCAN_C) $(srcdir)/parse-scan.y
lex.c: keyword.h lex.h
keyword.h: keyword.gperf
gperf -p -t -j1 -i 1 -g -o -N java_keyword -k1,3,$$ \
keyword.gperf > keyword.h
# These exist for maintenance purposes.
# Update the tags table.
TAGS: force
cd $(srcdir) ; \
etags *.c *.h ; \
echo 'l' | tr 'l' '\f' >> TAGS ; \
echo 'parse.y,0' >> TAGS ; \
etags -a ../*.h ../*.c;
.PHONY: TAGS
mostlyclean:
rm -f *.o
clean: mostlyclean
rm -f parse.c
force:
parse.o: $(PARSE_C) jcf-reader.c
jcf-dump.o: jcf-reader.c jcf.h javaop.h javaop.def
gjavah.o: jcf-reader.c jcf.h javaop.h
/* A "buffer" utility type.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* Written by Per Bothner <bothner@cygnus.com>, July 1998. */
#include "gansidecl.h"
#include "buffer.h"
/* Grow BUFP so there is room for at least SIZE more bytes. */
void
buffer_grow (bufp, size)
struct buffer *bufp;
int size;
{
if (bufp->limit - bufp->ptr >= size)
return;
if (bufp->data == 0)
{
if (size < 120)
size = 120;
bufp->data = (unsigned char*) xmalloc (size);
bufp->ptr = bufp->data;
}
else
{
int index = bufp->ptr - bufp->data;
size += 2 * (bufp->limit - bufp->data);
bufp->data = (unsigned char *) xrealloc (bufp->data, size);
bufp->ptr = bufp->data + index;
}
bufp->limit = bufp->data + size;
}
/* A "buffer" utility type.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* Written by Per Bothner <bothner@cygnus.com>, July 1998. */
/* A simple data structure for an expandable buffer. */
struct buffer
{
/* The start of the actual data buffer. */
unsigned char *data;
/* Where to write next in the buffer. */
unsigned char *ptr;
/* The end of the allocated data buffer. */
unsigned char *limit;
};
#define NULL_BUFFER { (void*) 0, (void*) 0, (void*) 0 }
#define BUFFER_LENGTH(BUFP) ((BUFP)->ptr - (BUFP)->data)
#define BUFFER_RESET(BUFP) ((BUFP)->ptr = (BUFP)->data)
extern void buffer_grow PROTO ((struct buffer*, int));
# Top level configure fragment for the GNU compiler for the Java(TM)
# language.
# Copyright (C) 1994, 1995 Free Software Foundation, Inc.
#This file is part of GNU CC.
#GNU CC 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 2, or (at your option)
#any later version.
#GNU CC 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 GNU CC; see the file COPYING. If not, write to
#the Free Software Foundation, 59 Temple Place - Suite 330,
#Boston, MA 02111-1307, USA.
#Java and all Java-based marks are trademarks or registered trademarks
#of Sun Microsystems, Inc. in the United States and other countries.
#The Free Software Foundation is independent of Sun Microsystems, Inc.
# Configure looks for the existence of this file to auto-config each language.
# We define several parameters used by configure:
#
# language - name of language as it would appear in $(LANGUAGES)
# compilers - value to add to $(COMPILERS)
# stagestuff - files to add to $(STAGESTUFF)
# diff_excludes - files to ignore when building diffs between two versions.
language="java"
compilers="jc1\$(exeext) jvgenmain\$(exeext)"
stagestuff="jc1\$(exeext) gcj\$(exeext) jvgenmain\$(exeext) gcjh\$(exeext)"
outputs=java/Makefile
/* Definition of conversion functions.
Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* Written by Jeffrey Hsu <hsu@cygnus.com> */
extern tree convert_to_boolean PROTO ((tree, tree));
extern tree convert_to_char PROTO ((tree, tree));
This diff is collapsed. Click to expand it.
/* Handle exceptions for GNU compiler for the Java(TM) language.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include <stdio.h>
#include "config.h"
#include "tree.h"
#include "real.h"
#include "rtl.h"
#include "java-tree.h"
#include "javaop.h"
#include "java-opcodes.h"
#include "jcf.h"
#include "except.h"
#include "java-except.h"
#include "eh-common.h"
extern struct obstack permanent_obstack;
struct eh_range *current_method_handlers;
struct eh_range *current_try_block = NULL;
struct eh_range *eh_range_freelist = NULL;
/* These variables are used to speed up find_handler. */
static int cache_range_start, cache_range_end;
static struct eh_range *cache_range;
static struct eh_range *cache_next_child;
/* A dummy range that represents the entire method. */
struct eh_range whole_range;
/* Search for the most specific eh_range containing PC.
Assume PC is within RANGE.
CHILD is a list of children of RANGE such that any
previous children have end_pc values that are too low. */
static struct eh_range *
find_handler_in_range (pc, range, child)
int pc;
struct eh_range *range;
register struct eh_range *child;
{
for (; child != NULL; child = child->next_sibling)
{
if (pc < child->start_pc)
break;
if (pc <= child->end_pc)
return find_handler_in_range (pc, child, child->first_child);
}
cache_range = range;
cache_range_start = pc;
cache_next_child = child;
cache_range_end = child == NULL ? range->end_pc : child->start_pc;
return range;
}
/* Find the inner-most handler that contains PC. */
struct eh_range *
find_handler (pc)
int pc;
{
struct eh_range *h;
if (pc >= cache_range_start)
{
h = cache_range;
if (pc < cache_range_end)
return h;
while (pc >= h->end_pc)
{
cache_next_child = h->next_sibling;
h = h->outer;
}
}
else
{
h = &whole_range;
cache_next_child = h->first_child;
}
return find_handler_in_range (pc, h, cache_next_child);
}
#if 0
first_child;
next_sibling;
outer;
#endif
/* Recursive helper routine for add_handler. */
static int
link_handler (start_pc, end_pc, handler, type, outer)
int start_pc, end_pc;
tree handler;
tree type;
struct eh_range *outer;
{
struct eh_range **ptr;
if (start_pc < outer->start_pc || end_pc > outer->end_pc)
return 0; /* invalid or non-nested exception range */
if (start_pc == outer->start_pc && end_pc == outer->end_pc)
{
outer->handlers = tree_cons (type, handler, outer->handlers);
return 1;
}
ptr = &outer->first_child;
for (;; ptr = &(*ptr)->next_sibling)
{
if (*ptr == NULL || end_pc <= (*ptr)->start_pc)
{
struct eh_range *h = (struct eh_range *)
oballoc (sizeof (struct eh_range));
h->start_pc = start_pc;
h->end_pc = end_pc;
h->next_sibling = *ptr;
h->first_child = NULL;
h->outer = outer;
h->handlers = build_tree_list (type, handler);
*ptr = h;
return 1;
}
else if (start_pc < (*ptr)->end_pc)
return link_handler (start_pc, end_pc, handler, type, *ptr);
/* end_pc > (*ptr)->start_pc && start_pc >= (*ptr)->end_pc. */
}
}
/* Called to re-initialize the exception machinery for a new method. */
void
method_init_exceptions ()
{
whole_range.start_pc = 0;
whole_range.end_pc = DECL_CODE_LENGTH (current_function_decl) + 1;
whole_range.outer = NULL;
whole_range.first_child = NULL;
whole_range.next_sibling = NULL;
cache_range_start = 0xFFFFFF;
set_exception_lang_code (EH_LANG_Java);
set_exception_version_code (1);
}
int
add_handler (start_pc, end_pc, handler, type)
int start_pc, end_pc;
tree handler;
tree type;
{
return link_handler (start_pc, end_pc, handler, type, &whole_range);
}
/* if there are any handlers for this range, issue start of region */
void
expand_start_java_handler (range)
struct eh_range *range;
{
expand_eh_region_start ();
}
/* if there are any handlers for this range, isssue end of range,
and then all handler blocks */
void
expand_end_java_handler (range)
struct eh_range *range;
{
tree handler = range->handlers;
expand_start_all_catch ();
for ( ; handler != NULL_TREE; handler = TREE_CHAIN (handler))
{
tree type = TREE_PURPOSE (handler);
tree exp;
/* The "type" (metch_info) in a (Java) exception table is one:
* a) NULL - meaning match any type in a try-finally.
* b) a pointer to a (ccmpiled) class (low-order bit 0).
* c) a pointer to the Utf8Const name of the class, plus one
* (which yields a value with low-order bit 1). */
push_obstacks (&permanent_obstack, &permanent_obstack);
if (type == NULL_TREE)
exp = null_pointer_node;
else if (is_compiled_class (type))
exp = build_class_ref (type);
else
exp = fold (build (PLUS_EXPR, ptr_type_node,
build_utf8_ref (build_internal_class_name (type)),
size_one_node));
pop_obstacks ();
start_catch_handler (exp);
expand_goto (TREE_VALUE (handler));
}
expand_end_all_catch ();
}
/* Recursive helper routine for maybe_start_handlers. */
static void
check_start_handlers (range, pc)
struct eh_range *range;
int pc;
{
if (range != NULL_EH_RANGE && range->start_pc == pc)
{
check_start_handlers (range->outer, pc);
expand_start_java_handler (range);
}
}
struct eh_range *current_range;
/* Emit any start-of-try-range start at PC. */
void
maybe_start_try (pc)
int pc;
{
if (! doing_eh (1))
return;
current_range = find_handler (pc);
check_start_handlers (current_range, pc);
}
/* Emit any end-of-try-range end at PC. */
void
maybe_end_try (pc)
int pc;
{
if (! doing_eh (1))
return;
while (current_range != NULL_EH_RANGE && current_range->end_pc <= pc)
{
expand_end_java_handler (current_range);
current_range = current_range->outer;
}
}
/* Emit the handler labels and their code */
void
emit_handlers ()
{
if (catch_clauses)
{
rtx funcend = gen_label_rtx ();
emit_jump (funcend);
emit_insns (catch_clauses);
expand_leftover_cleanups ();
emit_label (funcend);
}
}
This diff is collapsed. Click to expand it.
/* Definitions for exception handling for use by the GNU compiler
for the Java(TM) language compiler.
Copyright (C) 1997 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
struct eh_range
{
/* The (byte-code PC) range of the handled block. */
int start_pc;
int end_pc;
/* A list of handlers. For each element in the list,
the TREE_PURPOSE is the handled class (NULL_EXPR for a finally block),
and the TREE_VALUE is the LABEL_DECL of the handler. */
tree handlers;
/* Surrunding handler, if any. */
struct eh_range *outer;
/* The first child range. It is is nested inside this range
(i.e. this.start_pc <= first_child.end_pc
&& this.end_pc >= first_child.end_pc).
The children are linked together using next_sibling, and are sorted
by increasing start_pc and end_pc (we do not support non-nested
overlapping ranges). */
struct eh_range *first_child;
/* The next child of outer, in address order. */
struct eh_range *next_sibling;
#if 0
/* Next handler, sorted by ascending start_pc then descending end_pc. */
tree next;
#endif
};
/* A dummy range that represents the entire method. */
extern struct eh_range whole_range;
#define NULL_EH_RANGE (&whole_range)
extern struct eh_range * find_handler PROTO ((int));
extern void method_init_exceptions PROTO ((void));
extern void emit_handlers PROTO ((void));
enum java_opcode {
#define JAVAOP(NAME, CODE, KIND, TYPE, VALUE) OPCODE_##NAME = CODE,
#include "javaop.def"
#undef JAVAOP
};
/* Shift right, logical. */
DEFTREECODE (URSHIFT_EXPR, "urshift_expr", "2", 2)
/* Return -1, 0, 1 depending on whether the first argument is
less, equal, or greater to the second argument. */
DEFTREECODE (COMPARE_EXPR, "compare_expr", "2", 2)
/* Same as COMPARE_EXPR, but if either value is NaN, the result is -1. */
DEFTREECODE (COMPARE_L_EXPR, "compare_l_expr", "2", 2)
/* Same as COMPARE_EXPR, but if either value is NaN, the result is 1. */
DEFTREECODE (COMPARE_G_EXPR, "compare_g_expr", "2", 2)
/* Utility macros to handle Java(TM) byte codes.
Copyright (C) 1996 Free Software Foundation, 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 2, 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
#ifndef JAVAOP_H
#define JAVAOP_H
typedef char int8;
typedef unsigned char uint8;
#ifndef int16
#define int16 short
#endif
typedef unsigned int16 uint16;
#ifndef int32
#define int32 long
#endif
typedef unsigned int32 uint32;
/* A signed 64-bit (or more) integral type, suiteable for Java's 'long'. */
#ifndef int64
#define int64 long long
#endif
/* An unsigned 64-bit (or more) integral type, same length as int64. */
#ifndef uint64
#define uint64 unsigned int64
#endif
typedef uint16 jchar;
typedef int8 jbyte;
typedef int16 jshort;
typedef int32 jint;
typedef int64 jlong;
typedef void* jref;
/* A 32-bit IEEE single-precision float. */
#ifndef jfloat
#define jfloat float
#endif
/* A 32-bit IEEE double-precision float. */
#ifndef jdouble
#define jdouble double
#endif
union Word {
jint i;
jfloat f;
void *p;
};
/* A jword is an unsigned integral type big enough for a 32-bit jint
or jfloat *or* a pointer. It is the type appropriate for stack
locations and local variables in a Java interpreter. */
#ifndef jword
#define jword uint32
#endif
#if !defined(inline) && !defined(__GC__) && !defined(__cplusplus)
#define inline static
#endif
#ifndef IMMEDIATE_u1
#define IMMEDIATE_u1 (PC++, CHECK_PC_IN_RANGE(PC), BCODE[PC-1])
#endif
#ifndef IMMEDIATE_s1
#define IMMEDIATE_s1 (PC++, CHECK_PC_IN_RANGE(PC), (signed char)BCODE[PC-1])
#endif
#ifndef IMMEDIATE_s2
#define IMMEDIATE_s2 (PC+=2, CHECK_PC_IN_RANGE(PC), \
(signed char) BCODE[PC-2] * 256 + BCODE[PC-1])
#endif
#ifndef IMMEDIATE_u2
#define IMMEDIATE_u2 (PC+=2, CHECK_PC_IN_RANGE(PC),\
(BCODE[PC-2] * 256 + BCODE[PC-1]))
#endif
#ifndef IMMEDIATE_s4
#define IMMEDIATE_s4 (PC+=4, CHECK_PC_IN_RANGE(PC), \
((jint)((BCODE[PC-4] << 24) | (BCODE[PC-3] << 16) \
| (BCODE[PC-2] << 8) | (BCODE[PC-1]))))
#endif
inline jfloat
WORD_TO_FLOAT(jword w)
{ union Word wu;
wu.i = w;
return wu.f;
}
inline jlong
WORDS_TO_LONG(jword hi, jword lo)
{
return ((jlong) hi << 32) | ((jlong)lo & (((jlong)1 << 32) -1));
}
union DWord {
jdouble d;
jlong l;
jword w[2];
};
inline jdouble
WORDS_TO_DOUBLE(jword hi, jword lo)
{ union DWord wu;
wu.l = WORDS_TO_LONG(hi, lo);
return wu.d;
}
/* If PREFIX_CHAR is the first character of the Utf8 encoding of a character,
return the number of bytes taken by the encoding.
Return -1 for a continuation character. */
#define UT8_CHAR_LENGTH(PREFIX_CHAR) \
((unsigned char)(PREFIX_CHAR) < 128 ? 1 \
: ((PREFIX_CHAR) & 0x40) == 0 ? -1 \
: ((PREFIX_CHAR) & 0x20) == 0 ? 2 \
: ((PREFIX_CHAR) & 0x10) == 0 ? 3 \
: ((PREFIX_CHAR) & 0x08) == 0 ? 4 : 5)
#endif /* !JAVAOP_H */
/* This file read a Java(TM) .class file.
It is not stand-alone: It depends on tons of macros, and the
intent is you #include this file after you've defined the macros.
Copyright (C) 1996 Free Software Foundation, 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 2, 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "jcf.h"
#include "zipfile.h"
int
DEFUN(get_attribute, (jcf),
JCF *jcf)
{
uint16 attribute_name = (JCF_FILL (jcf, 6), JCF_readu2 (jcf));
uint32 attribute_length = JCF_readu4 (jcf);
uint32 start_pos = JCF_TELL(jcf);
int name_length;
unsigned char *name_data;
JCF_FILL (jcf, attribute_length);
if (attribute_name <= 0 || attribute_name >= JPOOL_SIZE(jcf))
return -2;
if (JPOOL_TAG (jcf, attribute_name) != CONSTANT_Utf8)
return -2;
name_length = JPOOL_UTF_LENGTH (jcf, attribute_name);
name_data = JPOOL_UTF_DATA (jcf, attribute_name);
#ifdef IGNORE_ATTRIBUTE
if (IGNORE_ATTRIBUTE (jcf, attribute_name, attribute_length))
{
JCF_SKIP (jcf, attribute_length);
}
else
#endif
#ifdef HANDLE_SOURCEFILE
if (name_length == 10 && memcmp (name_data, "SourceFile", 10) == 0)
{
uint16 sourcefile_index = JCF_readu2 (jcf);
HANDLE_SOURCEFILE(sourcefile_index);
}
else
#endif
#ifdef HANDLE_CONSTANTVALUE
if (name_length == 13 && memcmp (name_data, "ConstantValue", 13) == 0)
{
uint16 constantvalue_index = JCF_readu2 (jcf);
if (constantvalue_index <= 0 || constantvalue_index >= JPOOL_SIZE(jcf))
return -2;
HANDLE_CONSTANTVALUE(constantvalue_index);
}
else
#endif
#ifdef HANDLE_CODE_ATTRIBUTE
if (name_length == 4 && memcmp (name_data, "Code", 4) == 0)
{
uint16 j;
uint16 max_stack = JCF_readu2 (jcf);
uint16 max_locals = JCF_readu2 (jcf);
uint32 code_length = JCF_readu4 (jcf);
uint16 exception_table_length, attributes_count;
if (code_length + 12 > attribute_length)
return -1;
HANDLE_CODE_ATTRIBUTE(max_stack, max_locals, code_length);
JCF_SKIP (jcf, code_length);
exception_table_length = JCF_readu2 (jcf);
if (code_length + 8 * exception_table_length + 12 > attribute_length)
return -1;
JCF_SKIP (jcf, 2 * 4 * exception_table_length);
attributes_count = JCF_readu2 (jcf);
for (j = 0; j < attributes_count; j++)
{
int code = get_attribute (jcf);
if (code != 0)
return code;
}
}
else
#endif /* HANDLE_CODE_ATTRIBUTE */
#ifdef HANDLE_EXCEPTIONS_ATTRIBUTE
if (name_length == 10 && memcmp (name_data, "Exceptions", 10) == 0)
{
uint16 count = JCF_readu2 (jcf);
HANDLE_EXCEPTIONS_ATTRIBUTE (count);
}
else
#endif
#ifdef HANDLE_LINENUMBERTABLE_ATTRIBUTE
if (name_length == 15 && memcmp (name_data, "LineNumberTable", 15) == 0)
{
uint16 count = JCF_readu2 (jcf);
HANDLE_LINENUMBERTABLE_ATTRIBUTE (count);
}
else
#endif
#ifdef HANDLE_LOCALVARIABLETABLE_ATTRIBUTE
if (name_length == 18 && memcmp (name_data, "LocalVariableTable", 18) == 0)
{
uint16 count = JCF_readu2 (jcf);
HANDLE_LOCALVARIABLETABLE_ATTRIBUTE (count);
}
else
#endif
{
#ifdef PROCESS_OTHER_ATTRIBUTE
PROCESS_OTHER_ATTRIBUTE(jcf, attribute_name, attribute_length);
#else
JCF_SKIP (jcf, attribute_length);
#endif
}
if (start_pos + attribute_length != JCF_TELL(jcf))
return -1;
return 0;
}
/* Read and handle the pre-amble. */
int
DEFUN(jcf_parse_preamble, (jcf),
JCF* jcf)
{
uint32 magic = (JCF_FILL (jcf, 8), JCF_readu4 (jcf));
uint16 minor_version = JCF_readu2 (jcf);
uint16 major_version = JCF_readu2 (jcf);
#ifdef HANDLE_MAGIC
HANDLE_MAGIC (magic, minor_version, major_version);
#endif
if (magic != 0xcafebabe)
return -1;
else
return 0;
}
/* Read and handle the constant pool.
Return 0 if OK.
Return -2 if a bad cross-reference (index of other constant) was seen.
*/
int
DEFUN(jcf_parse_constant_pool, (jcf),
JCF* jcf)
{
int i, n;
JPOOL_SIZE (jcf) = (JCF_FILL (jcf, 2), JCF_readu2 (jcf));
jcf->cpool.tags = ALLOC (JPOOL_SIZE (jcf));
jcf->cpool.data = ALLOC (sizeof (jword) * JPOOL_SIZE (jcf));
jcf->cpool.tags[0] = 0;
#ifdef HANDLE_START_CONSTANT_POOL
HANDLE_START_CONSTANT_POOL (JPOOL_SIZE (jcf));
#endif
for (i = 1; i < (int) JPOOL_SIZE (jcf); i++)
{
int constant_kind;
/* Make sure at least 9 bytes are available. This is enough
for all fixed-sized constant pool entries (so we don't need many
more JCF_FILL calls below), but is is small enough that
we are guaranteed to not hit EOF (in a valid .class file). */
JCF_FILL (jcf, 9);
constant_kind = JCF_readu (jcf);
jcf->cpool.tags[i] = constant_kind;
switch (constant_kind)
{
case CONSTANT_String:
case CONSTANT_Class:
jcf->cpool.data[i] = JCF_readu2 (jcf);
break;
case CONSTANT_Fieldref:
case CONSTANT_Methodref:
case CONSTANT_InterfaceMethodref:
case CONSTANT_NameAndType:
jcf->cpool.data[i] = JCF_readu2 (jcf);
jcf->cpool.data[i] |= JCF_readu2 (jcf) << 16;
break;
case CONSTANT_Integer:
case CONSTANT_Float:
jcf->cpool.data[i] = JCF_readu4 (jcf);
break;
case CONSTANT_Long:
case CONSTANT_Double:
jcf->cpool.data[i] = JCF_readu4 (jcf);
i++; /* These take up two spots in the constant pool */
jcf->cpool.tags[i] = 0;
jcf->cpool.data[i] = JCF_readu4 (jcf);
break;
case CONSTANT_Utf8:
n = JCF_readu2 (jcf);
JCF_FILL (jcf, n);
#ifdef HANDLE_CONSTANT_Utf8
HANDLE_CONSTANT_Utf8(jcf, i, n);
#else
jcf->cpool.data[i] = JCF_TELL(jcf) - 2;
JCF_SKIP (jcf, n);
#endif
break;
default:
return i;
}
}
return 0;
}
/* Read various class flags and numbers. */
void
DEFUN(jcf_parse_class, (jcf),
JCF* jcf)
{
int i;
uint16 interfaces_count;
JCF_FILL (jcf, 8);
jcf->access_flags = JCF_readu2 (jcf);
jcf->this_class = JCF_readu2 (jcf);
jcf->super_class = JCF_readu2 (jcf);
interfaces_count = JCF_readu2 (jcf);
#ifdef HANDLE_CLASS_INFO
HANDLE_CLASS_INFO(jcf->access_flags, jcf->this_class, jcf->super_class, interfaces_count);
#endif
JCF_FILL (jcf, 2 * interfaces_count);
/* Read interfaces. */
for (i = 0; i < interfaces_count; i++)
{
uint16 index = JCF_readu2 (jcf);
#ifdef HANDLE_CLASS_INTERFACE
HANDLE_CLASS_INTERFACE (index);
#endif
}
}
/* Read fields. */
int
DEFUN(jcf_parse_fields, (jcf),
JCF* jcf)
{
int i, j;
uint16 fields_count;
JCF_FILL (jcf, 2);
fields_count = JCF_readu2 (jcf);
#ifdef HANDLE_START_FIELDS
HANDLE_START_FIELDS (fields_count);
#endif
for (i = 0; i < fields_count; i++)
{
uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
uint16 name_index = JCF_readu2 (jcf);
uint16 signature_index = JCF_readu2 (jcf);
uint16 attribute_count = JCF_readu2 (jcf);
#ifdef HANDLE_START_FIELD
HANDLE_START_FIELD (access_flags, name_index, signature_index,
attribute_count);
#endif
for (j = 0; j < attribute_count; j++)
{
int code = get_attribute (jcf);
if (code != 0)
return code;
}
#ifdef HANDLE_END_FIELD
HANDLE_END_FIELD ();
#endif
}
#ifdef HANDLE_END_FIELDS
HANDLE_END_FIELDS ();
#endif
return 0;
}
/* Read methods. */
int
DEFUN(jcf_parse_one_method, (jcf),
JCF* jcf)
{
int i;
uint16 access_flags = (JCF_FILL (jcf, 8), JCF_readu2 (jcf));
uint16 name_index = JCF_readu2 (jcf);
uint16 signature_index = JCF_readu2 (jcf);
uint16 attribute_count = JCF_readu2 (jcf);
#ifdef HANDLE_METHOD
HANDLE_METHOD(access_flags, name_index, signature_index, attribute_count);
#endif
for (i = 0; i < attribute_count; i++)
{
int code = get_attribute (jcf);
if (code != 0)
return code;
}
return 0;
}
int
DEFUN(jcf_parse_methods, (jcf),
JCF* jcf)
{
int i;
uint16 methods_count;
JCF_FILL (jcf, 2);
methods_count = JCF_readu2 (jcf);
#ifdef HANDLE_START_METHODS
HANDLE_START_METHODS (methods_count);
#endif
for (i = 0; i < methods_count; i++)
{
int code = jcf_parse_one_method (jcf);
if (code != 0)
return code;
}
#ifdef HANDLE_END_METHODS
HANDLE_END_METHODS ();
#endif
return 0;
}
/* Read attributes. */
int
DEFUN(jcf_parse_final_attributes, (jcf),
JCF *jcf)
{
int i;
uint16 attributes_count = (JCF_FILL (jcf, 2), JCF_readu2 (jcf));
#ifdef START_FINAL_ATTRIBUTES
START_FINAL_ATTRIBUTES (attributes_count)
#endif
for (i = 0; i < attributes_count; i++)
{
int code = get_attribute (jcf);
if (code != 0)
return code;
}
return 0;
}
/* Utility macros to read Java(TM) .class files and byte codes.
Copyright (C) 1996 Free Software Foundation, 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 2, 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Written by Per Bothner <bothner@cygnus.com>, February 1996. */
#ifndef JCF_H
#define JCF_H
#include "javaop.h"
#ifndef DEFUN
#if defined (__STDC__)
#define AND ,
#define PTR void *
#define DEFUN(name, arglist, args) name(args)
#else
#define PTR char *
#define AND ;
#define DEFUN(name, arglist, args) name arglist args;
#define inline static
#endif
#endif /* !DEFUN */
#ifndef PROTO
#if defined (__STDC__)
#define PROTO(paramlist) paramlist
#else
#define PROTO(paramlist) ()
#endif
#endif
#ifndef JCF_u4
#define JCF_u4 unsigned long
#endif
#ifndef JCF_u2
#define JCF_u2 unsigned short
#endif
#define ALLOC (void*)malloc
#define REALLOC (void*)realloc
#ifndef FREE
#define FREE(PTR) free(PTR)
#endif
#ifdef JCF_word
#define JCF_word JCF_u4
#endif
#define JCF_ZIP 1
#define JCF_CLASS 2
#define JCF_SOURCE 3
struct JCF;
typedef int (*jcf_filbuf_t) PROTO ((struct JCF*, int needed));
typedef struct CPool {
/* Available number of elements in the constants array, before it
must be re-allocated. */
int capacity;
/* The constant_pool_count. */
int count;
uint8* tags;
jword* data;
} CPool;
/* JCF encapsulates the state of reading a Java Class File. */
typedef struct JCF {
unsigned char *buffer;
unsigned char *buffer_end;
unsigned char *read_ptr;
unsigned char *read_end;
int seen_in_zip;
int java_source;
int outofsynch; /* Found a class file out of synch
with the matching source file. */
long zip_offset;
jcf_filbuf_t filbuf;
void *read_state;
char *filename;
char *classname;
void *zipd; /* Directory entry where it was found */
JCF_u2 access_flags, this_class, super_class;
CPool cpool;
} JCF;
/*typedef JCF* JCF_FILE;*/
/* The CPOOL macros take a (pointer to a) CPool.
The JPOOL macros take a (pointer to a) JCF.
Some of the latter should perhaps be deprecated or removed. */
#define CPOOL_COUNT(CPOOL) ((CPOOL)->count)
#define JPOOL_SIZE(JCF) CPOOL_COUNT(&(JCF)->cpool)
#define JPOOL_TAG(JCF, INDEX) ((JCF)->cpool.tags[INDEX])
/* The INDEX'th constant pool entry as a JCF_u4. */
#define CPOOL_UINT(CPOOL, INDEX) ((CPOOL)->data[INDEX])
#define JPOOL_UINT(JCF, INDEX) CPOOL_UINT(&(JCF)->cpool, INDEX) /*deprecated*/
/* The first uint16 of the INDEX'th constant pool entry. */
#define CPOOL_USHORT1(CPOOL, INDEX) ((CPOOL)->data[INDEX] & 0xFFFF)
#define JPOOL_USHORT1(JCF, INDEX) CPOOL_USHORT1(&(JCF)->cpool, INDEX)
/* The second uint16 of the INDEX'th constant pool entry. */
#define CPOOL_USHORT2(CPOOL, INDEX) ((CPOOL)->data[INDEX] >> 16)
#define JPOOL_USHORT2(JCF, INDEX) CPOOL_USHORT2(&(JCF)->cpool, INDEX)
#define JPOOL_LONG(JCF, INDEX) \
WORDS_TO_LONG (JPOOL_UINT(JCF, INDEX), JPOOL_UINT(JCF, (INDEX)+1))
#define JPOOL_DOUBLE(JCF, INDEX) \
WORDS_TO_DOUBLE (JPOOL_UINT(JCF, INDEX), JPOOL_UINT(JCF, (INDEX)+1))
#ifndef JPOOL_UTF_LENGTH
#define JPOOL_UTF_LENGTH(JCF, INDEX) \
GET_u2 ((JCF)->buffer+JPOOL_UINT(JCF, INDEX))
#endif
#ifndef JPOOL_UTF_DATA
#define JPOOL_UTF_DATA(JCF, INDEX) \
((JCF)->buffer+JPOOL_UINT(JCF, INDEX)+2)
#endif
#define JPOOL_INT(JCF, INDEX) ((jint) JPOOL_UINT (JCF, INDEX))
#define JPOOL_FLOAT(JCF, INDEX) WORD_TO_FLOAT (JPOOL_UINT (JCF, INDEX))
#define CPOOL_INDEX_IN_RANGE(CPOOL, INDEX) \
((INDEX) > 0 && (INDEX) < CPOOL_COUNT(CPOOL))
#define CPOOL_FINISH(CPOOL) { \
if ((CPOOL)->tags) FREE ((CPOOL)->tags); \
if ((CPOOL)->data) FREE ((CPOOL)->data); }
#define JCF_FINISH(JCF) { \
CPOOL_FINISH(&(JCF)->cpool); \
if ((JCF)->buffer) FREE ((JCF)->buffer); \
if ((JCF)->filename) FREE ((JCF)->filename); \
if ((JCF)->classname) FREE ((JCF)->classname); }
#define CPOOL_INIT(CPOOL) \
((CPOOL)->capacity = 0, (CPOOL)->count = 0, (CPOOL)->tags = 0, (CPOOL)->data = 0)
#define CPOOL_REINIT(CPOOL) ((CPOOL)->count = 0)
#define JCF_ZERO(JCF) \
((JCF)->buffer = (JCF)->buffer_end = (JCF)->read_ptr = (JCF)->read_end = 0,\
(JCF)->read_state = 0, (JCF)->filename = (JCF)->classname = 0, \
CPOOL_INIT(&(JCF)->cpool), (JCF)->java_source = 0)
/* Given that PTR points to a 2-byte unsigned integer in network
(big-endian) byte-order, return that integer. */
#define GET_u2(PTR) (((PTR)[0] << 8) | ((PTR)[1]))
/* Like GET_u2, but for little-endian format. */
#define GET_u2_le(PTR) (((PTR)[1] << 8) | ((PTR)[0]))
/* Given that PTR points to a 4-byte unsigned integer in network
(big-endian) byte-order, return that integer. */
#define GET_u4(PTR) (((JCF_u4)(PTR)[0] << 24) | ((JCF_u4)(PTR)[1] << 16) \
| ((JCF_u4)(PTR)[2] << 8) | ((JCF_u4)(PTR)[3]))
/* Like GET_u4, but for little-endian order. */
#define GET_u4_le(PTR) (((JCF_u4)(PTR)[3] << 24) | ((JCF_u4)(PTR)[2] << 16) \
| ((JCF_u4)(PTR)[1] << 8) | ((JCF_u4)(PTR)[0]))
/* Make sure there are COUNT bytes readable. */
#define JCF_FILL(JCF, COUNT) \
((JCF)->read_end-(JCF)->read_ptr >= (COUNT) ? 0 : (*(JCF)->filbuf)(JCF, COUNT))
#define JCF_GETC(JCF) (JCF_FILL(JCF, 1) ? -1 : *(JCF)->read_ptr++)
#define JCF_READ(JCF, BUFFER, N) \
(memcpy (BUFFER, (JCF)->read_ptr, N), (JCF)->read_ptr += (N))
#define JCF_SKIP(JCF,N) ((JCF)->read_ptr += (N))
#define JCF_readu(JCF) (*(JCF)->read_ptr++)
/* Reads an unsigned 2-byte integer in network (big-endian) byte-order
from JCF. Returns that integer.
Does not check for EOF (make sure to call JCF_FILL before-hand). */
#define JCF_readu2(JCF) ((JCF)->read_ptr += 2, GET_u2 ((JCF)->read_ptr-2))
#define JCF_readu2_le(JCF) ((JCF)->read_ptr += 2, GET_u2_le((JCF)->read_ptr-2))
/* Like JCF_readu2, but read a 4-byte unsigned integer. */
#define JCF_readu4(JCF) ((JCF)->read_ptr += 4, GET_u4 ((JCF)->read_ptr-4))
#define JCF_readu4_le(JCF) ((JCF)->read_ptr += 4, GET_u4_le((JCF)->read_ptr-4))
#define JCF_TELL(JCF) ((JCF)->read_ptr - (JCF)->buffer)
#define JCF_SEEK(JCF, POS) ((JCF)->read_ptr = (JCF)->buffer + (POS))
#define ACC_PUBLIC 0x0001
#define ACC_PRIVATE 0x0002
#define ACC_PROTECTED 0x0004
#define ACC_STATIC 0x0008
#define ACC_FINAL 0x0010
#define ACC_SYNCHRONIZED 0x0020
#define ACC_SUPER 0x0020
#define ACC_VOLATILE 0x0040
#define ACC_TRANSIENT 0x0080
#define ACC_NATIVE 0x0100
#define ACC_INTERFACE 0x0200
#define ACC_ABSTRACT 0x0400
#define CONSTANT_Class 7
#define CONSTANT_Fieldref 9
#define CONSTANT_Methodref 10
#define CONSTANT_InterfaceMethodref 11
#define CONSTANT_String 8
#define CONSTANT_Integer 3
#define CONSTANT_Float 4
#define CONSTANT_Long 5
#define CONSTANT_Double 6
#define CONSTANT_NameAndType 12
#define CONSTANT_Utf8 1
#define CONSTANT_Unicode 2
extern char *classpath;
#define DEFAULT_CLASS_PATH "."
extern char *find_class PROTO ((const char *, int, JCF*, int));
extern char *find_classfile PROTO ((char *, JCF*));
extern int jcf_filbuf_from_stdio PROTO ((JCF *jcf, int count));
extern void jcf_out_of_synch PROTO((JCF *));
extern int jcf_unexpected_eof PROTO ((JCF*, int));
/* Extract a character from a Java-style Utf8 string.
* PTR points to the current character.
* LIMIT points to the end of the Utf8 string.
* PTR is incremented to point after the character thta gets returns.
* On an error, -1 is returned. */
#define UTF8_GET(PTR, LIMIT) \
((PTR) >= (LIMIT) ? -1 \
: *(PTR) < 128 ? *(PTR)++ \
: (*(PTR)&0xE0) == 0xC0 && ((PTR)+=2)<=(LIMIT) && ((PTR)[-1]&0xC0) == 0x80 \
? (((PTR)[-2] & 0x1F) << 6) + ((PTR)[-1] & 0x3F) \
: (*(PTR) & 0xF0) == 0xE0 && ((PTR) += 3) <= (LIMIT) \
&& ((PTR)[-2] & 0xC0) == 0x80 && ((PTR)[-1] & 0xC0) == 0x80 \
? (((PTR)[-3]&0x1F) << 12) + (((PTR)[-2]&0x3F) << 6) + ((PTR)[-1]&0x3F) \
: ((PTR)++, -1))
/* Debug macros, for the front end */
extern int quiet_flag;
#ifdef SOURCE_FRONTEND_DEBUG
#undef SOURCE_FRONTEND_DEBUG
#define SOURCE_FRONTEND_DEBUG(X) \
{if (!quiet_flag) {printf ("* "); printf X; putchar ('\n');} }
#else
#define SOURCE_FRONTEND_DEBUG(X)
#endif
#endif
/* Main for jv-scan
Copyright (C) 1998 Free Software Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include <stdlib.h>
#ifdef __STDC__
#include <stdarg.h>
#else
#include <varargs.h>
#endif
#include "gansidecl.h" /* Definitions of PROTO and VPROTO */
#include "obstack.h" /* We use obstacks in lex.c */
void fatal VPROTO((char *s, ...));
void warning VPROTO((char *s, ...));
void gcc_obstack_init PROTO ((struct obstack *obstack));
extern void reset_report PROTO ((void));
#define JC1_LITE
#include "parse.h"
/* Current input file and output file IO streams. */
FILE *finput, *out;
/* Current input filename. */
char *input_filename;
/* Executable name. */
char *exec_name;
/* Flags matching command line options. */
int flag_find_main = 0;
int flag_dump_class = 0;
int flag_list_filename = 0;
/* jc1-lite main entry point */
int
main (argc, argv, envp)
int argc;
char **argv;
char **envp;
{
int i = 1;
char *output_file = NULL;
long ft;
exec_name = argv[0];
/* Default for output */
out = stdout;
/* Process options first */
while (argv [i])
{
if (argv [i][0] == '-')
{
/* Dump result into a file */
if (!strcmp (argv [i], "-o") && i+1 < argc)
{
argv [i] = NULL;
output_file = argv [++i];
argv [i] = NULL;
}
/* Print the name of the class that contains main */
else if (!strcmp (argv [i], "--print-main"))
flag_find_main = 1;
else if (!strcmp (argv [i], "--list-filename"))
flag_list_filename = 1;
/* List all the classes found in a source file */
else if (!strcmp (argv [i], "--list-class"))
flag_dump_class = 1;
else
warning ("Unrecognized argument `%s'", argv[i]);
/* non recognized argument ignored silently */
argv [i] = NULL; /* Nullify so it's not considered a file */
}
i++;
}
/* No flags? Do nothing */
if (!flag_find_main && !flag_dump_class)
exit (0);
/* Check on bad usage */
if (flag_find_main && flag_dump_class)
fatal ("Options `--print-main' and `--list-class' can't be turned on "
"at the same time", argv [0]);
if (output_file && !(out = fopen (output_file, "w")))
fatal ("Can't open output file `%s'", argv [0], output_file);
ft = ftell (out);
gcc_obstack_init (&temporary_obstack);
java_push_parser_context ();
for ( i = 1; i < argc; i++ )
if (argv [i])
{
input_filename = argv [i];
if ( (finput = fopen (argv [i], "r")) )
{
java_init_lex ();
yyparse ();
if (ftell (out) != ft)
fputc ('\n', out);
ft = ftell (out);
fclose (finput);
reset_report ();
}
else
fatal ("File not found `%s'", argv [0], argv [i]);
}
/* Flush and close */
if (ftell (out) != ft)
fputc ('\n', out);
if (!output_file)
fclose (out);
exit (0);
}
/* Error report, memory, obstack initialization and other utility
functions */
void
fatal VPROTO((char *s, ...))
{
#ifndef __STDC__
char *s;
#endif
va_list ap;
VA_START (ap, s);
#ifndef __STDC__
s = va_arg (ap, char *);
#endif
fprintf (stderr, "%s: error: ", exec_name);
vfprintf (stderr, s, ap);
fputc ('\n', stderr);
va_end (ap);
exit (1);
}
char *
xmalloc (size)
unsigned size;
{
register char *value;
if (size == 0)
size = 1;
value = (char *) malloc (size);
if (value == 0)
fatal ("virtual memory exhausted");
return value;
}
char *
xstrdup (string)
char *string;
{
int length = strlen (string)+1;
char *to_return = xmalloc (length);
strcpy (to_return, string);
return to_return;
}
void
warning VPROTO((char *s, ...))
{
#ifndef __STDC__
char *s;
#endif
va_list ap;
VA_START (ap, s);
#ifndef __STDC__
s = va_arg (ap, char *);
#endif
fprintf (stderr, "%s: warning: ", exec_name);
vfprintf (stderr, s, ap);
fputc ('\n', stderr);
va_end (ap);
}
void
gcc_obstack_init (obstack)
struct obstack *obstack;
{
/* Let particular systems override the size of a chunk. */
#ifndef OBSTACK_CHUNK_SIZE
#define OBSTACK_CHUNK_SIZE 0
#endif
/* Let them override the alloc and free routines too. */
#ifndef OBSTACK_CHUNK_ALLOC
#define OBSTACK_CHUNK_ALLOC xmalloc
#endif
#ifndef OBSTACK_CHUNK_FREE
#define OBSTACK_CHUNK_FREE free
#endif
_obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
(void *(*) ()) OBSTACK_CHUNK_ALLOC,
(void (*) ()) OBSTACK_CHUNK_FREE);
}
/* Program to generate "main" a Java(TM) class containing a main method.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Written by Per Bothner <bothner@cygnus.com> */
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "obstack.h"
const char main_method_prefix[] = "main__";
const char main_method_suffix[] = "Pt6JArray1ZPQ34java4lang6String";
const char class_mangling_prefix[] = "_CL_";
struct obstack name_obstack;
void
error (const char *str)
{
fprintf (stderr, "%s\n", str);
exit (-1);
}
void *
xmalloc (size)
size_t size;
{
void *ptr = malloc (size);
if (ptr == NULL)
{
fprintf (stderr, "Not enough memory!\n");
exit (-1);
}
return ptr;
}
void
gcc_obstack_init (obstack)
struct obstack *obstack;
{
/* Let particular systems override the size of a chunk. */
#ifndef OBSTACK_CHUNK_SIZE
#define OBSTACK_CHUNK_SIZE 0
#endif
/* Let them override the alloc and free routines too. */
#ifndef OBSTACK_CHUNK_ALLOC
#define OBSTACK_CHUNK_ALLOC xmalloc
#endif
#ifndef OBSTACK_CHUNK_FREE
#define OBSTACK_CHUNK_FREE free
#endif
_obstack_begin (obstack, OBSTACK_CHUNK_SIZE, 0,
(void *(*) ()) OBSTACK_CHUNK_ALLOC,
(void (*) ()) OBSTACK_CHUNK_FREE);
}
int
main (int argc, const char **argv)
{
const char *classname;
FILE *stream;
char *mangled_classname;
if (argc < 2 || argc > 3)
{
fprintf (stderr, "Usage: %s CLASSNAME [OUTFILE]\n", argv[0]);
exit(-1);
}
classname = argv[1];
gcc_obstack_init (&name_obstack);
append_gpp_mangled_classtype (&name_obstack, classname);
mangled_classname = obstack_finish (&name_obstack);
if (argc > 2 && strcmp (argv[2], "-") != 0)
{
const char *outfile = argv[2];
stream = fopen (outfile, "w");
if (stream == NULL)
{
fprintf (stderr, "%s: Cannot open output file: %s\n",
argv[0], outfile);
exit (-1);
}
}
else
stream = stdout;
fprintf (stream, "extern struct Class %s%s;\n",
class_mangling_prefix, mangled_classname);
fprintf (stream, "int main (int argc, const char **argv)\n");
fprintf (stream, "{\n");
fprintf (stream, " JvRunMain (&%s%s, argc, argv);\n",
class_mangling_prefix, mangled_classname);
fprintf (stream, "}\n");
if (stream != stdout && fclose (stream) != 0)
{
fprintf (stderr, "%s: Failed to close output file %s\n",
argv[0], argv[2]);
exit (-1);
}
return 0;
}
/* Specific flags and argument handling of the front-end of the
GNU compiler for the Java(TM) language.
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
#include "config.h"
#include "system.h"
#include "gansidecl.h"
#if defined (WITH_THREAD_posix) || defined (WITH_THREAD_pthreads)
#define THREAD_NAME "-lpthread"
#elif defined (WITH_THREAD_qt)
#define THREAD_NAME "-lqthreads"
#endif
/* This bit is set if we saw a `-xfoo' language specification. */
#define LANGSPEC (1<<1)
/* This bit is set if they did `-lm' or `-lmath'. */
#define MATHLIB (1<<2)
/* This bit is set if they did `-lc'. */
#define WITHLIBC (1<<3)
/* This bit is set if they did `-lgc'. */
#define GCLIB (1<<4)
/* This bit is set if they did `-lpthread' (or added some other thread
library). */
#define THREADLIB (1<<5)
#ifndef MATH_LIBRARY
#define MATH_LIBRARY "-lm"
#endif
extern char *xmalloc PROTO((size_t));
extern int do_spec PROTO((char *));
extern char *input_filename;
extern size_t input_filename_length;
char *main_class_name = NULL;
int lang_specific_extra_outfiles = 0;
char jvgenmain_spec[] =
"jvgenmain %i %{!pipe:%g.i} |\n\
cc1 %{!pipe:%g.i} %1 \
%{!Q:-quiet} -dumpbase %b.c %{d*} %{m*} %{a*}\
%{g*} %{O*} \
%{v:-version} %{pg:-p} %{p} %{f*}\
%{aux-info*}\
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
%{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
%{!S:as %a %Y -o %w%b%O %{!pipe:%g.s} %A\n }";
void
lang_specific_driver (fn, in_argc, in_argv, in_added_libraries)
void (*fn)();
int *in_argc;
char ***in_argv;
int *in_added_libraries;
{
int i, j;
/* If non-zero, the user gave us the `-v' flag. */
int saw_verbose_flag = 0;
/* This will be 0 if we encounter a situation where we should not
link in libjava. */
int library = 1;
/* The number of arguments being added to what's in argv, other than
libraries. We use this to track the number of times we've inserted
-xc++/-xnone. */
int added = 2;
/* Used to track options that take arguments, so we don't go wrapping
those with -xc++/-xnone. */
char *quote = NULL;
/* The new argument list will be contained in this. */
char **arglist;
/* Non-zero if we saw a `-xfoo' language specification on the
command line. Used to avoid adding our own -xc++ if the user
already gave a language for the file. */
int saw_speclang = 0;
/* "-lm" or "-lmath" if it appears on the command line. */
char *saw_math = 0;
/* "-lc" if it appears on the command line. */
char *saw_libc = 0;
/* "-lgc" if it appears on the command line. */
char *saw_gc = 0;
/* Saw `-l' option for the thread library. */
char *saw_threadlib = 0;
/* Saw `-ljava' on command line. */
int saw_libjava = 0;
/* An array used to flag each argument that needs a bit set for
LANGSPEC, MATHLIB, WITHLIBC, or GCLIB. */
int *args;
/* By default, we throw on the math library. */
int need_math = 1;
/* By default, we throw in the thread library (if one is required).
*/
int need_thread = 1;
/* The total number of arguments with the new stuff. */
int argc;
/* The argument list. */
char **argv;
/* The number of libraries added in. */
int added_libraries;
/* The total number of arguments with the new stuff. */
int num_args = 1;
argc = *in_argc;
argv = *in_argv;
added_libraries = *in_added_libraries;
args = (int *) xmalloc (argc * sizeof (int));
bzero ((char *) args, argc * sizeof (int));
for (i = 1; i < argc; i++)
{
/* If the previous option took an argument, we swallow it here. */
if (quote)
{
quote = NULL;
continue;
}
/* We don't do this anymore, since we don't get them with minus
signs on them. */
if (argv[i][0] == '\0' || argv[i][1] == '\0')
continue;
if (argv[i][0] == '-')
{
if (library != 0 && (strcmp (argv[i], "-nostdlib") == 0
|| strcmp (argv[i], "-nodefaultlibs") == 0))
{
library = 0;
}
else if (strcmp (argv[i], "-lm") == 0
|| strcmp (argv[i], "-lmath") == 0
#ifdef ALT_LIBM
|| strcmp (argv[i], ALT_LIBM) == 0
#endif
)
{
args[i] |= MATHLIB;
need_math = 0;
}
else if (strncmp (argv[i], "-fmain=", 7) == 0)
main_class_name = argv[i] + 7;
else if (strcmp (argv[i], "-ljava") == 0)
saw_libjava = 1;
else if (strcmp (argv[i], "-lc") == 0)
args[i] |= WITHLIBC;
else if (strcmp (argv[i], "-lgc") == 0)
args[i] |= GCLIB;
#ifdef THREAD_NAME
else if (strcmp (argv[i], THREAD_NAME) == 0)
{
args[i] |= THREADLIB;
need_thread = 0;
}
#endif
else if (strcmp (argv[i], "-v") == 0)
{
saw_verbose_flag = 1;
if (argc == 2)
{
/* If they only gave us `-v', don't try to link
in libjava. */
library = 0;
}
}
else if (strncmp (argv[i], "-x", 2) == 0)
saw_speclang = 1;
else if (((argv[i][2] == '\0'
&& (char *)strchr ("bBVDUoeTuIYmLiA", argv[i][1]) != NULL)
|| strcmp (argv[i], "-Tdata") == 0))
quote = argv[i];
else if (library != 0 && ((argv[i][2] == '\0'
&& (char *) strchr ("cSEM", argv[i][1]) != NULL)
|| strcmp (argv[i], "-MM") == 0))
{
/* Don't specify libraries if we won't link, since that would
cause a warning. */
library = 0;
added -= 2;
}
else
/* Pass other options through. */
continue;
}
else
{
int len;
if (saw_speclang)
{
saw_speclang = 0;
continue;
}
/* If the filename ends in .c or .i, put options around it.
But not if a specified -x option is currently active. */
len = strlen (argv[i]);
if (len > 2
&& (argv[i][len - 1] == 'c' || argv[i][len - 1] == 'i')
&& argv[i][len - 2] == '.')
{
args[i] |= LANGSPEC;
added += 2;
}
}
}
if (quote)
(*fn) ("argument to `%s' missing\n", quote);
/* If we know we don't have to do anything, bail now. */
if (! added && ! library && main_class_name == NULL)
{
free (args);
return;
}
num_args = argc + added + need_math + need_thread;
if (main_class_name)
{
lang_specific_extra_outfiles++;
}
arglist = (char **) xmalloc (num_args * sizeof (char *));
/* NOTE: We start at 1 now, not 0. */
for (i = 0, j = 0; i < argc; i++, j++)
{
arglist[j] = argv[i];
if (strncmp (argv[i], "-fmain=", 7) == 0)
{
--j;
continue;
}
/* Make sure -ljava is before the math library, since libjava
itself uses those math routines. */
if (!saw_math && (args[i] & MATHLIB) && library)
{
--j;
saw_math = argv[i];
}
/* Likewise -ljava must come before -lc. */
if (!saw_libc && (args[i] & WITHLIBC) && library)
{
--j;
saw_libc = argv[i];
}
/* And -ljava must come before -lgc. */
if (!saw_gc && (args[i] & GCLIB) && library)
{
--j;
saw_gc = argv[i];
}
/* And -ljava must come before thread library. */
if (!saw_threadlib && (args[i] & THREADLIB) && library)
{
--j;
saw_threadlib = argv[i];
}
}
/* Add `-ljava' if we haven't already done so. */
if (library && ! saw_libjava)
{
arglist[j++] = "-ljava";
added_libraries++;
}
if (saw_math)
arglist[j++] = saw_math;
else if (library)
{
arglist[j++] = MATH_LIBRARY;
added_libraries++;
}
/* FIXME: we need a way to know when the GC library should be
added. Then we can add it if the user hasn't already. */
if (saw_gc)
arglist[j++] = saw_gc;
/* Thread library must come after GC library as well as after
-ljava. */
if (saw_threadlib)
arglist[j++] = saw_threadlib;
#ifdef THREAD_NAME
else if (library)
{
arglist[j++] = THREAD_NAME;
added_libraries++;
}
#endif
if (saw_libc)
arglist[j++] = saw_libc;
arglist[j] = NULL;
*in_argc = j;
*in_argv = arglist;
*in_added_libraries = added_libraries;
}
int
lang_specific_pre_link ()
{
if (main_class_name == NULL)
return 0;
input_filename = main_class_name;
input_filename_length = strlen (main_class_name);
return do_spec (jvgenmain_spec);
}
%{
/* Keyword definition for the GNU compiler for the Java(TM) language.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
%}
struct java_keyword { char *name; int token; };
%%
abstract, ABSTRACT_TK
default, DEFAULT_TK
if, IF_TK
private, PRIVATE_TK
throw, THROW_TK
boolean, BOOLEAN_TK
do, DO_TK
implements, IMPLEMENTS_TK
protected, PROTECTED_TK
throws, THROWS_TK
break, BREAK_TK
double, DOUBLE_TK
import, IMPORT_TK
public, PUBLIC_TK
transient, TRANSIENT_TK
byte, BYTE_TK
else, ELSE_TK
instanceof, INSTANCEOF_TK
return, RETURN_TK
try, TRY_TK
case, CASE_TK
extends, EXTENDS_TK
int, INT_TK
short, SHORT_TK
void, VOID_TK
catch, CATCH_TK
final, FINAL_TK
interface, INTERFACE_TK
static, STATIC_TK
volatile, VOLATILE_TK
char, CHAR_TK
finally, FINALLY_TK
long, LONG_TK
super, SUPER_TK
while, WHILE_TK
class, CLASS_TK
float, FLOAT_TK
native, NATIVE_TK
switch, SWITCH_TK
const, CONST_TK
for, FOR_TK
new, NEW_TK
synchronized, SYNCHRONIZED_TK
continue, CONTINUE_TK
goto, GOTO_TK
package, PACKAGE_TK
this, THIS_TK
# true, false and null aren't keyword. But we match them easily this way
true, TRUE_TK
false, FALSE_TK
null, NULL_TK
/* C code produced by gperf version 2.5 (GNU C++ version) */
/* Command-line: gperf -p -t -j1 -i 1 -g -o -N java_keyword -k1,3,$ keyword.gperf */
/* Keyword definitions for the GNU compiler for the Java(TM) language.
Copyright (C) 1997, 1998 Free Software Foundation, Inc.
Contributed by Alexandre Petit-Bianco (apbianco@cygnus.com)
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
struct java_keyword { char *name; int token; };
#define TOTAL_KEYWORDS 50
#define MIN_WORD_LENGTH 2
#define MAX_WORD_LENGTH 12
#define MIN_HASH_VALUE 6
#define MAX_HASH_VALUE 86
/* maximum key range = 81, duplicates = 0 */
#ifdef __GNUC__
inline
#endif
static unsigned int
hash (str, len)
register char *str;
register int unsigned len;
{
static unsigned char asso_values[] =
{
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 87, 87, 87,
87, 87, 87, 87, 87, 87, 87, 18, 37, 38,
27, 1, 30, 3, 12, 8, 87, 2, 11, 87,
8, 1, 5, 87, 24, 1, 1, 30, 2, 36,
87, 1, 87, 87, 87, 87, 87, 87,
};
register int hval = len;
switch (hval)
{
default:
case 3:
hval += asso_values[str[2]];
case 2:
case 1:
hval += asso_values[str[0]];
break;
}
return hval + asso_values[str[len - 1]];
}
#ifdef __GNUC__
inline
#endif
struct java_keyword *
java_keyword (str, len)
register char *str;
register unsigned int len;
{
static struct java_keyword wordlist[] =
{
{"",}, {"",}, {"",}, {"",}, {"",}, {"",},
{"try", TRY_TK},
{"else", ELSE_TK},
{"short", SHORT_TK},
{"goto", GOTO_TK},
{"extends", EXTENDS_TK},
{"",}, {"",},
{"int", INT_TK},
{"this", THIS_TK},
{"",},
{"native", NATIVE_TK},
{"",}, {"",},
{"interface", INTERFACE_TK},
{"import", IMPORT_TK},
{"private", PRIVATE_TK},
{"volatile", VOLATILE_TK},
{"",},
{"implements", IMPLEMENTS_TK},
{"",},
{"long", LONG_TK},
{"switch", SWITCH_TK},
{"abstract", ABSTRACT_TK},
{"transient", TRANSIENT_TK},
{"do", DO_TK},
{"",},
{"throws", THROWS_TK},
{"",},
{"null", NULL_TK},
{"super", SUPER_TK},
{"true", TRUE_TK},
{"float", FLOAT_TK},
{"",},
{"return", RETURN_TK},
{"if", IF_TK},
{"void", VOID_TK},
{"protected", PROTECTED_TK},
{"byte", BYTE_TK},
{"case", CASE_TK},
{"break", BREAK_TK},
{"finally", FINALLY_TK},
{"false", FALSE_TK},
{"synchronized", SYNCHRONIZED_TK},
{"instanceof", INSTANCEOF_TK},
{"while", WHILE_TK},
{"package", PACKAGE_TK},
{"const", CONST_TK},
{"boolean", BOOLEAN_TK},
{"final", FINAL_TK},
{"continue", CONTINUE_TK},
{"catch", CATCH_TK},
{"",}, {"",}, {"",}, {"",}, {"",},
{"class", CLASS_TK},
{"static", STATIC_TK},
{"double", DOUBLE_TK},
{"default", DEFAULT_TK},
{"throw", THROW_TK},
{"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",}, {"",},
{"",}, {"",}, {"",}, {"",}, {"",},
{"for", FOR_TK},
{"",},
{"new", NEW_TK},
{"char", CHAR_TK},
{"",},
{"public", PUBLIC_TK},
};
if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
{
register int key = hash (str, len);
if (key <= MAX_HASH_VALUE && key >= 0)
{
register char *s = wordlist[key].name;
if (*s == *str && !strcmp (str + 1, s + 1))
return &wordlist[key];
}
}
return 0;
}
/* Switch definitions for the GNU compiler for the Java(TM) language.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* This is the contribution to the `lang_options' array in gcc.c for
java. */
DEFINE_LANG_NAME ("Java")
{ "-fbounds-check", "" },
{ "-fno-bounds-check", "Disable automatic array bounds checking" },
{ "-fassume-compiled", "Make is_compiled_class return 1"},
{ "-fno-assume-compiled", "" },
{ "-femit-class-file", "" },
{ "-femit-class-files", "Dump class files to <name>.class" },
/* Definitions for specs for the GNU compiler for the Java(TM) language.
Copyright (C) 1996 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* This is the contribution to the `default_compilers' array in gcc.c for
Java. */
{".java", "@java" },
{".class", "@java" },
{"@java",
"%{!M:%{!MM:%{!E:jc1 %i %1 %2 %{!Q:-quiet} %{d*} %{m*} %{a}\
%{g*} %{O*} %{W*} %{w} %{pedantic*} %{ansi}\
%{traditional} %{v:-version} %{pg:-p} %{p}\
%{f*} %{+e*} %{aux-info*}\
%{pg:%{fomit-frame-pointer:%e-pg and -fomit-frame-pointer are incompatible}}\
%{S:%W{o*}%{!o*:-o %b.s}}%{!S:-o %{|!pipe:%g.s}} |\n\
%{!S:as %a %Y\
%{c:%W{o*}%{!o*:-o %w%b%O}}%{!c:-o %d%w%u%O}\
%{!pipe:%g.s} %A\n }}}}"},
/* Java(TM) language-specific utility routines.
Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Hacked by Per Bothner <bothner@cygnus.com> February 1996. */
#include <stdio.h>
#include "config.h"
#include "tree.h"
#include "input.h"
#include "java-tree.h"
#include "jcf.h"
int compiling_from_source;
char *language_string = "GNU Java";
/* Nonzero if we want to automatically do array bounds checking;
on by default. Use -fno-bounds-check to disable. */
int flag_bounds_check = 1;
/* Nonzero if we should make is_compiled_class always return 1 for
appropriate classes that we're referencing. */
int flag_assume_compiled = 1;
int flag_emit_class_files = 0;
/* From gcc/flags.h, and idicates if exceptions are turned on or not. */
extern int flag_new_exceptions;
extern int flag_exceptions;
/* Table of language-dependent -f options.
STRING is the option name. VARIABLE is the address of the variable.
ON_VALUE is the value to store in VARIABLE
if `-fSTRING' is seen as an option.
(If `-fno-STRING' is seen as an option, the opposite value is stored.) */
static struct { char *string; int *variable; int on_value;} lang_f_options[] =
{
{"bounds-check", &flag_bounds_check, 1},
{"assume-compiled", &flag_assume_compiled, 1},
{"emit-class-file", &flag_emit_class_files, 1},
{"emit-class-files", &flag_emit_class_files, 1},
};
JCF main_jcf[1];
JCF *current_jcf;
/*
* process java-specific compiler command-line options
*/
int
lang_decode_option (argc, argv)
int argc;
char **argv;
{
char *p = argv[0];
if (p[0] == '-' && p[1] == 'f')
{
/* Some kind of -f option.
P's value is the option sans `-f'.
Search for it in the table of options. */
int found = 0, j;
p += 2;
for (j = 0;
!found && j < sizeof (lang_f_options) / sizeof (lang_f_options[0]);
j++)
{
if (!strcmp (p, lang_f_options[j].string))
{
*lang_f_options[j].variable = lang_f_options[j].on_value;
/* A goto here would be cleaner,
but breaks the vax pcc. */
found = 1;
}
if (p[0] == 'n' && p[1] == 'o' && p[2] == '-'
&& ! strcmp (p+3, lang_f_options[j].string))
{
*lang_f_options[j].variable = ! lang_f_options[j].on_value;
found = 1;
}
}
return found;
}
return 0;
}
FILE *finput;
char *
init_parse (filename)
char *filename;
{
/* Open input file. */
if (filename == 0 || !strcmp (filename, "-"))
{
finput = stdin;
filename = "stdin";
}
else
finput = fopen (filename, "r");
if (finput == 0)
pfatal_with_name (filename);
#ifdef IO_BUFFER_SIZE
setvbuf (finput, (char *) xmalloc (IO_BUFFER_SIZE), _IOFBF, IO_BUFFER_SIZE);
#endif
init_lex ();
return filename;
}
void
finish_parse ()
{
fclose (finput);
}
/* Buffer used by lang_printable_name. */
static char *decl_buf = NULL;
/* Allocated size of decl_buf. */
static int decl_buflen = 0;
/* Length of used part of decl_buf; position for next character. */
static int decl_bufpos = 0;
/* Append the string STR to decl_buf.
It length is given by LEN; -1 means the string is nul-terminated. */
static void
put_decl_string (str, len)
char *str;
int len;
{
if (len < 0)
len = strlen (str);
if (decl_bufpos + len >= decl_buflen)
{
if (decl_buf == NULL)
{
decl_buflen = len + 100;
decl_buf = (char *) xmalloc (decl_buflen);
}
else
{
decl_buflen *= 2;
decl_buf = (char *) xrealloc (decl_buf, decl_buflen);
}
}
strcpy (decl_buf + decl_bufpos, str);
decl_bufpos += len;
}
/* Append to decl_buf a printable name for NODE. */
static void
put_decl_node (node)
tree node;
{
int was_pointer = 0;
if (TREE_CODE (node) == POINTER_TYPE)
{
node = TREE_TYPE (node);
was_pointer = 1;
}
if (TREE_CODE_CLASS (TREE_CODE (node)) == 'd'
&& DECL_NAME (node) != NULL_TREE)
{
#if 0
if (DECL_CONTEXT (node) != NULL_TREE)
{
put_decl_node (DECL_CONTEXT (node));
put_decl_string (".", 1);
}
#endif
put_decl_node (DECL_NAME (node));
if (TREE_CODE (node) == FUNCTION_DECL && TREE_TYPE (node) != NULL_TREE)
{
int i = 0;
tree args = TYPE_ARG_TYPES (TREE_TYPE (node));
if (TREE_CODE (TREE_TYPE (node)) == METHOD_TYPE)
args = TREE_CHAIN (args);
put_decl_string ("(", 1);
for ( ; args != NULL_TREE; args = TREE_CHAIN (args), i++)
{
if (i > 0)
put_decl_string (",", 1);
put_decl_node (TREE_VALUE (args));
}
put_decl_string (")", 1);
}
}
else if (TREE_CODE_CLASS (TREE_CODE (node)) == 't'
&& TYPE_NAME (node) != NULL_TREE)
{
if (TREE_CODE (node) == RECORD_TYPE && TYPE_ARRAY_P (node))
{
put_decl_node (TYPE_ARRAY_ELEMENT (node));
put_decl_string("[]", 2);
}
else if (node == promoted_byte_type_node)
put_decl_string ("byte", 4);
else if (node == promoted_short_type_node)
put_decl_string ("short", 5);
else if (node == promoted_char_type_node)
put_decl_string ("char", 4);
else if (node == promoted_boolean_type_node)
put_decl_string ("boolean", 7);
else if (node == void_type_node && was_pointer)
put_decl_string ("null", 4);
else
put_decl_node (TYPE_NAME (node));
}
else if (TREE_CODE (node) == IDENTIFIER_NODE)
put_decl_string (IDENTIFIER_POINTER (node), IDENTIFIER_LENGTH (node));
else
put_decl_string ("<unknown>", -1);
}
/* Return a user-friendly name for DECL.
The resulting string is only valid until the next call.
The value of the hook decl_printable_name is this function,
which is also called directly by lang_print_error. */
char *
lang_printable_name (decl, v)
tree decl;
int v;
{
decl_bufpos = 0;
put_decl_node (decl);
put_decl_string ("", 1);
return decl_buf;
}
/* Print on stderr the current class and method context. This function
is the value of the hook print_error_function, called from toplev.c. */
void
lang_print_error (file)
char *file;
{
static tree last_error_function_context = NULL_TREE;
static tree last_error_function = NULL;
if (current_function_decl != NULL
&& DECL_CONTEXT (current_function_decl) != last_error_function_context)
{
if (file)
fprintf (stderr, "%s: ", file);
last_error_function_context = DECL_CONTEXT (current_function_decl);
fprintf (stderr, "In class `%s':\n",
lang_printable_name (last_error_function_context));
}
if (last_error_function != current_function_decl)
{
if (file)
fprintf (stderr, "%s: ", file);
if (current_function_decl == NULL)
fprintf (stderr, "At top level:\n");
else
{
char *name = lang_printable_name (current_function_decl, 2);
fprintf (stderr, "In method `%s':\n", name);
}
last_error_function = current_function_decl;
}
}
void
lang_init ()
{
extern struct rtx_def * java_lang_expand_expr ();
extern struct rtx_def * (*lang_expand_expr) ();
extern void (*print_error_function) PROTO((char *));
#if 0
extern int flag_minimal_debug;
flag_minimal_debug = 0;
#endif
decl_printable_name = lang_printable_name;
print_error_function = lang_print_error;
lang_expand_expr = java_lang_expand_expr;
JCF_ZERO (main_jcf);
main_jcf->read_state = finput;
main_jcf->filbuf = jcf_filbuf_from_stdio;
current_jcf = main_jcf;
flag_exceptions = 1;
}
/* This doesn't do anything on purpose. It's used to satisfy the
print_error_function hook we don't print error messages with bogus
function prototypes. */
void java_dummy_print (s)
char *s;
{
}
/* Called to install the PRINT_ERROR_FUNCTION hook differently
according to LEVEL. LEVEL is 1 during early parsing, when function
prototypes aren't fully resolved. print_error_function is set so it
doesn't print incomplete function prototypes. When LEVEL is 2,
function prototypes are fully resolved and can be printed when
reporting errors. */
void lang_init_source (level)
int level;
{
extern void (*print_error_function) PROTO((char *));
if (level == 1)
print_error_function = java_dummy_print;
else
print_error_function = lang_print_error;
}
void
lang_init_options ()
{
flag_new_exceptions = 1;
}
void
lang_finish ()
{
}
char*
lang_identify ()
{
return "Java";
}
/* Hooks for print_node. */
void
print_lang_decl (file, node, indent)
FILE *file;
tree node;
int indent;
{
}
void
print_lang_type (file, node, indent)
FILE *file;
tree node;
int indent;
{
}
void
print_lang_identifier (file, node, indent)
FILE *file;
tree node;
int indent;
{
}
void
print_lang_statistics ()
{
}
/* used by print-tree.c */
void
lang_print_xnode (file, node, indent)
FILE *file;
tree node;
int indent;
{
}
This diff is collapsed. Click to expand it.
This diff is collapsed. Click to expand it.
/* Functions related to mangling class names for the GNU compiler
for the Java(TM) language.
Copyright (C) 1998 Free Software Foundation, Inc.
This file is part of GNU CC.
GNU CC 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 2, or (at your option)
any later version.
GNU CC 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
/* Written by Per Bothner <bothner@cygnus.com> */
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "jcf.h"
#include "obstack.h"
/* Assuming (NAME, LEN) is a Utf8-encoding string, calculate
the length of the string as mangled (a la g++) including Unicode escapes.
If no escapes are needed, return 0. */
int
unicode_mangling_length (name, len)
char *name;
int len;
{
unsigned char *ptr;
unsigned char *limit = (unsigned char *)name + len;
int need_escapes = 0;
int num_chars = 0;
int underscores = 0;
for (ptr = (unsigned char *) name; ptr < limit; )
{
int ch = UTF8_GET(ptr, limit);
if (ch < 0)
error ("internal error - invalid Utf8 name");
if (ch >= '0' && ch <= '9')
need_escapes += num_chars == 0;
else if (ch == '_')
underscores++;
else if ((ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z'))
need_escapes++;
num_chars++;
}
if (need_escapes)
return num_chars + 4 * (need_escapes + underscores);
else
return 0;
}
/* Assuming (NAME, LEN) is a Utf8-encoding string, emit the string
appropriately mangled (with Unicode escapes) to OBSTACK. */
void
emit_unicode_mangled_name (obstack, name, len)
struct obstack *obstack;
char *name;
{
unsigned char *ptr;
unsigned char *limit = (unsigned char *)name + len;
for (ptr = (unsigned char *) name; ptr < limit; )
{
int ch = UTF8_GET(ptr, limit);
int emit_escape;
if (ch < 0)
{
error ("internal error - bad Utf8 string");
break;
}
if (ch >= '0' && ch <= '9')
emit_escape = (ptr == (unsigned char*) name);
else
emit_escape = (ch < 'a' || ch > 'z') && (ch < 'A' || ch > 'Z');
if (emit_escape)
{
char buf[6];
sprintf (buf, "_%04x", ch);
obstack_grow (obstack, buf, 5);
}
else
{
obstack_1grow (obstack, ch);
}
}
}
/* Assuming (NAME, LEN) is a Utf8-encoding string, emit the string
appropriately mangled (with Unicode escapes if needed) to OBSTACK. */
void
append_gpp_mangled_name (obstack, name, len)
struct obstack *obstack;
char *name;
int len;
{
int encoded_len = unicode_mangling_length (name, len);
int needs_escapes = encoded_len > 0;
char buf[6];
if (needs_escapes)
{
sprintf (buf, "U%d", encoded_len);
obstack_grow (obstack, buf, strlen(buf));
emit_unicode_mangled_name (obstack, name, len);
}
else
{
sprintf (buf, "%d", len);
obstack_grow (obstack, buf, strlen(buf));
obstack_grow (obstack, name, len);
}
}
/* Append the mangled name of a class named CLASSNAME onto OBSTACK. */
void
append_gpp_mangled_classtype (obstack, class_name)
struct obstack *obstack;
char *class_name;
{
char *ptr;
int qualifications = 0;
for (ptr = class_name; *ptr != '\0'; ptr++)
{
if (*ptr == '.')
qualifications++;
}
if (qualifications)
{
char buf[8];
if (qualifications >= 9)
sprintf (buf, "Q_%d_", qualifications + 1);
else
sprintf (buf, "Q%d", qualifications + 1);
obstack_grow (obstack, buf, strlen (buf));
}
for (ptr = class_name; ; ptr++)
{
if (ptr[0] == '.' || ptr[0] == '\0')
{
append_gpp_mangled_name (obstack, class_name, ptr - class_name);
if (ptr[0] == '\0')
break;
class_name = ptr + 1;
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
/* Definitions for using a zipped' archive.
Copyright (C) 1996 Free Software Foundation, 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 2, 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 GNU CC; see the file COPYING. If not, write to
the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Java and all Java-based marks are trademarks or registered trademarks
of Sun Microsystems, Inc. in the United States and other countries.
The Free Software Foundation is independent of Sun Microsystems, Inc. */
struct ZipFile {
int fd;
long size;
long count;
long dir_size;
char *central_directory;
};
typedef struct ZipFile ZipFile;
struct ZipDirectory {
int direntry_size;
int filename_offset;
long size; /* length of file */
long filestart; /* start of file in archive */
long filename_length;
/* char mid_padding[...]; */
/* char filename[filename_length]; */
/* char end_padding[...]; */
};
typedef struct ZipDirectory ZipDirectory;
struct ZipFileCache {
struct ZipFile z;
struct ZipFileCache *next;
char *name;
};
extern struct ZipFileCache *SeenZipFiles;
#define ZIPDIR_FILENAME(ZIPD) ((char*)(ZIPD)+(ZIPD)->filename_offset)
#define ZIPDIR_NEXT(ZIPD) \
((ZipDirectory*)((char*)(ZIPD)+(ZIPD)->direntry_size))
#define ZIPMAGIC 0x504b0304
Markdown is supported
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