Esempio n. 1
0
void init_attrs(void)
{
  /* This will allow these attributes to occur on clauses. */
  /* Mace4 will ignore these attributes. */

  int id;
  id = register_attribute("label",         STRING_ATTRIBUTE);
  id = register_attribute("bsub_hint_wt",     INT_ATTRIBUTE);
  id = register_attribute("answer",          TERM_ATTRIBUTE);
  id = register_attribute("action",          TERM_ATTRIBUTE);
  id = register_attribute("action2",         TERM_ATTRIBUTE);
}  /* init_attrs */
int main(int argc, char **argv)
{
  FILE *rule_fp;
  Topform c;
  Term t;
  int i;
  Clause_eval compiled_rule;
  Plist rules = NULL;

  init_standard_ladr();
  init_weight(NULL, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0);
  i = register_attribute("label",  STRING_ATTRIBUTE);  /* ignore these */
  i = register_attribute("answer", TERM_ATTRIBUTE);  /* ignore these */

  rule_fp = fopen(argv[1], "r");
  if (rule_fp == NULL)
    fatal_error("test_clause_eval, rule file cannot be opened for reading");

  t = read_term(rule_fp, stderr);  /* get first rule */

  while (t != NULL) {
    compiled_rule = compile_clause_eval_rule(t);
    rules = plist_append(rules, compiled_rule);
    fwrite_term_nl(stdout, t);
    zap_term(t);
    t = read_term(rule_fp, stderr);
  }
  fclose(rule_fp);

  /* Evaluate each clause on stdin. */

  c = read_clause(stdin, stderr);

  while (c != NULL && !end_of_list_clause(c)) {
    Plist p;
    c->weight = clause_weight(c->literals);
    for (p = rules; p; p = p->next) {
      Clause_eval rule = p->v;
      BOOL result = eval_clause_in_rule(c, rule);
      printf("%d  (wt=%.3f) : ", result, c->weight);
      fwrite_clause(stdout, c, CL_FORM_BARE);
    }
    printf("\n");
    
    zap_topform(c);
    c = read_clause(stdin, stderr);
  }
  
  exit(0);
}  /* main */
/* Plugin callback called during attribute registration.
Registered with register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL)
*/
static void register_attributes(void *event_data, void *data)
{
#ifdef DEBUG
    fprintf(stderr, "Registering attribute `instrument'\n");
#endif
    register_attribute(&instrument_attr);
}
Esempio n. 4
0
void gcc_plugin_attributes(void *gcc_data, void *user_data)
{
#define XIL_MAKE_ATTR(NAME, STR, _)                     \
  static struct attribute_spec NAME ## _attribute = {   \
    .name = STR,                                        \
    .min_length = 1,                                    \
    .max_length = 1                                     \
  };                                                    \
  register_attribute(&(NAME ## _attribute));

    XIL_ITERATE_ANNOT(XIL_MAKE_ATTR)
#undef XIL_MAKE_ATTR

    // attributes used in the files emitted during annotation processing.
    register_attribute(&annotation_name_attribute);
    register_attribute(&annotation_this_attribute);
    register_attribute(&annotation_this_var_attribute);
    register_attribute(&annotation_global_attribute);
    register_attribute(&annotation_param_attribute);
    register_attribute(&annotation_return_attribute);
    register_attribute(&annotation_local_attribute);
    register_attribute(&annotation_source_attribute);
}
int main(int argc, char **argv)
{
  Plist formulas, p;

  init_standard_ladr();

  clear_parse_type_for_all_symbols();
  declare_tptp_parse_types();
  set_variable_style(PROLOG_STYLE);
  set_quote_char('\'');  /* TPTP uses single quotes for strings. */

  int label_att  = register_attribute("label",        STRING_ATTRIBUTE);

  formulas = read_tptp_file(stdin);

  for (p = formulas; p; p = p->next) {
    p_formula(p->v);
    fwrite_formula(stdout, p->v);
  }

  exit(0);
}  /* main */
Esempio n. 6
0
static void 
register_attributes (void *event_data, void *data) 
{
  warning (0, G_("Callback to register attributes"));
  register_attribute (&user_attr);
}
Esempio n. 7
0
static void register_attributes(void __unused *event_data, void __unused *data)
{
	register_attribute(&nocapture_attr);
}
PyObject*
PyGcc_RegisterAttribute(PyObject *self, PyObject *args, PyObject *kwargs)
{
    const char *name;
    int min_length;
    int max_length;
    int decl_required;
    int type_required;
    int function_type_required;
    PyObject *callable;
    struct attribute_spec *attr;

    const char *keywords[] = {"name",
                              "min_length",
                              "max_length",
                              "decl_required",
                              "type_required",
                              "function_type_required",
                              "callable",
                              NULL};

    if (!PyArg_ParseTupleAndKeywords(args, kwargs,
                                     "siiiiiO:register_attribute", (char**)keywords,
                                     &name,
                                     &min_length,
                                     &max_length,
                                     &decl_required,
                                     &type_required,
                                     &function_type_required,
                                     &callable)) {
        return NULL;
    }

    /*
      "struct attribute_spec" is declared in gcc/tree.h

      register_attribute() is called by GCC for various attrs stored in
      tables of global data e.g.:
         const struct attribute_spec lto_attribute_table[]

      Hence we must malloc the data, so that it persists for the rest of the
      lifetime of the process

      We get a "handler" callback, it gets passed the name of the attribute,
      so maybe we can map names to callables.
    */
    attr = PyMem_New(struct attribute_spec, 1);
    if (!attr) {
        return PyErr_NoMemory();
    }

    /* Clear it first, for safety: */
    memset(attr, 0, sizeof(struct attribute_spec));

    /*
       Populate "attr"

       Annoyingly, all of the fields are marked as "const" within
       struct attribute_spec, so we have to cast away the constness, leading
       to the following deeply ugly code:
    */
    *(char**)&attr->name = PyGcc_strdup(name);
    if (!attr->name) {
        PyMem_Free(attr);
        return PyErr_NoMemory();
    }
    *(int*)&attr->min_length = min_length;
    *(int*)&attr->max_length = max_length;
    *(bool*)&attr->decl_required = decl_required;
    *(bool*)&attr->type_required = type_required;
    *(bool*)&attr->function_type_required = function_type_required;
    *(tree (**) (tree *node, tree name, tree args, int flags, bool *no_add_attrs))&attr->handler = handle_python_attribute;

    /*
       Associate the user-supplied callable with the given name, so that
       handle_python_attribute knows which one to call:
    */
    if (!attribute_dict) {
        attribute_dict = PyDict_New();
        if (!attribute_dict) {
            PyMem_Free((char*)attr->name);
            PyMem_Free(attr);
            return NULL;
        }
    }
    assert(attribute_dict);

    if (-1 == PyDict_SetItemString(attribute_dict, name, callable)) {
        PyMem_Free((char*)attr->name);
        PyMem_Free(attr);
        return NULL;
    }

    /*
       OK, call into GCC to register the attribute.

       (register_attribute doesn't have a return value; failures appear
       to be fatal)
    */
    register_attribute (attr);

    Py_RETURN_NONE;
}
int main(int argc, char **argv)
{
  Plist sos, goals, usable, p;
  int given_count = 0;
  int generated_count = 0;
  int kept_count = 0;
  int just_att_id;

  init_standard_ladr();

  just_att_id = register_attribute("just", TERM_ATTRIBUTE);

  sos    = read_clause_list(stdin, stderr, TRUE);
  goals  = read_clause_list(stdin, stderr, TRUE);
  usable = NULL;

  fwrite_clause_list(stdout, sos, "sos", CL_FORM_BARE);
  fwrite_clause_list(stdout, goals, "goals", CL_FORM_BARE);

  for (p = sos; p; p = p->next) {
    Clause c = p->v;
    Term just = get_term_attribute(c->attributes, just_att_id, 1);
    c->weight = clause_symbol_count(c);
    if (just) {
      int i;
      for (i = 0; i < ARITY(just); i++) {
	Term arg = ARG(just,i);
	int val;
	if (term_to_int(arg, &val)) {
	  printf("justfication arg = %d\n", val);
	}
      }
    }
  }

  while (sos != NULL) {
    Plist resolvents, p;
    Clause given = extract_given_clause(&sos);  /* updates sos */
    given_count++;
    printf("given #%d (wt=%d): ", given_count, given->weight);
    fwrite_clause(stdout, given, CL_FORM_STD);
    usable = plist_append(usable, given);

    resolvents = cd_given(given, usable);
    for (p = resolvents; p; p = p->next) {
      Clause res = p->v;
      generated_count++;
      if (subsumed_by_member(res, usable) ||
	  subsumed_by_member(res, sos))
	delete_clause(res);
      else {
	Clause empty_clause;
	kept_count++;
	assign_clause_id(res);
	res->weight = clause_symbol_count(res);
    
	sos = plist_append(sos, res);
	printf("kept (wt=%d): ", res->weight);
	fwrite_clause(stdout, res, CL_FORM_BARE);

	empty_clause = conflicts_with_member(res, goals);
	if (empty_clause) {
	  Plist proof = get_clause_ancestors(empty_clause);
	  printf("\n-------- PROOF --------\n");
	  for (p = proof; p; p = p->next)
	    fwrite_clause(stdout, p->v, CL_FORM_BARE);
	  printf("\n-------- end of proof  -------\n");
	  zap_plist(proof);  /* shallow */
	  exit(0);
	}
      }
    }
  }
  printf("exiting %s\n", PROGRAM_NAME);
  exit(0);
}  /* main */
Esempio n. 10
0
static void register_attributes(void *event_data, void *data)
{
	register_attribute(&latent_entropy_attr);
}
Esempio n. 11
0
static void
init_attributes (void)
{
  size_t i;
  int k;

  attribute_tables[0] = lang_hooks.common_attribute_table;
  attribute_tables[1] = lang_hooks.attribute_table;
  attribute_tables[2] = lang_hooks.format_attribute_table;
  attribute_tables[3] = targetm.attribute_table;

  /* Translate NULL pointers to pointers to the empty table.  */
  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
    if (attribute_tables[i] == NULL)
      attribute_tables[i] = empty_attribute_table;

#ifdef ENABLE_CHECKING
  /* Make some sanity checks on the attribute tables.  */
  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
    {
      int j;

      for (j = 0; attribute_tables[i][j].name != NULL; j++)
	{
	  /* The name must not begin and end with __.  */
	  const char *name = attribute_tables[i][j].name;
	  int len = strlen (name);

	  gcc_assert (!(name[0] == '_' && name[1] == '_'
			&& name[len - 1] == '_' && name[len - 2] == '_'));

	  /* The minimum and maximum lengths must be consistent.  */
	  gcc_assert (attribute_tables[i][j].min_length >= 0);

	  gcc_assert (attribute_tables[i][j].max_length == -1
		      || (attribute_tables[i][j].max_length
			  >= attribute_tables[i][j].min_length));

	  /* An attribute cannot require both a DECL and a TYPE.  */
	  gcc_assert (!attribute_tables[i][j].decl_required
		      || !attribute_tables[i][j].type_required);

	  /* If an attribute requires a function type, in particular
	     it requires a type.  */
	  gcc_assert (!attribute_tables[i][j].function_type_required
		      || attribute_tables[i][j].type_required);
	}
    }

  /* Check that each name occurs just once in each table.  */
  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
    {
      int j, k;
      for (j = 0; attribute_tables[i][j].name != NULL; j++)
	for (k = j + 1; attribute_tables[i][k].name != NULL; k++)
	  gcc_assert (strcmp (attribute_tables[i][j].name,
			      attribute_tables[i][k].name));
    }
  /* Check that no name occurs in more than one table.  */
  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
    {
      size_t j, k, l;

      for (j = i + 1; j < ARRAY_SIZE (attribute_tables); j++)
	for (k = 0; attribute_tables[i][k].name != NULL; k++)
	  for (l = 0; attribute_tables[j][l].name != NULL; l++)
	    gcc_assert (strcmp (attribute_tables[i][k].name,
				attribute_tables[j][l].name));
    }
#endif

  attribute_hash = htab_create (200, hash_attr, eq_attr, NULL);
  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
    for (k = 0; attribute_tables[i][k].name != NULL; k++)
      {
        register_attribute (&attribute_tables[i][k]);
      }
  invoke_plugin_callbacks (PLUGIN_ATTRIBUTES, NULL);
  attributes_initialized = true;
}