visitor_ge_pi2asm.cc

Go to the documentation of this file.
00001 #include <lestes/backend_v2/intercode/ge.g.hh>
00002 #include <lestes/backend_v2/intercode/pi.g.hh>
00003 #include <lestes/backend_v2/intercode/visitor_ge_pi2asm.g.hh>
00004 #include <lestes/backend_v2/intercode/visitor_ge_operand2asm.g.hh>
00005 #include <lestes/backend_v2/debug/debug.hh>
00006 #include <lestes/backend_v2/workers/bb_finder.g.hh>
00007 #include <lestes/md/instructions/tm_instr.g.hh>
00008 #include <lestes/md/symbols/name_mangler.g.hh>
00009 #include <lestes/md/tasm/tm_asm.mdg.hh>
00010 #include <lestes/lang/cplus/sem/ss_declaration.g.hh>
00011 #include <sstream>
00012 
00013 package(lestes);
00014 package(backend_v2);
00015 package(intercode);
00016 
00017 using namespace ::lestes::backend_v2::debug;
00018 using namespace ::lestes::backend_v2::workers;
00019 using namespace ::lestes::md::instructions;
00020 using namespace ::lestes::md::symbols;
00021 using namespace ::lestes::md::tasm;
00022 using namespace ::lestes::md;
00023 
00024 typedef vector<srp<ge_operand> > ge_operand_vector__type;
00025 typedef vector<srp<ge_sp> > ge_sp_vector__type;
00026 typedef map<ulint,lstring > id2lstring__type;
00027 
00028 /*!
00029         \brief Generates output asm code for generic ge_pi pseudoinstruction.
00030 */
00031 lstring visitor_ge_pi2asm::generate_generic_code(ptr< ::lestes::backend_v2::intercode::ge_pi > ge) {
00032         //Get target instruction that ge is mapped to
00033         ptr<tm_instr_base> tm = ge->instruction_get();
00034 
00035         lstring asm_code;
00036         
00037         if ( !tm ) {
00038                 asm_code = lstring();
00039         }  else {       
00040                 //Get asm output template
00041                 asm_code = tm->asm_output_get();
00042         
00043                 //Replace operand placeholders in template
00044                 ptr<visitor_ge_operand2asm> op2asm = visitor_ge_operand2asm::create();
00045                 op2asm->instruction_set(ge);
00046         
00047                 ptr<ge_operand_vector__type> input_ops = ge->operands_input_get();
00048                 for(ulint i=0; i<input_ops->size(); ++i) {
00049                         ptr<ge_operand> op = (*input_ops)[i];
00050                 
00051                         lstring op_asm_code = op->accept_visitor_ge_operand2lstring_gen_base(op2asm);
00052                         lstring op_asm_type = op->type_get()->asm_output_get();
00053                 
00054                         ::std::ostringstream oss1;
00055                         oss1 << "I_" << i+1;
00056                 
00057                         asm_code = string_replace(asm_code, "$" + oss1.str(), op_asm_code);     
00058                         asm_code = string_replace(asm_code, "$TYPE_" + oss1.str(), op_asm_type);        
00059                 }
00060         
00061                 ptr<ge_operand_vector__type> output_ops = ge->operands_output_get();
00062                 for(ulint i=0; i<output_ops->size(); ++i) {
00063                         ptr<ge_operand> op = (*output_ops)[i];
00064                 
00065                         lstring op_asm_code = op->accept_visitor_ge_operand2lstring_gen_base(op2asm);
00066                         lstring op_asm_type = op->type_get()->asm_output_get();
00067                 
00068                         ::std::ostringstream oss1;
00069                         oss1 << "O_" << i+1;
00070                 
00071                         asm_code = string_replace(asm_code, "$" + oss1.str(), op_asm_code);     
00072                         asm_code = string_replace(asm_code, "$TYPE_" + oss1.str(), op_asm_type);                
00073                 }
00074 
00075                 //Replace jump target placeholders
00076                 if ( ge->jmp_targets_get() ) {
00077                 
00078                         ptr<ge_sp_vector__type> targets = ge->jmp_targets_get();
00079                         for(ulint i=0; i<targets->size(); ++i) {
00080                                 ptr<ge_sp> sp = (*targets)[i];
00081                                 
00082                                 lstring label = tm_asm::ent_label_get();
00083                 
00084                                 ::std::ostringstream oss1;
00085                                 oss1 << sp->uid_get();
00086                         
00087                                 ::std::ostringstream oss2;
00088                                 oss2 <<  "$label_" << i+1;
00089                         
00090                                 label = string_replace(label, "$id", oss1.str());
00091                 
00092                                 asm_code = string_replace(asm_code, oss2.str(), label); 
00093                         }
00094                 }
00095         }
00096 
00097 #ifdef BACKEND_V2_DEBUG
00098         ::std::ostringstream oss;
00099                 
00100         oss << "id=" << ge->uid_get()  << " (sch_pos:" << ge->schedule_pos_get() << ")";
00101         
00102         if ( ge->pi_source_get() ) {
00103                 oss << " pi_src=" << ge->pi_source_get()->reflection_get()->back()->name_get() << "(id:" << ge->pi_source_get()->uid_get() << ")";
00104         }
00105         
00106         if ( ge->bb_get() ) {
00107                 oss << " bb=" << ge->bb_get()->uid_get();
00108         }
00109         
00110         if ( ge->properties_get()) {
00111                 id2lstring__type::iterator it = ge->properties_get()->find(ge_pi::PROPERTY_SPILLGEN_INFO);
00112                 
00113                 if ( it!=ge->properties_get()->end() ) {
00114                         oss << " SPILLGEN: " << it->second;
00115                 }
00116         }
00117         
00118         asm_code += string_replace(tm_asm::ent_inline_comment_get(),"$text",oss.str()) ;        
00119 #endif
00120         
00121         return asm_code;
00122 }
00123 
00124 lstring visitor_ge_pi2asm::visit_ge_pi(ptr< ::lestes::backend_v2::intercode::ge_pi > ge) {
00125         return generate_generic_code(ge);       
00126 }
00127 
00128 
00129 lstring visitor_ge_pi2asm::visit_ge_sp(ptr< ::lestes::backend_v2::intercode::ge_sp > ge) {
00130         lstring asm_code;
00131         
00132         if ( ge->is_jmp_target_get() ) {
00133                 ::std::ostringstream oss1;
00134                 oss1 << ge->uid_get();
00135                 
00136                 asm_code = string_replace(tm_asm::ent_label_get(), "$id", oss1.str());
00137                 asm_code = string_replace(tm_asm::ent_label_def_get(), "$label", asm_code);
00138         }
00139 
00140 #ifdef BACKEND_V2_DEBUG
00141         ::std::ostringstream oss;
00142         oss << "id=" << ge->uid_get()  << " (sch_pos:" << ge->schedule_pos_get() << ")";
00143         
00144         if ( ge->pi_source_get() ) {
00145                 oss << " pi_src=" << ge->pi_source_get()->reflection_get()->back()->name_get() << "(id:" << ge->pi_source_get()->uid_get() << ")";
00146         }
00147         
00148         if ( ge->bb_get() ) {
00149                 oss << " bb=" << ge->bb_get()->uid_get();
00150         }
00151         
00152         if ( ge->properties_get()) {
00153                 id2lstring__type::iterator it = ge->properties_get()->find(ge_pi::PROPERTY_SPILLGEN_INFO);
00154                 
00155                 if ( it!=ge->properties_get()->end() ) {
00156                         oss << " SPILLGEN: " << it->second;
00157                 }
00158         }
00159         
00160         asm_code += string_replace(tm_asm::ent_inline_comment_get(),"$text",oss.str()) ;        
00161 #endif
00162         
00163         return asm_code;
00164 }
00165 
00166 lstring visitor_ge_pi2asm::visit_ge_call(ptr< ::lestes::backend_v2::intercode::ge_call > ge) {
00167         //Get asm output template
00168         lstring asm_code = generate_generic_code(ge);
00169         
00170         //Mangle name
00171         lstring mangled_name = name_mangler::instance()->mangle(ge->function_decl_get());       
00172         
00173         asm_code = string_replace(asm_code, "$name", mangled_name);     
00174         
00175         return asm_code;
00176 }
00177 
00178 end_package(intercode);
00179 end_package(backend_v2);
00180 end_package(lestes);
00181 

Generated on Mon Feb 12 18:23:44 2007 for lestes by doxygen 1.5.1-20070107