Ejemplo n.º 1
0
boolean BigNumber_to_unsigned_long_long(Number* number,
                                        unsigned long long* target)
{
  QNumber* org = (number2qnumber(*number));

  nusmv_assert(target != (unsigned long long*) NULL);

  if (!QNumber_big(org)) {
    long t;
    int b = BVQNumber_to_long(org, &t);
    nusmv_assert(b);
    *target = (unsigned long long) t;
    return b;
  }
  else {
    unsigned long long ull;
    char* str;
    char* err;

    str = QNumber_print_integer(org, 10);
    ull = strtoull(str, &err, 10);
    if (NULL == (char*) str || '\0' != *err) {
      return false;
    }
    *target = ull;
    return true;
  }
}
Ejemplo n.º 2
0
void heap_add(heap h, float val, void * el)
{
  nusmv_assert(h);

  if (h->length == h->maxlength) {
    h->maxlength = h->maxlength * 2 + 1;
    h->array = REALLOC(heap_el_struct, h->array, h->maxlength);
    nusmv_assert(h->array);
  }

  {
    int pos = h->length;

    h->length++;

    h->array[pos].val = val; 
    h->array[pos].el = el; 

    while (pos > 0) {
      int newpos = (pos - 1) / 2;
      
      if (h->array[pos].val > h->array[newpos].val) {
	heap_switch(h,pos,newpos);
	pos = newpos;
      } else {
	break;
      }
    }
  }
}
Ejemplo n.º 3
0
/*!
  \brief auxiliary part of bmc_tableauGetUntilAtTime

  
*/
static be_ptr
bmc_tableauGetUntilAtTime_aux(const BeEnc_ptr be_enc,
                              const node_ptr p, const node_ptr q,
                              const int time, const int k, const int l,
                              const int steps)
{
  Be_Manager_ptr be_mgr;
  be_ptr tableau_temp; /* for increasing of performances */
  be_ptr tableau_following; /* to increase readability */

  nusmv_assert((time < k) || (time==k && Bmc_Utils_IsNoLoopback(l)) );
  nusmv_assert (steps >= 1);

  be_mgr = BeEnc_get_be_manager(be_enc);
  tableau_temp = BmcInt_Tableau_GetAtTime(be_enc, q, time, k, l);

  if (steps > 1) {
    tableau_following =
      bmc_tableauGetUntilAtTime_aux(be_enc, p, q,
                                    Bmc_Utils_GetSuccTime(time, k, l),
                                    k, l, steps - 1);

    tableau_temp =
      Be_Or( be_mgr,
             tableau_temp,
             Be_And(be_mgr,
                    BmcInt_Tableau_GetAtTime(be_enc, p, time, k, l),
                    tableau_following) );
  }
  return tableau_temp;
}
Ejemplo n.º 4
0
void heap_destroy(heap h)
{
  nusmv_assert(h);
  nusmv_assert(h->length == 0);
  
  FREE(h->array);
  FREE(h);
}
Ejemplo n.º 5
0
void BigNumber_set_bit(Number* number, int location, int value)
{
  QNumber* org;

  nusmv_assert(location >= 0);
  nusmv_assert(value >=0 && value <= 1);

  org = (number2qnumber(*number));
  BVQNumber_set_bit(org, location, value);
}
Ejemplo n.º 6
0
int main(int argc, char * argv[])
{
  int length, num, c;
  int * array;
  heap h;
  if (argc != 3) {
    fprintf(stderr,"Usage: %s <heap-length> <num-tests>\n", argv[0]);
    return 1;
  }
  length = atoi(argv[1]);
  num = atoi(argv[2]);

  if (length <= 0) {
    fprintf(stderr,"Error: length <= 0\n");
    return 1;    
  }

  h = heap_create();
  
  array = ALLOC(int,length);
  nusmv_assert(array);

  for (c = 1; c <= num; c++) {
    int i, i1, i2;
    printf("Test %2d:", c);
    for (i = 0; i < length; i++) {
      array[i] = i+1;
    }
    for (i = 0; i < 4 * length; i++) {
      i1 = utils_random() % length;
      i2 = utils_random() % length;
      if (i1 == i2) continue;
      array[i1] = array[i1] + array[i2];
      array[i2] = array[i1] - array[i2];
      array[i1] = array[i1] - array[i2];
    }
    for (i = 0; i < length; i++) {
      printf(" %d", array[i]);
      heap_add(h, -array[i], (void *)array[i]);
    }
    printf("\n------->");
    for (i = 0; i < length; i++) {
      int val = (int)heap_getmax(h);
      printf(" %d", val);
      nusmv_assert(val == i+1);
    }
    printf("\n");
    assert(heap_isempty(h));
  }

  heap_destroy(h);

  return 0;
}
Ejemplo n.º 7
0
void BigNumber_divmod(Number* left, Number* right, Number* q, Number* r)
{
  const QNumber* orgl = (number2qnumber(*left));
  const QNumber* orgr = (number2qnumber(*right));
  QNumber* target_q = (number2qnumber(*q));
  QNumber* target_r = (number2qnumber(*r));

  nusmv_assert(q != (Number*) NULL);
  nusmv_assert(r != (Number*) NULL);

  QNumber_divmod(orgl, orgr, target_q, target_r);
}
Ejemplo n.º 8
0
heap heap_create()
{
  heap h = ALLOC(heap_struct,1);
  nusmv_assert(h);

  h->maxlength = HEAP_MAXLENGTH_INIT;
  h->length = 0;
  h->array = ALLOC(heap_el_struct, h->maxlength);
  nusmv_assert(h->array);

  return h;
}
Ejemplo n.º 9
0
be_ptr
bmc_tableauGetEventuallyAtTime(const BeEnc_ptr be_enc,
                               const node_ptr ltl_wff,
                               const int intime, const int k, const int l)
{
  Be_Manager_ptr be_mgr;
  int time;
  be_ptr tableau;
  int stop_time;
  int start_time;

  nusmv_assert((intime < k) || (intime==k && Bmc_Utils_IsNoLoopback(l)) );

  /* checks out the validity of [l, k] only if a loop exists: */
  nusmv_assert(Bmc_Utils_IsNoLoopback(l) || (k > l));

  be_mgr = BeEnc_get_be_manager(be_enc);
  tableau = Be_Falsity(be_mgr);

  /* there exist three cases:
     1) no loop: iterates from k downto intime;
     2) loop, (intime < l): iterates from k-1 downto intime;
     3) loop, (l <= intime < k) : iterates from k-1 downto l */

  if (Bmc_Utils_IsNoLoopback(l)) {
    /* The first case */
    start_time = k;
    stop_time  = intime;
  }
  else {
    /* The second and third case*/
    start_time = k-1;
    stop_time  = min(intime,l);
  }

  for (time = start_time; time>=stop_time; --time) {
    /* lazy evaluation: */
    be_ptr tableau_at_time = BmcInt_Tableau_GetAtTime(be_enc, ltl_wff,
                                                      time, k, l);

    if ( Be_IsTrue(be_mgr, tableau_at_time) ) {
      tableau = tableau_at_time;
      break;
    }
    tableau = Be_Or(be_mgr,
           tableau_at_time, tableau);
  } /* loop */

  return tableau;
}
Ejemplo n.º 10
0
be_ptr bmc_tableau_memoization_lookup(hash_ptr tableau_ltl_hash,
                                             node_ptr key)
{
  nusmv_assert(tableau_ltl_hash != (hash_ptr) NULL);

  return (be_ptr) find_assoc(tableau_ltl_hash, key);
}
Ejemplo n.º 11
0
boolean SymbLayer_must_insert_before(const SymbLayer_ptr self,
                                     const SymbLayer_ptr other)
{
  LayerInsertPolicy p1, p2;

  SYMB_LAYER_CHECK_INSTANCE(self);

  p1 = SymbLayer_get_insert_policy(self);
  p2 = SymbLayer_get_insert_policy(other);

  /* checks that p1 and p2 do not refer the same forced position */
  nusmv_assert((p1 != p2) || ((p1 != SYMB_LAYER_POS_FORCE_TOP) &&
                              (p1 != SYMB_LAYER_POS_FORCE_BOTTOM)));

  switch (p1) {
  case SYMB_LAYER_POS_FORCE_TOP: return true;

  case SYMB_LAYER_POS_TOP:
    return p2 != SYMB_LAYER_POS_FORCE_TOP;

  case SYMB_LAYER_POS_DEFAULT:
  case SYMB_LAYER_POS_BOTTOM: return p2 == SYMB_LAYER_POS_FORCE_BOTTOM;

  default:
    ErrorMgr_internal_error(self->errors, "Unexpected layer insertion policy");
  }

  return false;
}
Ejemplo n.º 12
0
void bmc_tableau_memoization_insert(hash_ptr tableau_ltl_hash,
                                           node_ptr key, be_ptr be)
{
  nusmv_assert(tableau_ltl_hash != (hash_ptr) NULL);

  insert_assoc(tableau_ltl_hash, key, (node_ptr) be);
}
Ejemplo n.º 13
0
/**Function********************************************************************

  Synopsis     [Extends current simulation trace and prints it]

  Description  [Extends current simulation trace by creating a new
                trace for simulation fragment and concatenating it to
                existing one.]

                The trace is printed it if the variable printyesno is
                true (this is set by the user via the command simulate
                options -p or -v). It returns the index of the stored
                trace inside the trace-manager.]

  SideEffects  []

  SeeAlso      [Trace_concat]

******************************************************************************/
static void simulate_extend_print_curr_trace(BddEnc_ptr enc,
                                             node_ptr fragment,
                                             boolean printyesno,
                                             boolean only_changes,
                                             NodeList_ptr symbols)
{
  Trace_ptr trace;
  Trace_ptr extension;

  unsigned prev_length;

  trace = \
    TraceManager_get_trace_at_index(global_trace_manager,
                    TraceManager_get_current_trace_number(global_trace_manager));

  prev_length = Trace_get_length(trace);

  /*  extend simulation trace */
  extension = \
    Mc_create_trace_from_bdd_state_input_list(enc, symbols, NIL(char),
                                              TRACE_TYPE_UNSPECIFIED,
                                              fragment);

  /* extend existing simulation trace */
  trace = Trace_concat(trace, &extension);
  nusmv_assert(TRACE(NULL) == extension);

  if (opt_verbose_level_gt(OptsHandler_get_instance(), 1) && printyesno) {

    fprintf(nusmv_stdout,
            "#####################################################\n"
            "######         Print Of Current Trace         #######\n"
            "#####################################################\n");
  }

  if (printyesno) {
    TracePlugin_ptr plugin;

    /* only the TraceExplainer plugin can be used here: */

    if (only_changes) {
      plugin = TraceManager_get_plugin_at_index(global_trace_manager, 0);
    }
    else {
      plugin = TraceManager_get_plugin_at_index(global_trace_manager, 1);
    }

    {
      TraceOpt_ptr trace_opt = \
        TraceOpt_create_from_env(OptsHandler_get_instance());

      TraceOpt_set_from_here(trace_opt, prev_length);
      TracePlugin_action(plugin, trace, trace_opt);

      TraceOpt_destroy(trace_opt);
    }
  } /* if printyesno */

  return ;
}
Ejemplo n.º 14
0
inline QNumber* number2qnumber(Number n)
{
  void* struct_p = n.repr;
  QNumber* rvalue = ((QNumber*) struct_p);

  nusmv_assert(struct_p != (void*) NULL);
  return rvalue;
}
Ejemplo n.º 15
0
void SymbLayer_remove_var(SymbLayer_ptr self, node_ptr name)
{
  SymbType_ptr type;

  /* IMPORTANT: do not remove this assertion! (read comment) */
  nusmv_assert(self->committed_to_encs == 0); /* not in use */

  nusmv_assert(SymbCache_is_symbol_var(self->cache, name));

  type = SymbCache_get_var_type(self->cache, name);


  if (SymbCache_is_symbol_state_var(self->cache, name)) {
    --self->state_vars_num;
    if (SymbType_is_boolean(type)) {
      --self->bool_state_vars_num;
    }
  }
  else if (SymbCache_is_symbol_frozen_var(self->cache, name)) {
    --self->frozen_vars_num;
    if (SymbType_is_boolean(type)) {
      --self->bool_frozen_vars_num;
    }
  }
  else if (SymbCache_is_symbol_input_var(self->cache, name)) {
    --self->input_vars_num;
    if (SymbType_is_boolean(type)) {
      --self->bool_input_vars_num;
    }
  }
  else {
    error_unreachable_code();
  }

  /* removes the variable  */
  SymbCache_remove_var(self->cache, name);

  symb_layer_remove_symbol(self, name);

  if (opt_verbose_level_gt(self->options, 3)) {
    Logger_nlog(self->logger, self->printer,
                "SymbLayer '%s': removed variable '%N'\n",
                self->name, name);
  }
}
Ejemplo n.º 16
0
be_ptr
bmc_tableauGetGloballyAtTime(const BeEnc_ptr be_enc,
                             const node_ptr ltl_wff,
                             const int intime, const int k, const int l)
{
  Be_Manager_ptr be_mgr;
  int time;
  be_ptr tableau;
  int stop_time;

  nusmv_assert((intime < k) || (intime==k && Bmc_Utils_IsNoLoopback(l)) );

  /* checks out the validity of [l, k] only if a loop exists: */
  nusmv_assert(Bmc_Utils_IsNoLoopback(l) || (k > l));

  be_mgr = BeEnc_get_be_manager(be_enc);

  /* there exist three cases:
     1) no loop: cannot assure nothing, so return falsity;
     2) loop, (intime < l): iterates from intime to k-1;
     3) loop, (l <= intime < k) : iterates from intime to k-1, and then from
        l to intime-1 (so more efficiently from l to k-1.)  */
  if (Bmc_Utils_IsNoLoopback(l)) {
    tableau = Be_Falsity(be_mgr);
  }
  else {
    /* second and third cases */
    tableau = Be_Truth(be_mgr);

    stop_time = min(intime, l);
    for (time=k-1; time >= stop_time; --time) {
      /* lazy evaluation: */
      be_ptr tableau_at_time = BmcInt_Tableau_GetAtTime(be_enc, ltl_wff,
                                                        time, k, l);
      if ( Be_IsFalse(be_mgr, tableau_at_time) ) {
        tableau = tableau_at_time;
        break;
      }
      tableau = Be_And(be_mgr,
                       tableau_at_time, tableau);
    }
  }

  return tableau;
}
Ejemplo n.º 17
0
/**Function********************************************************************

   Synopsis           [Expands the given case expression]

   Description        [Expands the given case expression]

   SideEffects        []

   SeeAlso            []

******************************************************************************/
static node_ptr w2w_wff_expand_case(node_ptr wff)
{
  node_ptr res;

  nusmv_assert(CASE == node_get_type(wff) || IFTHENELSE == node_get_type(wff));
  res = w2w_wff_expand_case_aux(wff);

  return res;
}
Ejemplo n.º 18
0
void Be_Cnf_Delete(Be_Cnf_ptr self)
{
  nusmv_assert(self != NULL);

  Slist_destroy_and_free_elements(self->cnfClauses, _be_cnf_destroy_clause);
  Slist_destroy(self->cnfVars);

  FREE(self);
}
Ejemplo n.º 19
0
node_ptr Wff_make_opnext_times(NodeMgr_ptr nodemgr, node_ptr arg, int x)
{
  nusmv_assert(x >= 0);

  if (x == 0)
    return arg;
  else
    return Wff_make_opnext(nodemgr, Wff_make_opnext_times(nodemgr, arg, x - 1));
}
Ejemplo n.º 20
0
/**Function********************************************************************

  Synopsis           [Checks that the given layer occurs within the used bool 
  encoder, and then adds this layer to the set of committed layers. ]

  Description        [This method must always be called by derived classes]

  SideEffects        []

  SeeAlso            [BoolEncClient_destroy]   
  
******************************************************************************/
void bool_enc_client_commit_layer(BaseEnc_ptr base_enc, const char* layer_name)
{
  BoolEncClient_ptr self;

  self = BOOL_ENC_CLIENT(base_enc);

  nusmv_assert(BaseEnc_layer_occurs(BASE_ENC(self->bool_enc), layer_name));
  
  base_enc_commit_layer(base_enc, layer_name);
}
Ejemplo n.º 21
0
/**Function********************************************************************

  Synopsis    [DFS private function]

  Description []

  SideEffects [None]

  SeeAlso     []

******************************************************************************/
static void inline_first(Rbc_t* f, char* _data, nusmv_ptrint sign)
{
  nusmv_assert(f->symbol == RBCAND || f->symbol == RBCVAR ||
               f->symbol == RBCTOP);

  /* Reset the counter for the sons list */
  if (f->symbol == RBCAND) {
    f->gRef = (char*) ALLOC(Rbc_t*, RBC_MAX_OUTDEGREE);
    f->iRef = 0;
  }
Ejemplo n.º 22
0
boolean Wff_is_propositional(SymbTable_ptr symb_table,
                             node_ptr wff,
                             node_ptr context,
                             boolean is_next_allowed)
{
  NuSMVEnv_ptr env = NULL;
  MasterLogicRecognizer_ptr master_recogn = NULL;

  TypeChecker_ptr type_checker = NULL;
  SymbType_ptr symb_type = NULL;
  LogicType logic = EXP_NONE;
  boolean retval = true;

  SYMB_TABLE_CHECK_INSTANCE(symb_table);
  nusmv_assert(retval);

  env = EnvObject_get_environment(ENV_OBJECT(symb_table));
  master_recogn = MASTER_LOGIC_RECOGNIZER(NuSMVEnv_get_value(env, ENV_MASTER_LOGIC_RECOGNIZER));

  type_checker = SymbTable_get_type_checker(symb_table);

  if (TypeChecker_is_expression_type_checked(type_checker, wff, context)) {
    symb_type = TypeChecker_get_expression_type(type_checker, wff, context);
    if (! SymbType_is_boolean(symb_type)) retval = false;
  }

  if (retval) {
    logic = MasterLogicRecognizer_recognize(master_recogn, wff, context);
    switch(logic) {
    case EXP_CTL:
    case EXP_LTL:
      retval = false; break;

    case EXP_NEXT:
      if (! is_next_allowed) retval = false;
      break;

    case EXP_SIMPLE:
      break;

    default:
      error_unreachable_code();
    }
  }

  if (retval) {
    if (! TypeChecker_is_expression_type_checked(type_checker, wff, context)) {
      symb_type = TypeChecker_get_expression_type(type_checker, wff, context);
      if (! SymbType_is_boolean(symb_type)) retval = false;
    }
  }

  return retval;
}
Ejemplo n.º 23
0
Number BigNumber_pow2(int widht)
{
  QNumber value;
  QNumber* nnumber;

  nusmv_assert(widht >= 0);
  value = BVQNumber_pow2(widht);

  nnumber = QNumber_copy_to_heap(&value);
  return qnumber2number(nnumber);
}
Ejemplo n.º 24
0
boolean BigNumber_test_bit(Number* number, int location)
{
  QNumber* org = (number2qnumber(*number));
  boolean rvalue;

  nusmv_assert(location >= 0);

  rvalue = BVQNumber_test_bit(org, location);

  return rvalue;
}
Ejemplo n.º 25
0
void SymbLayer_remove_variable_array(SymbLayer_ptr self, node_ptr name)
{
  /* IMPORTANT: do not remove this assertion! (read comment) */
  nusmv_assert(self->committed_to_encs == 0); /* not in use */

  nusmv_assert(SymbCache_is_symbol_variable_array(self->cache, name));

  /* removes the variable  */
  SymbCache_remove_variable_array(self->cache, name);

  symb_layer_remove_symbol(self, name);

  --self->variable_arrays_num;

  if (opt_verbose_level_gt(self->options, 3)) {
    Logger_nlog(self->logger, self->printer,
                "SymbLayer '%s': removed array '%N'\n",
                self->name, name);
  }
}
Ejemplo n.º 26
0
Be_Cnf_ptr Be_Cnf_Create(const be_ptr be)
{
  Be_Cnf_ptr self = ALLOC(Be_Cnf, 1);
  nusmv_assert(self != NULL);

  self->originalBe = be;
  self->cnfVars = Slist_create();
  self->cnfClauses = Slist_create();
  self->cnfMaxVarIdx = 0;
  self->formulaLiteral = 0;

  return self;
}
Ejemplo n.º 27
0
Number BigNumber_bit_left_shift(Number* number, int amount)
{
  const QNumber* org;
  QNumber value;
  QNumber* nnumber;

  nusmv_assert(amount >= 0);
  org = (number2qnumber(*number));
  value = BVQNumber_bit_left_shift(org, amount);
  nnumber = QNumber_copy_to_heap(&value);

  return qnumber2number(nnumber);
}
Ejemplo n.º 28
0
void SymbLayer_removed_from_enc(SymbLayer_ptr self)
{
  SYMB_LAYER_CHECK_INSTANCE(self);
  nusmv_assert(self->committed_to_encs > 0);

  self->committed_to_encs -= 1;

  if (opt_verbose_level_gt(self->options, 4)) {
    Logger_log(self->logger,
               "SymbLayer '%s': removed from encoding (%d remaining)\n",
               SymbLayer_get_name(self), self->committed_to_encs);
  }
}
Ejemplo n.º 29
0
/*!
  \brief Removes the given symbol from the layer

  Removes the given symbol from the layer
*/
static inline void
symb_layer_remove_symbol(SymbLayer_ptr self, const node_ptr sym)
{
  unsigned int pos = NODE_TO_INT(remove_assoc(self->symbol2position, sym));

  nusmv_assert(0 != pos);

  /* Remove from the list */
  self->symbols[pos - 1] = Nil;
  self->symbols_empty++;

  symb_layer_check_and_shrink_symbols(self);
}
Ejemplo n.º 30
0
/*!
  \brief auxiliary part of bmc_tableauGetReleasesAtTime

  Builds the release operator expression
*/
static be_ptr
bmc_tableauGetReleasesAtTime_aux(const BeEnc_ptr be_enc,
                                 const node_ptr p, const node_ptr q,
                                 const int time, const int k, const int l,
                                 const int steps)
{
  be_ptr tableau_p;
  be_ptr tableau_q;
  be_ptr tableau_result;

  nusmv_assert((time < k) || (time==k && Bmc_Utils_IsNoLoopback(l)) );
  nusmv_assert (steps >= 1);

  tableau_p = BmcInt_Tableau_GetAtTime(be_enc, p, time, k, l);
  tableau_q = BmcInt_Tableau_GetAtTime(be_enc, q, time, k, l);

  if (steps == 1) {
    if (Bmc_Utils_IsNoLoopback(l)) { /* q & p */
      tableau_result = Be_And(BeEnc_get_be_manager(be_enc),
                              tableau_p, tableau_q);
    } else { /* q */
      tableau_result = tableau_q;
    }
  }
  else { /* q & ( p | X(p R q) ) */
    be_ptr tableau_following =
      bmc_tableauGetReleasesAtTime_aux(be_enc, p, q,
                                       Bmc_Utils_GetSuccTime(time, k, l),
                                       k, l, steps - 1);
    tableau_result =
      Be_And(BeEnc_get_be_manager(be_enc),
             tableau_q,
             Be_Or(BeEnc_get_be_manager(be_enc),
                   tableau_p, tableau_following));
  }

  return tableau_result;
}