Author: kjs
Date: Thu Dec 4 16:46:14 2008
New Revision: 33499
Modified:
trunk/compilers/pirc/new/pircompunit.c
trunk/compilers/pirc/new/pirsymbol.c
trunk/compilers/pirc/t/stmts.t
Log:
[pirc] fix local label offsets.
+ this makes jumping instructions work (at least a few of them anyway)
+ update tests
+ it seems I can't go to bed till I fixed this :-( discipline-- I'd like to
have 36-hour days.
Modified: trunk/compilers/pirc/new/pircompunit.c
==============================================================================
--- trunk/compilers/pirc/new/pircompunit.c (original)
+++ trunk/compilers/pirc/new/pircompunit.c Thu Dec 4 16:46:14 2008
@@ -383,7 +383,21 @@
/* Each instruction has a sequence number to be able to
* calculate offsets for label branches.
*/
- instr->offset = lexer->instr_counter++;
+
+ /* the codesize so far will be the offset of this instruction. */
+ instr->offset = lexer->codesize;
+
+
+ /* XXX instr_counter still needed? Think so, for lin.scan.reg.alloc.
+ can instr->offset be used for that? or is it already used?
+ instr->offset is now just incremented in bigger steps...
+ */
+ lexer->instr_counter++;
+ /*instr->offset = lexer->instr_counter++;*/
+
+ /*
+ fprintf(stderr, "offset of %s is: %d\n", opname, instr->offset);
+ */
if (CURRENT_INSTRUCTION(lexer) == NULL)
instr->next = instr;
@@ -2191,22 +2205,14 @@
if (TEST_FLAG(iter->oplabelbits, BIT(flag))) {
/* the current operand is a label; fix it up. No, not a
date. */
- char const * labelid = operand->expr.id;
- unsigned offset = find_local_label(lexer, labelid);
+ char const * labelid = operand->expr.id;
+ unsigned offset = find_local_label(lexer, labelid);
+ unsigned curr_instr = iter->offset;
/* fprintf(stderr, "operand %d is a label\n", BIT(flag));
*/
-
- if (offset) { /* label was found */
- unsigned curr_instr = iter->offset;
-
- /* convert the label identifier into a real label
object */
- operand->expr.l = new_label(lexer, labelid, offset -
curr_instr);
- operand->type = EXPR_LABEL;
- }
- else {
- yypirerror(lexer->yyscanner, lexer,
- "cannot fix up reference to label '%s'",
labelid);
- }
+ /* convert the label identifier into a real label object */
+ operand->expr.l = new_label(lexer, labelid, offset -
curr_instr);
+ operand->type = EXPR_LABEL;
}
++flag;
Modified: trunk/compilers/pirc/new/pirsymbol.c
==============================================================================
--- trunk/compilers/pirc/new/pirsymbol.c (original)
+++ trunk/compilers/pirc/new/pirsymbol.c Thu Dec 4 16:46:14 2008
@@ -663,8 +663,12 @@
bucket *b = get_bucket(table, hashcode);
while (b) {
- if (STREQ(bucket_local(b)->name, labelname))
+ if (STREQ(bucket_local(b)->name, labelname)) {
+ /*
+ fprintf(stderr, "found offset for label %s (%d)\n", labelname,
bucket_local(b)->offset);
+ */
return bucket_local(b)->offset;
+ }
b = b->next;
}
Modified: trunk/compilers/pirc/t/stmts.t
==============================================================================
--- trunk/compilers/pirc/t/stmts.t (original)
+++ trunk/compilers/pirc/t/stmts.t Thu Dec 4 16:46:14 2008
@@ -40,8 +40,8 @@
CODE
.namespace []
main:
- lt I0, I1, 2
- le I1, I0, 1
+ lt I0, I1, 8
+ le I1, I0, 4
X:
Y:
Z:
@@ -62,7 +62,7 @@
CODE
.namespace []
int:
- lt I1, I0, 1
+ lt I1, I0, 4
goto:
L:
set_returns