Author: chromatic
Date: Mon Nov 10 21:15:23 2008
New Revision: 32508
Modified:
trunk/compilers/imcc/imc.h
trunk/compilers/imcc/main.c
Log:
[IMCC] Replaced several more global variables in IMCC with flags in IMCC_INFO.
Modified: trunk/compilers/imcc/imc.h
==============================================================================
--- trunk/compilers/imcc/imc.h (original)
+++ trunk/compilers/imcc/imc.h Mon Nov 10 21:15:23 2008
@@ -14,11 +14,11 @@
#ifdef PARROT_HAS_HEADER_SYSEXITS
# include <sysexits.h>
#else
-# define EX_DATAERR 1
-# define EX_SOFTWARE 1
-# define EX_NOINPUT 1
-# define EX_IOERR 1
-# define EX_USAGE 1
+# define EX_DATAERR 1
+# define EX_SOFTWARE 1
+# define EX_NOINPUT 1
+# define EX_IOERR 1
+# define EX_USAGE 1
# define EX_UNAVAILABLE 1
#endif /* PARROT_HAS_HEADER_SYSEXITS */
@@ -527,6 +527,7 @@
int nargs;
int n_comp_units;
int nkeys;
+ int compiler_state; /* see PBC_* flags */
int verbose;
int write_pbc;
opcode_t npc;
@@ -534,12 +535,43 @@
#define IMCC_INFO(i) (((Parrot_Interp)(i))->imc_info)
-#define IMC_TRACE 0
+#define IMC_TRACE 0
#define IMC_TRACE_HIGH 0
+/* main.c */
+#define PBC_LOAD (1 << 0)
+#define PBC_RUN (1 << 1)
+#define PBC_WRITE (1 << 2)
+#define PBC_PRE_PROCESS (1 << 3)
+#define PBC_PASM_FILE (1 << 4)
+#define PBC_RUN_FILE (1 << 5)
+
+#define COMPILER_STATE(i) IMCC_INFO(i)->compiler_state
+
+#define STATE_LOAD_PBC(i) (COMPILER_STATE(i) & PBC_LOAD)
+#define STATE_RUN_PBC(i) (COMPILER_STATE(i) & PBC_RUN)
+#define STATE_WRITE_PBC(i) (COMPILER_STATE(i) & PBC_WRITE)
+#define STATE_PRE_PROCESS(i) (COMPILER_STATE(i) & PBC_PRE_PROCESS)
+#define STATE_PASM_FILE(i) (COMPILER_STATE(i) & PBC_PASM_FILE)
+#define STATE_RUN_FROM_FILE(i) (COMPILER_STATE(i) & PBC_RUN_FILE)
+
+#define SET_STATE_LOAD_PBC(i) (COMPILER_STATE(i) |= PBC_LOAD)
+#define SET_STATE_RUN_PBC(i) (COMPILER_STATE(i) |= PBC_RUN)
+#define SET_STATE_WRITE_PBC(i) (COMPILER_STATE(i) |= PBC_WRITE)
+#define SET_STATE_PRE_PROCESS(i) (COMPILER_STATE(i) |= PBC_PRE_PROCESS)
+#define SET_STATE_PASM_FILE(i) (COMPILER_STATE(i) |= PBC_PASM_FILE)
+#define SET_STATE_RUN_FROM_FILE(i) (COMPILER_STATE(i) |= PBC_RUN_FILE)
+
+#define UNSET_STATE_LOAD_PBC(i) (COMPILER_STATE(i) &= ~PBC_LOAD)
+#define UNSET_STATE_RUN_PBC(i) (COMPILER_STATE(i) &= ~PBC_RUN)
+#define UNSET_STATE_WRITE_PBC(i) (COMPILER_STATE(i) &= ~PBC_WRITE)
+#define UNSET_STATE_PRE_PROCESS(i) (COMPILER_STATE(i) &= ~PBC_PRE_PROCESS)
+#define UNSET_STATE_PASM_FILE(i) (COMPILER_STATE(i) &= ~PBC_PASM_FILE)
+#define UNSET_STATE_RUN_FROM_FILE(i) (COMPILER_STATE(i) &= ~PBC_RUN_FILE)
+
/* imclexer.c */
-PARROT_API FILE* imc_yyin_set(FILE* new_yyin, void *yyscanner);
-PARROT_API FILE* imc_yyin_get(void *yyscanner);
+PARROT_API FILE * imc_yyin_set(FILE *new_yyin, void *yyscanner);
+PARROT_API FILE * imc_yyin_get(void *yyscanner);
#endif /* PARROT_IMCC_IMC_H_GUARD */
Modified: trunk/compilers/imcc/main.c
==============================================================================
--- trunk/compilers/imcc/main.c (original)
+++ trunk/compilers/imcc/main.c Mon Nov 10 21:15:23 2008
@@ -96,16 +96,14 @@
static void Parrot_version(PARROT_INTERP)
__attribute__nonnull__(1);
-static void usage(ARGMOD(FILE* fp))
+static void usage(ARGMOD(FILE *fp))
__attribute__nonnull__(1)
- FUNC_MODIFIES(* fp);
+ FUNC_MODIFIES(*fp);
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will
be lost. */
/* HEADERIZER END: static */
-static int load_pbc, run_pbc, write_pbc, pre_process_only, pasm_file;
-
/*
=item C<static void usage>
@@ -117,7 +115,7 @@
*/
static void
-usage(ARGMOD(FILE* fp))
+usage(ARGMOD(FILE *fp))
{
fprintf(fp,
"parrot -[abcCEfgGhjprStvVwy.] [-d [FLAGS]] [-D [FLAGS]]"
@@ -341,7 +339,9 @@
usage(stderr);
exit(EXIT_SUCCESS);
}
- run_pbc = 1;
+
+ SET_STATE_RUN_PBC(interp);
+ UNSET_STATE_RUN_FROM_FILE(interp);
while ((status = longopt_get(interp, *argc, (const char **)*argv, options,
&opt)) > 0) {
@@ -435,7 +435,7 @@
fgetc(stdin);
break;
case 'a':
- pasm_file = 1;
+ SET_STATE_PASM_FILE(interp);
break;
case 'h':
help();
@@ -453,10 +453,12 @@
Parrot_version(interp);
break;
case 'r':
- ++run_pbc;
+ if (STATE_RUN_PBC(interp))
+ SET_STATE_RUN_FROM_FILE(interp);
+ SET_STATE_RUN_PBC(interp);
break;
case 'c':
- load_pbc = 1;
+ SET_STATE_LOAD_PBC(interp);
break;
case 'v':
IMCC_INFO(interp)->verbose++;
@@ -465,16 +467,18 @@
yydebug = 1;
break;
case 'E':
- pre_process_only = 1;
+ SET_STATE_PRE_PROCESS(interp);
break;
case 'o':
- run_pbc = 0;
+ UNSET_STATE_RUN_PBC(interp);
+ UNSET_STATE_RUN_FROM_FILE(interp);
interp->output_file = opt.opt_arg;
break;
case OPT_PBC_OUTPUT:
- run_pbc = 0;
- write_pbc = 1;
+ UNSET_STATE_RUN_PBC(interp);
+ UNSET_STATE_RUN_FROM_FILE(interp);
+ SET_STATE_WRITE_PBC(interp);
if (!interp->output_file)
interp->output_file = "-";
break;
@@ -854,18 +858,18 @@
const char * const ext = strrchr(sourcefile, '.');
if (ext && (STREQ(ext, ".pbc"))) { /* a PBC file */
- load_pbc = 1;
- write_pbc = 0;
+ SET_STATE_LOAD_PBC(interp);
+ UNSET_STATE_WRITE_PBC(interp);
}
- else if (!load_pbc) {
+ else if (!STATE_LOAD_PBC(interp)) {
if (!(imc_yyin_set(fopen(sourcefile, "r"), yyscanner))) {
IMCC_fatal_standalone(interp, EXCEPTION_EXTERNAL_ERROR,
"Error reading source file %s.\n",
sourcefile);
}
- if (ext && STREQ(ext, ".pasm")) {
- pasm_file = 1;
- }
+
+ if (ext && STREQ(ext, ".pasm"))
+ SET_STATE_PASM_FILE(interp);
}
}
}
@@ -887,14 +891,14 @@
const char * const ext = strrchr(output_file, '.');
if (ext) {
- if (STREQ(ext, ".pbc")) {
- write_pbc = 1;
- }
+ if (STREQ(ext, ".pbc"))
+ SET_STATE_WRITE_PBC(interp);
else if (STREQ(ext, PARROT_OBJ_EXT)) {
#if EXEC_CAPABLE
- load_pbc = 1;
- write_pbc = 0;
- run_pbc = 1;
+ SET_STATE_LOAD_PBC(interp);
+ SET_STATE_RUN_PBC(interp);
+ UNSET_STATE_WRITE_PBC(interp);
+ UNSET_STATE_RUN_FROM_FILE(interp);
*obj_file = 1;
Parrot_set_run_core(interp, PARROT_EXEC_CORE);
#else
@@ -920,10 +924,10 @@
ARGIN(const char * const sourcefile),
ARGIN(const char * const output_file))
{
+ PackFile *pf;
yyscan_t yyscanner = IMCC_INFO(interp)->yyscanner;
- const int per_pbc = (write_pbc | run_pbc) != 0;
+ const int per_pbc = (STATE_WRITE_PBC(interp) | STATE_RUN_PBC(interp))
!=0;
const int opt_level = IMCC_INFO(interp)->optimizer_level;
- PackFile *pf;
/* Shouldn't be more than five, but five extra is cheap */
char opt_desc[10];
@@ -943,7 +947,8 @@
IMCC_info(interp, 1, "Starting parse...\n");
- IMCC_INFO(interp)->state->pasm_file = pasm_file;
+ IMCC_INFO(interp)->state->pasm_file = STATE_PASM_FILE(interp) ? 1 : 0;
+
IMCC_TRY(IMCC_INFO(interp)->jump_buf,
IMCC_INFO(interp)->error_code) {
if (yyparse(yyscanner, interp))
@@ -1013,7 +1018,7 @@
else
determine_input_file_type(interp, sourcefile);
- if (pre_process_only) {
+ if (STATE_PRE_PROCESS(interp)) {
do_pre_process(interp);
Parrot_destroy(interp);
yylex_destroy(yyscanner);
@@ -1031,7 +1036,7 @@
IMCC_fatal_standalone(interp, 1, "main: outputfile is
sourcefile\n");
}
- IMCC_INFO(interp)->write_pbc = write_pbc;
+ IMCC_INFO(interp)->write_pbc = STATE_WRITE_PBC(interp) ? 1 : 0;
if (IMCC_INFO(interp)->verbose) {
IMCC_info(interp, 1, "debug = 0x%x\n", IMCC_INFO(interp)->debug);
@@ -1041,7 +1046,7 @@
/* If the input file is Parrot bytecode, then we simply read it
into a packfile, which Parrot then loads */
- if (load_pbc) {
+ if (STATE_LOAD_PBC(interp)) {
PackFile * const pf = Parrot_readbc(interp, sourcefile);
if (!pf)
@@ -1052,7 +1057,7 @@
compile_to_bytecode(interp, sourcefile, output_file);
/* Produce a PBC output file, if one was requested */
- if (write_pbc) {
+ if (STATE_WRITE_PBC(interp)) {
if (!output_file) {
IMCC_fatal_standalone(interp, 1,
"main: NULL output_file when trying to write .pbc\n");
@@ -1060,7 +1065,7 @@
imcc_write_pbc(interp, output_file);
/* If necessary, load the file written above */
- if (run_pbc == 2 && !STREQ(output_file, "-")) {
+ if (STATE_RUN_FROM_FILE(interp) && !STREQ(output_file, "-")) {
PackFile *pf;
IMCC_info(interp, 1, "Loading %s\n", output_file);
@@ -1068,12 +1073,12 @@
if (!pf)
IMCC_fatal_standalone(interp, 1, "Packfile loading failed\n");
Parrot_loadbc(interp, pf);
- load_pbc = 1;
+ STATE_LOAD_PBC(interp);
}
}
/* Run the bytecode */
- if (run_pbc)
+ if (STATE_RUN_PBC(interp))
imcc_run_pbc(interp, obj_file, output_file, argc, argv);
yylex_destroy(yyscanner);