[svn:parrot] r46919 - in trunk: compilers/imcc include/parrot src

plobsing at svn.parrot.org plobsing at svn.parrot.org
Sun May 23 20:30:36 UTC 2010


Author: plobsing
Date: Sun May 23 20:30:36 2010
New Revision: 46919
URL: https://trac.parrot.org/parrot/changeset/46919

Log:
separate imcc argument parsing from parrot argument parsing

Modified:
   trunk/compilers/imcc/main.c
   trunk/include/parrot/imcc.h
   trunk/include/parrot/longopt.h
   trunk/src/longopt.c
   trunk/src/main.c

Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c	Sun May 23 18:15:48 2010	(r46918)
+++ trunk/compilers/imcc/main.c	Sun May 23 20:30:36 2010	(r46919)
@@ -61,12 +61,9 @@
         __attribute__nonnull__(3);
 
 static void determine_output_file_type(PARROT_INTERP,
-    ARGMOD(int *obj_file),
     ARGIN(const char *output_file))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(3)
-        FUNC_MODIFIES(*obj_file);
+        __attribute__nonnull__(2);
 
 static void do_pre_process(PARROT_INTERP, yyscan_t yyscanner)
         __attribute__nonnull__(1);
@@ -78,13 +75,11 @@
         __attribute__nonnull__(3)
         FUNC_MODIFIES(*opt_desc);
 
-static void imcc_run_pbc(PARROT_INTERP,
-    int obj_file,
-    ARGIN_NULLOK(const char *output_file),
+static void imcc_parseflags(PARROT_INTERP,
     int argc,
     ARGIN(const char **argv))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(5);
+        __attribute__nonnull__(3);
 
 static void imcc_write_pbc(PARROT_INTERP, ARGIN(const char *output_file))
         __attribute__nonnull__(1)
@@ -105,14 +100,13 @@
     , PARROT_ASSERT_ARG(yyscanner))
 #define ASSERT_ARGS_determine_output_file_type __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(obj_file) \
     , PARROT_ASSERT_ARG(output_file))
 #define ASSERT_ARGS_do_pre_process __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp))
 #define ASSERT_ARGS_imcc_get_optimization_description \
      __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(opt_desc))
-#define ASSERT_ARGS_imcc_run_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+#define ASSERT_ARGS_imcc_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(argv))
 #define ASSERT_ARGS_imcc_write_pbc __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -153,116 +147,89 @@
     return 1;
 }
 
-/*
-
-=item C<void imcc_start_handling_flags(PARROT_INTERP)>
-
-Initialize handling of IMCC related command line flags.
-
-=cut
-
-*/
-void
-imcc_start_handling_flags(PARROT_INTERP)
+static void
+imcc_parseflags(PARROT_INTERP, int argc, ARGIN(const char **argv))
 {
-    SET_STATE_RUN_PBC(interp);
-}
-
-/*
-
-=item C<int imcc_handle_flag(PARROT_INTERP, struct longopt_opt_info *opt,
-Parrot_Run_core_t *core)>
-
-Handle Parrot's command line for IMCC related option and set appropriate flags.
+    ASSERT_ARGS(imcc_parseflags)
+    struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
 
-Return 1 if flag handled, 0 if not.
+    /* default state: run pbc */
+    SET_STATE_RUN_PBC(interp);
 
-=cut
+    while (longopt_get(interp, argc, argv, Parrot_cmd_options, &opt) > 0) {
+        switch (opt.opt_id) {
+          case 'd':
+            if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) {
+                IMCC_INFO(interp)->debug = strtoul(opt.opt_arg, NULL, 16);
+            }
+            else {
+                IMCC_INFO(interp)->debug++;
+            }
+            break;
+          case 'w':
+            /* FIXME It's not best way to set warnings... */
+            Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG);
+            IMCC_INFO(interp)->imcc_warn = 1;
+            break;
+          case 'G':
+            IMCC_INFO(interp)->gc_off = 1;
+            break;
+          case 'a':
+            SET_STATE_PASM_FILE(interp);
+            break;
+          case 'r':
+            if (STATE_RUN_PBC(interp))
+                SET_STATE_RUN_FROM_FILE(interp);
+            SET_STATE_RUN_PBC(interp);
+            break;
+          case 'c':
+            SET_STATE_LOAD_PBC(interp);
+            break;
+          case 'v':
+            IMCC_INFO(interp)->verbose++;
+            break;
+          case 'y':
+            yydebug = 1;
+            break;
+          case 'E':
+            SET_STATE_PRE_PROCESS(interp);
+            break;
+          case 'o':
+            UNSET_STATE_RUN_PBC(interp);
+            interp->output_file = opt.opt_arg;
+            break;
 
-*/
+          case OPT_PBC_OUTPUT:
+            UNSET_STATE_RUN_PBC(interp);
+            SET_STATE_WRITE_PBC(interp);
+            if (!interp->output_file)
+                interp->output_file = "-";
+            break;
 
-PARROT_WARN_UNUSED_RESULT
-PARROT_CAN_RETURN_NULL
-int
-imcc_handle_flag(PARROT_INTERP, struct longopt_opt_info *opt,
-    Parrot_Run_core_t *core)
-{
-    PARROT_ASSERT(opt);
-    PARROT_ASSERT(core);
+          case 'O':
+            if (!opt.opt_arg) {
+                IMCC_INFO(interp)->optimizer_level |= OPT_PRE;
+                break;
+            }
+            if (strchr(opt.opt_arg, 'p'))
+                IMCC_INFO(interp)->optimizer_level |= OPT_PASM;
+            if (strchr(opt.opt_arg, 'c'))
+                IMCC_INFO(interp)->optimizer_level |= OPT_SUB;
+
+            /* currently not ok due to different register allocation */
+            if (strchr(opt.opt_arg, '1')) {
+                IMCC_INFO(interp)->optimizer_level |= OPT_PRE;
+            }
+            if (strchr(opt.opt_arg, '2')) {
+                IMCC_INFO(interp)->optimizer_level |= (OPT_PRE | OPT_CFG);
+            }
+            break;
 
-    switch (opt->opt_id) {
-      case 'd':
-        if (opt->opt_arg && is_all_hex_digits(opt->opt_arg)) {
-            IMCC_INFO(interp)->debug = strtoul(opt->opt_arg, NULL, 16);
-        }
-        else {
-            IMCC_INFO(interp)->debug++;
-        }
-        break;
-      case 'w':
-        /* FIXME It's not best way to set warnings... */
-        Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG);
-        IMCC_INFO(interp)->imcc_warn = 1;
-        break;
-      case 'G':
-        IMCC_INFO(interp)->gc_off = 1;
-        break;
-      case 'a':
-        SET_STATE_PASM_FILE(interp);
-        break;
-      case 'r':
-        if (STATE_RUN_PBC(interp))
-            SET_STATE_RUN_FROM_FILE(interp);
-        SET_STATE_RUN_PBC(interp);
-        break;
-      case 'c':
-        SET_STATE_LOAD_PBC(interp);
-        break;
-      case 'v':
-        IMCC_INFO(interp)->verbose++;
-        break;
-      case 'y':
-        yydebug = 1;
-        break;
-      case 'E':
-        SET_STATE_PRE_PROCESS(interp);
-        break;
-      case 'o':
-        UNSET_STATE_RUN_PBC(interp);
-        interp->output_file = opt->opt_arg;
-        break;
-
-      case OPT_PBC_OUTPUT:
-        UNSET_STATE_RUN_PBC(interp);
-        SET_STATE_WRITE_PBC(interp);
-        if (!interp->output_file)
-            interp->output_file = "-";
-        break;
-
-      case 'O':
-        if (!opt->opt_arg) {
-            IMCC_INFO(interp)->optimizer_level |= OPT_PRE;
+          default:
+            /* skip already processed arguments */
             break;
         }
-        if (strchr(opt->opt_arg, 'p'))
-            IMCC_INFO(interp)->optimizer_level |= OPT_PASM;
-        if (strchr(opt->opt_arg, 'c'))
-            IMCC_INFO(interp)->optimizer_level |= OPT_SUB;
-
-        /* currently not ok due to different register allocation */
-        if (strchr(opt->opt_arg, '1')) {
-            IMCC_INFO(interp)->optimizer_level |= OPT_PRE;
-        }
-        if (strchr(opt->opt_arg, '2')) {
-            IMCC_INFO(interp)->optimizer_level |= (OPT_PRE | OPT_CFG);
-        }
-        break;
-
-      default:
-        return 0;
     }
-
-    return 1;
 }
 
 /*
@@ -413,8 +380,8 @@
 
 /*
 
-=item C<static void imcc_run_pbc(PARROT_INTERP, int obj_file, const char
-*output_file, int argc, const char **argv)>
+=item C<void imcc_run_pbc(PARROT_INTERP, const char *output_file, int argc,
+const char **argv)>
 
 Write out or run Parrot bytecode.
 
@@ -422,25 +389,13 @@
 
 */
 
-static void
-imcc_run_pbc(PARROT_INTERP, int obj_file, ARGIN_NULLOK(const char *output_file),
+void
+imcc_run_pbc(PARROT_INTERP, ARGIN_NULLOK(const char *output_file),
         int argc, ARGIN(const char **argv))
 {
-    ASSERT_ARGS(imcc_run_pbc)
-    if (IMCC_INFO(interp)->imcc_warn)
-        PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG);
-    else
-        PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG);
-
-    if (!IMCC_INFO(interp)->gc_off) {
-        Parrot_unblock_GC_mark(interp);
-        Parrot_unblock_GC_sweep(interp);
-    }
+    /* ASSERT_ARGS(imcc_run_pbc) */
 
-    if (obj_file)
-        IMCC_info(interp, 1, "Writing %s\n", output_file);
-    else
-        IMCC_info(interp, 1, "Running...\n");
+    IMCC_info(interp, 1, "Running...\n");
 
     /* runs :init functions */
     PackFile_fixup_subs(interp, PBC_IMMEDIATE, NULL);
@@ -536,8 +491,8 @@
 
 /*
 
-=item C<static void determine_output_file_type(PARROT_INTERP, int *obj_file,
-const char *output_file)>
+=item C<static void determine_output_file_type(PARROT_INTERP, const char
+*output_file)>
 
 Decide what kind of file we are to output.
 
@@ -546,8 +501,7 @@
 */
 
 static void
-determine_output_file_type(PARROT_INTERP,
-    ARGMOD(int *obj_file), ARGIN(const char *output_file))
+determine_output_file_type(PARROT_INTERP, ARGIN(const char *output_file))
 {
     ASSERT_ARGS(determine_output_file_type)
     const char * const ext = strrchr(output_file, '.');
@@ -555,10 +509,6 @@
     if (ext) {
         if (STREQ(ext, ".pbc"))
             SET_STATE_WRITE_PBC(interp);
-        else if (STREQ(ext, PARROT_OBJ_EXT)) {
-            UNUSED(obj_file);
-            IMCC_fatal_standalone(interp, 1, "main: can't produce object file");
-        }
     }
 }
 
@@ -642,10 +592,11 @@
 imcc_run(PARROT_INTERP, ARGIN(const char *sourcefile), int argc,
         ARGIN(const char **argv))
 {
-    int                obj_file;
     yyscan_t           yyscanner;
     const char * const output_file = interp->output_file;
 
+    imcc_parseflags(interp, argc, argv);
+
     /* PMCs in IMCC_INFO won't get marked */
     Parrot_block_GC_mark(interp);
     Parrot_block_GC_sweep(interp);
@@ -667,9 +618,8 @@
     }
 
     /* Do we need to produce an output file? If so, what type? */
-    obj_file = 0;
     if (output_file) {
-        determine_output_file_type(interp, &obj_file, output_file);
+        determine_output_file_type(interp, output_file);
 
         if (STREQ(sourcefile, output_file) && !STREQ(sourcefile, "-"))
             IMCC_fatal_standalone(interp, 1, "main: outputfile is sourcefile\n");
@@ -716,12 +666,24 @@
         }
     }
 
-    /* Run the bytecode */
-    if (STATE_RUN_PBC(interp))
-        imcc_run_pbc(interp, obj_file, output_file, argc, argv);
+    /* tear down the compilation context */
+    if (IMCC_INFO(interp)->imcc_warn)
+        PARROT_WARNINGS_on(interp, PARROT_WARNINGS_ALL_FLAG);
+    else
+        PARROT_WARNINGS_off(interp, PARROT_WARNINGS_ALL_FLAG);
+
+    if (!IMCC_INFO(interp)->gc_off) {
+        Parrot_unblock_GC_mark(interp);
+        Parrot_unblock_GC_sweep(interp);
+    }
 
     yylex_destroy(yyscanner);
-    return 0;
+
+    /* should the bytecode be run */
+    if (STATE_RUN_PBC(interp))
+        return 1;
+    else
+        return 0;
 }
 
 /*

Modified: trunk/include/parrot/imcc.h
==============================================================================
--- trunk/include/parrot/imcc.h	Sun May 23 18:15:48 2010	(r46918)
+++ trunk/include/parrot/imcc.h	Sun May 23 20:30:36 2010	(r46919)
@@ -6,9 +6,8 @@
 #ifndef PARROT_IMCC_H_GUARD
 #define PARROT_IMCC_H_GUARD
 
-PARROT_EXPORT void imcc_start_handling_flags(PARROT_INTERP);
-PARROT_EXPORT int imcc_handle_flag(PARROT_INTERP, struct longopt_opt_info *opt, Parrot_Run_core_t *core);
-PARROT_EXPORT int imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv);
+PARROT_EXPORT int  imcc_run(PARROT_INTERP, const char *sourcefile, int argc, const char **argv);
+PARROT_EXPORT void imcc_run_pbc(PARROT_INTERP, const char *outputfile, int argc, const char **argv);
 
 #endif /* PARROT_IMCC_H_GUARD */
 

Modified: trunk/include/parrot/longopt.h
==============================================================================
--- trunk/include/parrot/longopt.h	Sun May 23 18:15:48 2010	(r46918)
+++ trunk/include/parrot/longopt.h	Sun May 23 20:30:36 2010	(r46919)
@@ -44,6 +44,16 @@
 
 #define LONGOPT_OPT_INFO_INIT { 1, 0, NULL, NULL, NULL }
 
+#define OPT_GC_DEBUG       128
+#define OPT_DESTROY_FLAG   129
+#define OPT_HELP_DEBUG     130
+#define OPT_PBC_OUTPUT     131
+#define OPT_RUNTIME_PREFIX 132
+#define OPT_HASH_SEED      133
+
+PARROT_EXPORT
+const struct longopt_opt_decl Parrot_cmd_options[];
+
 /* HEADERIZER BEGIN: src/longopt.c */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 

Modified: trunk/src/longopt.c
==============================================================================
--- trunk/src/longopt.c	Sun May 23 18:15:48 2010	(r46918)
+++ trunk/src/longopt.c	Sun May 23 20:30:36 2010	(r46919)
@@ -62,6 +62,39 @@
 
 static char longopt_error_buffer[512];
 
+PARROT_EXPORT
+const struct longopt_opt_decl Parrot_cmd_options[] = {
+    { '.', '.', (OPTION_flags)0, { "--wait" } },
+    { 'D', 'D', OPTION_optional_FLAG, { "--parrot-debug" } },
+    { 'E', 'E', (OPTION_flags)0, { "--pre-process-only" } },
+    { 'G', 'G', (OPTION_flags)0, { "--no-gc" } },
+    { '\0', OPT_HASH_SEED, OPTION_required_FLAG, { "--hash-seed" } },
+    { 'I', 'I', OPTION_required_FLAG, { "--include" } },
+    { 'L', 'L', OPTION_required_FLAG, { "--library" } },
+    { 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
+    { 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
+    { 'g', 'g', OPTION_required_FLAG, { "--gc" } },
+    { 'V', 'V', (OPTION_flags)0, { "--version" } },
+    { 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
+    { '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
+                                 { "--leak-test", "--destroy-at-end" } },
+    { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
+    { 'a', 'a', (OPTION_flags)0, { "--pasm" } },
+    { 'c', 'c', (OPTION_flags)0, { "--pbc" } },
+    { 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
+    { '\0', OPT_HELP_DEBUG, (OPTION_flags)0, { "--help-debug" } },
+    { 'h', 'h', (OPTION_flags)0, { "--help" } },
+    { 'o', 'o', OPTION_required_FLAG, { "--output" } },
+    { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } },
+    { 'r', 'r', (OPTION_flags)0, { "--run-pbc" } },
+    { '\0', OPT_RUNTIME_PREFIX, (OPTION_flags)0, { "--runtime-prefix" } },
+    { 't', 't', OPTION_optional_FLAG, { "--trace" } },
+    { 'v', 'v', (OPTION_flags)0, { "--verbose" } },
+    { 'w', 'w', (OPTION_flags)0, { "--warnings" } },
+    { 'y', 'y', (OPTION_flags)0, { "--yydebug" } },
+    { 0, 0, (OPTION_flags)0, { NULL } }
+};
+
 /*
 
 =item C<int longopt_get(PARROT_INTERP, int argc, const char* argv[], const

Modified: trunk/src/main.c
==============================================================================
--- trunk/src/main.c	Sun May 23 18:15:48 2010	(r46918)
+++ trunk/src/main.c	Sun May 23 20:30:36 2010	(r46919)
@@ -45,17 +45,20 @@
 static void Parrot_version(void);
 PARROT_CAN_RETURN_NULL
 static const char * parseflags(PARROT_INTERP,
-    ARGMOD(int *argc),
-    ARGMOD(const char **argv[]),
+    int argc,
+    ARGIN(const char *argv[]),
+    ARGOUT(int *pgm_argc),
+    ARGOUT(const char ***pgm_argv),
     ARGMOD(Parrot_Run_core_t *core),
     ARGMOD(Parrot_trace_flags *trace))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
         __attribute__nonnull__(3)
         __attribute__nonnull__(4)
         __attribute__nonnull__(5)
-        FUNC_MODIFIES(*argc)
-        FUNC_MODIFIES(*argv[])
+        __attribute__nonnull__(6)
+        __attribute__nonnull__(7)
+        FUNC_MODIFIES(*pgm_argc)
+        FUNC_MODIFIES(*pgm_argv)
         FUNC_MODIFIES(*core)
         FUNC_MODIFIES(*trace);
 
@@ -76,8 +79,9 @@
 #define ASSERT_ARGS_Parrot_version __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_parseflags __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
-    , PARROT_ASSERT_ARG(argc) \
     , PARROT_ASSERT_ARG(argv) \
+    , PARROT_ASSERT_ARG(pgm_argc) \
+    , PARROT_ASSERT_ARG(pgm_argv) \
     , PARROT_ASSERT_ARG(core) \
     , PARROT_ASSERT_ARG(trace))
 #define ASSERT_ARGS_parseflags_minimal __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -101,11 +105,13 @@
 int
 main(int argc, const char *argv[])
 {
-    int         stacktop;
-    const char *sourcefile;
-    const char *execname;
-    Interp     *interp;
-    int         status;
+    int          stacktop;
+    const char  *sourcefile;
+    const char  *execname;
+    Interp      *interp;
+    int          status;
+    int          pir_argc;
+    const char **pir_argv;
 
     Parrot_Run_core_t  core  = PARROT_SLOW_CORE;
     Parrot_trace_flags trace = PARROT_NO_TRACE;
@@ -131,63 +137,26 @@
     initialize_interpreter(interp, (void*)&stacktop);
 
     /* Parse flags */
-    sourcefile = parseflags(interp, &argc, &argv, &core, &trace);
+    sourcefile = parseflags(interp, argc, argv, &pir_argc, &pir_argv, &core, &trace);
 
     Parrot_set_trace(interp, trace);
     Parrot_set_run_core(interp, (Parrot_Run_core_t) core);
     Parrot_set_executable_name(interp, Parrot_str_new(interp, execname, 0));
 
-    status     = imcc_run(interp, sourcefile, argc, argv);
-    UNUSED(status);
+    status = imcc_run(interp, sourcefile, argc, argv);
+
+    if (status)
+        imcc_run_pbc(interp, interp->output_file, pir_argc, pir_argv);
 
     /* Clean-up after ourselves */
     Parrot_destroy(interp);
     Parrot_exit(interp, 0);
 }
 
-#define OPT_GC_DEBUG       128
-#define OPT_DESTROY_FLAG   129
-#define OPT_HELP_DEBUG     130
-#define OPT_PBC_OUTPUT     131
-#define OPT_RUNTIME_PREFIX 132
-#define OPT_HASH_SEED      133
-
 #define SET_FLAG(flag)   Parrot_set_flag(interp, (flag))
 #define SET_DEBUG(flag)  Parrot_set_debug(interp, (flag))
 #define SET_TRACE(flag)  Parrot_set_trace(interp, (flag))
 
-static struct longopt_opt_decl options[] = {
-    { '.', '.', (OPTION_flags)0, { "--wait" } },
-    { 'D', 'D', OPTION_optional_FLAG, { "--parrot-debug" } },
-    { 'E', 'E', (OPTION_flags)0, { "--pre-process-only" } },
-    { 'G', 'G', (OPTION_flags)0, { "--no-gc" } },
-    { '\0', OPT_HASH_SEED, OPTION_required_FLAG, { "--hash-seed" } },
-    { 'I', 'I', OPTION_required_FLAG, { "--include" } },
-    { 'L', 'L', OPTION_required_FLAG, { "--library" } },
-    { 'O', 'O', OPTION_optional_FLAG, { "--optimize" } },
-    { 'R', 'R', OPTION_required_FLAG, { "--runcore" } },
-    { 'g', 'g', OPTION_required_FLAG, { "--gc" } },
-    { 'V', 'V', (OPTION_flags)0, { "--version" } },
-    { 'X', 'X', OPTION_required_FLAG, { "--dynext" } },
-    { '\0', OPT_DESTROY_FLAG, (OPTION_flags)0,
-                                 { "--leak-test", "--destroy-at-end" } },
-    { '\0', OPT_GC_DEBUG, (OPTION_flags)0, { "--gc-debug" } },
-    { 'a', 'a', (OPTION_flags)0, { "--pasm" } },
-    { 'c', 'c', (OPTION_flags)0, { "--pbc" } },
-    { 'd', 'd', OPTION_optional_FLAG, { "--imcc-debug" } },
-    { '\0', OPT_HELP_DEBUG, (OPTION_flags)0, { "--help-debug" } },
-    { 'h', 'h', (OPTION_flags)0, { "--help" } },
-    { 'o', 'o', OPTION_required_FLAG, { "--output" } },
-    { '\0', OPT_PBC_OUTPUT, (OPTION_flags)0, { "--output-pbc" } },
-    { 'r', 'r', (OPTION_flags)0, { "--run-pbc" } },
-    { '\0', OPT_RUNTIME_PREFIX, (OPTION_flags)0, { "--runtime-prefix" } },
-    { 't', 't', OPTION_optional_FLAG, { "--trace" } },
-    { 'v', 'v', (OPTION_flags)0, { "--verbose" } },
-    { 'w', 'w', (OPTION_flags)0, { "--warnings" } },
-    { 'y', 'y', (OPTION_flags)0, { "--yydebug" } },
-    { 0, 0, (OPTION_flags)0, { NULL } }
-};
-
 /*
 
 =item C<static int is_all_hex_digits(const char *s)>
@@ -422,8 +391,9 @@
 
 /*
 
-=item C<static const char * parseflags(PARROT_INTERP, int *argc, const char
-**argv[], Parrot_Run_core_t *core, Parrot_trace_flags *trace)>
+=item C<static const char * parseflags(PARROT_INTERP, int argc, const char
+*argv[], int *pgm_argc, const char ***pgm_argv, Parrot_Run_core_t *core,
+Parrot_trace_flags *trace)>
 
 Parse Parrot's command line for options and set appropriate flags.
 
@@ -434,26 +404,20 @@
 PARROT_CAN_RETURN_NULL
 static const char *
 parseflags(PARROT_INTERP,
-        ARGMOD(int *argc), ARGMOD(const char **argv[]),
+        int argc, ARGIN(const char *argv[]),
+        ARGOUT(int *pgm_argc), ARGOUT(const char ***pgm_argv),
         ARGMOD(Parrot_Run_core_t *core), ARGMOD(Parrot_trace_flags *trace))
 {
     ASSERT_ARGS(parseflags)
     struct longopt_opt_info opt  = LONGOPT_OPT_INFO_INIT;
     int                     status;
-    /* g++ complains if we cast char** to const char** directly. However, nobody
-       ever complains if you const to void* first. Sure we lose a certain
-       amount of compiler-enforced type safety, but this is a rare occasion
-       with a very long explanatory comment. */
-    const char ** const _tempargv = (const char **)((void *)*argv);
 
-    if (*argc == 1) {
+    if (argc == 1) {
         usage(stderr);
         exit(EXIT_SUCCESS);
     }
 
-    imcc_start_handling_flags(interp);
-
-    while ((status = longopt_get(interp, *argc, _tempargv, options, &opt)) > 0) {
+    while ((status = longopt_get(interp, argc, argv, Parrot_cmd_options, &opt)) > 0) {
         switch (opt.opt_id) {
           case 'R':
             if (STREQ(opt.opt_arg, "slow") || STREQ(opt.opt_arg, "bounds"))
@@ -543,16 +507,19 @@
             Parrot_lib_add_path_from_cstring(interp, opt.opt_arg,
                     PARROT_LIB_PATH_DYNEXT);
             break;
+          case 'w':
+            /* FIXME It's not best way to set warnings... */
+            Parrot_setwarnings(interp, PARROT_WARNINGS_ALL_FLAG);
+            break;
+          case 'o':
+            interp->output_file = opt.opt_arg;
+            break;
+          case OPT_PBC_OUTPUT:
+            if (!interp->output_file)
+                interp->output_file = "-";
           default:
-            /* Delegate handling of IMCC flags to IMCC */
-            if (imcc_handle_flag(interp, &opt, core))
-                break;
-
-            /* PIRC flags handling goes here */
-            fprintf(stderr,
-                    "main: Invalid flag '%s' used.\n\nhelp: parrot -h\n",
-                    (*argv)[0]);
-            exit(EXIT_FAILURE);
+            /* languages handle their arguments later (after being initialized) */
+            break;
         }
     }
 
@@ -563,7 +530,7 @@
     }
 
     /* reached the end of the option list and consumed all of argv */
-    if (*argc == opt.opt_index) {
+    if (argc == opt.opt_index) {
         if (interp->output_file) {
             fprintf(stderr, "Missing program name or argument for -o\n");
         }
@@ -575,10 +542,10 @@
         exit(EXIT_FAILURE);
     }
 
-    *argc -= opt.opt_index;
-    *argv += opt.opt_index;
+    *pgm_argc = argc - opt.opt_index;
+    *pgm_argv = argv + opt.opt_index;
 
-    return (*argv)[0];
+    return (*pgm_argv)[0];
 }
 /*
 


More information about the parrot-commits mailing list