Esempio n. 1
0
static map_list_t *elab_map(tree_t t, tree_t arch,
                            tree_formals_t tree_Fs, tree_formal_t tree_F,
                            tree_actuals_t tree_As, tree_actual_t tree_A)
{
   tree_t unit = tree_ref(arch);
   assert(tree_kind(unit) == T_ENTITY);

   const int nformals = tree_Fs(unit);
   const int nactuals = (tree_As != NULL) ? tree_As(t) : 0;

   bool *have_formals = xmalloc(sizeof(bool) * nformals);

   for (int i = 0; i < nformals; i++)
      have_formals[i] = false;

   const int maxr = nformals + nactuals;

   tree_t *rformals = xmalloc(sizeof(tree_t) * maxr);
   tree_t *ractuals = xmalloc(sizeof(tree_t) * maxr);
   int count = 0;

   map_list_t *maps = NULL;

   for (int i = 0; i < nactuals; i++) {
      tree_t p = tree_A(t, i);
      tree_t formal = NULL;

      switch (tree_subkind(p)) {
      case P_POS:
         {
            const int pos = tree_pos(p);
            formal = tree_F(unit, pos);
            have_formals[pos] = true;
         }
         break;
      case P_NAMED:
         {
            ident_t name = elab_formal_name(tree_name(p));
            for (int j = 0; j < nformals; j++) {
               tree_t port = tree_F(unit, j);
               if (tree_ident(port) == name) {
                  formal = port;
                  have_formals[j] = true;
                  break;
               }
            }
         }
         break;
      default:
         assert(false);
      }
      assert(formal != NULL);

      switch (tree_class(formal)) {
      case C_SIGNAL:
         ractuals[count] = elab_signal_port(arch, formal, p, &maps);
         break;

      case C_CONSTANT:
         ractuals[count] = tree_value(p);
         break;

      default:
         assert(false);
      }

      rformals[count] = formal;
      count++;
   }

   // Assign default values
   for (unsigned i = 0; i < nformals; i++) {
      if (!have_formals[i]) {
         tree_t f = tree_F(unit, i);
         if (tree_has_value(f)) {
            rformals[count] = f;
            ractuals[count] = tree_value(f);
            count++;
         }
      }
   }

   assert(count <= maxr);

   if (count > 0) {
      rewrite_params_t params = {
         .formals = rformals,
         .actuals = ractuals,
         .count   = count
      };
      tree_rewrite(arch, rewrite_refs, &params);

      tree_t ent = tree_ref(arch);
      if (tree_stmts(ent) > 0 || tree_decls(ent) > 0)
         tree_rewrite(ent, rewrite_refs, &params);
   }
Esempio n. 2
0
File: opt.c Progetto: chiggs/nvc
static void opt_delete_wait_only(tree_t top)
{
   tree_rewrite(top, opt_delete_wait_only_fn, NULL);
}