Handle JMP to labels preceding the JMP instruction itself.
authorMario de Sousa <msousa@fe.up.pt>
Sat, 03 Mar 2012 20:42:48 +0000
changeset 464 319ee8b218f3
parent 463 fafa9abc166e
child 465 b52ec62773db
Handle JMP to labels preceding the JMP instruction itself.
stage3/fill_candidate_datatypes.cc
stage3/fill_candidate_datatypes.hh
--- a/stage3/fill_candidate_datatypes.cc	Sat Mar 03 20:27:20 2012 +0000
+++ b/stage3/fill_candidate_datatypes.cc	Sat Mar 03 20:42:48 2012 +0000
@@ -800,7 +800,27 @@
 
 /*| instruction_list il_instruction */
 // SYM_LIST(instruction_list_c)
-// void *visit(instruction_list_c *symbol);
+void *fill_candidate_datatypes_c::visit(instruction_list_c *symbol) {
+	/* In order to execute the narrow algoritm ll the data type candidates correctly
+	 * ĩn IL instruction lists containing JMPs to labels that come before the JMP instruction
+	 * itself, we need to run the fill candidate datatypes 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 algorithm, most of the candidate datatypes are already filled
+	 * in, so it will be able to produce tha correct candidate datatypes for the IL instruction referenced
+	 * by the label, as in the 2nd pass we already know the candidate datatypes of the JMP instruction!
+	 */
+	for(int j = 0; j < 2; j++) {
+		for(int i = 0; i < symbol->n; i++) {
+			symbol->elements[i]->accept(*this);
+		}
+	}
+	return NULL;
+}
 
 
 
--- a/stage3/fill_candidate_datatypes.hh	Sat Mar 03 20:27:20 2012 +0000
+++ b/stage3/fill_candidate_datatypes.hh	Sat Mar 03 20:42:48 2012 +0000
@@ -194,7 +194,7 @@
     /***********************************/
     /* B 2.1 Instructions and Operands */
     /***********************************/
-    // void *visit(instruction_list_c *symbol);
+    void *visit(instruction_list_c *symbol);
     void *visit(il_instruction_c *symbol);
     void *visit(il_simple_operation_c *symbol);
     void *visit(il_function_call_c *symbol);