Hello all,
Extended label syntax in macros (with percent placeholder) currently
does not work with forward references. For example, the following will
not assemble:
.macro dummy
rjmp label%
label%:
.endm
This happens because the running number substituted for % is incremented
on the label definition encounter, but if the label is referenced before
it's defined the non-incremented number is inserted instead; i.e., the
above example will be translated to
rjmp label0
label1:
The attached patches should fix this issue. Note that the fix was not
extensively tested (e.g. not tested with nested macros). Use at your own
risk :)
Patches are against the current git snapshot (from 25.Jul.2011).
--
Sincerely yours,
Alexey
--- macro.c.original Sat Jun 11 00:24:44 2011
+++ macro.c Mon Jul 25 16:22:10 2011
@@ -140,6 +140,7 @@
}
for(macro_label = macro->first_label; macro_label; macro_label
= macro_label->next) {
macro_label->running_number = 0;
+ macro_label->forward_label = True;
}
}
@@ -183,6 +184,7 @@
strcpy(macro_label->label,
&pi->fi->buff[start]);
pi->fi->buff[i-1] = ':';
macro_label->running_number = 0;
+ macro_label->forward_label =
True;
}
macro_line = calloc(1, sizeof(struct
macro_line));
@@ -463,6 +465,11 @@
//printf("\nconvert macro: '%s'\n",macro->name);
+ for(macro_label = macro->first_label; macro_label; macro_label =
macro_label->next) {
+ /* reset forward_label flags for all labels on each macro entry */
+ macro_label->forward_label = True;
+ }
+
for(pi->macro_line = macro->first_macro_line; pi->macro_line && ok;
pi->macro_line = pi->macro_line->next) {
macro_call->line_index++;
if(GET_ARG_I(pi->args, ARG_LISTMAC))
@@ -481,6 +488,7 @@
c = strlen(macro_label->label);
if(temp[c] == ':') { /* it is a label definition */
macro_label->running_number++;
+ macro_label->forward_label = False;
strncpy(buff, macro_label->label, c - 1);
buff[c - 1] = 0;
i = strlen(buff) + 2; /* we set the process indeafter label */
@@ -493,7 +501,10 @@
temp = strstr(buff, macro_label->label);
i = temp - buff + strlen(macro_label->label);
strncpy(temp, macro_label->label, c - 1);
- strcpy(&temp[c-1], itoa(macro_label->running_number, tmp, 10));
+ if (macro_label->forward_label)
+ strcpy(&temp[c-1], itoa(macro_label->running_number+1, tmp, 10));
+ else
+ strcpy(&temp[c-1], itoa(macro_label->running_number, tmp, 10));
}
}
else {
--- avra.h.original Sat Jul 23 16:01:02 2011
+++ avra.h Mon Jul 25 22:09:04 2011
@@ -255,6 +255,7 @@
char *label;
struct macro_label *next;
int running_number;
+ int forward_label; /* boolean */
};
struct macro_line
------------------------------------------------------------------------------
Storage Efficiency Calculator
This modeling tool is based on patent-pending intellectual property that
has been used successfully in hundreds of IBM storage optimization engage-
ments, worldwide. Store less, Store more with what you own, Move data to
the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
_______________________________________________
Avra-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/avra-user