Use doubly linked connections for flow control graph (will be used later).
--- a/absyntax/absyntax.def Thu Oct 04 18:54:15 2012 +0100
+++ b/absyntax/absyntax.def Sat Oct 06 22:29:04 2012 +0100
@@ -908,11 +908,11 @@
SYM_LIST(instruction_list_c)
/* | label ':' [il_incomplete_instruction] eol_list */
-/* NOTE: The parameter 'prev_il_instruction' is used to point to all previous il instructions that may be executed imedaitely before this instruction.
- * In case of an il instruction preceded by a label, this will include all IL instructions that jump to this label!
+/* NOTE: The parameters 'prev_il_instruction'/'next_il_instruction' are used to point to all previous/next il instructions that may be executed imedaitely before/after this instruction.
+ * In case of an il instruction preceded by a label, the previous_il_instruction will include all IL instructions that jump to this label!
* It is filled in by the flow_control_analysis_c during stage 3.
*/
-SYM_REF2(il_instruction_c, label, il_instruction, std::vector <symbol_c *> prev_il_instruction;)
+SYM_REF2(il_instruction_c, label, il_instruction, std::vector <symbol_c *> prev_il_instruction, next_il_instruction;)
/* | il_simple_operator [il_operand] */
--- a/stage3/flow_control_analysis.cc Thu Oct 04 18:54:15 2012 +0100
+++ b/stage3/flow_control_analysis.cc Sat Oct 06 22:29:04 2012 +0100
@@ -131,6 +131,25 @@
}
+void flow_control_analysis_c::link_insert(symbol_c *prev_instruction, symbol_c *next_instruction) {
+ il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction);
+ il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction);
+ if ((NULL == next) || (NULL == prev)) ERROR;
+
+ next->prev_il_instruction.insert(next->prev_il_instruction.begin(), prev);
+ prev->next_il_instruction.insert(prev->next_il_instruction.begin(), next);
+}
+
+
+void flow_control_analysis_c::link_pushback(symbol_c *prev_instruction, symbol_c *next_instruction) {
+ il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction);
+ il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction);
+ if ((NULL == next) || (NULL == prev)) ERROR;
+
+ next->prev_il_instruction.push_back(prev);
+ prev->next_il_instruction.push_back(next);
+}
+
/************************************/
/* B 1.5 Program organization units */
@@ -209,7 +228,7 @@
/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
* In order to do that, we use insert() instead of push_back()
*/
- symbol->prev_il_instruction.insert(symbol->prev_il_instruction.begin() , prev_il_instruction);
+ link_insert(prev_il_instruction, symbol);
/* check if it is an il_expression_c, a JMP[C[N]], or a RET, and if so, handle it correctly */
prev_il_instruction_is_JMP_or_RET = false;
@@ -255,9 +274,8 @@
/* give the visit(JMP_operator *) an oportunity to set the prev_il_instruction_is_JMP_or_RET flag! */
symbol->il_jump_operator->accept(*this);
- /* add, to that il_instruction's list of prev_il_intsructions, the curr_il_instruction */
if (NULL != destination)
- destination->prev_il_instruction.push_back(curr_il_instruction);
+ link_pushback(curr_il_instruction, destination);
return NULL;
}
@@ -297,7 +315,8 @@
/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
* In order to do that, we use insert() instead of push_back()
*/
- symbol->prev_il_instruction.insert(symbol->prev_il_instruction.begin() , prev_il_instruction);
+ link_insert(prev_il_instruction, symbol);
+
return NULL;
}
--- a/stage3/flow_control_analysis.hh Thu Oct 04 18:54:15 2012 +0100
+++ b/stage3/flow_control_analysis.hh Sat Oct 06 22:29:04 2012 +0100
@@ -49,10 +49,14 @@
private:
search_il_label_c *search_il_label;
- symbol_c *prev_il_instruction;
- symbol_c *curr_il_instruction;
+ symbol_c *prev_il_instruction;
+ symbol_c *curr_il_instruction;
bool prev_il_instruction_is_JMP_or_RET;
+ private:
+ void link_insert (symbol_c *prev_instruction, symbol_c *next_instruction);
+ void link_pushback(symbol_c *prev_instruction, symbol_c *next_instruction);
+
public:
flow_control_analysis_c(symbol_c *ignore);
virtual ~flow_control_analysis_c(void);