Ejemplo n.º 1
0
void pp_declaration_(struct node *node)
{
  pp_print(node->data.declaration->type_specifier);
  fputs(" (", output_file);
  pp_print(node->data.declaration->declarator);
  fputs(");\n", output_file);
}
Ejemplo n.º 2
0
void pp_array_declarator_(struct node *node)
{
  fputs("(", output_file);
  pp_print(node->data.array_declarator->declarator);
  fputs("[", output_file);
  if (node->data.array_declarator->length) pp_print(node->data.array_declarator->length);
  fputs("])", output_file);
}
Ejemplo n.º 3
0
void pp_declaration_list_(struct node *node)
{
  if (node->data.list->next) 
  {
    pp_print(node->data.list->next);
  }
  pp_print(node->data.list->current);
}
Ejemplo n.º 4
0
void pp_declarator_list_(struct node* node, int add_comma)
{
  if (node->data.list->next)
  {
    pp_declarator_list_(node->data.list->next, 1);
  }
  pp_print(node->data.list->current);
  if (add_comma) fputs(", ", output_file);
}
Ejemplo n.º 5
0
// Render the given term into the output stream.
void
print(std::ostream& os, Tree* t) {
  if (not t) {
    os << "<null>";
    return;
  }

  switch (t->kind) {
  case id_tree: return pp_terminal(os, as<Id_tree>(t));
  case lit_tree: return pp_terminal(os, as<Lit_tree>(t));
  case var_tree: return pp_var(os, as<Var_tree>(t));
  case init_tree: return pp_init(os, as<Init_tree>(t));
  case abs_tree: return pp_abs(os, as<Abs_tree>(t));
  case fn_tree: return pp_fn(os, as<Fn_tree>(t));
  case app_tree: return pp_app(os, as<App_tree>(t));
  case if_tree:  return pp_if(os, as<If_tree>(t));
  case succ_tree: return pp_succ(os, as<Succ_tree>(t));
  case pred_tree: return pp_pred(os, as<Pred_tree>(t));
  case ls_tree: return pp_ls(os, as<Ls_tree>(t));//Rishi
  case mkdir_tree: return pp_mkdir(os, as<Mkdir_tree>(t));//Rishi
  case rmdir_tree: return pp_rmdir(os, as<Rmdir_tree>(t));//Rishi
  case cd_tree: return pp_cd(os, as<Cd_tree>(t));//Rishi
  case mv_tree: return pp_mv(os, as<Mv_tree>(t));//Rishi
  case iszero_tree: return pp_iszero(os, as<Iszero_tree>(t));
  case arrow_tree: return pp_arrow(os, as<Arrow_tree>(t));
  case def_tree: return pp_def(os, as<Def_tree>(t));
  case print_tree: return pp_print(os, as<Print_tree>(t));
  case typeof_tree: return pp_typeof(os, as<Typeof_tree>(t));
  case tuple_tree: return pp_tuple(os, as<Tuple_tree>(t));
  case list_tree: return pp_list(os, as<List_tree>(t));
  case variant_tree: return pp_variant(os, as<Variant_tree>(t));
  case comma_tree: return pp_comma(os, as<Comma_tree>(t));
  case dot_tree: return pp_dot(os, as<Dot_tree>(t));
  case prog_tree: return pp_prog(os, as<Prog_tree>(t));
  }
  lang_unreachable(format("print unknown node '{}'", node_name(t)));
}
Ejemplo n.º 6
0
static const struct parsed_proto *check_var(FILE *fhdr,
  const char *sym, const char *varname)
{
  const struct parsed_proto *pp, *pp_sym;
  char fp_sym[256], fp_var[256], *p;
  int i;

  pp = proto_parse(fhdr, varname, 1);
  if (pp == NULL) {
    if (IS_START(varname, "sub_"))
      awarn("sub_ sym missing proto: '%s'\n", varname);
    return NULL;
  }

  if (!pp->is_func && !pp->is_fptr)
    return NULL;

  pp_print(fp_var, sizeof(fp_var), pp);

  if (pp->argc_reg == 0)
    goto check_sym;
  if (pp->argc_reg == 1 && pp->argc_stack == 0
    && IS(pp->arg[0].reg, "ecx"))
  {
    goto check_sym;
  }
  if (!g_cconv_novalidate
    && (pp->argc_reg != 2
       || !IS(pp->arg[0].reg, "ecx")
       || !IS(pp->arg[1].reg, "edx")))
  {
    awarn("unhandled reg call: %s\n", fp_var);
  }

check_sym:
  // fptrs must use 32bit args, callsite might have no information and
  // lack a cast to smaller types, which results in incorrectly masked
  // args passed (callee may assume masked args, it does on ARM)
  for (i = 0; i < pp->argc; i++) {
    if (pp->arg[i].type.is_ptr)
      continue;
    p = pp->arg[i].type.name;
    if (strstr(p, "int8") || strstr(p, "int16")
      || strstr(p, "char") || strstr(p, "short"))
    {
      awarn("reference to %s with arg%d '%s'\n", pp->name, i + 1, p);
    }
  }

  sprint_pp_short(pp, g_comment, sizeof(g_comment));

  if (sym != NULL) {
    g_func_sym_pp = NULL;
    pp_sym = proto_parse(fhdr, sym, 1);
    if (pp_sym == NULL)
      return pp;
    if (!pp_sym->is_fptr)
      aerr("func ptr data, but label '%s' !is_fptr\n", pp_sym->name);
    g_func_sym_pp = pp_sym;
  }
  else {
    pp_sym = g_func_sym_pp;
    if (pp_sym == NULL)
      return pp;
  }

  if (pp_cmp_func(pp, pp_sym)) {
    pp_print(fp_sym, sizeof(fp_sym), pp_sym);
    anote("var: %s\n", fp_var);
    anote("sym: %s\n", fp_sym);
    awarn("^ mismatch\n");
  }

  return pp;
}
Ejemplo n.º 7
0
void pp_pointer_(struct node *node)
{
  fputs("(*", output_file);
  pp_print(node->data.pointer_to);
  fputs(")", output_file);
}
Ejemplo n.º 8
0
Archivo: s2.cpp Proyecto: dCache/s2
/********************************************************************
 * Parse command-line arguments (non -+ options)
 *
 * Returns:
 *   ERR_OK: if success
 *   >= ERR_OK: otherwise
 ********************************************************************/
static int
s2_run(int argc, char **argv, int i)
{
  int rval = ERR_OK, lval;
  int i_1 = i;
  Node *root = NULL;
  Process *proc = NULL;
  BOOL tp_created = FALSE;

  /* init progress bar */
  Process::progress(-1,proc);

#if defined(HAVE_SRM21) || defined(HAVE_SRM22)
  srm_init();
#endif

  lval = parse(opts.scr_fname, &root);
  DM_DBG(DM_N(1), "parser return value=%d\n", lval);
  UPDATE_MAX(rval, lval);
  if(rval > opts.s2_eval) {
    /* stop evaluation */
    UPDATE_MAX(rval, ERR_NEXEC);
    goto cleanup;
  }

  /* create thread pool */
  if(!tp_created) tp_init(opts.tp_size);
  tp_created = TRUE;

  /* pretty-print S2 tree ($ENV{VAR} are evaluated) */
  if(opts.pp_fname) lval = pp_print(root);
  DM_DBG(DM_N(1), "pretty-printer return value=%d\n", lval);
  UPDATE_MAX(rval, lval);

  if(root) {
    Process::threads_init();
    proc = new Process(root, NULL, NULL);

    if(!proc) {
      DM_ERR(ERR_SYSTEM, _("failed to create a Process: %s\n"), _(strerror(errno)));
      UPDATE_MAX(rval, ERR_SYSTEM);
      goto cleanup;
    }

    /* write ${0}..${n} variables */
    const char *name = cmd_label();
    proc->WriteVariable("0", name, TRUE);
    for(; i < argc; i++) {
      proc->WriteVariable(i2str(i - i_1 + 1).c_str(), argv[i], TRUE);
    }

    setenv("CLIENT_INFO", build_client_info(name), 1);

    lval = proc->eval();
    Process::threads_destroy();
    DM_DBG(DM_N(1), "evaluation return value=%d\n", lval);
    UPDATE_MAX(rval, lval);
  }

  /* after-evaluation print of the tree */
  if(opts.e2_fname) lval = e2_print(root);
  DM_DBG(DM_N(2), "after-evaluation print return value=%d\n", lval);
  UPDATE_MAX(rval, lval);

cleanup:
  /* cleanup */
  DELETE(proc);	/* free proc *first*, then root */
  DELETE(root);

  /* destroy thread pool */
  if(tp_created) tp_cleanup();

  /* hide progress bar */
  Process::progress(0,proc);

  DM_DBG(DM_N(1), "s2_run return value=%d\n", rval);
  return rval;
}