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
28 #define ISBUILTIN(v) (bte->fp == (functionptr) (v))
31 builtintable_entry *bte;
33 bte = state->iptr->sx.s23.s3.bte;
35 /* XXX this is an ugly if-chain but twisti did not want a function */
36 /* pointer in builtintable_entry for this, so here you go.. ;) */
38 if (ISBUILTIN(BUILTIN_new)) {
40 #if defined(TYPECHECK_TYPEINFERER)
41 assert(state->iptr[-1].opc == ICMD_ACONST);
42 typeinfo_init_class(&(dv->typeinfo), state->iptr[-1].sx.val.c);
44 if (state->iptr[-1].opc != ICMD_ACONST)
45 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_new without class");
46 TYPEINFO_INIT_NEWOBJECT(dv->typeinfo,state->iptr);
49 else if (ISBUILTIN(BUILTIN_newarray_boolean)) {
52 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BOOLEAN);
54 else if (ISBUILTIN(BUILTIN_newarray_char)) {
57 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_CHAR);
59 else if (ISBUILTIN(BUILTIN_newarray_float)) {
62 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_FLOAT);
64 else if (ISBUILTIN(BUILTIN_newarray_double)) {
67 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_DOUBLE);
69 else if (ISBUILTIN(BUILTIN_newarray_byte)) {
72 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BYTE);
74 else if (ISBUILTIN(BUILTIN_newarray_short)) {
77 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_SHORT);
79 else if (ISBUILTIN(BUILTIN_newarray_int)) {
82 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_INT);
84 else if (ISBUILTIN(BUILTIN_newarray_long)) {
87 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_LONG);
89 else if (ISBUILTIN(BUILTIN_newarray))
92 if (state->iptr[-1].opc != ICMD_ACONST)
93 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without class");
94 /* XXX check that it is an array class(ref) */
96 typeinfo_init_class(&(dv->typeinfo),state->iptr[-1].sx.val.c);
98 else if (ISBUILTIN(BUILTIN_arrayinstanceof))
101 if (state->iptr[-1].opc != ICMD_ACONST)
102 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_arrayinstanceof without class");
104 /* XXX check that it is an array class(ref) */
109 #if !defined(TYPECHECK_TYPEINFERER)
112 #if defined(TYPECHECK_STACKBASED)
116 /* verify a generic builtin call */
118 TYPECHECK_COUNT(stat_ins_builtin_gen);
121 #if !defined(TYPECHECK_TYPEINFERER)
124 /* check the types of the arguments on the stack */
126 #if defined(TYPECHECK_STACKBASED)
127 av = stack - (md->paramslots - 1);
130 for (i--; i >= 0; i--) {
131 #if defined(TYPECHECK_VARIABLESBASED)
132 varinfo *av = VAR(state->iptr->sx.s23.s2.args[i]);
135 if (av->type != md->paramtypes[i].type) {
136 TYPECHECK_VERIFYERROR_bool("parameter type mismatch for builtin method");
139 #ifdef TYPECHECK_DEBUG
140 /* generic builtins may only take primitive types and java.lang.Object references */
141 if (av->type == TYPE_ADR && md->paramtypes[i].classref->name != utf_java_lang_Object) {
142 exceptions_throw_internalerror("generic builtin method with non-generic reference parameter");
147 #if defined(TYPECHECK_STACKBASED)
148 av += (IS_2_WORD_TYPE(av->type)) ? 2 : 1;
151 #endif /* !defined(TYPECHECK_TYPEINFERER) */
153 /* set the return type */
155 rtype = md->returntype.type;
156 if (rtype != TYPE_VOID) {
158 if (!typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dv->typeinfo)))
167 * These are local overrides for various environment variables in Emacs.
168 * Please do not remove this and leave it at the end of the file, where
169 * Emacs will automagically detect them.
170 * ---------------------------------------------------------------------
173 * indent-tabs-mode: t
177 * vim:noexpandtab:sw=4:ts=4:filetype=c: