Beispiel #1
0
void generate_block(block b, bool discard, fncode fn)
{
  env_block_push(b->locals);
  generate_decls(b->locals, fn);
  generate_clist(b->sequence, discard, fn);
  env_block_pop();
}
Beispiel #2
0
void generate_for(component init, component condition, component next,
		  component iteration, const char *continue_label,
		  bool discard, fncode fn)
{
  struct whiledata wdata;

  env_block_push(NULL); /* init may have local declarations */
  if (init)
    generate_component(init, NULL, TRUE, fn);

  start_block(NULL, FALSE, discard, fn);
  wdata.continue_label = continue_label;
  wdata.looplab = new_label(fn);
  wdata.mainlab = new_label(fn);
  wdata.endlab = new_label(fn);
  wdata.code = iteration;
  wdata.next = next;

  set_label(wdata.looplab, fn);
  if (condition)
    {
      generate_condition(condition, wdata.mainlab, wmain_code, &wdata,
			 wdata.endlab, NULL, NULL, fn);
      set_label(wdata.endlab, fn);
      if (!discard)
	generate_component(component_undefined, NULL, FALSE, fn);
    }
  else
    wmain_code(&wdata, fn);
  end_block(fn);
  env_block_pop();
}
Beispiel #3
0
static void generate_block(block b, fncode fn)
{
  clist cc = b->sequence;

  env_block_push(b->locals, b->statics);

  if (b->statics)
    for (vlist vl = b->locals; vl; vl = vl->next)
      {
        ulong offset;
        bool is_static;
        variable_class vclass = env_lookup(vl->var, &offset,
                                           false, true, &is_static);
        assert(is_static && vclass == local_var);
        ins_constant(alloc_string(vl->var), fn);
        mexecute(g_get_static, NULL, 1, fn);
        ins1(op_assign + vclass, offset, fn);
      }

  /* Generate code for sequence */
  for (; cc; cc = cc->next)
    {
      generate_component(cc->c, fn);
      if (cc->next) ins0(op_discard, fn);
    }

  for (vlist vl = b->locals; vl; vl = vl->next)
    if (!vl->was_written)
      if (!vl->was_read)
	warning_line(b->filename, b->nicename, vl->lineno,
                     "local variable %s is unused", vl->var);
      else
	warning_line(b->filename, b->nicename, vl->lineno,
                     "local variable %s is never written", vl->var);
    else if (!vl->was_read)
      warning_line(b->filename, b->nicename, vl->lineno,
                   "local variable %s is never read", vl->var);
  env_block_pop();
}