Example #1
0
/**
 * Handle special cases of options like compile time defaults
 *
 * return CONTINUE if no errors else an ponyc_opt_process_t EXIT_XXX code.
 */
static ponyc_opt_process_t special_opt_processing(pass_opt_t *opt)
{
  // Suppress compiler errors due to conditional compilation
  MAYBE_UNUSED(opt);

#if defined(PONY_DEFAULT_PIC)
  #if (PONY_DEFAULT_PIC == true) || (PONY_DEFAULT_PIC == false)
    opt->pic = PONY_DEFAULT_PIC;
  #else
    #error "PONY_DEFAULT_PIC must be true or false"
  #endif
#endif

#if defined(USE_SCHEDULER_SCALING_PTHREADS)
  // Defined "scheduler_scaling_pthreads" so that SIGUSR2 is made available for
  // use by the signals package when not using signals for scheduler scaling
  define_build_flag("scheduler_scaling_pthreads");
#endif

  define_build_flag(PONY_DEFAULT_SSL);

  return CONTINUE;
}
Example #2
0
int main(int argc, char* argv[])
{
  stringtab_init();

  pass_opt_t opt;
  pass_opt_init(&opt);

  opt.release = true;
  opt.output = ".";

  ast_setwidth(get_width());
  bool print_program_ast = false;
  bool print_package_ast = false;

  opt_state_t s;
  ponyint_opt_init(args, &s, &argc, argv);

  bool ok = true;
  bool print_usage = false;
  int id;

  while((id = ponyint_opt_next(&s)) != -1)
  {
    switch(id)
    {
      case OPT_VERSION:
        printf("%s [%s] (llvm %s)\n", PONY_VERSION, PONY_BUILD_CONFIG,
          LLVM_VERSION);
        return 0;

      case OPT_DEBUG: opt.release = false; break;
      case OPT_BUILDFLAG: define_build_flag(s.arg_val); break;
      case OPT_STRIP: opt.strip_debug = true; break;
      case OPT_PATHS: package_add_paths(s.arg_val, &opt); break;
      case OPT_OUTPUT: opt.output = s.arg_val; break;
      case OPT_LIBRARY: opt.library = true; break;
      case OPT_RUNTIMEBC: opt.runtimebc = true; break;
      case OPT_PIC: opt.pic = true; break;
      case OPT_DOCS: opt.docs = true; break;

      case OPT_SAFE:
        if(!package_add_safe(s.arg_val, &opt))
          ok = false;
        break;

      case OPT_IEEEMATH: opt.ieee_math = true; break;
      case OPT_CPU: opt.cpu = s.arg_val; break;
      case OPT_FEATURES: opt.features = s.arg_val; break;
      case OPT_TRIPLE: opt.triple = s.arg_val; break;
      case OPT_STATS: opt.print_stats = true; break;
      case OPT_LINK_ARCH: opt.link_arch = s.arg_val; break;
      case OPT_LINKER: opt.linker = s.arg_val; break;

      case OPT_AST: print_program_ast = true; break;
      case OPT_ASTPACKAGE: print_package_ast = true; break;
      case OPT_TRACE: parse_trace(true); break;
      case OPT_WIDTH: ast_setwidth(atoi(s.arg_val)); break;
      case OPT_IMMERR: errors_set_immediate(opt.check.errors, true); break;
      case OPT_VERIFY: opt.verify = true; break;
      case OPT_EXTFUN: opt.extfun = true; break;
      case OPT_FILENAMES: opt.print_filenames = true; break;
      case OPT_CHECKTREE: opt.check_tree = true; break;

      case OPT_BNF: print_grammar(false, true); return 0;
      case OPT_ANTLR: print_grammar(true, true); return 0;
      case OPT_ANTLRRAW: print_grammar(true, false); return 0;

      case OPT_VERBOSE:
        {
          int v = atoi(s.arg_val);
          if (v >= 0 && v <= 4) {
            opt.verbosity = (verbosity_level)v;
          } else {
            ok = false;
          }
        }
        break;

      case OPT_PASSES:
        if(!limit_passes(&opt, s.arg_val))
        {
          ok = false;
          print_usage = true;
        }
        break;

      default: usage(); return -1;
    }
  }

  for(int i = 1; i < argc; i++)
  {
    if(argv[i][0] == '-')
    {
      printf("Unrecognised option: %s\n", argv[i]);
      ok = false;
      print_usage = true;
    }
  }

#if defined(PLATFORM_IS_WINDOWS)
  opt.strip_debug = true;
#endif

  if(!ok)
  {
    errors_print(opt.check.errors);

    if(print_usage)
      usage();

    return -1;
  }

  if(ponyc_init(&opt))
  {
    if(argc == 1)
    {
      ok &= compile_package(".", &opt, print_program_ast, print_package_ast);
    } else {
      for(int i = 1; i < argc; i++)
        ok &= compile_package(argv[i], &opt, print_program_ast,
          print_package_ast);
    }
  }

  if(!ok && errors_get_count(opt.check.errors) == 0)
    printf("Error: internal failure not reported\n");

  ponyc_shutdown(&opt);
  pass_opt_done(&opt);

  return ok ? 0 : -1;
}
Example #3
0
File: main.c Project: mgist/ponyc
int main(int argc, char* argv[])
{
  stringtab_init();

  pass_opt_t opt;
  pass_opt_init(&opt);

  opt.release = true;
  opt.output = ".";

  ast_setwidth(get_width());
  bool print_program_ast = false;
  bool print_package_ast = false;

  opt_state_t s;
  opt_init(args, &s, &argc, argv);

  bool ok = true;
  bool print_usage = false;
  int id;

  while((id = opt_next(&s)) != -1)
  {
    switch(id)
    {
      case OPT_VERSION:
        printf("%s\n", PONY_VERSION);
        return 0;

      case OPT_DEBUG: opt.release = false; break;
      case OPT_BUILDFLAG: define_build_flag(s.arg_val); break;
      case OPT_STRIP: opt.strip_debug = true; break;
      case OPT_PATHS: package_add_paths(s.arg_val); break;
      case OPT_OUTPUT: opt.output = s.arg_val; break;
      case OPT_LIBRARY: opt.library = true; break;
      case OPT_DOCS: opt.docs = true; break;

      case OPT_SAFE:
        if(!package_add_safe(s.arg_val))
          ok = false;
        break;

      case OPT_IEEEMATH: opt.ieee_math = true; break;
      case OPT_CPU: opt.cpu = s.arg_val; break;
      case OPT_FEATURES: opt.features = s.arg_val; break;
      case OPT_TRIPLE: opt.triple = s.arg_val; break;
      case OPT_STATS: opt.print_stats = true; break;

      case OPT_AST: print_program_ast = true; break;
      case OPT_ASTPACKAGE: print_package_ast = true; break;
      case OPT_TRACE: parse_trace(true); break;
      case OPT_WIDTH: ast_setwidth(atoi(s.arg_val)); break;
      case OPT_IMMERR: error_set_immediate(true); break;
      case OPT_VERIFY: opt.verify = true; break;
      case OPT_FILENAMES: opt.print_filenames = true; break;
      case OPT_CHECKTREE: enable_check_tree(true); break;

      case OPT_BNF: print_grammar(false, true); return 0;
      case OPT_ANTLR: print_grammar(true, true); return 0;
      case OPT_ANTLRRAW: print_grammar(true, false); return 0;

      case OPT_PASSES:
        if(!limit_passes(&opt, s.arg_val))
        {
          ok = false;
          print_usage = true;
        }
        break;

      default: usage(); return -1;
    }
  }

  for(int i = 1; i < argc; i++)
  {
    if(argv[i][0] == '-')
    {
      printf("Unrecognised option: %s\n", argv[i]);
      ok = false;
      print_usage = true;
    }
  }

#ifdef PLATFORM_IS_WINDOWS
  opt.strip_debug = true;
#endif

  if(!ok)
  {
    print_errors();

    if(print_usage)
      usage();

    return -1;
  }

  if(package_init(&opt))
  {
    if(argc == 1)
    {
      ok &= compile_package(".", &opt, print_program_ast, print_package_ast);
    } else {
      for(int i = 1; i < argc; i++)
        ok &= compile_package(argv[i], &opt, print_program_ast,
          print_package_ast);
    }
  }

  if(!ok && get_error_count() == 0)
    printf("Error: internal failure not reported\n");

  package_done(&opt);
  pass_opt_done(&opt);
  stringtab_done();

  return ok ? 0 : -1;
}
Example #4
0
ponyc_opt_process_t ponyc_opt_process(opt_state_t* s, pass_opt_t* opt,
       /*OUT*/ bool* print_program_ast,
       /*OUT*/ bool* print_package_ast)
{
  ponyc_opt_process_t exit_code = CONTINUE;
  int id;
  *print_program_ast = false;
  *print_package_ast = false;

  exit_code = special_opt_processing(opt);
  if(exit_code != CONTINUE)
    return exit_code;

  bool wants_help = false;

  while((id = ponyint_opt_next(s)) != -1)
  {
    switch(id)
    {
      case OPT_VERSION:
        printf("%s\n", PONY_VERSION_STR);
        printf("Defaults: pic=%s ssl=%s\n", opt->pic ? "true" : "false",
            PONY_DEFAULT_SSL);
        return EXIT_0;

      case OPT_HELP:
        wants_help = true; break;
      case OPT_DEBUG: opt->release = false; break;
      case OPT_BUILDFLAG:
        if(is_openssl_flag(s->arg_val))
        {
          if(validate_openssl_flag(s->arg_val))
          { // User wants to add an openssl_flag,
            // remove any existing openssl_flags.
            remove_build_flags(valid_openssl_flags);
          } else {
            printf("Error: %s is invalid openssl flag, expecting one of:\n",
                s->arg_val);
            for(const char** next=valid_openssl_flags; *next != NULL; next++)
              printf("       %s\n", *next);
            return EXIT_255;
          }
        }
        define_build_flag(s->arg_val);
        break;
      case OPT_STRIP: opt->strip_debug = true; break;
      case OPT_PATHS: package_add_paths(s->arg_val, opt); break;
      case OPT_OUTPUT: opt->output = s->arg_val; break;
      case OPT_BIN_NAME: opt->bin_name = s->arg_val; break;
      case OPT_LIBRARY: opt->library = true; break;
      case OPT_RUNTIMEBC: opt->runtimebc = true; break;
      case OPT_STATIC: opt->staticbin = true; break;
      case OPT_PIC: opt->pic = true; break;
      case OPT_NOPIC: opt->pic = false; break;
      case OPT_DOCS:
        {
          opt->docs = true;
          opt->docs_private = true;
        }
        break;
      case OPT_DOCS_PUBLIC:
        {
          opt->docs = true;
          opt->docs_private = false;
        }
        break;
      case OPT_SAFE:
        if(!package_add_safe(s->arg_val, opt))
        {
          printf("Error adding safe packages: %s\n", s->arg_val);
          exit_code = EXIT_255;
        }
        break;

      case OPT_CPU: opt->cpu = s->arg_val; break;
      case OPT_FEATURES: opt->features = s->arg_val; break;
      case OPT_TRIPLE: opt->triple = s->arg_val; break;
      case OPT_STATS: opt->print_stats = true; break;
      case OPT_LINK_ARCH: opt->link_arch = s->arg_val; break;
      case OPT_LINKER: opt->linker = s->arg_val; break;
      case OPT_PLUGIN:
        if(!plugin_load(opt, s->arg_val))
        {
          printf("Error loading plugins: %s\n", s->arg_val);
          exit_code = EXIT_255;
        }
        break;

      case OPT_AST: *print_program_ast = true; break;
      case OPT_ASTPACKAGE: *print_package_ast = true; break;
      case OPT_TRACE: opt->parse_trace = true; break;
      case OPT_WIDTH: opt->ast_print_width = atoi(s->arg_val); break;
      case OPT_IMMERR: errors_set_immediate(opt->check.errors, true); break;
      case OPT_VERIFY: opt->verify = true; break;
      case OPT_EXTFUN: opt->extfun = true; break;
      case OPT_SIMPLEBUILTIN: opt->simple_builtin = true; break;
      case OPT_FILENAMES: opt->print_filenames = true; break;
      case OPT_CHECKTREE: opt->check_tree = true; break;
      case OPT_LINT_LLVM: opt->lint_llvm = true; break;

      case OPT_BNF: print_grammar(false, true); return EXIT_0;
      case OPT_ANTLR: print_grammar(true, true); return EXIT_0;
      case OPT_ANTLRRAW: print_grammar(true, false); return EXIT_0;

      case OPT_VERBOSE:
        {
          int v = atoi(s->arg_val);
          if(v >= 0 && v <= 4)
          {
            opt->verbosity = (verbosity_level)v;
          } else {
            printf("Verbosity must be 0..4, %d is invalid\n", v);
            exit_code = EXIT_255;
          }
        }
        break;

      case OPT_PASSES:
        if(!limit_passes(opt, s->arg_val))
        {
          printf("Invalid pass=%s it should be one of:\n", s->arg_val);
          print_passes();
          exit_code = EXIT_255;
        }
        break;

      default:
        printf("BUG: unprocessed option id %d\n", id);
        return EXIT_255;
    }
  }

  if(!plugin_parse_options(opt, s->argc, s->argv))
    exit_code = EXIT_255;

  if(wants_help)
  {
    usage();
    plugin_print_help(opt);

    if(exit_code != EXIT_255)
      exit_code = EXIT_0;

    return exit_code;
  }

  for(int i = 1; i < (*s->argc); i++)
  {
    if(s->argv[i][0] == '-')
    {
      printf("Unrecognised option: %s\n", s->argv[i]);
      exit_code = EXIT_255;
    }
  }

  return exit_code;
}