From 20f74c784824e8910a792897e10d7baa709ca08a Mon Sep 17 00:00:00 2001 From: Reini Urban Date: Fri, 10 Oct 2014 14:18:59 +0200 Subject: [PATCH] [imcc] fix U type in sub fixup Honor mk_const Slp, do not change S to U when called a 2nd time as S with already stripped quotes. Change -t8 private trace flag to -d2 proper imcc flag for mk_const tracking Add more debugging verboseness. --- compilers/imcc/debug.h | 25 ++++++++++++------------- compilers/imcc/imcc.y | 11 +++++------ compilers/imcc/pbc.c | 11 +++++++---- compilers/imcc/symreg.c | 32 ++++++++++++-------------------- include/parrot/interpreter.h | 1 + 5 files changed, 37 insertions(+), 43 deletions(-) diff --git a/compilers/imcc/debug.h b/compilers/imcc/debug.h index 7c1cca73ee..a1cce1bdf4 100644 --- a/compilers/imcc/debug.h +++ b/compilers/imcc/debug.h @@ -6,20 +6,19 @@ #define PARROT_IMCC_DEBUG_H_GUARD -#define DEBUG_PARROT 0x0001 +#define DEBUG_PARROT 0x0001 +#define DEBUG_MKCONST 0x0002 /* was DEBUG_LEXER */ +#define DEBUG_PARSER 0x0004 +#define DEBUG_IMC 0x0008 +#define DEBUG_CFG 0x0010 +#define DEBUG_OPT1 0x0020 +#define DEBUG_OPT2 0x0040 +#define DEBUG_SPILL 0x0080 + +#define DEBUG_AST 0x0100 /* unused: -#define DEBUG_LEXER 0x0002 */ -#define DEBUG_PARSER 0x0004 -#define DEBUG_IMC 0x0008 -#define DEBUG_CFG 0x0010 -#define DEBUG_OPT1 0x0020 -#define DEBUG_OPT2 0x0040 -#define DEBUG_SPILL 0x0080 - -#define DEBUG_AST 0x0100 -/* unused: -#define DEBUG_REG 0x0200 -#define DEBUG_REG2 0x0400 */ +#define DEBUG_REG 0x0200 +#define DEBUG_REG2 0x0400 */ #define DEBUG_PBC 0x1000 #define DEBUG_PBC_CONST 0x2000 diff --git a/compilers/imcc/imcc.y b/compilers/imcc/imcc.y index aebf0c6355..9fd30cdb2a 100644 --- a/compilers/imcc/imcc.y +++ b/compilers/imcc/imcc.y @@ -469,7 +469,7 @@ mk_pmc_const_named(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit), ASSERT_ARGS(mk_pmc_const_named) SymReg *rhs; SymReg *r[3]; - //const int ascii = (*constant == '\'' || *constant == '"'); + const int ascii = (*constant == '\'' || *constant == '"'); char *unquoted_name = mem_sys_strdup(name + 1); size_t name_length; @@ -490,14 +490,14 @@ mk_pmc_const_named(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit), if ((strncmp(unquoted_name, "Sub", name_length) == 0) || (strncmp(unquoted_name, "Coroutine", name_length) == 0)) { rhs = mk_const(imcc, constant, 'p'); - //if (!ascii) - // rhs->type |= VT_ENCODED; + if (!ascii) + rhs->type |= VT_ENCODED; rhs->usage |= U_FIXUP | U_SUBID_LOOKUP; } else if (strncmp(unquoted_name, "LexInfo", name_length) == 0) { rhs = mk_const(imcc, constant, 'l'); - //if (!ascii) - // rhs->type |= VT_ENCODED; + if (!ascii) + rhs->type |= VT_ENCODED; rhs->usage |= U_FIXUP | U_LEXINFO_LOOKUP; } else { @@ -509,7 +509,6 @@ mk_pmc_const_named(ARGMOD(imc_info_t *imcc), ARGMOD(IMC_Unit *unit), Parrot_str_new(imcc->interp, unquoted_name, name_length)); mem_sys_free(unquoted_name); - //mem_sys_free(const_name); return INS(imcc, unit, "set_p_pc", "", r, 2, 0, 1); } diff --git a/compilers/imcc/pbc.c b/compilers/imcc/pbc.c index c6266f5640..a9a35a7dc0 100644 --- a/compilers/imcc/pbc.c +++ b/compilers/imcc/pbc.c @@ -699,8 +699,9 @@ get_code_size(ARGMOD(imc_info_t * imcc), ARGIN(const IMC_Unit *unit), else { if (ins->op == &core_ops->op_info_table[PARROT_OP_set_p_pc]) { /* set_p_pc opcode */ - IMCC_debug(imcc, DEBUG_PBC_FIXUP, "PMC constant %s\n", - ins->symregs[1]->name); + IMCC_debug(imcc, DEBUG_PBC_FIXUP, "PMC constant %s type=%d usage=%d set=%d\n", + ins->symregs[1]->name, ins->symregs[1]->type, + ins->symregs[1]->usage, ins->symregs[1]->set); if (ins->symregs[1]->usage & U_FIXUP) store_fixup(imcc, ins->symregs[1], code_size, 2); @@ -1809,6 +1810,8 @@ build_key(ARGMOD(imc_info_t * imcc), ARGIN(SymReg *key_reg), /* Fall through. */ case VTCONST: case VTCONST|VT_ENCODED: + IMCC_debug(imcc, DEBUG_PBC_CONST, " const key reg %s set=%c color=%d type=%x\n", + r->name, r->set, (int)r->color, r->type); switch (r->set) { case 'S': /* P["key"] */ /* str constant */ @@ -2140,8 +2143,8 @@ add_1_const(ARGMOD(imc_info_t * imcc), ARGMOD(SymReg *r), if (!r) return; - IMCC_debug(imcc, DEBUG_PBC_CONST, "const %s\tcolor %d use_count %d\n", - r->name, r->color, r->use_count); + IMCC_debug(imcc, DEBUG_PBC_CONST, "const %s\tset=%c color=%d use_count=%d type=%x\n", + r->name, r->set, r->color, r->use_count, r->type); } diff --git a/compilers/imcc/symreg.c b/compilers/imcc/symreg.c index b32767828c..83247235e9 100644 --- a/compilers/imcc/symreg.c +++ b/compilers/imcc/symreg.c @@ -848,33 +848,25 @@ mk_const(ARGMOD(imc_info_t * imcc), ARGIN(const char *name), int t) SymHash * const h = &imcc->ghash; int encoded = 0; SymReg * result; - char *const_name; + char *const_name = (char *)name; if (!h->data) create_symhash(imcc, h); - if (t == 'U') { - const_name = (char *)name; - } - else if (*name == '"') { - STRING *unescaped = Parrot_str_unescape(imcc->interp, name+1, '"', NULL); - const_name = Parrot_str_to_cstring(imcc->interp, unescaped); - } - else if (*name == '\'') { - const_name = mem_sys_strdup(name + 1); - const_name[strlen(const_name) - 1] = 0; - } - else { /* else encoded. TODO: Unify encodings per aliases.*/ - const_name = (char *)name; - if (t =='S') t = 'U'; - else encoded++; + if (t != 'U') { + if (*name == '"') { + STRING *unescaped = Parrot_str_unescape(imcc->interp, name+1, '"', NULL); + const_name = Parrot_str_to_cstring(imcc->interp, unescaped); + } + else if (*name == '\'') { + const_name = mem_sys_strdup(name + 1); + const_name[strlen(const_name) - 1] = 0; + } } - if (Interp_trace_TEST(imcc->interp, 8)) - fprintf(stderr, "# mk_const '%s' %c\n", const_name, t); + IMCC_debug(imcc, DEBUG_MKCONST, "# mk_const '%s' %c\n", + const_name, t); result = _mk_const(imcc, h, const_name, t); - if (encoded) - result->type |= VT_ENCODED; return result; } diff --git a/include/parrot/interpreter.h b/include/parrot/interpreter.h index 920f86bfb7..e49853794c 100644 --- a/include/parrot/interpreter.h +++ b/include/parrot/interpreter.h @@ -55,6 +55,7 @@ typedef enum { typedef enum { /* sync with compilers/imcc/debug.h */ PARROT_IMCC_DEBUG_NONE = 0x0000, PARROT_IMCC_VERBOSE = 0x0001, + PARROT_IMCC_DEBUG_MKCONST = 0x0002, PARROT_IMCC_DEBUG_PARSER = 0x0004, /* sets yydebug */ PARROT_IMCC_DEBUG_IMC = 0x0008, /* dump symreg, insns */ PARROT_IMCC_DEBUG_CFG = 0x0010,