1 /* src/vm/jit/parse.c - parser for JavaVM to intermediate code translation
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
29 Changes: Carolyn Oates
34 $Id: parse.c 4921 2006-05-15 14:24:36Z twisti $
46 #include "mm/memory.h"
47 #include "native/native.h"
48 #include "toolbox/logging.h"
49 #include "vm/builtin.h"
50 #include "vm/exceptions.h"
51 #include "vm/global.h"
52 #include "vm/linker.h"
53 #include "vm/loader.h"
54 #include "vm/resolve.h"
55 #include "vm/options.h"
56 #include "vm/statistics.h"
57 #include "vm/stringlocal.h"
58 #include "vm/jit/asmpart.h"
59 #include "vm/jit/jit.h"
60 #include "vm/jit/parse.h"
61 #include "vm/jit/patcher.h"
62 #include "vm/jit/loop/loop.h"
64 /*******************************************************************************
66 function 'parse' scans the JavaVM code and generates intermediate code
68 During parsing the block index table is used to store at bit pos 0
69 a flag which marks basic block starts and at position 1 to 31 the
70 intermediate instruction index. After parsing the block index table
71 is scanned, for marked positions a block is generated and the block
72 number is stored in the block index table.
74 *******************************************************************************/
76 static exceptiontable * fillextable(methodinfo *m,
77 exceptiontable *extable,
78 exceptiontable *raw_extable,
79 int exceptiontablelength,
84 if (exceptiontablelength == 0)
87 b_count = *block_count;
89 for (src = exceptiontablelength-1; src >=0; src--) {
90 /* the start of the handled region becomes a basic block start */
91 p = raw_extable[src].startpc;
92 CHECK_BYTECODE_INDEX(p);
96 p = raw_extable[src].endpc; /* see JVM Spec 4.7.3 */
97 CHECK_BYTECODE_INDEX_EXCLUSIVE(p);
99 #if defined(ENABLE_VERIFIER)
100 if (p <= raw_extable[src].startpc) {
101 *exceptionptr = new_verifyerror(m,
102 "Invalid exception handler range");
108 /* end of handled region becomes a basic block boundary */
109 /* (If it is the bytecode end, we'll use the special */
110 /* end block that is created anyway.) */
111 if (p < m->jcodelength)
114 /* the start of the handler becomes a basic block start */
115 p = raw_extable[src].handlerpc;
116 CHECK_BYTECODE_INDEX(p);
117 extable->handlerpc = p;
120 extable->catchtype = raw_extable[src].catchtype;
121 extable->next = NULL;
122 extable->down = &extable[1];
126 *block_count = b_count;
131 #if defined(ENABLE_VERIFIER)
132 throw_invalid_bytecode_index:
134 new_verifyerror(m, "Illegal bytecode index in exception table");
139 /*** macro for checking the length of the bytecode ***/
141 #if defined(ENABLE_VERIFIER)
142 #define CHECK_END_OF_BYTECODE(neededlength) \
144 if ((neededlength) > m->jcodelength) \
145 goto throw_unexpected_end_of_bytecode; \
147 #else /* !ENABLE_VERIFIER */
148 #define CHECK_END_OF_BYTECODE(neededlength)
149 #endif /* ENABLE_VERIFIER */
151 bool parse(jitdata *jd)
155 int p; /* java instruction counter */
156 int nextp; /* start of next java instruction */
157 int opcode; /* java opcode */
158 int i; /* temporary for different uses (ctrs)*/
159 int ipc = 0; /* intermediate instruction counter */
160 int b_count = 0; /* basic block counter */
161 int s_count = 0; /* stack element counter */
162 bool blockend = false; /* true if basic block end has been reached */
163 bool iswide = false; /* true if last instruction was a wide*/
164 instruction *iptr; /* current ptr into instruction array */
165 int gp; /* global java instruction counter */
167 u1 *instructionstart; /* 1 for pcs which are valid instr. starts */
169 constant_classref *cr;
170 constant_classref *compr;
172 builtintable_entry *bte;
176 unresolved_method *um;
177 resolve_result_t result;
183 /* get required compiler data */
188 /* allocate instruction array and block index table */
190 /* 1 additional for end ipc */
191 m->basicblockindex = DMNEW(s4, m->jcodelength + 1);
192 memset(m->basicblockindex, 0, sizeof(s4) * (m->jcodelength + 1));
194 instructionstart = DMNEW(u1, m->jcodelength + 1);
195 memset(instructionstart, 0, sizeof(u1) * (m->jcodelength + 1));
197 /* 1 additional for TRACEBUILTIN and 4 for MONITORENTER/EXIT */
198 /* additional MONITOREXITS are reached by branches which are 3 bytes */
200 iptr = m->instructions = DMNEW(instruction, m->jcodelength + 5);
202 /* Zero the intermediate instructions array so we don't have any
203 * invalid pointers in it if we cannot finish analyse_stack(). */
205 memset(iptr, 0, sizeof(instruction) * (m->jcodelength + 5));
207 /* compute branch targets of exception table */
210 &(cd->exceptiontable[cd->exceptiontablelength-1]),
212 m->exceptiontablelength,
218 s_count = 1 + m->exceptiontablelength; /* initialize stack element counter */
220 #if defined(ENABLE_THREADS)
221 if (checksync && (m->flags & ACC_SYNCHRONIZED)) {
222 m->isleafmethod = false;
226 /* scan all java instructions */
230 if (m->linenumbercount == 0) {
234 linepcchange = m->linenumbers[0].start_pc;
237 for (p = 0, gp = 0; p < m->jcodelength; gp += (nextp - p), p = nextp) {
239 /* mark this position as a valid instruction start */
240 instructionstart[gp] = 1;
241 if (linepcchange == p) {
242 if (m->linenumbercount > lineindex) {
244 currentline = m->linenumbers[lineindex].line_number;
246 if (lineindex < m->linenumbercount) {
247 linepcchange = m->linenumbers[lineindex].start_pc;
248 if (linepcchange == p)
249 goto next_linenumber;
254 /* fetch next opcode */
256 opcode = code_get_u1(p, m);
258 m->basicblockindex[gp] |= (ipc << 1); /*store intermed cnt*/
260 /* some compilers put a JAVA_NOP after a blockend instruction */
262 if (blockend && (opcode != JAVA_NOP)) {
263 /* start new block */
269 nextp = p + jcommandsize[opcode]; /* compute next instruction start */
271 CHECK_END_OF_BYTECODE(nextp);
273 s_count += stackreq[opcode]; /* compute stack element count */
278 /* pushing constants onto the stack p */
281 LOADCONST_I(code_get_s1(p+1,m));
285 LOADCONST_I(code_get_s2(p+1,m));
289 i = code_get_u1(p + 1, m);
290 goto pushconstantitem;
294 i = code_get_u2(p + 1, m);
298 #if defined(ENABLE_VERIFIER)
299 if (i >= m->class->cpcount) {
300 *exceptionptr = new_verifyerror(m,
301 "Attempt to access constant outside range");
306 switch (m->class->cptags[i]) {
307 case CONSTANT_Integer:
308 LOADCONST_I(((constant_integer *) (m->class->cpinfos[i]))->value);
311 LOADCONST_L(((constant_long *) (m->class->cpinfos[i]))->value);
314 LOADCONST_F(((constant_float *) (m->class->cpinfos[i]))->value);
316 case CONSTANT_Double:
317 LOADCONST_D(((constant_double *) (m->class->cpinfos[i]))->value);
319 case CONSTANT_String:
320 LOADCONST_A(literalstring_new((utf *) (m->class->cpinfos[i])));
323 cr = (constant_classref *) (m->class->cpinfos[i]);
325 if (!resolve_classref(m, cr, resolveLazy, true,
329 /* if not resolved, c == NULL */
332 iptr->target = (void*) 0x02; /* XXX target used temporarily as flag */
336 iptr->target = (void*) 0x03; /* XXX target used temporarily as flag */
341 #if defined(ENABLE_VERIFIER)
343 *exceptionptr = new_verifyerror(m,
344 "Invalid constant type to push");
350 case JAVA_ACONST_NULL:
361 LOADCONST_I(opcode - JAVA_ICONST_0);
366 LOADCONST_L(opcode - JAVA_LCONST_0);
372 LOADCONST_F(opcode - JAVA_FCONST_0);
377 LOADCONST_D(opcode - JAVA_DCONST_0);
380 /* loading variables onto the stack */
386 i = code_get_u1(p + 1,m);
389 i = code_get_u2(p + 1,m);
393 OP1LOAD_ONEWORD(opcode, i);
399 i = code_get_u1(p + 1,m);
402 i = code_get_u2(p + 1,m);
406 OP1LOAD_TWOWORD(opcode, i);
413 OP1LOAD_ONEWORD(ICMD_ILOAD, opcode - JAVA_ILOAD_0);
420 OP1LOAD_TWOWORD(ICMD_LLOAD, opcode - JAVA_LLOAD_0);
427 OP1LOAD_ONEWORD(ICMD_FLOAD, opcode - JAVA_FLOAD_0);
434 OP1LOAD_TWOWORD(ICMD_DLOAD, opcode - JAVA_DLOAD_0);
441 OP1LOAD_ONEWORD(ICMD_ALOAD, opcode - JAVA_ALOAD_0);
444 /* storing stack values into local variables */
450 i = code_get_u1(p + 1,m);
453 i = code_get_u2(p + 1,m);
457 OP1STORE_ONEWORD(opcode, i);
463 i = code_get_u1(p + 1,m);
466 i = code_get_u2(p + 1,m);
470 OP1STORE_TWOWORD(opcode, i);
477 OP1STORE_ONEWORD(ICMD_ISTORE, opcode - JAVA_ISTORE_0);
484 OP1STORE_TWOWORD(ICMD_LSTORE, opcode - JAVA_LSTORE_0);
491 OP1STORE_ONEWORD(ICMD_FSTORE, opcode - JAVA_FSTORE_0);
498 OP1STORE_TWOWORD(ICMD_DSTORE, opcode - JAVA_DSTORE_0);
505 OP1STORE_ONEWORD(ICMD_ASTORE, opcode - JAVA_ASTORE_0);
513 i = code_get_u1(p + 1,m);
514 v = code_get_s1(p + 2,m);
518 i = code_get_u2(p + 1,m);
519 v = code_get_s2(p + 3,m);
528 /* wider index for loading, storing and incrementing */
536 /* managing arrays ****************************************************/
539 switch (code_get_s1(p + 1, m)) {
541 bte = builtintable_get_internal(BUILTIN_newarray_boolean);
544 bte = builtintable_get_internal(BUILTIN_newarray_char);
547 bte = builtintable_get_internal(BUILTIN_newarray_float);
550 bte = builtintable_get_internal(BUILTIN_newarray_double);
553 bte = builtintable_get_internal(BUILTIN_newarray_byte);
556 bte = builtintable_get_internal(BUILTIN_newarray_short);
559 bte = builtintable_get_internal(BUILTIN_newarray_int);
562 bte = builtintable_get_internal(BUILTIN_newarray_long);
564 #if defined(ENABLE_VERIFIER)
566 *exceptionptr = new_verifyerror(m,
567 "Invalid array-type to create");
571 BUILTIN(bte, true, NULL, currentline);
575 i = code_get_u2(p + 1, m);
576 compr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
580 if (!(cr = class_get_classref_multiarray_of(1, compr)))
583 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
586 LOADCONST_A_BUILTIN(c, cr);
587 bte = builtintable_get_internal(BUILTIN_newarray);
588 BUILTIN(bte, true, NULL, currentline);
592 case JAVA_MULTIANEWARRAY:
593 m->isleafmethod = false;
594 i = code_get_u2(p + 1, m);
596 s4 v = code_get_u1(p + 3, m);
598 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
602 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
605 /* if unresolved, c == NULL */
606 OP2AT(opcode, v, c, cr, currentline);
628 i = p + code_get_s2(p + 1,m);
629 CHECK_BYTECODE_INDEX(i);
637 i = p + code_get_s4(p + 1,m);
638 CHECK_BYTECODE_INDEX(i);
646 i = code_get_u1(p + 1,m);
649 i = code_get_u2(p + 1,m);
655 OP1LOAD_ONEWORD(opcode, i);
665 /* zero val.a so no patcher is inserted */
666 /* the type checker may set this later */
673 /* zero val.a so no patcher is inserted */
674 /* the type checker may set this later */
680 /* table jumps ********************************************************/
682 case JAVA_LOOKUPSWITCH:
686 #if defined(ENABLE_VERIFIER)
691 nextp = ALIGN((p + 1), 4);
693 CHECK_END_OF_BYTECODE(nextp + 8);
695 tablep = (s4 *) (m->jcode + nextp);
697 OP2A(opcode, 0, tablep, currentline);
701 j = p + code_get_s4(nextp, m);
702 *tablep = j; /* restore for little endian */
705 CHECK_BYTECODE_INDEX(j);
708 /* number of pairs */
710 num = code_get_u4(nextp, m);
715 CHECK_END_OF_BYTECODE(nextp + 8 * num);
717 for (i = 0; i < num; i++) {
720 j = code_get_s4(nextp, m);
721 *tablep = j; /* restore for little endian */
725 #if defined(ENABLE_VERIFIER)
726 /* check if the lookup table is sorted correctly */
728 if (i && (j <= prevvalue)) {
729 *exceptionptr = new_verifyerror(m, "Unsorted lookup switch");
737 j = p + code_get_s4(nextp,m);
738 *tablep = j; /* restore for little endian */
741 CHECK_BYTECODE_INDEX(j);
749 case JAVA_TABLESWITCH:
755 nextp = ALIGN((p + 1), 4);
757 CHECK_END_OF_BYTECODE(nextp + 12);
759 tablep = (s4 *) (m->jcode + nextp);
761 OP2A(opcode, 0, tablep, currentline);
765 j = p + code_get_s4(nextp, m);
766 *tablep = j; /* restore for little endian */
769 CHECK_BYTECODE_INDEX(j);
774 j = code_get_s4(nextp, m);
775 *tablep = j; /* restore for little endian */
781 num = code_get_s4(nextp, m);
782 *tablep = num; /* restore for little endian */
786 num -= j; /* difference of upper - lower */
788 #if defined(ENABLE_VERIFIER)
790 *exceptionptr = new_verifyerror(m,
791 "invalid TABLESWITCH: upper bound < lower bound");
796 CHECK_END_OF_BYTECODE(nextp + 4 * (num + 1));
798 for (i = 0; i <= num; i++) {
799 j = p + code_get_s4(nextp,m);
800 *tablep = j; /* restore for little endian */
803 CHECK_BYTECODE_INDEX(j);
811 /* load and store of object fields ************************************/
815 m->isleafmethod = false;
824 unresolved_field *uf;
826 i = code_get_u2(p + 1, m);
827 fr = class_getconstant(m->class, i,
832 OP2A_NOINC(opcode, fr->parseddesc.fd->type, fr, currentline);
834 /* only with -noverify, otherwise the typechecker does this */
836 #if defined(ENABLE_VERIFIER)
839 result = resolve_field_lazy(iptr,NULL,m);
840 if (result == resolveFailed)
843 if (result != resolveSucceeded) {
844 uf = create_unresolved_field(m->class,
850 /* store the unresolved_field pointer */
852 /* XXX this will be changed */
854 iptr->target = (void*) 0x01; /* XXX target temporarily used as flag */
859 #if defined(ENABLE_VERIFIER)
870 /* method invocation **************************************************/
872 case JAVA_INVOKESTATIC:
873 i = code_get_u2(p + 1, m);
874 mr = class_getconstant(m->class, i,
879 md = mr->parseddesc.md;
882 if (!descriptor_params_from_paramtypes(md, ACC_STATIC))
887 case JAVA_INVOKEINTERFACE:
888 i = code_get_u2(p + 1, m);
890 mr = class_getconstant(m->class, i,
891 CONSTANT_InterfaceMethodref);
893 goto invoke_nonstatic_method;
895 case JAVA_INVOKESPECIAL:
896 case JAVA_INVOKEVIRTUAL:
897 i = code_get_u2(p + 1, m);
898 mr = class_getconstant(m->class, i,
901 invoke_nonstatic_method:
905 md = mr->parseddesc.md;
908 if (!descriptor_params_from_paramtypes(md, 0))
912 m->isleafmethod = false;
914 OP2A_NOINC(opcode, 0, mr, currentline);
916 /* only with -noverify, otherwise the typechecker does this */
918 #if defined(ENABLE_VERIFIER)
921 result = resolve_method_lazy(iptr,NULL,m);
922 if (result == resolveFailed)
925 if (result != resolveSucceeded) {
926 um = create_unresolved_method(m->class,
932 /* store the unresolved_method pointer */
934 /* XXX this will be changed */
936 iptr->target = (void*) 0x01; /* XXX target temporarily used as flag */
939 /* the method could be resolved */
942 #if defined(ENABLE_VERIFIER)
951 /* miscellaneous object operations ************************************/
954 i = code_get_u2(p + 1, m);
955 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
959 if (!resolve_classref(m, cr, resolveLazy, true, true,
963 LOADCONST_A_BUILTIN(c, cr);
964 bte = builtintable_get_internal(BUILTIN_new);
965 BUILTIN(bte, true, NULL, currentline);
970 i = code_get_u2(p + 1, m);
971 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
975 if (!resolve_classref(m, cr, resolveLazy, true,
979 if (cr->name->text[0] == '[') {
980 /* array type cast-check */
981 OP2AT(opcode, 0, c, cr, currentline);
982 m->isleafmethod = false;
986 /* object type cast-check */
987 OP2AT(opcode, 1, c, cr, currentline);
991 case JAVA_INSTANCEOF:
992 i = code_get_u2(p + 1,m);
993 cr = (constant_classref *) class_getconstant(m->class, i, CONSTANT_Class);
997 if (!resolve_classref(m, cr, resolveLazy, true, true, &c))
1000 if (cr->name->text[0] == '[') {
1001 /* array type cast-check */
1002 LOADCONST_A_BUILTIN(c, cr);
1003 bte = builtintable_get_internal(BUILTIN_arrayinstanceof);
1004 BUILTIN(bte, false, NULL, currentline);
1009 /* object type cast-check */
1010 OP2AT(opcode, 1, c, cr, currentline);
1014 case JAVA_MONITORENTER:
1015 #if defined(ENABLE_THREADS)
1018 bte = builtintable_get_internal(BUILTIN_monitorenter);
1019 BUILTIN(bte, false, NULL, currentline);
1029 case JAVA_MONITOREXIT:
1030 #if defined(ENABLE_THREADS)
1032 bte = builtintable_get_internal(BUILTIN_monitorexit);
1033 BUILTIN(bte, false, NULL, currentline);
1042 /* any other basic operation ******************************************/
1045 #if !SUPPORT_DIVISION
1046 bte = builtintable_get_internal(BUILTIN_idiv);
1047 OP2A(opcode, bte->md->paramcount, bte, currentline);
1048 m->isleafmethod = false;
1055 #if !SUPPORT_DIVISION
1056 bte = builtintable_get_internal(BUILTIN_irem);
1057 OP2A(opcode, bte->md->paramcount, bte, currentline);
1058 m->isleafmethod = false;
1065 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1066 bte = builtintable_get_internal(BUILTIN_ldiv);
1067 OP2A(opcode, bte->md->paramcount, bte, currentline);
1068 m->isleafmethod = false;
1075 #if !(SUPPORT_DIVISION && SUPPORT_LONG && SUPPORT_LONG_DIV)
1076 bte = builtintable_get_internal(BUILTIN_lrem);
1077 OP2A(opcode, bte->md->paramcount, bte, currentline);
1078 m->isleafmethod = false;
1085 #if defined(__I386__)
1088 bte = builtintable_get_internal(BUILTIN_frem);
1089 BUILTIN(bte, false, NULL, currentline);
1094 #if defined(__I386__)
1097 bte = builtintable_get_internal(BUILTIN_drem);
1098 BUILTIN(bte, false, NULL, currentline);
1103 #if defined(__ALPHA__)
1105 bte = builtintable_get_internal(BUILTIN_f2i);
1106 BUILTIN(bte, false, NULL, currentline);
1116 #if defined(__ALPHA__)
1118 bte = builtintable_get_internal(BUILTIN_f2l);
1119 BUILTIN(bte, false, NULL, currentline);
1129 #if defined(__ALPHA__)
1131 bte = builtintable_get_internal(BUILTIN_d2i);
1132 BUILTIN(bte, false, NULL, currentline);
1142 #if defined(__ALPHA__)
1144 bte = builtintable_get_internal(BUILTIN_d2l);
1145 BUILTIN(bte, false, NULL, currentline);
1154 /* check for invalid opcodes if the verifier is enabled */
1155 #if defined(ENABLE_VERIFIER)
1156 case JAVA_BREAKPOINT:
1158 new_verifyerror(m, "Quick instructions shouldn't appear yet.");
1161 case 186: /* unused opcode */
1216 new_verifyerror(m,"Illegal opcode %d at instr %d\n",
1220 #endif /* defined(ENABLE_VERIFIER) */
1223 /* straight-forward translation to ICMD */
1229 #if defined(ENABLE_VERIFIER)
1230 /* If WIDE was used correctly, iswide should have been reset by now. */
1232 *exceptionptr = new_verifyerror(m,
1233 "Illegal instruction: WIDE before incompatible opcode");
1236 #endif /* defined(ENABLE_VERIFIER) */
1240 #if defined(ENABLE_VERIFIER)
1241 if (p != m->jcodelength) {
1242 *exceptionptr = new_verifyerror(m,
1243 "Command-sequence crosses code-boundary");
1248 *exceptionptr = new_verifyerror(m, "Falling off the end of the code");
1251 #endif /* defined(ENABLE_VERIFIER) */
1253 /* adjust block count if target 0 is not first intermediate instruction */
1255 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1))
1258 /* copy local to method variables */
1260 m->instructioncount = ipc;
1261 m->basicblockcount = b_count;
1262 m->stackcount = s_count + m->basicblockcount * m->maxstack;
1264 /* allocate stack table */
1266 m->stack = DMNEW(stackelement, m->stackcount);
1271 bptr = m->basicblocks = DMNEW(basicblock, b_count + 1); /* one more for end ipc */
1276 /* additional block if target 0 is not first intermediate instruction */
1278 if (!m->basicblockindex[0] || (m->basicblockindex[0] > 1)) {
1279 BASICBLOCK_INIT(bptr,m);
1281 bptr->iinstr = m->instructions;
1282 /* bptr->icount is set when the next block is allocated */
1286 bptr[-1].next = bptr;
1289 /* allocate blocks */
1291 for (p = 0; p < m->jcodelength; p++) {
1292 if (m->basicblockindex[p] & 1) {
1293 /* Check if this block starts at the beginning of an */
1295 #if defined(ENABLE_VERIFIER)
1296 if (!instructionstart[p]) {
1297 *exceptionptr = new_verifyerror(m,
1298 "Branch into middle of instruction");
1303 /* allocate the block */
1305 BASICBLOCK_INIT(bptr,m);
1307 bptr->iinstr = m->instructions + (m->basicblockindex[p] >> 1);
1309 bptr[-1].icount = bptr->iinstr - bptr[-1].iinstr;
1311 /* bptr->icount is set when the next block is allocated */
1313 m->basicblockindex[p] = b_count;
1317 bptr[-1].next = bptr;
1321 /* set instruction count of last real block */
1324 bptr[-1].icount = (m->instructions + m->instructioncount) - bptr[-1].iinstr;
1327 /* allocate additional block at end */
1329 BASICBLOCK_INIT(bptr,m);
1331 bptr->instack = bptr->outstack = NULL;
1332 bptr->indepth = bptr->outdepth = 0;
1333 bptr->iinstr = NULL;
1337 /* set basicblock pointers in exception table */
1339 if (cd->exceptiontablelength > 0) {
1340 cd->exceptiontable[cd->exceptiontablelength - 1].down = NULL;
1343 for (i = 0; i < cd->exceptiontablelength; ++i) {
1344 p = cd->exceptiontable[i].startpc;
1345 cd->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1347 p = cd->exceptiontable[i].endpc;
1348 cd->exceptiontable[i].end = (p == m->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1350 p = cd->exceptiontable[i].handlerpc;
1351 cd->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1354 /* XXX activate this if you want to try inlining */
1356 for (i = 0; i < m->exceptiontablelength; ++i) {
1357 p = m->exceptiontable[i].startpc;
1358 m->exceptiontable[i].start = m->basicblocks + m->basicblockindex[p];
1360 p = m->exceptiontable[i].endpc;
1361 m->exceptiontable[i].end = (p == m->jcodelength) ? (m->basicblocks + m->basicblockcount /*+ 1*/) : (m->basicblocks + m->basicblockindex[p]);
1363 p = m->exceptiontable[i].handlerpc;
1364 m->exceptiontable[i].handler = m->basicblocks + m->basicblockindex[p];
1370 /* everything's ok */
1374 #if defined(ENABLE_VERIFIER)
1376 throw_unexpected_end_of_bytecode:
1377 *exceptionptr = new_verifyerror(m, "Unexpected end of bytecode");
1380 throw_invalid_bytecode_index:
1382 new_verifyerror(m, "Illegal target of branch instruction");
1385 throw_illegal_local_variable_number:
1387 new_verifyerror(m, "Illegal local variable number");
1390 #endif /* ENABLE_VERIFIER */
1395 * These are local overrides for various environment variables in Emacs.
1396 * Please do not remove this and leave it at the end of the file, where
1397 * Emacs will automagically detect them.
1398 * ---------------------------------------------------------------------
1401 * indent-tabs-mode: t
1405 * vim:noexpandtab:sw=4:ts=4: