|
65 | 65 | #include "Expression.h" |
66 | 66 | #include "VectorFilter.h" |
67 | 67 |
|
| 68 | +#include <string> |
| 69 | +#include <vector> |
68 | 70 | using namespace std; |
69 | 71 |
|
70 | 72 | /////////////////////////////////////////////////////////////////////////////// |
@@ -188,14 +190,40 @@ Block::make_random(CGContext &cg_context, bool looping) |
188 | 190 |
|
189 | 191 | curr_func->stack.pop_back(); |
190 | 192 | if (Error::get_error() != SUCCESS) { |
191 | | - //curr_func->stack.pop_back(); |
| 193 | + curr_func->stack.pop_back(); |
192 | 194 | delete b; |
193 | 195 | return NULL; |
194 | 196 | } |
195 | 197 |
|
196 | 198 | // ISSUE: in the exhaustive mode, do we need a return statement here |
197 | 199 | // if the last statement is not? |
198 | 200 | Error::set_error(SUCCESS); |
| 201 | + |
| 202 | + |
| 203 | + if(CGOptions::computed_goto()){ |
| 204 | + if(curr_func->blocks[0]->stm_id==b->stm_id){ |
| 205 | + std::vector<string> labels; |
| 206 | + labels.clear(); |
| 207 | + curr_func->blocks[0]->find_contained_labels(labels); |
| 208 | + string ss=""; |
| 209 | + for (std::vector<string>::iterator itr=labels.begin();itr!=labels.end();itr++) { |
| 210 | + ss.clear(); |
| 211 | + ss += "&&"; |
| 212 | + ss += *itr; |
| 213 | + curr_func->blocks[0]->addr_labels.push_back(ss);//only adds in the main array related to function. |
| 214 | + } |
| 215 | + //__________________________________________________________ |
| 216 | + for (size_t i=0; i<fm->cfg_edges.size();i++) { |
| 217 | + const CFGEdge* e = fm->cfg_edges[i]; |
| 218 | + if(e->src->eType == eGoto) { |
| 219 | + const StatementGoto* sg = dynamic_cast<const StatementGoto* >(e->src); |
| 220 | + assert(sg); |
| 221 | + sg->change_label(curr_func->blocks[0]->addr_labels); |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + } |
| 226 | + } |
199 | 227 | return b; |
200 | 228 | } |
201 | 229 |
|
@@ -295,6 +323,10 @@ Block::Output(std::ostream &out, FactMgr* fm, int indent) const |
295 | 323 | ss << "block id: " << stm_id; |
296 | 324 | output_comment_line(out, ss.str()); |
297 | 325 |
|
| 326 | + if(CGOptions::computed_goto()){ |
| 327 | + if(!this->addr_labels.empty()) |
| 328 | + this->print_label_addr_array(out,indent); |
| 329 | + } |
298 | 330 | if (CGOptions::depth_protect()) { |
299 | 331 | out << "DEPTH++;" << endl; |
300 | 332 | } |
@@ -805,6 +837,19 @@ Block::post_creation_analysis(CGContext& cg_context, const Effect& pre_effect) |
805 | 837 | } |
806 | 838 | } |
807 | 839 |
|
| 840 | +void |
| 841 | +Block::print_label_addr_array(std::ostream &out , int indent) const{ |
| 842 | + ostringstream ss; |
| 843 | + output_tab (out,indent); |
| 844 | + cout << "/*\nNUMBER OF GOTO'S IN ABOVEE BLOCK:" << addr_labels.size() << "*\/"; |
| 845 | + cout << "\nvoid *target[] = { "; |
| 846 | + for(unsigned int i=0; i < addr_labels.size();i++){ |
| 847 | + i!=0 ? cout << ", " : cout << ""; |
| 848 | + cout << addr_labels[i]; |
| 849 | + } |
| 850 | + |
| 851 | + cout << "};\n"; |
| 852 | +} |
808 | 853 | /////////////////////////////////////////////////////////////////////////////// |
809 | 854 |
|
810 | 855 | // Local Variables: |
|
0 commit comments