Exemplo n.º 1
0
PT_Tree PT_findTreeParentRecursive(PT_Tree needle, PT_Tree haystack)
{
  assert(needle != NULL);
  assert(haystack != NULL);
  assert(needle != haystack);

  if (ATtableGet(findParentCache, PT_TreeToTerm(haystack)) != NULL) {
	  return NULL;
  }

  if (PT_hasTreeArgs(haystack)) {
    PT_Args children = PT_getTreeArgs(haystack);
    while (!PT_isArgsEmpty(children)) {
      PT_Tree child = PT_getArgsHead(children);
      if (PT_isEqualTree(child, needle)) {
	return haystack;
      }
      else {
	PT_Tree suspect = PT_findTreeParentRecursive(needle, child);
	if (suspect != NULL) {
	  return suspect;
	}
      }
      children = PT_getArgsTail(children);
    }
  }

  ATtablePut(findParentCache, PT_TreeToTerm(haystack), PT_TreeToTerm(NeedleNotHere));
  return NULL;
}
Exemplo n.º 2
0
static PT_Tree set_anno(PT_Tree term, PT_Tree key, PT_Tree value)
{
  return PT_setTreeAnnotation(term,
			      PT_TreeToTerm(key),
			      PT_TreeToTerm(value));
}
Exemplo n.º 3
0
int main(int argc, char **argv) {
  ATerm bos, term;
  ATermTable opcodes;
  AIL_Definition def;
  AIL_Program prg;
  ABFBuffer buffer;
  ABF abf;
  PT_Tree tree;
  int size;

  /* Option processing */
  int arg_ct = optionProcess(&ailcOptions, argc, argv);
  argc -= arg_ct;
  argv += arg_ct;
  if (HAVE_OPT(INPUT))
    ailc_input = open_file(OPT_ARG(INPUT), "r");
  else 
    ailc_input = stdin;
  if (HAVE_OPT(OUTPUT)) 
    ailc_output = open_file(OPT_ARG(OUTPUT), "w");
  else 
    ailc_output = stdout;
  if (HAVE_OPT(GENERATE_API)) {
    ailc_generate_api = 1;
    ailc_name = OPT_ARG(NAME);
/*     if (HAVE_OPT(PREFIX)) */
/*       ailc_prefix = OPT_ARG(PREFIX); */
/*     else */
/*       ailc_prefix = default_ail_prefix; */
  }
  if (HAVE_OPT(AIL_LIST)) 
    ailc_def = OPT_ARG(AIL_LIST);
  else
    ailc_def = default_ail_def;
  if (HAVE_OPT(VERBOSE))
    ail2abf_set_verbose(1);

  /* end option processing. */

  ATinit(argc, argv, &bos);
  AIL_initAILApi();
  PT_initMEPTApi();
  abf_init_buffer(&buffer);

  /* Read definition. */
  term = ATreadFromNamedFile(ailc_def);
  tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term));
  def = AIL_DefinitionFromTerm(PT_TreeToTerm(tree));

  /* Save api if needed. */
  if (ailc_generate_api)
    save_opcode_api(ailc_name, def);
  else {
    AIL_ByteCode bc;
    term = ATreadFromBinaryFile(ailc_input);
    tree = PT_getParseTreeTree(PT_ParseTreeFromTerm(term));
    prg = AIL_ProgramFromTerm(PT_TreeToTerm(tree));
    bc = compile_ail(&buffer, def, prg);
    AIL_writeToFile(ailc_output, bc);
  }
  return 0;
}