builtins.c (define_builtin_type, [...]): Delete.

* builtins.c (define_builtin_type, builtin_types): Delete.
	(define_builtin): Rewritten to take just the built-in code,
	the function's name, type and fallback library function name.
	All built-ins used by Java are implicit and BUILT_IN_NORMAL.
	(initialize_builtins): Overhaul to define the GCC builtins
	used by gcj manually, providing the Java run-time's
	implementations as the fallback library function.

	* libjava.lang/MathBuiltin.java: New test case.
	* libjava.lang/MathBuiltin.out: New file.

From-SVN: r67632
This commit is contained in:
Roger Sayle 2003-06-08 18:17:53 +00:00 committed by Roger Sayle
parent f32c53c215
commit 5f158b4400
5 changed files with 124 additions and 98 deletions

View File

@ -1,3 +1,13 @@
2003-06-08 Roger Sayle <roger@eyesopen.com>
* builtins.c (define_builtin_type, builtin_types): Delete.
(define_builtin): Rewritten to take just the built-in code,
the function's name, type and fallback library function name.
All built-ins used by Java are implicit and BUILT_IN_NORMAL.
(initialize_builtins): Overhaul to define the GCC builtins
used by gcj manually, providing the Java run-time's
implementations as the fallback library function.
2003-06-08 Anthony Green <green@redhat.com>
* parse.y (patch_cast): Fix conversions from floating-point to

View File

@ -69,8 +69,7 @@ static tree abs_builtin (tree, tree);
static tree java_build_function_call_expr (tree, tree);
static void define_builtin (enum built_in_function, const char *,
enum built_in_class, tree, int, int);
static tree define_builtin_type (int, int, int, int, int);
tree, const char *);
@ -114,10 +113,6 @@ static GTY(()) struct builtin_record java_builtins[] =
{ { NULL }, { NULL }, NULL, END_BUILTINS }
};
/* This is only used transiently, so we don't mark it as roots for the
GC. */
static tree builtin_types[(int) BT_LAST];
/* Internal functions which implement various builtin conversions. */
@ -163,70 +158,22 @@ java_build_function_call_expr (tree fn, tree arglist)
static void
define_builtin (enum built_in_function val,
const char *name,
enum built_in_class class,
tree type,
int fallback_p,
int implicit)
const char *libname)
{
tree decl;
if (! name || ! type)
return;
if (strncmp (name, "__builtin_", strlen ("__builtin_")) != 0)
abort ();
decl = build_decl (FUNCTION_DECL, get_identifier (name), type);
DECL_EXTERNAL (decl) = 1;
TREE_PUBLIC (decl) = 1;
if (fallback_p)
SET_DECL_ASSEMBLER_NAME (decl,
get_identifier (name + strlen ("__builtin_")));
SET_DECL_ASSEMBLER_NAME (decl, get_identifier (libname));
make_decl_rtl (decl, NULL);
pushdecl (decl);
DECL_BUILT_IN_CLASS (decl) = class;
DECL_BUILT_IN_CLASS (decl) = BUILT_IN_NORMAL;
DECL_FUNCTION_CODE (decl) = val;
implicit_built_in_decls[val] = decl;
built_in_decls[val] = decl;
if (implicit)
implicit_built_in_decls[val] = decl;
}
/* Compute the type for a builtin. */
static tree
define_builtin_type (int ret, int arg1, int arg2, int arg3, int arg4)
{
tree args;
if (builtin_types[ret] == NULL_TREE)
return NULL_TREE;
args = void_list_node;
if (arg4 != -1)
{
if (builtin_types[arg4] == NULL_TREE)
return NULL_TREE;
args = tree_cons (NULL_TREE, builtin_types[arg4], args);
}
if (arg3 != -1)
{
if (builtin_types[arg3] == NULL_TREE)
return NULL_TREE;
args = tree_cons (NULL_TREE, builtin_types[arg3], args);
}
if (arg2 != -1)
{
if (builtin_types[arg2] == NULL_TREE)
return NULL_TREE;
args = tree_cons (NULL_TREE, builtin_types[arg2], args);
}
if (arg1 != -1)
{
if (builtin_types[arg1] == NULL_TREE)
return NULL_TREE;
args = tree_cons (NULL_TREE, builtin_types[arg1], args);
}
return build_function_type (builtin_types[ret], args);
}
@ -235,6 +182,9 @@ define_builtin_type (int ret, int arg1, int arg2, int arg3, int arg4)
void
initialize_builtins (void)
{
tree double_ftype_double, double_ftype_double_double;
tree float_ftype_float, float_ftype_float_float;
tree t;
int i;
for (i = 0; java_builtins[i].builtin_code != END_BUILTINS; ++i)
@ -248,48 +198,39 @@ initialize_builtins (void)
void_list_node = end_params_node;
/* Work around C-specific junk in builtin-types.def. */
#define intmax_type_node NULL_TREE
#define c_size_type_node NULL_TREE
#define const_string_type_node NULL_TREE
#define va_list_ref_type_node NULL_TREE
#define va_list_arg_type_node NULL_TREE
#define flag_isoc99 0
t = tree_cons (NULL_TREE, float_type_node, end_params_node);
float_ftype_float = build_function_type (float_type_node, t);
t = tree_cons (NULL_TREE, float_type_node, t);
float_ftype_float_float = build_function_type (float_type_node, t);
#define DEF_PRIMITIVE_TYPE(ENUM, VALUE) \
builtin_types[(int) ENUM] = VALUE;
#define DEF_FUNCTION_TYPE_0(ENUM, RETURN) \
builtin_types[(int) ENUM] \
= define_builtin_type (RETURN, -1, -1, -1, -1);
#define DEF_FUNCTION_TYPE_1(ENUM, RETURN, ARG1) \
builtin_types[(int) ENUM] \
= define_builtin_type (RETURN, ARG1, -1, -1, -1);
#define DEF_FUNCTION_TYPE_2(ENUM, RETURN, ARG1, ARG2) \
builtin_types[(int) ENUM] \
= define_builtin_type (RETURN, ARG1, ARG2, -1, -1);
#define DEF_FUNCTION_TYPE_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
builtin_types[(int) ENUM] \
= define_builtin_type (RETURN, ARG1, ARG2, ARG3, -1);
#define DEF_FUNCTION_TYPE_4(ENUM, RETURN, ARG1, ARG2, ARG3, ARG4) \
builtin_types[(int) ENUM] \
= define_builtin_type (RETURN, ARG1, ARG2, ARG3, ARG4);
#define DEF_FUNCTION_TYPE_VAR_0(ENUM, RETURN) \
builtin_types[(int) ENUM] = NULL_TREE;
#define DEF_FUNCTION_TYPE_VAR_1(ENUM, RETURN, ARG1) \
builtin_types[(int) ENUM] = NULL_TREE;
#define DEF_FUNCTION_TYPE_VAR_2(ENUM, RETURN, ARG1, ARG2) \
builtin_types[(int) ENUM] = NULL_TREE;
#define DEF_FUNCTION_TYPE_VAR_3(ENUM, RETURN, ARG1, ARG2, ARG3) \
builtin_types[(int) ENUM] = NULL_TREE;
#define DEF_POINTER_TYPE(ENUM, TYPE) \
builtin_types[(int) ENUM] = NULL_TREE;
t = tree_cons (NULL_TREE, double_type_node, end_params_node);
double_ftype_double = build_function_type (double_type_node, t);
t = tree_cons (NULL_TREE, double_type_node, t);
double_ftype_double_double = build_function_type (double_type_node, t);
#include "builtin-types.def"
define_builtin (BUILT_IN_FMOD, "__builtin_fmod",
double_ftype_double_double, "fmod");
define_builtin (BUILT_IN_FMODF, "__builtin_fmodf",
float_ftype_float_float, "fmodf");
#define DEF_BUILTIN(ENUM, NAME, CLASS, TYPE, LIBTYPE, BOTH_P, \
FALLBACK_P, NONANSI_P, ATTRS, IMPLICIT) \
define_builtin (ENUM, NAME, CLASS, builtin_types[TYPE], FALLBACK_P, IMPLICIT);
#include "builtins.def"
define_builtin (BUILT_IN_ATAN, "__builtin_atan",
double_ftype_double, "_ZN4java4lang4Math4atanEd");
define_builtin (BUILT_IN_ATAN2, "__builtin_atan2",
double_ftype_double_double, "_ZN4java4lang4Math5atan2Edd");
define_builtin (BUILT_IN_COS, "__builtin_cos",
double_ftype_double, "_ZN4java4lang4Math3cosEd");
define_builtin (BUILT_IN_EXP, "__builtin_exp",
double_ftype_double, "_ZN4java4lang4Math3expEd");
define_builtin (BUILT_IN_LOG, "__builtin_log",
double_ftype_double, "_ZN4java4lang4Math3logEd");
define_builtin (BUILT_IN_POW, "__builtin_pow",
double_ftype_double_double, "_ZN4java4lang4Math3powEdd");
define_builtin (BUILT_IN_SIN, "__builtin_sin",
double_ftype_double, "_ZN4java4lang4Math3sinEd");
define_builtin (BUILT_IN_SQRT, "__builtin_sqrt",
double_ftype_double, "_ZN4java4lang4Math4sqrtEd");
define_builtin (BUILT_IN_TAN, "__builtin_tan",
double_ftype_double, "_ZN4java4lang4Math3tanEd");
}
/* If the call matches a builtin, return the

View File

@ -1,3 +1,8 @@
2003-06-08 Roger Sayle <roger@eyesopen.com>
* libjava.lang/MathBuiltin.java: New test case.
* libjava.lang/MathBuiltin.out: New file.
2003-06-05 Mark Wielaard <mark@klomp.org>
* libjava.mauve/mauve.exp (test_mauve): Add -wno-deprecated to GCJ.

View File

@ -0,0 +1,70 @@
class MathBuiltin
{
static double abs(double x)
{
return Math.abs(x);
}
static double atan(double x)
{
return Math.atan(x);
}
static double atan2(double x, double y)
{
return Math.atan2(x,y);
}
static double cos(double x)
{
return Math.cos(x);
}
static double exp(double x)
{
return Math.exp(x);
}
static double log(double x)
{
return Math.log(x);
}
static double max(double x, double y)
{
return Math.max(x,y);
}
static double min(double x, double y)
{
return Math.min(x,y);
}
static double pow(double x, double y)
{
return Math.pow(x,y);
}
static double sin(double x)
{
return Math.sin(x);
}
static double sqrt(double x)
{
return Math.sqrt(x);
}
static double tan(double x)
{
return Math.tan(x);
}
public static void main(String argv[])
{
double sum = abs (1.0) + atan (1.0) + atan2 (1.0, 1.0) + cos (1.0)
+ exp (1.0) + log(1.0) + max(1.0, 1.0) + min (1.0, 1.0)
+ pow (1.0, 1.0) + sin (1.0) + sqrt(1.0) + tan(1.0);
}
}