cvsuser 03/11/23 22:03:23
Modified: imcc imcc.l imcc.y pbc.c pcc.c symreg.h symreg.c
Log:
Make IMCC_INTERNAL_CHAR visible and easy to change.
Changed from # to @ due to line comment conflict.
Add a routine with a better name for making sub labels.
Document a couple of routines.
Revision Changes Path
1.79 +1 -1 parrot/imcc/imcc.l
Index: imcc.l
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.l,v
retrieving revision 1.78
retrieving revision 1.79
diff -u -w -r1.78 -r1.79
--- imcc.l 19 Nov 2003 07:25:20 -0000 1.78
+++ imcc.l 24 Nov 2003 06:03:23 -0000 1.79
@@ -86,7 +86,7 @@
SIGN [-+]
FLOATNUM {SIGN}?{DIGITS}{DOT}{DIGIT}*([eE]{SIGN}?{DIGITS})?
LETTERDIGIT [a-zA-Z0-9_]
-LABELLETTERDIGIT ([a-zA-Z0-9_#]|"::")
+LABELLETTERDIGIT ([EMAIL PROTECTED]|"::")
ID {LETTER}{LABELLETTERDIGIT}*
STRINGCONSTANT \"(\\\"|[^"\n]*)*\"
CHARCONSTANT \'[^'\n]*\'
1.112 +9 -9 parrot/imcc/imcc.y
Index: imcc.y
===================================================================
RCS file: /cvs/public/parrot/imcc/imcc.y,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -w -r1.111 -r1.112
--- imcc.y 19 Nov 2003 07:25:51 -0000 1.111
+++ imcc.y 24 Nov 2003 06:03:23 -0000 1.112
@@ -294,7 +294,7 @@
free($2); }
| PCC_SUB LABEL {
char *name = str_dup($2);
- $$ = iSUBROUTINE(cur_unit, mk_address($2,
U_add_uniq_sub));
+ $$ = iSUBROUTINE(cur_unit, mk_sub_label($2));
$$->r[1] = mk_pcc_sub(name, 0);
}
| /* none */ { $$ = 0;}
@@ -394,7 +394,7 @@
IDENTIFIER pcc_sub_proto '\n'
{
char *name = str_dup($3);
- Instruction *i = iSUBROUTINE(cur_unit, mk_address($3, U_add_uniq_sub));
+ Instruction *i = iSUBROUTINE(cur_unit, mk_sub_label($3));
i->r[1] = $<sr>$ = mk_pcc_sub(name, 0);
i->r[1]->pcc_sub->prototyped = $4;
}
@@ -423,7 +423,7 @@
SUB { cur_unit = imc_open_unit(interp,
IMC_PCCSUB); }
IDENTIFIER '\n'
{ $$ = 0;
- iSUBROUTINE(cur_unit, mk_address($3, U_add_uniq_sub));
+ iSUBROUTINE(cur_unit, mk_sub_label($3));
}
;
*/
@@ -433,7 +433,7 @@
IDENTIFIER pcc_sub_proto '\n'
{
char *name = str_dup($3);
- Instruction *i = iSUBROUTINE(cur_unit, mk_address($3, U_add_uniq_sub));
+ Instruction *i = iSUBROUTINE(cur_unit, mk_sub_label($3));
i->r[1] = $<sr>$ = mk_pcc_sub(name, 0);
i->r[1]->pcc_sub->prototyped = $4;
}
@@ -455,7 +455,7 @@
SymReg * r;
Instruction *i;
- sprintf(name, "_#pcc_sub_call_%d", line - 1);
+ sprintf(name, "_%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, line - 1);
$<sr>$ = r = mk_pcc_sub(str_dup(name), 0);
r->pcc_sub->prototyped = $2;
/* this mid rule action has the semantic value of the
@@ -527,7 +527,7 @@
if (!ins || !ins->r[1] || ins->r[1]->type != VT_PCC_SUB)
fataly(EX_SOFTWARE, sourcefile, line,
"pcc_return not inside pcc subroutine\n");
- sprintf(name, "_#pcc_sub_ret_%d", line - 1);
+ sprintf(name, "_%cpcc_sub_ret_%d", IMCC_INTERNAL_CHAR, line - 1);
$<sr>$ = r = mk_pcc_sub(str_dup(name), 0);
i = iLABEL(cur_unit, r);
i->type = ITPCCSUB | ITLABEL;
@@ -545,7 +545,7 @@
fataly(EX_SOFTWARE, sourcefile, line,
"pcc_yield not inside pcc subroutine\n");
ins->r[1]->pcc_sub->calls_a_sub = 1;
- sprintf(name, "_#pcc_sub_yield_%d", line - 1);
+ sprintf(name, "_%cpcc_sub_yield_%d", IMCC_INTERNAL_CHAR, line - 1);
$<sr>$ = r = mk_pcc_sub(str_dup(name), 0);
i = iLABEL(cur_unit, r);
i->type = ITPCCSUB | ITLABEL | ITPCCYIELD;
@@ -712,7 +712,7 @@
char name[128];
SymReg * r;
Instruction *i;
- sprintf(name, "_#pcc_sub_call_%d", line - 1);
+ sprintf(name, "_%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, line - 1);
r = mk_pcc_sub(str_dup(name), 0);
current_call = i = iLABEL(cur_unit, r);
i->type = ITCALL | ITPCCSUB;
@@ -735,7 +735,7 @@
char name[128];
SymReg * r;
Instruction *i;
- sprintf(name, "_#pcc_sub_call_%d", line - 1);
+ sprintf(name, "_%cpcc_sub_call_%d", IMCC_INTERNAL_CHAR, line - 1);
r = mk_pcc_sub(str_dup(name), 0);
current_call = i = iLABEL(cur_unit, r);
i->type = ITCALL | ITPCCSUB;
1.60 +5 -4 parrot/imcc/pbc.c
Index: pbc.c
===================================================================
RCS file: /cvs/public/parrot/imcc/pbc.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -w -r1.59 -r1.60
--- pbc.c 20 Nov 2003 15:34:06 -0000 1.59
+++ pbc.c 24 Nov 2003 06:03:23 -0000 1.60
@@ -77,11 +77,11 @@
{
struct cs_t *cs, *prev_cs;
struct subs *s, *prev_s;
- struct Parrot_Interp *interpreter = (struct Parrot_Interp *)param;
+ struct Parrot_Interp *interp = (struct Parrot_Interp *)param;
SymReg **h;
UNUSED(ex);
- UNUSED(interpreter);
+ UNUSED(interp);
cs = globals.cs;
while (cs) {
s = cs->subs;
@@ -299,6 +299,7 @@
PackFile_find_fixup_entry(interpreter, enum_fixup_label, name);
return fe != NULL;
}
+
/* store global labels and bsr for later fixup
* return size in ops
*/
@@ -405,7 +406,7 @@
addr->name);
glabel = addr->name;
/* append inter_cs jump */
- sprintf(buf, "_#isc_%d", globals.inter_seg_n++);
+ sprintf(buf, "_%cisc_%d", IMCC_INTERNAL_CHAR, globals.inter_seg_n++);
addr->name = str_dup(buf);
INS_LABEL(unit, addr, 1);
/* this is the new location */
@@ -423,7 +424,7 @@
}
-/* get a globale label, return the pc (absolute) */
+/* get a global label, return the pc (absolute) */
static SymReg *
find_global_label(char *name, int *pc)
{
1.36 +52 -22 parrot/imcc/pcc.c
Index: pcc.c
===================================================================
RCS file: /cvs/public/parrot/imcc/pcc.c,v
retrieving revision 1.35
retrieving revision 1.36
diff -u -w -r1.35 -r1.36
--- pcc.c 22 Nov 2003 12:13:49 -0000 1.35
+++ pcc.c 24 Nov 2003 06:03:23 -0000 1.36
@@ -85,14 +85,18 @@
SymReg *sub, SymReg *i0, SymReg *p3, int first, int type)
{
SymReg *check_sub, *regs[IMCC_MAX_REGS], *check_type, *what, *check_pmc;
- char buf[128];
+ char buf[256];
+ char * s;
SymReg *err_nparam, *err_type;
/*
* generate check subroutine if not done yet
*/
- what = mk_symreg(str_dup("_#what"), 'I');
- strcpy(buf, "_#check_params");
+ s = str_dup("?what");
+ *s = IMCC_INTERNAL_CHAR; /* Avoid an sprintf/copy */
+ what = mk_symreg(s, 'I');
+ strcpy(buf, "_?check_params");
+ buf[1] = IMCC_INTERNAL_CHAR; /* Avoid an sprintf/copy */
check_sub = _get_sym(ghash, buf);
if (!check_sub) {
@@ -103,7 +107,9 @@
* first time check: amount of params, elements in P3
* we can globber I0
*/
- err_nparam = mk_address(str_dup("_#check_err_nparam"), U_add_uniq_label);
+ s = str_dup("_?check_err_nparam");
+ s[1] = IMCC_INTERNAL_CHAR;
+ err_nparam = mk_address(s, U_add_uniq_label);
if (p3) {
if (!i0)
i0 = mk_pasm_reg(str_dup("I0"));
@@ -131,13 +137,14 @@
pcc_emit_err(interpreter, unit, err_nparam, "\"wrong param count\"");
}
- strcpy(buf, "_#check_param_type");
- check_type = _get_sym(ghash, buf);
+ s = str_dup("_?check_param_type");
+ s[1] = IMCC_INTERNAL_CHAR; /* Avoid sprintf call */
+ check_type = _get_sym(ghash, s);
if (!check_type && type) {
/*
* type check entry to check sub
*/
- check_type = mk_address(str_dup(buf), U_add_uniq_label);
+ check_type = mk_address(s, U_add_uniq_label);
INS_LABEL(unit, check_type, 1);
/*
* param type check, we get the entry type in what
@@ -147,7 +154,10 @@
regs[1] = p3;
regs[2] = mk_const(str_dup("0"), 'I');
INS(interpreter, unit, "typeof", NULL, regs, 3, 4, 1);
- err_type = mk_address(str_dup("_#check_err_type"), U_add_uniq_label);
+
+ s = str_dup("_?check_err_type");
+ s[1] = IMCC_INTERNAL_CHAR; /* Avoid sprintf */
+ err_type = mk_address(s, U_add_uniq_label);
regs[0] = i0;
regs[1] = what;
regs[2] = err_type;
@@ -157,8 +167,9 @@
/*
* PMC type check entry to check sub
*/
- check_pmc = mk_address(str_dup("_#check_param_type_pmc"),
- U_add_uniq_label);
+ s = str_dup("_?check_param_type_pmc");
+ s[1] = IMCC_INTERNAL_CHAR; /* Avoid sprintf */
+ check_pmc = mk_address(s, U_add_uniq_label);
INS_LABEL(unit, check_pmc, 1);
/*
* either type = enum_type_PMC || > 0
@@ -196,9 +207,15 @@
sprintf(buf, "%d", type);
regs[1] = mk_const(str_dup(buf), 'I');
ins = insINS(interpreter, unit, ins, "set", regs, 2);
- strcpy(buf, enum_type_PMC == type ?
- "_#check_param_type_pmc" : "_#check_param_type");
+ if(enum_type_PMC == type)
+ sprintf(buf, "_%ccheck_param_type_pmc", IMCC_INTERNAL_CHAR);
+ else
+ sprintf(buf, "_%ccheck_param_type", IMCC_INTERNAL_CHAR);
check_type = _get_sym(ghash, buf);
+ if(!check_type) {
+ PIO_eprintf(NULL, "imcc: fatal: pcc_emit_check_param: symbol %s not
found\n", buf);
+ exit(1);
+ }
regs[0] = check_type;
ins = insINS(interpreter, unit, ins, "bsr", regs, 1);
return ins;
@@ -241,7 +258,7 @@
/* subroutine can handle both */
i0 = mk_pasm_reg(str_dup("I0"));
regs[0] = i0;
- sprintf(buf, "_#sub_%s_p1", sub->name);
+ sprintf(buf, "_%csub_%s_p1", IMCC_INTERNAL_CHAR, sub->name);
regs[1] = label1 = mk_address(str_dup(buf), U_add_uniq_label);
ins = insINS(interpreter, unit, ins, "if", regs, 2);
@@ -334,7 +351,7 @@
if (ps != pe) {
if (!proto) {
/* branch to the end */
- sprintf(buf, "_#sub_%s_p0", sub->name);
+ sprintf(buf, "_%csub_%s_p0", IMCC_INTERNAL_CHAR, sub->name);
regs[0] = label2 = mk_address(str_dup(buf), U_add_uniq_label);
ins = insINS(interpreter, unit, ins, "branch", regs, 1);
tmp = INS_LABEL(unit, label1, 0);
@@ -532,7 +549,6 @@
int call_found, ret_found;
int i, j, matching;
struct pcc_sub_t *call, *ret;
-
UNUSED(unit);
/*
* currently only with -Oc
@@ -609,6 +625,7 @@
Instruction *tmp;
int lin;
char buf[128];
+ char * s;
/*
* emited code is
* $I2 = i+5 # once
@@ -646,10 +663,23 @@
*
*/
- i0 = mk_symreg(str_dup("#i0"), 'I'); /* TODO cache syms */
- i1 = mk_symreg(str_dup("#i1"), 'I');
+ s = str_dup("?i0");
+ s[0] = IMCC_INTERNAL_CHAR;
+ i0 = mk_symreg(s, 'I'); /* TODO cache syms */
+
+ s = str_dup("?i1");
+ s[0] = IMCC_INTERNAL_CHAR;
+ i1 = mk_symreg(s, 'I');
+
+ s = str_dup("?i0");
+ s[0] = IMCC_INTERNAL_CHAR;
+
i2 = mk_pasm_reg(str_dup("I2"));
- py = mk_symreg(str_dup("#py"), 'P');
+
+ s = str_dup("?py");
+ s[0] = IMCC_INTERNAL_CHAR;
+ py = mk_symreg(s, 'P');
+
p3 = mk_pasm_reg(str_dup("P3"));
/* first time */
if (!(*flatten)++) {
@@ -659,13 +689,13 @@
ins = insINS(interpreter, unit, ins, "set", regs, 2);
}
lin = ins->line;
- sprintf(buf, "_#arg_loop_%d_%d", lin, i);
+ sprintf(buf, "_%carg_loop_%d_%d", IMCC_INTERNAL_CHAR, lin, i);
loop = mk_address(str_dup(buf), U_add_uniq_label);
- sprintf(buf, "_#next_arg_%d_%d", lin, i);
+ sprintf(buf, "_%cnext_arg_%d_%d", IMCC_INTERNAL_CHAR, lin, i);
next = mk_address(str_dup(buf), U_add_uniq_label);
- sprintf(buf, "_#over_flow_%d_1_%d", lin, i);
+ sprintf(buf, "_%cover_flow_%d_1_%d", IMCC_INTERNAL_CHAR, lin, i);
over1 = mk_address(str_dup(buf), U_add_uniq_label);
- sprintf(buf, "_#over_flow_%d_%d", lin, i);
+ sprintf(buf, "_%cover_flow_%d_%d", IMCC_INTERNAL_CHAR, lin, i);
over = mk_address(str_dup(buf), U_add_uniq_label);
if (arg->type & VT_FLATTEN) {
1.37 +1 -0 parrot/imcc/symreg.h
Index: symreg.h
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.h,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -w -r1.36 -r1.37
--- symreg.h 19 Nov 2003 07:29:40 -0000 1.36
+++ symreg.h 24 Nov 2003 06:03:23 -0000 1.37
@@ -96,6 +96,7 @@
SymReg * mk_const(char *, int t);
SymReg * mk_const_ident(char *, int t, SymReg *, int);
SymReg * mk_address(char *, int uniq);
+SymReg * mk_sub_label(char *);
SymReg * mk_pcc_sub(char *, int proto);
char * symreg_to_str(SymReg *);
void add_pcc_arg(SymReg *r, SymReg * arg);
1.42 +25 -2 parrot/imcc/symreg.c
Index: symreg.c
===================================================================
RCS file: /cvs/public/parrot/imcc/symreg.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -w -r1.41 -r1.42
--- symreg.c 19 Nov 2003 07:29:40 -0000 1.41
+++ symreg.c 24 Nov 2003 06:03:23 -0000 1.42
@@ -54,7 +54,14 @@
/* symbolic registers */
-/* Makes a new SymReg from its varname and type */
+/* Makes a new SymReg from its varname and type
+ *
+ * char * name is a malloced string that will
+ * be used if the symbol needs to be created, or
+ * freed if an old symbol is found.
+ * This is a potentially dangerous semantic that
+ * should be changed.
+ */
SymReg *
_mk_symreg(SymReg* hsh[],char * name, int t)
{
@@ -332,6 +339,16 @@
return _mk_address(h, name, uniq);
}
+/*
+ * Make and store a new address label for a sub.
+ */
+SymReg * mk_sub_label(char * name)
+{
+ return _mk_address(ghash, name, U_add_uniq_sub);
+}
+
+
+
/* link keys to a keys structure = SymReg
*
* we might have
@@ -472,6 +489,9 @@
_store_symreg(SymReg *hsh[], SymReg * r)
{
int i = hash_str(r->name) % HASH_SIZE;
+#if IMC_TRACE
+ printf(" store [%s]\n", r->name);
+#endif
r->next = hsh[i];
hsh[i] = r;
}
@@ -489,6 +509,9 @@
SymReg * p;
int i = hash_str(name) % HASH_SIZE;
for(p = hsh[i]; p; p = p->next) {
+#if IMC_TRACE_HIGH
+ printf(" [%s]\n", p->name);
+#endif
if(!strcmp(name, p->name))
return p;
}