Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[imcc] add imcc flags to the refactored API and use it in parrot_old …

…(again)

parrot_old -y works fine now.
Also re-enable symbolic api_flags by including the relevant headers.
Issue [GH #1033]

Add old imcc optim flags as Parrot_trace_flags, but the optimizations
are not yet passed through
  • Loading branch information...
commit 8d9ded478ea4a83ae30b36d369fced5f5512a50b 1 parent 90e3128
@rurban rurban authored
View
1  compilers/imcc/Rules.in
@@ -14,6 +14,7 @@ compilers/imcc/api$(O) : \
compilers/imcc/debug.h \
include/parrot/api.h \
compilers/imcc/instructions.h \
+ include/pmc/pmc_imccompiler.h \
$(PARROT_H_HEADERS)
compilers/imcc/pcc$(O) : \
View
25 compilers/imcc/api.c
@@ -26,6 +26,7 @@ IMCC call-in routines for use with the Parrot embedding API
#include "parrot/parrot.h"
#include "parrot/extend.h"
#include "imcc/api.h"
+#include "pmc/pmc_imccompiler.h"
#include "imc.h"
/* HEADERIZER HFILE: include/imcc/api.h */
@@ -203,6 +204,30 @@ imcc_preprocess_file_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
}
/*
+
+=item C<Parrot_Int imcc_set_debug_api(Parrot_PMC interp_pmc, Parrot_PMC
+compiler, Parrot_Int traceflags, Parrot_Int yydebug)>
+
+=cut
+
+*/
+
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+Parrot_Int
+imcc_set_debug_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
+ Parrot_Int traceflags, Parrot_Int yydebug)
+{
+ ASSERT_ARGS(imcc_set_debug_api)
+ IMCC_API_CALLIN(interp_pmc, interp)
+
+ struct imc_info_t * imcc = (struct imc_info_t *)VTABLE_get_pointer(interp, compiler);
+ imcc_set_debug_mode(imcc, traceflags, yydebug);
+
+ IMCC_API_CALLOUT(interp_pmc, interp)
+}
+
+/*
* Local variables:
* c-file-style: "parrot"
* End:
View
7 config/gen/makefiles/root.in
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2013, Parrot Foundation.
+# Copyright (C) 2001-2014, Parrot Foundation.
###############################################################################
#
@@ -1784,6 +1784,7 @@ $(FRP_DIR)/main$(O) : \
$(INC_DIR)/core_types.h \
$(INC_DIR)/feature.h \
$(INC_DIR)/has_header.h \
+ $(INC_DIR)/interpreter.h \
$(INC_DIR)/longopt.h \
$(INC_DIR)/pbcversion.h \
include/imcc/api.h \
@@ -2393,6 +2394,10 @@ testr : test_prep
testO1 : test_prep
$(PERL) t/harness $(EXTRA_TEST_ARGS) -O1 $(RUNCORE_TEST_FILES)
+# optimization level 2 has some errors
+testO2 : test_prep
+ $(PERL) t/harness $(EXTRA_TEST_ARGS) -O2 $(RUNCORE_TEST_FILES)
+
# test the EXEC stuff
testexec: test_prep
$(PERL) t/harness $(EXTRA_TEST_ARGS) --run-exec $(RUNCORE_TEST_FILES)
View
58 frontend/parrot/main.c
@@ -3,7 +3,7 @@ Copyright (C) 2007-2014, Parrot Foundation.
=head1 NAME
-frontend/parrot/main.c - The PIR/PASM compiler frontend to libparrot
+frontend/parrot/main.c - The old PIR/PASM compiler frontend to libparrot
=head1 DESCRIPTION
@@ -23,6 +23,9 @@ Start Parrot
#include <ctype.h>
#include "parrot/longopt.h"
#include "parrot/api.h"
+#include "parrot/interpreter.h"
+#include "parrot/settings.h"
+#include "parrot/warnings.h"
#include "imcc/api.h"
struct init_args_t {
@@ -36,6 +39,7 @@ struct init_args_t {
Parrot_Int have_pasm_file;
Parrot_Int turn_gc_off;
Parrot_Int preprocess_only;
+ Parrot_Int yydebug;
};
extern int Parrot_set_config_hash(Parrot_PMC interp_pmc);
@@ -248,6 +252,7 @@ static PMC *
run_imcc(Parrot_PMC interp, Parrot_String sourcefile, ARGIN(struct init_args_t *flags))
{
ASSERT_ARGS(run_imcc)
+ Parrot_Int r;
Parrot_PMC pir_compiler = NULL;
Parrot_PMC pasm_compiler = NULL;;
@@ -255,7 +260,12 @@ run_imcc(Parrot_PMC interp, Parrot_String sourcefile, ARGIN(struct init_args_t *
imcc_get_pasm_compreg_api(interp, 1, &pasm_compiler)))
show_last_error_and_exit(interp);
if (flags->preprocess_only) {
- Parrot_Int r = imcc_preprocess_file_api(interp, pir_compiler, sourcefile);
+ if (flags->yydebug) {
+ Parrot_api_debug_flag(interp, PARROT_YYDEBUG_FLAG, 1);
+ r = imcc_set_debug_api(interp, pir_compiler, 0, flags->yydebug);
+ if (!r) exit(EXIT_FAILURE);
+ }
+ r = imcc_preprocess_file_api(interp, pir_compiler, sourcefile);
exit(r ? EXIT_SUCCESS : EXIT_FAILURE);
}
else {
@@ -263,6 +273,11 @@ run_imcc(Parrot_PMC interp, Parrot_String sourcefile, ARGIN(struct init_args_t *
const Parrot_PMC compiler = pasm_mode ? pasm_compiler : pir_compiler;
Parrot_PMC pbc;
+ if (flags->yydebug) {
+ Parrot_api_debug_flag(interp, PARROT_YYDEBUG_FLAG, 1);
+ r = imcc_set_debug_api(interp, compiler, 0, flags->yydebug);
+ if (!r) exit(EXIT_FAILURE);
+ }
if (!imcc_compile_file_api(interp, compiler, sourcefile, &pbc))
show_last_error_and_exit(interp);
return pbc;
@@ -746,6 +761,7 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]),
args->outfile = NULL;
args->sourcefile = NULL;
args->preprocess_only = 0;
+ args->yydebug = 0;
if (argc == 1) {
usage(stderr);
@@ -768,23 +784,31 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]),
break;
case 't':
if (opt.opt_arg && is_all_hex_digits(opt.opt_arg)) {
- const unsigned long _temp = strtoul(opt.opt_arg, NULL, 16);
- /* const Parrot_trace_flags _temp_flag = (Parrot_trace_flags)_temp; */
- const Parrot_Int _temp_flag = _temp;
- args->trace = _temp_flag;
+ args->trace = strtoul(opt.opt_arg, NULL, 16);
}
else
- args->trace = 0x01;
- /* *trace = PARROT_TRACE_OPS_FLAG; */
+ args->trace = PARROT_TRACE_OPS_FLAG;
break;
case 'D':
if (opt.opt_arg && is_all_hex_digits(opt.opt_arg))
result = Parrot_api_debug_flag(interp, strtoul(opt.opt_arg, NULL, 16), 1);
else
- /* Parrot_api_debug_flag(interp, PARROT_MEM_STAT_DEBUG_FLAG, 1); */
- result = Parrot_api_debug_flag(interp, 0x01, 1);
+ result = Parrot_api_debug_flag(interp, PARROT_MEM_STAT_DEBUG_FLAG, 1);
break;
-
+ case 'O':
+ if (!opt.opt_arg || !*opt.opt_arg || opt.opt_arg[0] == '0') {
+ args->trace |= PARROT_TRACE_OPT_0;
+ break;
+ }
+ if (strchr(opt.opt_arg, 'p'))
+ args->trace |= PARROT_TRACE_OPT_PASM;
+ if (strchr(opt.opt_arg, 'c'))
+ args->trace |= PARROT_TRACE_OPT_SUB;
+ /* currently not ok due to different register allocation */
+ if (strchr(opt.opt_arg, '1'))
+ args->trace |= PARROT_TRACE_OPT_PRE;
+ if (strchr(opt.opt_arg, '2'))
+ args->trace |= (PARROT_TRACE_OPT_PRE|PARROT_TRACE_OPT_CFG);
case '.': /* Give Windows Parrot hackers an opportunity to
* attach a debuggger. */
fgetc(stdin);
@@ -831,19 +855,15 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]),
args->have_pbc_file = 1;
break;
case OPT_GC_DEBUG:
- /*
#if DISABLE_GC_DEBUG
Parrot_warn(interp, 0xFFFF,
"PARROT_GC_DEBUG is set but the binary was compiled "
"with DISABLE_GC_DEBUG.");
#endif
- */
- /* Parrot_api_flag(interp, PARROT_GC_DEBUG_FLAG, 1); */
- result = Parrot_api_flag(interp, 0x10, 1);
+ result = Parrot_api_flag(interp, PARROT_GC_DEBUG_FLAG, 1);
break;
case OPT_DESTROY_FLAG:
- /* Parrot_api_flag(interp, PARROT_DESTROY_FLAG, 1); */
- result = Parrot_api_flag(interp, 0x200, 1);
+ result = Parrot_api_flag(interp, PARROT_DESTROY_FLAG, 1);
break;
case 'I':
result = Parrot_api_add_include_search_path(interp, opt.opt_arg);
@@ -856,10 +876,12 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]),
break;
case 'w':
/* result = Parrot_api_set_warnings(interp, PARROT_WARNINGS_ALL_FLAG); */
- result = Parrot_api_set_warnings(interp, 0xFFFF);
+ result = Parrot_api_set_warnings(interp, PARROT_WARNINGS_ALL_FLAG);
break;
case 'E':
args->preprocess_only = 1;
+ case 'y':
+ args->yydebug = 1;
default:
/* languages handle their arguments later (after being initialized) */
break;
View
3  frontend/parrot2/main.c
@@ -1,6 +1,6 @@
/*
-Copyright (C) 2007-2012, Parrot Foundation.
+Copyright (C) 2007-2014, Parrot Foundation.
=head1 NAME
@@ -410,6 +410,7 @@ Parrot_cmd_options(void)
{ '\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" } },
{ '\0', OPT_GC_NURSERY_SIZE, OPTION_required_FLAG, { "--gc-nursery-size" } },
View
11 include/imcc/api.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2011, Parrot Foundation.
+ * Copyright (C) 2011-2014, Parrot Foundation.
*/
#ifndef PARROT_IMCC_API_H_GUARD
@@ -44,6 +44,14 @@ Parrot_Int imcc_preprocess_file_api(
Parrot_PMC compiler,
Parrot_String file);
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+Parrot_Int imcc_set_debug_api(
+ Parrot_PMC interp_pmc,
+ Parrot_PMC compiler,
+ Parrot_Int traceflags,
+ Parrot_Int yydebug);
+
#define ASSERT_ARGS_imcc_compile_file_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(pbc))
#define ASSERT_ARGS_imcc_get_pasm_compreg_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
@@ -51,6 +59,7 @@ Parrot_Int imcc_preprocess_file_api(
#define ASSERT_ARGS_imcc_get_pir_compreg_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(compiler))
#define ASSERT_ARGS_imcc_preprocess_file_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
+#define ASSERT_ARGS_imcc_set_debug_api __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: compilers/imcc/api.c */
View
8 include/parrot/interpreter.h
@@ -1,5 +1,5 @@
/* interpreter.h
- * Copyright (C) 2001-2012, Parrot Foundation.
+ * Copyright (C) 2001-2014, Parrot Foundation.
* Overview:
* The interpreter API handles running the operations
*/
@@ -38,6 +38,7 @@ typedef enum {
PARROT_EVAL_DEBUG_FLAG = 0x20, /* create EVAL_n file */
PARROT_REG_DEBUG_FLAG = 0x40, /* fill I,N with garbage */
PARROT_CTX_DESTROY_DEBUG_FLAG = 0x80, /* ctx of a sub is gone */
+ PARROT_YYDEBUG_FLAG = 0x100, /* debug imcc parsing */
PARROT_ALL_DEBUG_FLAGS = 0xffff
} Parrot_debug_flags;
/* &end_gen */
@@ -48,6 +49,11 @@ typedef enum {
PARROT_TRACE_OPS_FLAG = 0x01, /* op execution trace */
PARROT_TRACE_FIND_METH_FLAG = 0x02, /* find_method */
PARROT_TRACE_SUB_CALL_FLAG = 0x04, /* invoke/retcc */
+ PARROT_TRACE_OPT_0 = 0x08, /* TODO imcc -O0 or -O */
+ PARROT_TRACE_OPT_PRE = 0x10, /* TODO imcc -O1 */
+ PARROT_TRACE_OPT_CFG = 0x20, /* TODO imcc -O2 */
+ PARROT_TRACE_OPT_PASM = 0x40, /* TODO imcc OPT_PASM */
+ PARROT_TRACE_OPT_SUB = 0x80, /* TODO imcc OPT_SUB */
PARROT_ALL_TRACE_FLAGS = 0xffff
} Parrot_trace_flags;
/* &end_gen */
Please sign in to comment.
Something went wrong with that request. Please try again.