1 /* src/vm/jit/verify/typecheck-builtins.inc - type checking for ICMD_BUILTIN
3 Copyright (C) 1996-2005, 2006, 2007, 2008
4 CACAOVM - Verein zur Foerderung der freien virtuellen Maschine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #define ISBUILTIN(v) (bte->fp == (functionptr) (v))
29 builtintable_entry *bte;
31 bte = state->iptr->sx.s23.s3.bte;
33 /* XXX this is an ugly if-chain but twisti did not want a function */
34 /* pointer in builtintable_entry for this, so here you go.. ;) */
36 if (ISBUILTIN(BUILTIN_new)) {
38 #if defined(TYPECHECK_TYPEINFERER)
39 assert(state->iptr[-1].opc == ICMD_ACONST);
40 typeinfo_init_class(&(dv->typeinfo), state->iptr[-1].sx.val.c);
42 if (state->iptr[-1].opc != ICMD_ACONST)
43 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_new without class");
44 TYPEINFO_INIT_NEWOBJECT(dv->typeinfo,state->iptr);
47 else if (ISBUILTIN(BUILTIN_newarray_boolean)) {
50 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BOOLEAN);
52 else if (ISBUILTIN(BUILTIN_newarray_char)) {
55 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_CHAR);
57 else if (ISBUILTIN(BUILTIN_newarray_float)) {
60 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_FLOAT);
62 else if (ISBUILTIN(BUILTIN_newarray_double)) {
65 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_DOUBLE);
67 else if (ISBUILTIN(BUILTIN_newarray_byte)) {
70 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BYTE);
72 else if (ISBUILTIN(BUILTIN_newarray_short)) {
75 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_SHORT);
77 else if (ISBUILTIN(BUILTIN_newarray_int)) {
80 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_INT);
82 else if (ISBUILTIN(BUILTIN_newarray_long)) {
85 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_LONG);
87 else if (ISBUILTIN(BUILTIN_newarray))
90 if (state->iptr[-1].opc != ICMD_ACONST)
91 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without class");
92 /* XXX check that it is an array class(ref) */
94 typeinfo_init_class(&(dv->typeinfo),state->iptr[-1].sx.val.c);
96 else if (ISBUILTIN(BUILTIN_arrayinstanceof))
99 if (state->iptr[-1].opc != ICMD_ACONST)
100 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_arrayinstanceof without class");
102 /* XXX check that it is an array class(ref) */
107 #if !defined(TYPECHECK_TYPEINFERER)
110 #if defined(TYPECHECK_STACKBASED)
111 typedescriptor_t *av;
114 /* verify a generic builtin call */
116 TYPECHECK_COUNT(stat_ins_builtin_gen);
119 #if !defined(TYPECHECK_TYPEINFERER)
122 /* check the types of the arguments on the stack */
124 #if defined(TYPECHECK_STACKBASED)
125 av = stack - (md->paramslots - 1);
128 for (i--; i >= 0; i--) {
129 #if defined(TYPECHECK_VARIABLESBASED)
130 varinfo *av = VAR(state->iptr->sx.s23.s2.args[i]);
133 if (av->type != md->paramtypes[i].type) {
134 TYPECHECK_VERIFYERROR_bool("parameter type mismatch for builtin method");
137 #ifdef TYPECHECK_DEBUG
138 /* generic builtins may only take primitive types and java.lang.Object references */
139 if (av->type == TYPE_ADR && md->paramtypes[i].classref->name != utf_java_lang_Object) {
140 exceptions_throw_internalerror("generic builtin method with non-generic reference parameter");
145 #if defined(TYPECHECK_STACKBASED)
146 av += (IS_2_WORD_TYPE(av->type)) ? 2 : 1;
149 #endif /* !defined(TYPECHECK_TYPEINFERER) */
151 /* set the return type */
153 rtype = md->returntype.type;
154 if (rtype != TYPE_VOID) {
156 if (!typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dv->typeinfo)))
165 * These are local overrides for various environment variables in Emacs.
166 * Please do not remove this and leave it at the end of the file, where
167 * Emacs will automagically detect them.
168 * ---------------------------------------------------------------------
171 * indent-tabs-mode: t
175 * vim:noexpandtab:sw=4:ts=4:filetype=c: