| 266 | } |
| 267 | |
| 268 | int |
| 269 | ReducerOutputMgr::output_main_func(std::ostream& out) |
| 270 | { |
| 271 | size_t i; |
| 272 | const Function* f = reducer->main; |
| 273 | if (f->param.size() == 0 && (reducer->main_str == "" || reducer->main_str.find("func_")==0)) { |
| 274 | out << "int main(void)" << endl; |
| 275 | if (reducer->is_blk_deleted(f->body)) { |
| 276 | out << "{" << endl; |
| 277 | if (!reducer->crc_lines.empty()) { |
| 278 | output_crc_lines(out); |
| 279 | } |
| 280 | output_tab(out, 1); |
| 281 | out << "return 0;" << endl; |
| 282 | out << "}" << endl; |
| 283 | } |
| 284 | else { |
| 285 | output_block(f->body, out, 0); |
| 286 | } |
| 287 | } |
| 288 | else { |
| 289 | output_func(f, out); |
| 290 | out << endl << "int main(void) {" << endl; |
| 291 | output_tab(out, 1); |
| 292 | // break up function call and parameters, and skip parameters that are reduced |
| 293 | vector<string> strs; |
| 294 | StringUtils::split_string(reducer->main_str, strs, "();"); |
| 295 | assert(strs.size() == 2 || strs.size() == 1); |
| 296 | string func_name = strs[0]; |
| 297 | out << func_name << "("; |
| 298 | if (strs.size() == 2) { |
| 299 | const Function* f = find_function_by_name(func_name); |
| 300 | assert(f); |
| 301 | string params = strs[1]; |
| 302 | strs.clear(); |
| 303 | StringUtils::split_string(params, strs, ","); |
| 304 | bool first = true; |
| 305 | for (i=0; i<strs.size(); i++) { |
| 306 | if (!reducer->is_param_dropped(f, i)) { |
| 307 | if (!first) { |
| 308 | out << ", "; |
| 309 | } |
| 310 | out << strs[i]; |
| 311 | first = false; |
| 312 | } |
| 313 | } |
| 314 | } |
| 315 | out << ");" << endl; |
| 316 | output_tab(out, 1); |
| 317 | out << "return 0;" << endl << "}"; |
| 318 | outputln(out); |
| 319 | } |
| 320 | return 0; |
| 321 | } |
| 322 | int |
| 323 | ReducerOutputMgr::output_func(const Function* f, std::ostream& out) |
| 324 | { |
nothing calls this directly
no test coverage detected