Narrow IL lists twice, in order to handle JMP to labels before the JMP itself.
--- a/stage3/narrow_candidate_datatypes.cc Thu Mar 08 18:57:14 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.cc Thu Mar 08 18:57:55 2012 +0000
@@ -60,11 +60,11 @@
/* If we are trying to set to the undefined type, and the symbol's datatype has already been set to something else,
* we abort the compoiler as I don't think this should ever occur.
- * However, I (Mario) am not too sure of this, so if the compiler ever aborts here, please analyse the situation
- * carefully as it might be perfectly legal and something I have missed!
- */
- if ((NULL == datatype) && (NULL != symbol->datatype)) ERROR;
-
+ * NOTE: In order to handle JMPs to labels that come before the JMP itself, we run the narrow algorithm twice.
+ * This means that this situation may legally occur, so we cannot abort the compiler here!
+ */
+// if ((NULL == datatype) && (NULL != symbol->datatype)) ERROR;
+ if ((NULL == datatype) && (NULL != symbol->datatype)) return;
if ((NULL == datatype) && (NULL == symbol->datatype)) return;
if (search_in_candidate_datatype_list(datatype, symbol->candidate_datatypes) < 0)
@@ -521,8 +521,23 @@
/* In order to execute the narrow algoritm correctly, we need to go through the instructions backwards,
* so we can not use the base class' visitor
*/
- for(int i = symbol->n-1; i >= 0; i--) {
- symbol->elements[i]->accept(*this);
+ /* In order to execute the narrow algoritm correctly
+ * in IL instruction lists containing JMPs to labels that come before the JMP instruction
+ * itself, we need to run the narrow algorithm twice on the Instruction List.
+ * e.g.: ...
+ * ld 23
+ * label1:st byte_var
+ * ld 34
+ * JMP label1
+ *
+ * Note that the second time we run the narrow, most of the datatypes are already filled
+ * in, so it will be able to produce tha correct datatypes for the IL instruction referenced
+ * by the label, as in the 2nd pass we already know the datatypes of the JMP instruction!
+ */
+ for(int j = 0; j < 2; j++) {
+ for(int i = symbol->n-1; i >= 0; i--) {
+ symbol->elements[i]->accept(*this);
+ }
}
return NULL;
}
@@ -630,6 +645,22 @@
}
+
+
+/* il_jump_operator label */
+void *narrow_candidate_datatypes_c::visit(il_jump_operation_c *symbol) {
+ /* recursive call to fill the datatype */
+ symbol->il_jump_operator->datatype = symbol->datatype;
+ symbol->il_jump_operator->accept(*this);
+ return NULL;
+}
+
+
+
+
+
+
+
/* il_call_operator prev_declared_fb_name
* | il_call_operator prev_declared_fb_name '(' ')'
* | il_call_operator prev_declared_fb_name '(' eol_list ')'
--- a/stage3/narrow_candidate_datatypes.hh Thu Mar 08 18:57:14 2012 +0000
+++ b/stage3/narrow_candidate_datatypes.hh Thu Mar 08 18:57:55 2012 +0000
@@ -116,6 +116,7 @@
void *visit(il_simple_operation_c *symbol);
void *visit(il_function_call_c *symbol);
void *visit(il_expression_c *symbol);
+ void *visit(il_jump_operation_c *symbol);
void *visit(il_fb_call_c *symbol);
void *visit(il_formal_funct_call_c *symbol);
// void *visit(il_operand_list_c *symbol);