Author: chromatic
Date: Tue Apr 17 21:08:32 2007
New Revision: 18277

Added:
   trunk/include/parrot/imcc.h   (contents, props changed)
   trunk/src/main.c   (contents, props changed)
Modified:
   trunk/MANIFEST
   trunk/compilers/imcc/main.c
   trunk/config/gen/makefiles/root.in

Log:
[IMCC] Moved main() from compilers/imcc/main.c to src/main.c.

This is the first step in a laborious process that likely culminates in 
separating the concerns of IMCC from the rest of Parrot in a nicely decoupled 
fashion.

Modified: trunk/MANIFEST
==============================================================================
--- trunk/MANIFEST      (original)
+++ trunk/MANIFEST      Tue Apr 17 21:08:32 2007
@@ -771,6 +771,7 @@
 include/parrot/hash.h                                       [main]include
 include/parrot/headers.h                                    [main]include
 include/parrot/hll.h                                        [main]include
+include/parrot/imcc.h                                       [main]include
 include/parrot/inter_call.h                                 [main]include
 include/parrot/interpreter.h                                [main]include
 include/parrot/intlist.h                                    [main]include
@@ -2544,6 +2545,7 @@
 src/longopt.c                                               []
 src/malloc-trace.c                                          []
 src/malloc.c                                                []
+src/main.c                                                  []
 src/misc.c                                                  []
 src/mmd.c                                                   []
 src/nci_test.c                                              []

Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c (original)
+++ trunk/compilers/imcc/main.c Tue Apr 17 21:08:32 2007
@@ -24,6 +24,11 @@
 
 static int load_pbc, run_pbc, write_pbc, pre_process, pasm_file;
 
+char * parseflags(Interp *interp, int *argc, char **argv[]);
+int    imcc_initialize(Interp *interp);
+int    imcc_run(Interp *interp, const char *sourcefile, int argc,
+                char * argv[]);
+
 static void
 usage(FILE* fp)
 {
@@ -194,7 +199,7 @@
 }
 
 /* most stolen from test_main.c */
-static char *
+char *
 parseflags(Parrot_Interp interp, int *argc, char **argv[])
 {
     struct longopt_opt_info opt = LONGOPT_OPT_INFO_INIT;
@@ -511,7 +516,7 @@
     return;
 }
 
-static int
+int
 imcc_initialize(Interp *interp)
 {
     yyscan_t yyscanner = IMCC_INFO(interp)->yyscanner;
@@ -592,7 +597,7 @@
     free(packed);
 }
 
-static int
+int
 imcc_run(Interp *interp, const char *sourcefile, int argc, char * argv[])
 {
     PackFile *pf;
@@ -760,41 +765,6 @@
     return 0;
 }
 
-int
-main(int argc, char * argv[])
-{
-    char    *sourcefile;
-    Interp  *interp;
-    STRING  *executable_name;
-    PMC     *executable_name_pmc;
-    int      status;
-
-    Parrot_set_config_hash();
-
-    interp     = Parrot_new(NULL);
-    if (!imcc_initialize(interp))
-        internal_exception(1, "Could not initialize IMCC\n");
-
-    /* We parse the arguments, but first store away the name of the Parrot
-       executable, since parsing destroys that and we want to make it
-       available. */
-    executable_name     = string_from_cstring(interp, argv[0], 0);
-    executable_name_pmc = pmc_new(interp, enum_class_String);
-    VTABLE_set_string_native(interp, executable_name_pmc, executable_name);
-    VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
-        executable_name_pmc);
-
-    sourcefile = parseflags(interp, &argc, &argv);
-    status     = imcc_run(interp, sourcefile, argc, argv);
-
-    /* Clean-up after ourselves */
-    Parrot_destroy(interp);
-    Parrot_exit(interp, 0);
-
-    return status;
-}
-
-
 /*
  * Local variables:
  *   c-file-style: "parrot"

Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in  (original)
+++ trunk/config/gen/makefiles/root.in  Tue Apr 17 21:08:32 2007
@@ -371,6 +371,7 @@
     $(IMCC_DIR)/imcparser$(O) \
     $(IMCC_DIR)/imclexer$(O) \
     $(IMCC_DIR)/imc$(O) \
+    $(IMCC_DIR)/main$(O) \
     $(IMCC_DIR)/symreg$(O) \
     $(IMCC_DIR)/instructions$(O) \
     $(IMCC_DIR)/cfg$(O) \
@@ -425,6 +426,7 @@
     $(SRC_DIR)/inter_run$(O)  \
     $(SRC_DIR)/gc/register$(O) \
     $(SRC_DIR)/gc/memory$(O) \
+    $(SRC_DIR)/main$(O) \
     $(SRC_DIR)/objects$(O) \
     $(SRC_DIR)/packfile$(O) \
     $(SRC_DIR)/stacks$(O) \
@@ -1082,6 +1084,8 @@
 
 $(SRC_DIR)/gc/memory$(O) : $(GENERAL_H_FILES)
 
+$(SRC_DIR)/main$(O) : $(SRC_DIR)/main.c $(GENERAL_H_FILES)
+
 $(SRC_DIR)/pic$(O) : $(GENERAL_H_FILES)
 
 $(SRC_DIR)/pic_jit$(O) : $(GENERAL_H_FILES)

Added: trunk/include/parrot/imcc.h
==============================================================================
--- (empty file)
+++ trunk/include/parrot/imcc.h Tue Apr 17 21:08:32 2007
@@ -0,0 +1,20 @@
+/*
+ * Copyright (C) 2007, The Perl Foundation
+ * $Id$
+ */
+
+#if !defined(PARROT_IMCC_H_GUARD)
+#define PARROT_IMCC_H_GUARD
+
+int imcc_initialize(Interp *interp);
+char * parseflags(Interp *interp, int *argc, char **argv[]);
+int imcc_run(Interp *interp, const char *sourcefile, int argc, char * argv[]);
+
+#endif
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Added: trunk/src/main.c
==============================================================================
--- (empty file)
+++ trunk/src/main.c    Tue Apr 17 21:08:32 2007
@@ -0,0 +1,87 @@
+/*
+Copyright (C) 2007, The Perl Foundation
+$Id$
+
+=head1 NAME
+
+src/main.c - the Entry Point to Parrot Programs
+
+=head1 DESCRIPTION
+
+Start Parrot
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include <stdio.h>
+#include <string.h>
+
+#include "parrot/parrot.h"
+#include "parrot/embed.h"
+#include "parrot/imcc.h"
+
+/*
+
+=item C<int main(int argc, char * argv[])>
+
+The entry point from the command line into Parrot.
+
+*/
+
+int
+main(int argc, char * argv[])
+{
+    char    *sourcefile;
+    Interp  *interp;
+    STRING  *executable_name;
+    PMC     *executable_name_pmc;
+    int      status;
+
+    Parrot_set_config_hash();
+
+    interp     = Parrot_new(NULL);
+    if (!imcc_initialize(interp))
+        internal_exception(1, "Could not initialize IMCC\n");
+
+    /* We parse the arguments, but first store away the name of the Parrot
+       executable, since parsing destroys that and we want to make it
+       available. */
+    executable_name     = string_from_cstring(interp, argv[0], 0);
+    executable_name_pmc = pmc_new(interp, enum_class_String);
+    VTABLE_set_string_native(interp, executable_name_pmc, executable_name);
+    VTABLE_set_pmc_keyed_int(interp, interp->iglobals, IGLOBALS_EXECUTABLE,
+        executable_name_pmc);
+
+    sourcefile = parseflags(interp, &argc, &argv);
+    status     = imcc_run(interp, sourcefile, argc, argv);
+
+    /* Clean-up after ourselves */
+    Parrot_destroy(interp);
+    Parrot_exit(interp, 0);
+
+    return status;
+}
+
+/*
+
+=back
+
+=head1 SEE ALSO
+
+F<compilers/imcc/main.c>, unfortunately.
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ *   c-file-style: "parrot"
+ * End:
+ * vim: expandtab shiftwidth=4:
+ */

Reply via email to