1 /* src/vm/jit/verify/typecheck-builtins.inc - type checking for ICMD_BUILTIN
3 Copyright (C) 1996-2005, 2006 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
25 Contact: cacao@cacaojvm.org
27 Authors: Edwin Steiner
36 #define ISBUILTIN(v) (bte->fp == (functionptr) (v))
39 builtintable_entry *bte;
40 classref_or_classinfo cls;
42 bte = state->iptr->sx.s23.s3.bte;
44 /* XXX this is an ugly if-chain but twisti did not want a function */
45 /* pointer in builtintable_entry for this, so here you go.. ;) */
47 if (ISBUILTIN(BUILTIN_new)) {
48 if (state->iptr[-1].opc != ICMD_ACONST)
49 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_new without class");
50 cls = state->iptr[-1].sx.val.c;
52 TYPEINFO_INIT_NEWOBJECT(dv->typeinfo,state->iptr);
54 else if (ISBUILTIN(BUILTIN_newarray_boolean)) {
57 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BOOLEAN);
59 else if (ISBUILTIN(BUILTIN_newarray_char)) {
62 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_CHAR);
64 else if (ISBUILTIN(BUILTIN_newarray_float)) {
67 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_FLOAT);
69 else if (ISBUILTIN(BUILTIN_newarray_double)) {
72 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_DOUBLE);
74 else if (ISBUILTIN(BUILTIN_newarray_byte)) {
77 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_BYTE);
79 else if (ISBUILTIN(BUILTIN_newarray_short)) {
82 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_SHORT);
84 else if (ISBUILTIN(BUILTIN_newarray_int)) {
87 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_INT);
89 else if (ISBUILTIN(BUILTIN_newarray_long)) {
92 TYPEINFO_INIT_PRIMITIVE_ARRAY(dv->typeinfo,ARRAYTYPE_LONG);
94 else if (ISBUILTIN(BUILTIN_newarray))
97 if (state->iptr[-1].opc != ICMD_ACONST)
98 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_newarray without class");
99 /* XXX check that it is an array class(ref) */
101 typeinfo_init_class(&(dv->typeinfo),state->iptr[-1].sx.val.c);
103 else if (ISBUILTIN(BUILTIN_arrayinstanceof))
106 if (state->iptr[-1].opc != ICMD_ACONST)
107 TYPECHECK_VERIFYERROR_bool("illegal instruction: builtin_arrayinstanceof without class");
109 /* XXX check that it is an array class(ref) */
115 #if defined(TYPECHECK_STACKBASED)
119 /* verify a generic builtin call */
121 TYPECHECK_COUNT(stat_ins_builtin_gen);
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 *exceptionptr = new_internalerror("generic builtin method with non-generic reference parameter");
149 #if defined(TYPECHECK_STACKBASED)
150 av += (IS_2_WORD_TYPE(av->type)) ? 2 : 1;
154 /* set the return type */
156 rtype = md->returntype.type;
157 if (rtype != TYPE_VOID) {
159 if (!typeinfo_init_from_typedesc(&(md->returntype),NULL,&(dv->typeinfo)))
168 * These are local overrides for various environment variables in Emacs.
169 * Please do not remove this and leave it at the end of the file, where
170 * Emacs will automagically detect them.
171 * ---------------------------------------------------------------------
174 * indent-tabs-mode: t
178 * vim:noexpandtab:sw=4:ts=4:filetype=c: