void print_backtrace (print_fn print) throw () { frame* frames = backtrace_frames_current (2); print_frames (frames, print); delete[] frames; }
void handle_read(const session_ptr& the_session, handler_allocator_type& the_allocator, const frame_buffer_ptr& frame_buffer, const boost::system::error_code& error, std::size_t frames_transferred) { print_frames(*frame_buffer, frames_transferred); if (boost::asio::error::eof == error) { std::cout << "Input stream was closed." \ " But it\'s a serial port so begin read operation again...\n"; the_session->async_read_some(frame_buffer->begin(), frame_buffer->end(), ma::make_custom_alloc_handler(the_allocator, ma::detail::bind( handle_read, the_session, ma::detail::ref(the_allocator), frame_buffer, ma::detail::placeholders::_1, ma::detail::placeholders::_2))); return; } if (error) { std::cout << "Read unsuccessful. Begin the session stop...\n"; the_session->async_stop(ma::make_custom_alloc_handler(the_allocator, ma::detail::bind(handle_stop, ma::detail::placeholders::_1))); return; } the_session->async_read_some(frame_buffer->begin(), frame_buffer->end(), ma::make_custom_alloc_handler(the_allocator, ma::detail::bind(handle_read, the_session, ma::detail::ref(the_allocator), frame_buffer, ma::detail::placeholders::_1, ma::detail::placeholders::_2))); // Only for test of cyclic_read_session::async_write_some //frame_ptr frame = *(frame_buffer->begin()); //the_session->async_write_some(boost::asio::buffer(*frame), // ma::detail::bind(handle_write, the_session, frame, // ma::detail::placeholders::_1, ma::detail::placeholders::_2)); }
int main(int argc, char *argv[]) { /* process arguments */ handle_opts(argc, argv); /* open files */ vlog("[plpcc] opening files\n"); FILE_INPUT = fopen(S_FILE_INPUT,"r"); if (FILE_INPUT == NULL) { err("[plpcc] cannot open input file: %s\n", S_FILE_INPUT); } FILE_OUTPUT = fopen(S_FILE_OUTPUT,"w"); if (FILE_OUTPUT == NULL) { err("[plpcc] cannot open output file: %s\n", S_FILE_OUTPUT); } yyset_in(FILE_INPUT); if (S_SYMBOL_OUTPUT != NULL) { SYMBOL_OUTPUT = fopen(S_SYMBOL_OUTPUT, "w"); if (SYMBOL_OUTPUT == NULL) { err("[plpcc] cannot open symbol table output file: %s\n", S_SYMBOL_OUTPUT); } } if (S_PARSE_OUTPUT != NULL) { PARSE_OUTPUT = fopen(S_PARSE_OUTPUT, "w"); if (PARSE_OUTPUT == NULL) { err("[plpcc] cannot open parse tree output file: %s\n", S_PARSE_OUTPUT); } } if (S_GRAPH_OUTPUT != NULL) { GRAPH_OUTPUT = fopen(S_GRAPH_OUTPUT, "w"); if (GRAPH_OUTPUT == NULL) { err("[plpcc] cannot open parse tree graph output file: %s\n", S_GRAPH_OUTPUT); } } /* grab the lines from the source for error handling and annotation */ build_lines(S_FILE_INPUT); /* create an empty symbol table */ sym = new_symbol_table(NULL); log("[plpcc] starting frontend\n"); yyparse(); /* print the parse tree */ if (PARSE_OUTPUT != NULL) { vlog("[plpcc] printing parse tree\n"); print_tree(parse_tree_head, PARSE_OUTPUT, 0); } /* print the parse tree graph formatted for Graphviz*/ if (GRAPH_OUTPUT != NULL) { vlog("[plpcc] printing parse tree graph\n"); print_tree_graph(parse_tree_head, GRAPH_OUTPUT, S_FILE_INPUT); /* close output file*/ fclose(GRAPH_OUTPUT); /* Run Graphviz command to generate PNG of parse tree */ S_GRAPH_COMMAND = malloc(sizeof(char) * (strlen(S_FILE_OUTPUT) * 2 + 22)); sprintf(S_GRAPH_COMMAND, "dot -Tpng %s.dot > %s.png", S_FILE_OUTPUT, S_FILE_OUTPUT); system(S_GRAPH_COMMAND); } /* print the symbol table */ if (SYMBOL_OUTPUT != NULL) { vlog("[plpcc] printing symbol table\n"); print_symbols(sym, SYMBOL_OUTPUT, 0); vlog("[plpcc] printing activation records\n"); print_frames(sym, SYMBOL_OUTPUT); } /* call the backend to compile the parse tree, starting from the head */ if (NO_COMPILE == 0) { handle(parse_tree_head); fprintf(FILE_OUTPUT, "%s", program); } vlog("[plpcc] closing files\n"); fclose(FILE_INPUT); fclose(FILE_OUTPUT); log("[plpcc] done\n"); return 0; }