backend_data_builder.cc

Go to the documentation of this file.
00001 /*!
00002         \file
00003         \brief Data builder class.
00004         \author jaz
00005 */
00006 #include <lestes/backend_v2/interface/backend_data_builder.g.hh>
00007 #include <lestes/backend_v2/intercode/pi.g.hh>
00008 #include <lestes/lang/cplus/sem/ss_misc.g.hh>
00009 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00010 #include <lestes/msg/logger.hh>
00011 #include <lestes/msg/logger_util.hh>
00012 #include <lestes/std/reflect.hh>
00013 
00014 package(lestes);
00015 package(backend_v2);
00016 package(interface);
00017 
00018 using ::lestes::lang::cplus::sem::ss_function_declaration;
00019 using ::lestes::backend_v2::intercode::pi_pi;
00020 using ::lestes::backend_v2::intercode::pi_sp;
00021 using ::lestes::backend_v2::structs::backend_data;
00022 
00023 using namespace ::lestes::msg;
00024 
00025 typedef vector<srp<builder_func_data> > builder_func_data__vector;
00026 
00027 declare_logger(log);
00028 initialize_logger( log, "backend_v2_data_builder", backend_v2_logger );
00029 
00030 /*!
00031         \brief Returns instance of builder.
00032 */
00033 ptr<backend_data_builder> backend_data_builder::instance() {
00034         if ( !singleton_instance ) {
00035                 //An singleton instance has not been created yet. Create it!
00036                 singleton_instance_set(backend_data_builder::create());
00037         }
00038         //Return instance.
00039         return singleton_instance;
00040 }
00041 
00042 
00043 /*!
00044         \brief Returns builder's result.
00045 */
00046 ptr<builder_func_data__vector> backend_data_builder::get_result(){
00047         return functions;
00048 }
00049 
00050 /*!
00051         \brief Adds a sequencepoint to the currently built function's body.
00052         
00053         \param sp The sequencepoint.
00054 */
00055 void backend_data_builder::add_sp(ptr<pi_sp> sp) {
00056         lassert(sp);
00057         
00058         //Add sp to the body.
00059     current_function_body->pi_body_get()->push_back(sp);
00060 
00061 #ifdef BACKEND_V2_DEBUG
00062         ::std::ostringstream oss;
00063         
00064     oss << "function(" << current_function_body->function_decl_get()->uid_get() << "): pi_sp(" << sp->uid_get() << ")";
00065         
00066         oss << "[psp=";
00067         if (sp->psp_get()) 
00068                 oss << sp->psp_get()->uid_get();
00069     else 
00070                 oss << "NULL";
00071                 
00072         oss << ",nsp=";
00073         if (sp->nsp_get()) 
00074                 oss << sp->nsp_get()->uid_get();
00075     else 
00076                 oss << "NULL";
00077         oss <<",level=" << sp->level_get() << "] added\n";
00078         
00079         log << oss.str() << eolog;
00080 #endif
00081 
00082 }
00083 
00084 /*!
00085         \brief Adds a pseudoinstruction to the currently built function's body.
00086         
00087         \param pi The pseudoinstruction.
00088 */
00089 void backend_data_builder::add_pi(ptr<pi_pi> pi) {
00090         lassert(pi);
00091         
00092     current_function_body->pi_body_get()->push_back(pi);
00093     
00094 #ifdef BACKEND_V2_DEBUG 
00095         ::std::ostringstream oss;
00096         
00097         oss << "function(" << current_function_body->function_decl_get()->uid_get() << "): " << pi->reflection_get()->back()->name_get() << "(" << pi->uid_get() << ")";
00098         
00099         oss << "[psp=";
00100         if (pi->psp_get()) 
00101                 oss << pi->psp_get()->uid_get();
00102     else 
00103                 oss << "NULL";
00104                 
00105         oss << ",nsp=";
00106         if (pi->nsp_get()) 
00107                 oss << pi->nsp_get()->uid_get();
00108     else 
00109                 oss << "NULL ";
00110         oss <<",level=" << pi->level_get() << "] added\n";
00111         
00112         log << oss.str() << eolog;
00113 #endif
00114 }
00115 
00116 /*!
00117         \brief Adds a list of pseudoinstructions to the currently built function's body.
00118         
00119         \param pis The list to be added.
00120 */
00121 void backend_data_builder::add_pis( ptr < ::lestes::std::list < srp<pi_pi> > > pis) {
00122         //Add pis to the body.
00123     for (::lestes::std::list < srp<pi_pi > >::iterator i = pis->begin(); i != pis->end(); i++) {
00124         add_pi(*i);
00125     }
00126 }
00127 
00128 
00129 /*!
00130         \brief Finishes processing of particular sematic structure.
00131         
00132         For debuging purposes.
00133 */
00134 void backend_data_builder::add_rail() {
00135     //for debug purposes only
00136         log << "function(" << current_function_body->function_decl_get()->uid_get() <<"): rail added\n" << eolog;
00137 }
00138 
00139 
00140 /*!
00141         \brief Initiates processing of another function's body.
00142         
00143         \param function The new function.
00144 */
00145 void backend_data_builder::add_function_start(ptr<ss_function_declaration> function) {
00146         //Assure that we are not inside an function body. Function nesting is not allowed.
00147         lassert(!current_function_body);
00148 
00149         ptr<builder_func_data> next_body = builder_func_data::create(function);
00150         
00151         //Get ready for processing of the function      
00152         current_function_body = next_body;
00153         
00154         log << "function(" << function->uid_get() <<"): begin\n" << eolog;
00155 }
00156 
00157 /*!
00158         \brief Finishes processing of the current function's body.
00159 */
00160 void backend_data_builder::add_function_end() {
00161         //Assure that we are inside an function body.
00162         lassert(current_function_body);
00163         
00164         //Finish processing of the current function and insert it to the list of translation unit's functions.
00165         functions->push_back(current_function_body);    
00166                 
00167         log << "function(" << current_function_body->function_decl_get()->uid_get() <<"): end\n" << eolog;
00168         
00169         //Clear fields holding info about processed function.
00170         current_function_body = NULL;
00171 }
00172 
00173 end_package(interface);
00174 end_package(backend_v2);
00175 end_package(lestes);
00176 

Generated on Mon Feb 12 18:22:31 2007 for lestes by doxygen 1.5.1-20070107