Пример #1
0
BtorParamCacheTuple *
btor_copy_param_cache_tuple (Btor * btor, BtorParamCacheTuple * t)
{
  assert (btor);
  assert (t);

  BtorParamCacheTuple *result;

  BTOR_NEW (btor->mm, result);
  BTOR_CLR (result);

  result->exp = btor_copy_exp (btor, t->exp);
  result->hash = t->hash;
  result->num_args = t->num_args;

  BTOR_NEWN (btor->mm, result->args, result->num_args);
  memcpy (result->args, t->args, t->num_args * sizeof (*result->args));

  return result;
}
Пример #2
0
static const char *
btor_parse_btor_parser (BtorBTORParser * parser, BtorCharStack * prefix,
			FILE * file, const char *name,
			BtorParseResult * res)
{
  BtorOpParser op_parser;
  int ch, len;
  BtorNode *e;

  assert (name);
  assert (file);

  if (parser->verbosity > 0)
    btor_msg_btor ("parsing %s", name);

  parser->nprefix = 0;
  parser->prefix = prefix;
  parser->file = file;
  parser->name = name;
  parser->lineno = 1;
  parser->saved = 0;

  BTOR_CLR (res);

NEXT:
  assert (!parser->error);
  ch = btor_nextch_btor (parser);
  if (isspace (ch))             /* also skip empty lines */
    goto NEXT;

  if (ch == EOF)
    {

    DONE:

      if (res)
	{
	  remove_regs_from_vars (parser);

	  if (parser->found_arrays)
	    res->logic = BTOR_LOGIC_QF_AUFBV;
	  else
	    res->logic = BTOR_LOGIC_QF_BV;
	  res->status = BTOR_PARSE_SAT_STATUS_UNKNOWN;

	  res->ninputs = BTOR_COUNT_STACK (parser->inputs);
	  res->inputs = parser->inputs.start;

	  res->noutputs = BTOR_COUNT_STACK (parser->outputs);
	  res->outputs = parser->outputs.start;

	  res->nregs = BTOR_COUNT_STACK (parser->regs);
	  res->regs = parser->regs.start;
	  res->nexts = parser->nexts.start;

	  if (parser->verbosity > 0)
	    {
	      btor_msg_btor ("parsed %d inputs", res->ninputs);
	      btor_msg_btor ("parsed %d registers", res->nregs);
	      btor_msg_btor ("parsed %d outputs", res->noutputs);
	    }
	}

      return 0;
    }

  if (ch == ';')                /* skip comments */
    {
    COMMENTS:
      while ((ch = btor_nextch_btor (parser)) != '\n')
	if (ch == EOF)
	  goto DONE;

      goto NEXT;
    }

  if (!isdigit (ch))
    return btor_perr_btor (parser, "expected ';' or digit");

  btor_savech_btor (parser, ch);

  if (parse_positive_int (parser, &parser->idx))
    return parser->error;

  while (BTOR_COUNT_STACK (parser->exps) <= parser->idx)
    {
      Info info;
      memset (&info, 0, sizeof info);
      BTOR_PUSH_STACK (parser->mem, parser->info, info);
      BTOR_PUSH_STACK (parser->mem, parser->exps, 0);
    }

  if (parser->exps.start[parser->idx])
    return btor_perr_btor (parser, "'%d' defined twice", parser->idx);

  if (parse_space (parser))
    return parser->error;

  assert (BTOR_EMPTY_STACK (parser->op));
  while (!isspace (ch = btor_nextch_btor (parser)) && ch != EOF)
    BTOR_PUSH_STACK (parser->mem, parser->op, ch);

  BTOR_PUSH_STACK (parser->mem, parser->op, 0);
  BTOR_RESET_STACK (parser->op);
  btor_savech_btor (parser, ch);

  if (parse_space (parser))
    return parser->error;

  if (parse_positive_int (parser, &len))
    return parser->error;

  if (!(op_parser = find_parser (parser, parser->op.start)))
    return btor_perr_btor (parser, "invalid operator '%s'", parser->op.start);

  if (!(e = op_parser (parser, len)))
    {
      assert (parser->error);
      return parser->error;
    }

  assert (btor_get_exp_len (parser->btor, e) == len);
  parser->exps.start[parser->idx] = e;

SKIP:
  ch = btor_nextch_btor (parser);
  if (ch == ' ' || ch == '\t')
    goto SKIP;

  if (ch == ';')
    goto COMMENTS;              /* ... and force new line */

  if (ch != '\n')
    return btor_perr_btor (parser, "expected new line");

  goto NEXT;
}
Пример #3
0
static BtorBTORParser *
btor_new_btor_parser (Btor * btor, BtorParseOpt * opts)
{
  BtorMemMgr *mem = btor->mm;
  BtorBTORParser *res;

  (void) opts->incremental;		// TODO what about incremental?
  (void) opts->need_model;		// TODO use at least this

  assert (opts->verbosity >= -1);

  BTOR_NEW (mem, res);
  BTOR_CLR (res);

  res->mem = mem;
  res->btor = btor;

  BTOR_NEWN (mem, res->parsers, SIZE_PARSERS);
  BTOR_NEWN (mem, res->ops, SIZE_PARSERS);
  BTOR_CLRN (res->ops, SIZE_PARSERS);

  new_parser (res, parse_add, "add");
  new_parser (res, parse_and, "and");
  new_parser (res, parse_array, "array");
  new_parser (res, parse_concat, "concat");
  new_parser (res, parse_cond, "cond");
  new_parser (res, parse_acond, "acond");
  new_parser (res, parse_const, "const");
  new_parser (res, parse_constd, "constd");
  new_parser (res, parse_consth, "consth");
  new_parser (res, parse_eq, "eq");
  new_parser (res, parse_iff, "iff");
  new_parser (res, parse_implies, "implies");
  new_parser (res, parse_mul, "mul");
  new_parser (res, parse_nand, "nand");
  new_parser (res, parse_neg, "neg");
  new_parser (res, parse_inc, "inc");
  new_parser (res, parse_dec, "dec");
  new_parser (res, parse_ne, "ne");
  new_parser (res, parse_next, "next"); /* only in parser */
  new_parser (res, parse_anext, "anext"); /* only in parser */
  new_parser (res, parse_nor, "nor");
  new_parser (res, parse_not, "not");
  new_parser (res, parse_one, "one");
  new_parser (res, parse_ones, "ones");
  new_parser (res, parse_or, "or");
  new_parser (res, parse_proxy, "proxy");
  new_parser (res, parse_read, "read");
  new_parser (res, parse_redand, "redand");
  new_parser (res, parse_redor, "redor");
  new_parser (res, parse_redxor, "redxor");
  new_parser (res, parse_rol, "rol");
  new_parser (res, parse_root, "root"); /* only in parser */
  new_parser (res, parse_ror, "ror");
  new_parser (res, parse_saddo, "saddo");
  new_parser (res, parse_sdivo, "sdivo");
  new_parser (res, parse_sdiv, "sdiv");
  new_parser (res, parse_sext, "sext");
  new_parser (res, parse_sgte, "sgte");
  new_parser (res, parse_sgt, "sgt");
  new_parser (res, parse_slice, "slice");
  new_parser (res, parse_sll, "sll");
  new_parser (res, parse_slte, "slte");
  new_parser (res, parse_slt, "slt");
  new_parser (res, parse_smod, "smod");
  new_parser (res, parse_smulo, "smulo");
  new_parser (res, parse_sra, "sra");
  new_parser (res, parse_srem, "srem");
  new_parser (res, parse_srl, "srl");
  new_parser (res, parse_ssubo, "ssubo");
  new_parser (res, parse_sub, "sub");
  new_parser (res, parse_uaddo, "uaddo");
  new_parser (res, parse_udiv, "udiv");
  new_parser (res, parse_uext, "uext");
  new_parser (res, parse_ugte, "ugte");
  new_parser (res, parse_ugt, "ugt");
  new_parser (res, parse_ulte, "ulte");
  new_parser (res, parse_ult, "ult");
  new_parser (res, parse_umulo, "umulo");
  new_parser (res, parse_urem, "urem");
  new_parser (res, parse_usubo, "usubo");
  new_parser (res, parse_var, "var");
  new_parser (res, parse_write, "write");
  new_parser (res, parse_xnor, "xnor");
  new_parser (res, parse_xor, "xor");
  new_parser (res, parse_zero, "zero");

  res->verbosity = opts->verbosity;

  return res;
}
Пример #4
0
BtorParamCacheTuple *
btor_new_param_cache_tuple (Btor * btor, BtorNode * exp)
{
  assert (btor);
  assert (exp);
  assert (BTOR_IS_REGULAR_NODE (exp));

  int i;
  unsigned int hash;
  BtorNode *param, *arg, *cur;
  BtorParamCacheTuple *t;
  BtorParameterizedIterator it;
  BtorNodeIterator pit;

  BTOR_NEW (btor->mm, t);
  BTOR_CLR (t);
  t->exp = btor_copy_exp (btor, exp);

  btor_init_parameterized_iterator (&it, btor, exp);

  hash = BTOR_REAL_ADDR_NODE (exp)->id;
  if (btor_has_next_parameterized_iterator (&it))
    {
      t->num_args = it.num_params; 
      if (BTOR_IS_LAMBDA_NODE (exp))
        t->num_args += btor_get_fun_arity (btor, exp);

      BTOR_NEWN (btor->mm, t->args, t->num_args);

      i = 0;
      if (BTOR_IS_LAMBDA_NODE (exp))
        {
          btor_init_lambda_iterator (&pit, exp);
          while (btor_has_next_lambda_iterator (&pit))
            {
              cur = btor_next_lambda_iterator (&pit);
              arg = btor_param_cur_assignment (cur->e[0]);
              if (!arg)
                arg = cur->e[0];
              assert (arg);
              t->args[i++] = btor_copy_exp (btor, arg);
              hash += (unsigned int) BTOR_GET_ID_NODE (arg);
            }
        }

      do
        {
          param = btor_next_parameterized_iterator (&it);
          assert (BTOR_IS_REGULAR_NODE (param));
          assert (BTOR_IS_PARAM_NODE (param));
          arg = btor_param_cur_assignment (param);
          if (!arg)
            arg = param;
          assert (arg);
          t->args[i++] = btor_copy_exp (btor, arg);
          hash += (unsigned int) BTOR_GET_ID_NODE (arg);
        }
      while (btor_has_next_parameterized_iterator (&it));
    }
  else if (BTOR_IS_LAMBDA_NODE (exp))
    {
      btor_init_lambda_iterator (&pit, exp);
      t->num_args = btor_get_fun_arity (btor, exp);
      BTOR_NEWN (btor->mm, t->args, t->num_args);

      i = 0;
      while (btor_has_next_lambda_iterator (&pit))
        {
          cur = btor_next_lambda_iterator (&pit);
          arg = btor_param_cur_assignment (cur->e[0]);
          if (!arg)
            arg = cur->e[0];
          assert (arg);
          t->args[i++] = btor_copy_exp (btor, arg);
          hash += (unsigned int) BTOR_GET_ID_NODE (arg);
        }
    }
  hash *= 7334147u;
  t->hash = hash;

  return t;
}