Skip to content

Commit

Permalink
wip: add imcc flags to the refactored API and use it (again)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Feb 24, 2014
1 parent 90e3128 commit 0cad250
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 7 deletions.
35 changes: 35 additions & 0 deletions compilers/imcc/api.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -202,6 +203,40 @@ imcc_preprocess_file_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
IMCC_API_CALLOUT(interp_pmc, interp)
}

/*
=item C<void imcc_set_debug_api(Parrot_PMC interp_pmc, Parrot_PMC
compiler, Parrot_Int traceflags, Parrot_Int yydebug)>
=cut
*/

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
void
imcc_set_debug_api(Parrot_PMC interp_pmc, Parrot_PMC compiler,
Parrot_Int traceflags, Parrot_Int yydebug)
{
ASSERT_ARGS(imcc_preprocess_file_api)

IMCC_API_CALLIN(interp_pmc, interp)
compiler = get_compreg_pmc(interp, 0, 0);
if (PMC_IS_NULL(compiler)) {
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_UNEXPECTED_NULL,
"Could not get PIR compiler PMC");
}
else {
PMC * result = PMCNULL;
STRING * const meth_name = Parrot_str_new(interp, "get_pointer", 0);
Parrot_pcc_invoke_method_from_c_args(interp, compiler, meth_name,
"->P", &result);
imcc_set_debug_mode(PARROT_IMCCOMPILER(result)->imcc_info, traceflags, yydebug);
}
IMCC_API_CALLOUT(interp_pmc, interp)
}

/*
* Local variables:
* c-file-style: "parrot"
Expand Down
24 changes: 19 additions & 5 deletions frontend/parrot/main.c
Expand Up @@ -24,6 +24,7 @@ Start Parrot
#include "parrot/longopt.h"
#include "parrot/api.h"
#include "imcc/api.h"
#include "parrot/interpreter.h"

struct init_args_t {
const char *run_core_name;
Expand All @@ -36,6 +37,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);
Expand Down Expand Up @@ -194,6 +196,8 @@ main(int argc, const char *argv[])
source_str = parsed_flags.sourcefile;
output_str = parsed_flags.outfile;

if (parsed_flags.yydebug)
Parrot_api_debug_flag(interp, PARROT_YYDEBUG_FLAG, 1);
if (!Parrot_api_set_runcore(interp, parsed_flags.run_core_name, parsed_flags.trace))
show_last_error_and_exit(interp);

Expand Down Expand Up @@ -255,14 +259,23 @@ 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);
Parrot_Int r;
if (flags->yydebug) {
Parrot_api_debug_flag(interp, PARROT_YYDEBUG_FLAG, 1);
imcc_set_debug_api(interp, pir_compiler, 0, flags->yydebug);
}
r = imcc_preprocess_file_api(interp, pir_compiler, sourcefile);
exit(r ? EXIT_SUCCESS : EXIT_FAILURE);
}
else {
const Parrot_Int pasm_mode = flags->have_pasm_file;
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);
imcc_set_debug_api(interp, pir_compiler, 0, flags->yydebug);
}
if (!imcc_compile_file_api(interp, compiler, sourcefile, &pbc))
show_last_error_and_exit(interp);
return pbc;
Expand Down Expand Up @@ -746,6 +759,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);
Expand Down Expand Up @@ -774,15 +788,15 @@ parseflags(Parrot_PMC interp, int argc, ARGIN(const char *argv[]),
args->trace = _temp_flag;
}
else
args->trace = 0x01;
/* *trace = PARROT_TRACE_OPS_FLAG; */
//args->trace = 0x01;
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);
//Parrot_api_debug_flag(interp, 0x01, 1);
break;

case '.': /* Give Windows Parrot hackers an opportunity to
Expand Down
10 changes: 9 additions & 1 deletion 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
Expand Down Expand Up @@ -44,6 +44,14 @@ Parrot_Int imcc_preprocess_file_api(
Parrot_PMC compiler,
Parrot_String file);

PARROT_EXPORT
PARROT_WARN_UNUSED_RESULT
void 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 = (\
Expand Down
3 changes: 2 additions & 1 deletion 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
*/
Expand Down Expand Up @@ -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 */
Expand Down

0 comments on commit 0cad250

Please sign in to comment.