+/* stack_create_locals *********************************************************
+
+ Create the local variables for the start of the given basic block.
+
+ IN:
+ sd...........stack analysis data
+ b............block to create the locals for
+
+*******************************************************************************/
+
+static void stack_create_locals(stackdata_t *sd, basicblock *b)
+{
+ s4 i;
+ s4 *jl;
+ varinfo *dv;
+
+ /* copy the current state of the local variables */
+ /* (one extra local is needed by the verifier) */
+
+ dv = DMNEW(varinfo, sd->localcount + VERIFIER_EXTRA_LOCALS);
+ b->inlocals = dv;
+ for (i=0; i<sd->localcount; ++i)
+ *dv++ = sd->var[i];
+
+ /* the current map from java locals to cacao variables */
+
+ jl = DMNEW(s4, sd->maxlocals);
+ b->javalocals = jl;
+ MCOPY(jl, sd->javalocals, s4, sd->maxlocals);
+}
+
+
+/* stack_merge_locals **********************************************************
+
+ Merge local variables at the beginning of the given basic block.
+
+ IN:
+ sd...........stack analysis data
+ b............the block that is reached
+
+*******************************************************************************/
+
+static void stack_merge_locals(stackdata_t *sd, basicblock *b)
+{
+ s4 i;
+ varinfo *dv;
+ varinfo *sv;
+
+ /* If a javalocal is mapped to different cacao locals along the */
+ /* incoming control-flow edges, it becomes undefined. */
+
+ for (i=0; i<sd->maxlocals; ++i) {
+ if (b->javalocals[i] != UNUSED && b->javalocals[i] != sd->javalocals[i]) {
+ b->javalocals[i] = UNUSED;
+ if (b->flags >= BBFINISHED)
+ b->flags = BBTYPECHECK_REACHED;
+ if (b->nr <= sd->bptr->nr)
+ sd->repeat = true;
+ }
+ }
+
+#if defined(ENABLE_VERIFIER)
+ if (b->inlocals) {
+ for (i=0; i<sd->localcount; ++i) {
+ dv = b->inlocals + i;
+ sv = sd->var + i;
+ if ((sv->type == TYPE_RET && dv->type == TYPE_RET)
+ && (sv->SBRSTART != dv->SBRSTART))
+ {
+#if defined(STACK_VERBOSE)
+ printf("JSR MISMATCH: setting variable %d to VOID\n", i);
+#endif
+ dv->type = TYPE_VOID;
+ if (b->flags >= BBFINISHED)
+ b->flags = BBTYPECHECK_REACHED;
+ sd->repeat = true; /* This is very rare, so just repeat */
+ }
+ }
+ }
+#endif /* defined(ENABLE_VERIFIER) */
+}
+
+