Пример #1
0
static tree_t run_elab(void)
{
   tree_t t, last_ent = NULL;
   while ((t = parse())) {
      sem_check(t);
      fail_if(sem_errors() > 0);

      simplify(t);

      if (tree_kind(t) == T_ENTITY)
         last_ent = t;
   }

   return elab(last_ent);
}
Пример #2
0
static int analyse(int argc, char **argv)
{
   set_work_lib();

   static struct option long_options[] = {
      { "bootstrap",       no_argument, 0, 'b' },
      { "dump-llvm",       no_argument, 0, 'd' },
      { "prefer-explicit", no_argument, 0, 'p' },
      { 0, 0, 0, 0 }
   };

   int c, index = 0;
   const char *spec = "";
   optind = 1;
   while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case '?':
         // getopt_long already printed an error message
         exit(EXIT_FAILURE);
      case 'b':
         opt_set_int("bootstrap", 1);
         break;
      case 'd':
         opt_set_int("dump-llvm", 1);
         break;
      case 'p':
         opt_set_int("prefer-explicit", 1);
         break;
      default:
         abort();
      }
   }

   size_t unit_list_sz = 32;
   tree_t *units LOCAL = xmalloc(sizeof(tree_t) * unit_list_sz);
   int n_units = 0;

   for (int i = optind; i < argc; i++) {
      input_from_file(argv[i]);

      tree_t unit;
      while ((unit = parse()) && sem_check(unit))
         ARRAY_APPEND(units, unit, n_units, unit_list_sz);
   }

   for (int i = 0; i < n_units; i++) {
      simplify(units[i]);
      bounds_check(units[i]);
   }

   if (parse_errors() + sem_errors() + bounds_errors() > 0)
      return EXIT_FAILURE;

   for (int i = 0; i < n_units; i++) {
      tree_kind_t kind = tree_kind(units[i]);
      const bool need_cgen =
         (kind == T_PACK_BODY)
         || ((kind == T_PACKAGE) && pack_needs_cgen(units[i]));
      if (need_cgen)
         opt(units[i]);
      else
         units[i] = NULL;
   }

   lib_save(lib_work());

   for (int i = 0; i < n_units; i++) {
      if (units[i] != NULL)
         cgen(units[i]);
   }

   return EXIT_SUCCESS;
}
Пример #3
0
static int analyse(int argc, char **argv)
{
   set_work_lib();

   static struct option long_options[] = {
      { "bootstrap",       no_argument,       0, 'b' },
      { "dump-llvm",       no_argument,       0, 'd' },
      { "dump-vcode",      optional_argument, 0, 'v' },
      { "prefer-explicit", no_argument,       0, 'p' },   // DEPRECATED
      { "relax",           required_argument, 0, 'r' },
      { 0, 0, 0, 0 }
   };

   int c, index = 0;
   const char *spec = "";
   optind = 1;
   while ((c = getopt_long(argc, argv, spec, long_options, &index)) != -1) {
      switch (c) {
      case 0:
         // Set a flag
         break;
      case '?':
         fatal("unrecognised analyse option %s", argv[optind - 1]);
      case 'b':
         opt_set_int("bootstrap", 1);
         break;
      case 'd':
         opt_set_int("dump-llvm", 1);
         break;
      case 'v':
         opt_set_str("dump-vcode", optarg ?: "");
         break;
      case 'p':
         warnf("the --prefer-explict option is deprecated: use "
               "--relax=prefer-explict instead");
         opt_set_int("relax", RELAX_PREFER_EXPLICT);
         break;
      case 'r':
         opt_set_int("relax", parse_relax(optarg));
         break;
      default:
         abort();
      }
   }

   size_t unit_list_sz = 32;
   tree_t *units LOCAL = xmalloc(sizeof(tree_t) * unit_list_sz);
   int n_units = 0;

   for (int i = optind; i < argc; i++) {
      input_from_file(argv[i]);

      tree_t unit;
      while ((unit = parse()) && sem_check(unit))
         ARRAY_APPEND(units, unit, n_units, unit_list_sz);
   }

   for (int i = 0; i < n_units; i++) {
      simplify(units[i]);
      bounds_check(units[i]);
   }

   if (parse_errors() + sem_errors() + bounds_errors() > 0)
      return EXIT_FAILURE;

   for (int i = 0; i < n_units; i++) {
      tree_kind_t kind = tree_kind(units[i]);
      const bool need_cgen =
         (kind == T_PACK_BODY)
         || ((kind == T_PACKAGE) && pack_needs_cgen(units[i]));
      if (need_cgen)
         opt(units[i]);
      else
         units[i] = NULL;
   }

   lib_save(lib_work());

   for (int i = 0; i < n_units; i++) {
      if (units[i] != NULL) {
         lower_unit(units[i]);
         cgen(units[i]);
      }
   }

   return EXIT_SUCCESS;
}