Skip to content

Commit

Permalink
[imcc] fix U type in sub fixup
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Reini Urban committed Oct 15, 2014
1 parent 25e3e43 commit 20f74c7
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 43 deletions.
25 changes: 12 additions & 13 deletions compilers/imcc/debug.h
Expand Up @@ -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
Expand Down
11 changes: 5 additions & 6 deletions compilers/imcc/imcc.y
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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);
}
Expand Down
11 changes: 7 additions & 4 deletions compilers/imcc/pbc.c
Expand Up @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
}


Expand Down
32 changes: 12 additions & 20 deletions compilers/imcc/symreg.c
Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions include/parrot/interpreter.h
Expand Up @@ -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,
Expand Down

0 comments on commit 20f74c7

Please sign in to comment.