stage3/flow_control_analysis.cc
changeset 672 dee28c5bdc73
parent 661 f537c3315f83
child 685 5b19e376cc94
equal deleted inserted replaced
671:d28c7ebaca21 672:dee28c5bdc73
   128 }
   128 }
   129 
   129 
   130 flow_control_analysis_c::~flow_control_analysis_c(void) {
   130 flow_control_analysis_c::~flow_control_analysis_c(void) {
   131 }
   131 }
   132 
   132 
       
   133 
       
   134 void flow_control_analysis_c::link_insert(symbol_c *prev_instruction, symbol_c *next_instruction) {
       
   135 	il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction);
       
   136 	il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction);
       
   137 	if ((NULL == next) || (NULL == prev)) ERROR;
       
   138 
       
   139 	next->prev_il_instruction.insert(next->prev_il_instruction.begin(), prev);
       
   140 	prev->next_il_instruction.insert(prev->next_il_instruction.begin(), next);
       
   141 }
       
   142 
       
   143 
       
   144 void flow_control_analysis_c::link_pushback(symbol_c *prev_instruction, symbol_c *next_instruction) {
       
   145 	il_instruction_c *next = dynamic_cast<il_instruction_c *>(next_instruction);
       
   146 	il_instruction_c *prev = dynamic_cast<il_instruction_c *>(prev_instruction);
       
   147 	if ((NULL == next) || (NULL == prev)) ERROR;
       
   148 
       
   149 	next->prev_il_instruction.push_back(prev);
       
   150 	prev->next_il_instruction.push_back(next);
       
   151 }
   133 
   152 
   134 
   153 
   135 /************************************/
   154 /************************************/
   136 /* B 1.5 Program organization units */
   155 /* B 1.5 Program organization units */
   137 /************************************/
   156 /************************************/
   207 void *flow_control_analysis_c::visit(il_instruction_c *symbol) {
   226 void *flow_control_analysis_c::visit(il_instruction_c *symbol) {
   208 	if ((NULL != prev_il_instruction) && (!prev_il_instruction_is_JMP_or_RET))
   227 	if ((NULL != prev_il_instruction) && (!prev_il_instruction_is_JMP_or_RET))
   209 		/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
   228 		/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
   210 		 * In order to do that, we use insert() instead of push_back()
   229 		 * In order to do that, we use insert() instead of push_back()
   211 		 */
   230 		 */
   212 		symbol->prev_il_instruction.insert(symbol->prev_il_instruction.begin() , prev_il_instruction);
   231 		link_insert(prev_il_instruction, symbol);
   213 
   232 
   214 	/* check if it is an il_expression_c, a JMP[C[N]], or a RET, and if so, handle it correctly */
   233 	/* check if it is an il_expression_c, a JMP[C[N]], or a RET, and if so, handle it correctly */
   215 	prev_il_instruction_is_JMP_or_RET = false;
   234 	prev_il_instruction_is_JMP_or_RET = false;
   216 	if (NULL != symbol->il_instruction)
   235 	if (NULL != symbol->il_instruction)
   217 		symbol->il_instruction->accept(*this);
   236 		symbol->il_instruction->accept(*this);
   253   /* search for the il_instruction_c containing the label */
   272   /* search for the il_instruction_c containing the label */
   254   il_instruction_c *destination = search_il_label->find_label(symbol->label);
   273   il_instruction_c *destination = search_il_label->find_label(symbol->label);
   255 
   274 
   256   /* give the visit(JMP_operator *) an oportunity to set the prev_il_instruction_is_JMP_or_RET flag! */
   275   /* give the visit(JMP_operator *) an oportunity to set the prev_il_instruction_is_JMP_or_RET flag! */
   257   symbol->il_jump_operator->accept(*this);
   276   symbol->il_jump_operator->accept(*this);
   258   /* add, to that il_instruction's list of prev_il_intsructions, the curr_il_instruction */
       
   259   if (NULL != destination)
   277   if (NULL != destination)
   260     destination->prev_il_instruction.push_back(curr_il_instruction);
   278     link_pushback(curr_il_instruction, destination);
   261   return NULL;
   279   return NULL;
   262 }
   280 }
   263 
   281 
   264 
   282 
   265 /*   il_call_operator prev_declared_fb_name
   283 /*   il_call_operator prev_declared_fb_name
   295 void *flow_control_analysis_c::visit(il_simple_instruction_c*symbol) {
   313 void *flow_control_analysis_c::visit(il_simple_instruction_c*symbol) {
   296 	if (NULL != prev_il_instruction)
   314 	if (NULL != prev_il_instruction)
   297 		/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
   315 		/* We try to guarantee that the previous il instruction that is in the previous line, will occupy the first element of the vector.
   298 		 * In order to do that, we use insert() instead of push_back()
   316 		 * In order to do that, we use insert() instead of push_back()
   299 		 */
   317 		 */
   300 		symbol->prev_il_instruction.insert(symbol->prev_il_instruction.begin() , prev_il_instruction);
   318 		link_insert(prev_il_instruction, symbol);
       
   319 
   301 	return NULL;
   320 	return NULL;
   302 }
   321 }
   303 
   322 
   304 
   323 
   305 /*
   324 /*