1 /* src/vm/jit/verify/typecheck-builtins.inc - type checking for ICMD_BUILTIN
3 Copyright (C) 1996-2005, 2006, 2007 R. Grafl, A. Krall, C. Kruegel,
4 C. Oates, R. Obermaisser, M. Platter, M. Probst, S. Ring,
5 E. Steiner, C. Thalinger, D. Thuernbeck, P. Tomsich, C. Ullrich,
6 J. Wenninger, Institut f. Computersprachen - TU Wien
8 This file is part of CACAO.
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2, or (at
13 your option) any later version.
15 This program is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 #define ISBUILTIN(v) (bte->fp == (functionptr) (v))
33 builtintable_entry *bte;
35 bte = state->iptr->sx.s23.s3.bte;
37 /* XXX this is an ugly if-chain but twisti did not want a function */
38 /* pointer in builtintable_entry for this, so here you go.. ;) */
40 if (ISBUILTIN(BUILTIN_new)) {
42 #if defined(TYPECHECK_TYPEINFERER)
43 assert(state->iptr[-1].opc == ICMD_ACONST);
44 typeinfo_init_class(&(dv->typeinfo), state->iptr[-1].sx.val.c);
46 if (state->iptr[-1].opc != ICMD_ACONST)
47 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_new without class");
48 TYPEINFO_INIT_NEWOBJECT(dv->typeinfo,state->iptr);
51 else if (ISBUILTIN(BUILTIN_newarray_boolean)) {
54 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BOOLEAN);
56 else if (ISBUILTIN(BUILTIN_newarray_char)) {
59 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_CHAR);
61 else if (ISBUILTIN(BUILTIN_newarray_float)) {
64 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_FLOAT);
66 else if (ISBUILTIN(BUILTIN_newarray_double)) {
69 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_DOUBLE);
71 else if (ISBUILTIN(BUILTIN_newarray_byte)) {
74 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BYTE);
76 else if (ISBUILTIN(BUILTIN_newarray_short)) {
79 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_SHORT);
81 else if (ISBUILTIN(BUILTIN_newarray_int)) {
84 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_INT);
86 else if (ISBUILTIN(BUILTIN_newarray_long)) {
89 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_LONG);
91 else if (ISBUILTIN(BUILTIN_newarray))
94 if (state->iptr[-1].opc != ICMD_ACONST)
95 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without class");
96 /* XXX check that it is an array class(ref) */
98 typeinfo_init_class(&(dv->typeinfo),state->iptr[-1].sx.val.c);
100 else if (ISBUILTIN(BUILTIN_arrayinstanceof))
103 if (state->iptr[-1].opc != ICMD_ACONST)
104 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_arrayinstanceof without class");
106 /* XXX check that it is an array class(ref) */
111 #if !defined(TYPECHECK_TYPEINFERER)
114 #if defined(TYPECHECK_STACKBASED)
118 /* verify a generic builtin call */
120 TYPECHECK_COUNT(stat_ins_builtin_gen);
123 #if !defined(TYPECHECK_TYPEINFERER)
126 /* check the types of the arguments on the stack */
128 #if defined(TYPECHECK_STACKBASED)
129 av = stack - (md->paramslots - 1);
132 for (i--; i >= 0; i--) {
133 #if defined(TYPECHECK_VARIABLESBASED)
134 varinfo *av = VAR(state->iptr->sx.s23.s2.args[i]);
137 if (av->type != md->paramtypes[i].type) {
138 TYPECHECK_VERIFYERROR_bool("parameter type mismatch for builtin method");
141 #ifdef TYPECHECK_DEBUG
142 /* generic builtins may only take primitive types and java.lang.Object references */
143 if (av->type == TYPE_ADR && md->paramtypes[i].classref->name != utf_java_lang_Object) {
144 exceptions_throw_internalerror("generic builtin method with non-generic reference parameter");
149 #if defined(TYPECHECK_STACKBASED)
150 av += (IS_2_WORD_TYPE(av->type)) ? 2 : 1;
153 #endif /* !defined(TYPECHECK_TYPEINFERER) */
155 /* set the return type */
157 rtype = md->returntype.type;
158 if (rtype != TYPE_VOID) {
160 if (!typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dv->typeinfo)))
169 * These are local overrides for various environment variables in Emacs.
170 * Please do not remove this and leave it at the end of the file, where
171 * Emacs will automagically detect them.
172 * ---------------------------------------------------------------------
175 * indent-tabs-mode: t
179 * vim:noexpandtab:sw=4:ts=4:filetype=c: