Exemplo n.º 1
0
Arquivo: js.c Projeto: shen390s/elvm
static void js_emit_pc_change(int pc) {
  emit_line("break;");
  emit_line("");
  dec_indent();
  emit_line("case %d:", pc);
  inc_indent();
}
Exemplo n.º 2
0
static int scala_init_state(Data* data) {
  int prev_mc = -1;
  for (int mp = 0; data; data = data->next, mp++) {
    if (data->v) {
      int mc = mp / 1000;
      while (prev_mc != mc) {
        if (prev_mc != -1) {
          dec_indent();
          emit_line("}");
        }
        prev_mc++;
        emit_line("def init%d(): Unit = {", prev_mc);
        inc_indent();
      }
      emit_line("mem(%d) = %d", mp, data->v);
    }
  }

  if (prev_mc != -1) {
    dec_indent();
    emit_line("}");
  }

  return prev_mc + 1;
}
Exemplo n.º 3
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_emit_set_dst(Inst* inst) {
  emit_line("G");
  emit_line("s/^\\([^\\n]*\\)\\n\\([^%c]* %c=\\)[^ ]*/\\2\\1/",
            SED_REG_NAMES[inst->dst.reg], SED_REG_NAMES[inst->dst.reg]);
  emit_line("x");
  emit_line("s/.*//");
}
Exemplo n.º 4
0
void gbB::minimalize_pairs(spairs &new_set)
     /* new_set: array of spair*  */
{
  std::stable_sort(new_set.begin(), new_set.end(), spair_sorter(nvars));
  MonomialTable *montab = MonomialTable::make(nvars);

  //  array_sort(new_set, (compareFcn)spair_compare, 0);
  spairs::iterator first = new_set.begin();
  spairs::iterator next = first;
  spairs::iterator end = new_set.end();
  for ( ; first != end; first = next)
    {
      next = first+1;
      spair *me = *first;
      while (next != end)
        {
          spair *p = *next;
          if (!exponents_equal(nvars, me->lcm, p->lcm)) break;
          next++;
        }
      /* At this point: [first,next) is the range of equal monomials */

      int inideal = montab->find_divisors(1, me->lcm, 1);
      if (inideal == 0)
        {
          spairs::iterator t = choose_pair(first, next);
          spair *p = *t;
          if (_is_ideal && is_gcd_one_pair(p))
            {
              stats_ngcd1++;
              if ((M2_gbTrace & PRINT_SPAIR_TRACKING) != 0)
                {
                  buffer o;
                  o << "removing spair because of gcd: ";
                  spair_text_out(o, p);
                  emit_line(o.str());
                }
              spair_delete(p);
            }
          else
            {
              if (M2_gbTrace >= 4)
                {
                  buffer o;
                  o << "    new ";
                  spair_text_out(o,p);
                  emit_line(o.str());
                }
              spair_set_insert(p);
              montab->insert(p->lcm, 1, 0);
            }
          *t = 0;
        }
    }

  delete montab;
  for (spairs::iterator i = new_set.begin(); i != new_set.end(); i++)
    spair_delete(*i);
}
Exemplo n.º 5
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_emit_jmp(Inst* inst) {
  if (inst->jmp.type == REG) {
    sed_emit_value(&inst->jmp);
    emit_line("bjmp_reg");
  } else {
    emit_line("bpc_%x", inst->jmp.imm);
  }
}
Exemplo n.º 6
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_emit_jmp_table(int last_pc) {
  emit_line("");
  emit_line(":jmp_reg");
  emit_line("s/^/000/");
  emit_line("s/.*\\(....\\)/\\1/");
  char reg[5];
  sed_emit_jmp_table_rec(0, reg, 0, last_pc);
}
Exemplo n.º 7
0
static void scala_emit_func_epilogue(void) {
  dec_indent();
  emit_line("}");
  emit_line("pc += 1");
  dec_indent();
  emit_line("}");
  dec_indent();
  emit_line("}");
}
Exemplo n.º 8
0
Arquivo: js.c Projeto: shen390s/elvm
static void js_emit_func_epilogue(void) {
  dec_indent();
  emit_line("}");
  emit_line("pc++;");
  dec_indent();
  emit_line("}");
  dec_indent();
  emit_line("};");
}
Exemplo n.º 9
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_emit_value(Value* v) {
  if (v->type == REG) {
    emit_line("G");
    emit_line("s/\\n[^%c]* %c=\\([^ ]*\\).*/\\1/",
              SED_REG_NAMES[v->reg], SED_REG_NAMES[v->reg]);
  } else {
    emit_line("s/$/%x/", v->imm);
  }
}
Exemplo n.º 10
0
Arquivo: lua.c Projeto: shen390s/elvm
static void lua_emit_func_epilogue(void) {
  dec_indent();
  emit_line("end");
  emit_line("pc = pc + 1");
  dec_indent();
  emit_line("end");
  dec_indent();
  emit_line("end");
}
Exemplo n.º 11
0
gbB::spair *gbB::spair_set_next()
  /* Removes the next element of the current degree, returning NULL if none left */
{
  spair *result = S->spair_list;
  if (result)
    {
      S->spair_list = result->next;
    }
  else
    {
      if (S->spair_deferred_list.next != 0)
        {
          if (M2_gbTrace >= 4)
            {
              emit_line("considering deferred pairs: ");
            }
          S->spair_list = S->spair_deferred_list.next;
          S->spair_deferred_list.next = 0;
          S->spair_last_deferred = &S->spair_deferred_list;
          result = S->spair_list;
          S->spair_list = result->next;
        }
      else
        {
          // Now do the same for generators
          result = S->gen_list;
          if (result)
            {
              S->gen_list = result->next;
            }
          else
            {
              if (S->gen_deferred_list.next != 0)
                {
                  if (M2_gbTrace >= 4)
                    {
                      emit_line("  deferred gen pairs: ");
                    }
                  S->gen_list = S->gen_deferred_list.next;
                  S->gen_deferred_list.next = 0;
                  S->gen_last_deferred = &S->gen_deferred_list;
                  result = S->gen_list;
                  S->gen_list = result->next;
                }
              else
                return 0;
            }
        }
    }

  result->next = 0;
  S->nelems--;
  S->n_in_degree--;
  S->n_computed++;
  return result;
}
Exemplo n.º 12
0
Arquivo: js.c Projeto: shen390s/elvm
static void js_emit_func_prologue(int func_id) {
  emit_line("");
  emit_line("var func%d = function() {", func_id);
  inc_indent();
  emit_line("while (%d <= pc && pc < %d && running) {",
            func_id * CHUNKED_FUNC_SIZE, (func_id + 1) * CHUNKED_FUNC_SIZE);
  inc_indent();
  emit_line("switch (pc) {");
  emit_line("case -1:  // dummy");
  inc_indent();
}
Exemplo n.º 13
0
void gbB::show() const
{
  buffer o;
  o << "Groebner basis, " << gb.size() << " elements";
  emit_line(o.str()); o.reset();
  for (unsigned int i=0; i<gb.size(); i++)
    {
      gbelem_text_out(o,i);
      emit_line(o.str());
      o.reset();
    }
}
Exemplo n.º 14
0
Arquivo: lua.c Projeto: shen390s/elvm
static void lua_emit_func_prologue(int func_id) {
  emit_line("");
  emit_line("function func%d()", func_id);
  inc_indent();
  emit_line("");

  emit_line("while %d <= pc and pc < %d do",
            func_id * CHUNKED_FUNC_SIZE, (func_id + 1) * CHUNKED_FUNC_SIZE);
  inc_indent();
  emit_line("if false then");
  inc_indent();
}
Exemplo n.º 15
0
Arquivo: lua.c Projeto: shen390s/elvm
static void init_state_lua(Data* data) {
  for (int i = 0; i < 7; i++) {
    emit_line("%s = 0", reg_names[i]);
  }
  emit_line("mem = {}");
  emit_line("for _ = 0, ((1 << 24) -1) do mem[_] = 0; end");
  for (int mp = 0; data; data = data->next, mp++) {
    if (data->v) {
      emit_line("mem[%d] = %d", mp, data->v);
    }
  }
}
Exemplo n.º 16
0
static void scala_emit_func_prologue(int func_id) {
  emit_line("");
  emit_line("private def func%d(): Unit = {", func_id);
  inc_indent();
  emit_line("while (%d <= pc && pc < %d) {",
            func_id * CHUNKED_FUNC_SIZE, (func_id + 1) * CHUNKED_FUNC_SIZE);
  inc_indent();
  emit_line("pc match {");
  inc_indent();
  emit_line("case -1 => () /* dummy */");
  dec_indent();
  inc_indent();
}
Exemplo n.º 17
0
Arquivo: js.c Projeto: shen390s/elvm
static void init_state_js(Data* data) {
  emit_line("var main = function(getchar, putchar) {");

  for (int i = 0; i < 7; i++) {
    emit_line("var %s = 0;", reg_names[i]);
  }
  emit_line("var mem = new Int32Array(1 << 24);");
  for (int mp = 0; data; data = data->next, mp++) {
    if (data->v) {
      emit_line("mem[%d] = %d;", mp, data->v);
    }
  }
}
Exemplo n.º 18
0
Computation /* or null */*
rawStartComputation(Computation *C)
  /* start or continue the computation */
{
     try {
          clear_emit_size();
          C->start_computation();

          if (M2_gbTrace == 15)
            {
              ComputationStatusCode ret = C->status();
              switch (ret) {
              case COMP_DONE_DEGREE_LIMIT:
                emit_line("computation stopped at degree limit");
                break;
              case COMP_DONE:
                emit_line("computation of GB completed");
                break;
              case COMP_DONE_PAIR_LIMIT:
                emit_line("computation stopped at pair limit");
                break;
              case COMP_NEED_RESIZE:
              case COMP_ERROR:
              case COMP_INTERRUPTED:
              case COMP_NOT_STARTED:
              case COMP_INITIAL_STOP:
              case COMP_DONE_LENGTH_LIMIT:
              case COMP_DONE_SYZYGY_LIMIT:
              case COMP_DONE_GB_LIMIT:
              case COMP_DONE_SYZ_LIMIT:
              case COMP_DONE_CODIM:
              case COMP_DONE_MIN_GENS:
              case COMP_DONE_STEPS:
              case COMP_DONE_SUBRING_LIMIT:
              case COMP_COMPUTING:
              case COMP_OVERFLOWED:
                emit_line("computation stopped for some good reason");
                break;
              default:
                emit_line("incorrect status code encountered");
                break;
              }
            }

          return error() ? 0 : C;
     }
     catch (exc::engine_error e) {
          ERROR(e.what());
          return NULL;
     }
}
Exemplo n.º 19
0
void gbB::remove_unneeded_pairs(int id)
{
  /* Removes all pairs from C->S that are not needed */
  spair head;
  spair *p = &head;
  gbelem *m = gb[id];

  head.next = S->heap;
  while (p->next != 0)
    if (pair_not_needed(p->next, m))
      {
        nsaved_unneeded++;
        spair *tmp = p->next;
        p->next = tmp->next;
        tmp->next = 0;
        if (M2_gbTrace >= 10)
          {
            buffer o;
            o << "removing unneeded ";
            spair_text_out(o, tmp);
            emit_line(o.str());
          }
        spair_delete(tmp);
        S->nelems--;
      }
  else
    p = p->next;
  S->heap = head.next;
}
Exemplo n.º 20
0
/************************************************************************
 * FPOP - pop to a previous level of input stream
 *
 * ARGUMENTS - none
 *
 * RETURNS  
 *	TRUE if successful, FALSE if the stack is empty
 *
 * SIDE EFFECTS  
 *	- Linenumber is restored to the old files line number
 *	- Filename is reset to the old filename
 *  - frees storage allocated for filename
 *
 * DESCRIPTION  
 *	Pop the top of the file stack, restoring the previous input stream.
 *
 * AUTHOR - Ralph Ryan, Sept. 9, 1982
 *
 * MODIFICATIONS - none
 *
 ************************************************************************/
UCHAR fpop(void)
{
    int	Old_line;

    if(Findex == -1) {		/* no files left */
	return(FALSE);
    }
    fclose(Fp);

    strappend(Filebuff,Fstack[Findex].fl_name);
    Old_line = Linenumber;
    Linenumber = (int)Fstack[Findex].fl_lineno;
    Current_char = Fstack[Findex].fl_currc;
    if(--Findex < 0) {			/* popped the last file */
	Linenumber = Old_line;
	return(FALSE);
    }
    Fp = Fstack[Findex].fl_file;
    vfCurrFileType = Fstack[Findex].fl_fFileType;
    if(Findex >= 2) {			/* popped off a deeply nested include */
	io_eob();
    }
    if(Eflag) {
	emit_line();
    }
    return(TRUE);
}
Exemplo n.º 21
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_emit_jmp_table_rec(int depth, char* reg, int pc, int last_pc) {
  static const int WIDTH[] = {
    4096, 256, 16, 1
  };
  const int w = WIDTH[depth];
  for (int i = 0; i < 16 && pc <= last_pc; i++, pc += w) {
    reg[depth] = i > 9 ? 'a' + i - 10 : '0' + i;
    reg[depth+1] = 0;
    if (depth == 3) {
      emit_line("/^%s$/bpc_%x", reg, pc);
    } else {
      emit_line("/^%s/{", reg);
      sed_emit_jmp_table_rec(depth + 1, reg, pc, last_pc);
      emit_line("}");
    }
  }
}
Exemplo n.º 22
0
void gbB::show_mem_usage()
{
  buffer o;

  long nmonoms = 0;
  for (int i=0; i<gb.size(); i++)
    {
      nmonoms += R->gbvector_n_terms(gb[i]->g.f);
      nmonoms += R->gbvector_n_terms(gb[i]->g.fsyz);
    }
  emit_line(o.str());
  o << "number of (nonminimal) gb elements = " << gb.size();
  emit_line(o.str());
  o.reset();
  o << "number of monomials                = " << nmonoms;
  emit_line(o.str());
}
Exemplo n.º 23
0
static MonomialIdeal /* or null */ *alexDual(const MonomialIdeal *I,
                                             const M2_arrayint top,
                                             int strategy)
{
  if (I->topvar() < 0)
    strategy =
        1;  // i.e. don't use frobby if there are no generators and/or variables
  switch (strategy)
    {
#if HAVE_FROBBY
      case 0:
        if (M2_gbTrace >= 1) emit_line(" -- [Alexander dual: frobby]");
        return wrapperFrobbyAlexanderDual(I, top);
#else
#warning "frobby not enabled"
#endif
      default:
        if (M2_gbTrace >= 1) emit_line(" -- [Alexander dual: M2 monideal]");
        return I->alexander_dual(top);
    }
}
Exemplo n.º 24
0
void gbB::compute_s_pair(spair *p)
{
  POLY f,g;
  if (M2_gbTrace >= 5 && M2_gbTrace != 15)
    {
      buffer o;
      spair_text_out(o,p);
      emit_line(o.str());
    }
  if (p->type > SPAIR_SKEW) return;
  R->gbvector_remove(p->lead_of_spoly);
  p->lead_of_spoly = 0;
  f = gb[p->x.pair.i]->g;
  if (p->type == SPAIR_SKEW)
    {
      const int *mon = R->skew_monomial_var(p->x.pair.j);
      R->gbvector_mult_by_term(F,Fsyz,
                               R->one(), mon,
                               f.f, f.fsyz,
                               p->f(), p->fsyz());
    }
  else
    {
      g = gb[p->x.pair.j]->g;
      R->gbvector_cancel_lead_terms(F, Fsyz,
                                    f.f, f.fsyz,
                                    g.f,g.fsyz,
                                    p->f(),
                                    p->fsyz());
    }
  p->type = SPAIR_ELEM;
  if (M2_gbTrace >= 5 && M2_gbTrace != 15)
    {
      buffer o;
      o << "    ";
      R->gbvector_text_out(o, F, p->f());
      emit_line(o.str());
    }
}
Exemplo n.º 25
0
void gbB::collect_syzygy(gbvector *f)
{
  _syz.push_back(f);
  n_syz++;

  if (M2_gbTrace >= 10)
    {
      buffer o;
      o << " new syzygy : ";
      R->gbvector_text_out(o,Fsyz,f,3);
      emit_line(o.str());
    }
}
Exemplo n.º 26
0
void gbB::start_computation()
{
  ncalls = 0;
  nloops = 0;
  nsaved_unneeded = 0;
  do_computation();
  if (M2_gbTrace >= 1)
    {
      show_mem_usage();
      if (M2_gbTrace >= 3)
        {
          buffer o;
          o << "ncalls = " << ncalls;
          emit_line(o.str());
          o.reset();
          o << "nloop = " << nloops;
          emit_line(o.str());
          o.reset();
          o << "nsaved = " << nsaved_unneeded;
          emit_line(o.str());
        }
      if (M2_gbTrace >= 15) show();
    }
}
Exemplo n.º 27
0
void gbB::auto_reduce_by(int id)
{
  /* Loop backwards while degree doesn't change */
  /* Don't change quotient ring elements */
  gbelem *me = gb[id];
  int a = me->gap;  // Only auto reduce those that are of the same degree
                      // and not a higher gap level
  for (int i= INTSIZE(gb)-1; i>=first_gb_element; i--)
    {
      if (i == id) continue;
      gbelem *g = gb[i];
      if (g->deg < me->deg) return;
      if (g->gap < a) continue;
      if (M2_gbTrace >= 10)
        {
          buffer o;
          o << "  auto reduce " << i << " by " << id;
          emit_line(o.str());
        }
      R->gbvector_auto_reduce(F, Fsyz,
                              g->g.f, g->g.fsyz, // these are modified
                              me->g.f, me->g.fsyz);
    }
}
Exemplo n.º 28
0
void gbB::spair_set_defer(spair *&p)
  // Defer the spair p until later in this same degree
  // The spair should have been reduced a number of times
  // already, so its type should be SPAIR_GEN or SPAIR_ELEM
{
  if (M2_gbTrace == 15)
    {
      emit_line("    deferred by reduction count");
    }
  else if (M2_gbTrace >= 4) emit_wrapped("D");
  //  spair_delete(p); // ONLY FOR TESTING!! THIS IS INCORRECT!!
  //  return;
  S->n_in_degree++;
  if (p->type == SPAIR_GEN)
    {
      S->gen_last_deferred->next = p;
      S->gen_last_deferred = p;
    }
  else
    {
      S->spair_last_deferred->next = p;
      S->spair_last_deferred = p;
    }
}
Exemplo n.º 29
0
Arquivo: lua.c Projeto: shen390s/elvm
void target_lua(Module* module) {
  init_state_lua(module->data);

  int num_funcs = emit_chunked_main_loop(module->text,
                                         lua_emit_func_prologue,
                                         lua_emit_func_epilogue,
                                         lua_emit_pc_change,
                                         lua_emit_inst);

  emit_line("");
  emit_line("while true do");
  inc_indent();
  emit_line("if false then");
  for (int i = 0; i < num_funcs; i++) {
    emit_line("elseif pc < %d then func%d();", (i + 1) * CHUNKED_FUNC_SIZE, i);
  }
  emit_line("end");
  dec_indent();
  emit_line("end");
}
Exemplo n.º 30
0
Arquivo: sed.c Projeto: shen390s/elvm
static void sed_init_state(Data* data) {
  emit_line(":in_loop");
  emit_line("/^$/{x\ns/$/a,/\nx\nbin_done\n}");
  for (int i = 1; i < 128; i++) {
    if (i == 10)
      continue;
    putchar('/');
    putchar('^');
    if (i == '$' || i == '.' || i == '/' ||
        i == '[' || i == '\\' || i == ']') {
      putchar('\\');
    }
    putchar(i);
    emit_line("/{s/.//\nx\ns/$/%x,/\nx\nbin_loop\n}", i);
  }
  emit_line(":in_done");
  emit_line("${");

  emit_line("x");
  emit_line("s/a,$//");
  emit_line("s/.*/i=& /");
  for (int i = 0; i < 6; i++) {
    emit_line("s/$/%c=0 /", SED_REG_NAMES[i]);
  }
  emit_line("s/$/o= /");
  for (int mp = 0; data; data = data->next, mp++) {
    emit_line("s/$/m%x=%x /", mp, data->v);
  }
  emit_line("x");
}