#include "build.h" void Instantiation::inject_local_pps( char* inst_env_path,char* default_pps_path ) { DEM_TRACE("Instantiation","void Instantiation::inject_local_pps(char* inst_env_path,char* default_pps_path)"); // prefix class wrappers assert( (inst_env_path != NULL) && (default_pps_path != NULL) ); char * u_1_path = new char[strlen(inst_env_path)+10]; sprintf(u_1_path,"%s",inst_env_path); char *inst_name; inst_name = inst_env_path + strlen(inst_env_path) - 1; while (*inst_name != '/') inst_name --; inst_name ++; pps->inject_local_pps(u_1_path,inst_name,default_pps_path); char *tmp = tempnam(tmpdir,"inst.meta"); ofstream inst_meta( tmp ); if (!inst_meta) { cerr << toolname << ": unable to open " << tmp << " for output." << endl; exit(1); } if (meta_def) { meta_def->g_print(inst_meta); inst_meta << "\n\n"; } inst_meta.close(); char *tfile = new char[MAXDIRLEN+1]; sprintf(tfile,"%s/inst.meta",u_1_path); mv_if_change(mv_interactive,tmp,tfile); delete tmp; delete tfile; delete u_1_path; // suffix class wrappers } void Pps::inject_local_pps( char* u_1_path,char* inst_name,char* default_pps_path ) { DEM_TRACE("Pps","void Pps::inject_local_pps(char* u_1_path,char* inst_name,char* default_pps_path)"); // prefix class wrappers if (pps->list_length() == 0) return; /* insert the default path for search pps */ if (pp_paths == NULL) pp_paths = new Search_path_Nlist(); char *default_path = new char[strlen(default_pps_path)+1]; strcpy(default_path,default_pps_path); DemString * s = new DemString(default_path); Search_path * p = new Search_path(); p->set_search_path(s); pp_paths->insert(p); pps->inject_local_pps(u_1_path,inst_name,pp_paths); // suffix class wrappers } void Propagation_pattern_List::inject_local_pps( char* u_1_path,char* inst_name,Search_path_Nlist* pp_path ) { DEM_TRACE("Propagation_pattern_List","void Propagation_pattern_List::inject_local_pps(char* u_1_path,char* inst_name,Search_path_Nlist* pp_path)"); // prefix class wrappers int file_count = 1; Propagation_pattern_list_iterator next(*this); Propagation_pattern * each; while (each = next()) { each->inject_local_pps(u_1_path,inst_name,pp_path,file_count); file_count++; } // suffix class wrappers } void Propagation_pattern::inject_local_pps( char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count ) { DEM_TRACE("Propagation_pattern","void Propagation_pattern::inject_local_pps(char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count)"); // prefix class wrappers impl_or_loc->inject_local_pps(u_1_path,inst_name,pp_path,file_count, header,rename,meta_def); // suffix class wrappers } // Impl_or_loc : Implementation | // Pp_location // *common* . void Impl_or_loc::inject_local_pps( char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def ) { DEM_TRACE("Impl_or_loc","void Impl_or_loc::inject_local_pps(char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def)"); #ifndef NOTRACE DemTrace demTraceEmptyMethod(__FILE__,__LINE__,"Impl_or_loc",form(" at %s , *** PREMATURELY TERMINATED *** ", this->get_type())); #endif } // Pp_location = + // File_name // - // *l. void Pp_location::inject_local_pps( char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def ) { DEM_TRACE("Pp_location","void Pp_location::inject_local_pps(char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers struct stat buf; Propagation_pattern * prop; char ppfile[MAXDIRLEN+1]; char org_n[MAXDIRLEN+1]; char *tmp,*targetfile; pp_file->fetch_fname(ppfile); strcpy(org_n,ppfile); if (*ppfile != '/') { cout << toolname << ": searching " << org_n << " for "; header->g_print(cout); cout << " ... " << endl; pp_path->search_file(ppfile); if (ppfile[0] == '\0') { cerr << toolname << ": error: unable to find " << org_n << endl; exit(1); } } else { if (lstat(ppfile,&buf) && (access(ppfile, R_OK) != 0)) { cerr << toolname << ": error: unable to open " << ppfile << " for input." << endl; exit(1); } } cout << toolname << ": reading " << ppfile << " ... " << endl; Propagation_patterns *pps = new Propagation_patterns(); pps = (Propagation_patterns *) pps->g_parse(ppfile); if (pps == NULL) derror('e',1," failed to parse the propagation pattern file.\n"); Propagation_pattern_List * props = pps->get_pps(); targetfile = cppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); ofstream tfile(tmp); if (pps->get_text() != NULL) tfile << "\n" << pps->get_text()->get_code()->get_val() << "\n\n"; else tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); /* find the propagation pattern */ Propagation_pattern_list_iterator next_p(*props); Propagation_pattern * each_p; prop = NULL; while (each_p = next_p()) if (each_p->get_header()->get_signature()->g_equal(header->get_signature())) { prop = each_p; break; } if (prop == NULL) derror('e',1," unable to find this operation.\n"); /* prop coannot contain another file name */ prop->no_filename(ppfile,header); if (prop->get_rename()) derror('e',1,"renaming is not allowed with known implementation."); targetfile = renfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (rename) { rename->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = metafname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (prop->get_meta_def()) { prop->get_meta_def()->g_print(tfile); tfile << "\n"; } if (meta_def) { meta_def->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = ppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); cout << toolname << ": generating " << targetfile << " for "; header->g_print(cout); cout << " ... " << endl; tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } /* print the pp */ prop->set_meta_def(NULL); prop->g_print(tfile); tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(tmp); delete props; // outgoing calls // suffix class wrappers // assignments for carrying out } // Implementation = [ Propagation_directive_exp ] // Carry_or_wrapper_List . void Implementation::inject_local_pps( char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def ) { DEM_TRACE("Implementation","void Implementation::inject_local_pps(char* u_1_path,char* inst_name,Search_path_Nlist* pp_path,int file_count,Header* header,Rename* rename,Meta_def* meta_def)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers char *tmp; char *targetfile; char * oname; char *p; if (rename) derror('e',1,"renaming is not allowed with known implementation."); targetfile = ppfname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); cout << toolname << ": generating " << targetfile << " for "; header->g_print(cout); cout << " ... " << endl; ofstream tfile(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } Propagation_pattern * tmp_pp = new Propagation_pattern(); tmp_pp->set_header(header); tmp_pp->set_impl_or_loc(this); tmp_pp->g_print(tfile); tfile << "\n"; tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); targetfile = metafname(u_1_path,inst_name,header,file_count); tmp = tmpfname(); tfile.open(tmp); if (!tfile) { cerr << toolname << ": unable to open " << tmp << " for output.\n"; exit(1); } if (meta_def) { meta_def->g_print(tfile); tfile << "\n"; } tfile.close(); mv_if_change(mv_interactive,tmp,targetfile); unlink(tmp); free(targetfile); free(tmp); // outgoing calls // suffix class wrappers // assignments for carrying out } void Search_path_Nlist::search_file( char* ppfile ) { DEM_TRACE("Search_path_Nlist","void Search_path_Nlist::search_file(char* ppfile)"); // prefix class wrappers char tmp[MAXDIRLEN+1]; struct stat buf; Search_path_list_iterator next(*this); Search_path * each; assert( ppfile != NULL ); while (each = next()) { each->fetch_fname(tmp); sprintf(tmp,"%s/%s",tmp,ppfile); if (lstat(tmp,&buf)) { if (errno == ENOENT) continue; else { cerr << toolname << ": error: unable to open " << tmp << " for input." << endl; perror(tmp); ppfile[0] = '\0'; return; } } else if (access(tmp, R_OK) != 0) { cerr << toolname << ": error: unable to open " << tmp << " for input." << endl; ppfile[0] = '\0'; return; } else { strcpy(ppfile,tmp); return; } } ppfile[0] = '\0'; // suffix class wrappers } void Search_path::fetch_fname( char* fname ) { DEM_TRACE("Search_path","void Search_path::fetch_fname(char* fname)"); // prefix class wrappers strcpy(fname,search_path->get_val()); // suffix class wrappers } void File_name::fetch_fname( char* fname ) { DEM_TRACE("File_name","void File_name::fetch_fname(char* fname)"); // prefix class wrappers strcpy(fname,name->get_val()); // suffix class wrappers } // Header = Signature // [ Vertex_selector ] . void Header::fetch_op_name( char* & oname ) { DEM_TRACE("Header","void Header::fetch_op_name(char* & oname)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls // construction edge prefix wrappers this->get_signature()->fetch_op_name( oname ); // construction edge suffix wrappers // suffix class wrappers // assignments for carrying out } // Signature = *l // "*operation*" // Type_spec // Op_name // "(" // [ Param_decl_Commalist ] // ")" // [ Const ] // [ CppCode ] // *l. void Signature::fetch_op_name( char* & oname ) { DEM_TRACE("Signature","void Signature::fetch_op_name(char* & oname)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls // construction edge prefix wrappers this->get_name()->fetch_op_name( oname ); // construction edge suffix wrappers // suffix class wrappers // assignments for carrying out } // Op_name = DemIdent . void Op_name::fetch_op_name( char* & oname ) { DEM_TRACE("Op_name","void Op_name::fetch_op_name(char* & oname)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers oname = op_name->get_val(); // outgoing calls // suffix class wrappers // assignments for carrying out } // Meta_macro_def = [ Term_Commalist ] // [ Meta_edge_Commalist ] // [ Class_set_def_Amplist ] // [ Dir_meta_def_Amplist ] // [ PCP_def_Amplist ] . void Meta_macro_def::no_filename( char* ppfile,Header* header ) { DEM_TRACE("Meta_macro_def","void Meta_macro_def::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls if ( this->get_macros() != NULL ) { // construction edge prefix wrappers this->get_macros()->no_filename( ppfile , header ); // construction edge prefix wrappers } // suffix class wrappers // assignments for carrying out } // PCP_def = PCP_def_name // "=" // PCP // ";" . void PCP_def::no_filename( char* ppfile,Header* header ) { DEM_TRACE("PCP_def","void PCP_def::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls // construction edge prefix wrappers this->get_pcp()->no_filename( ppfile , header ); // construction edge suffix wrappers // suffix class wrappers // assignments for carrying out } // PCP : Propagation_directive_exp | // Propagation_pattern // *common* . void PCP::no_filename( char* ppfile,Header* header ) { DEM_TRACE("PCP","void PCP::no_filename(char* ppfile,Header* header)"); #ifndef NOTRACE DemTrace demTraceEmptyMethod(__FILE__,__LINE__,"PCP",form(" at %s , *** PREMATURELY TERMINATED *** ", this->get_type())); #endif } // Meta_def = + // "*constraints*" // *l // Meta_macro_def // "*end*" // - // *l. void Meta_def::no_filename( char* ppfile,Header* header ) { DEM_TRACE("Meta_def","void Meta_def::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls // construction edge prefix wrappers this->get_meta_def()->no_filename( ppfile , header ); // construction edge suffix wrappers // suffix class wrappers // assignments for carrying out } // Propagation_pattern =
Header // [ Rename ] // [ Meta_def ] // Impl_or_loc . void Propagation_pattern::no_filename( char* ppfile,Header* header ) { DEM_TRACE("Propagation_pattern","void Propagation_pattern::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls if ( this->get_meta_def() != NULL ) { // construction edge prefix wrappers this->get_meta_def()->no_filename( ppfile , header ); // construction edge prefix wrappers } // construction edge prefix wrappers this->get_impl_or_loc()->no_filename( ppfile , header ); // construction edge suffix wrappers // suffix class wrappers // assignments for carrying out } // Impl_or_loc : Implementation | // Pp_location // *common* . void Impl_or_loc::no_filename( char* ppfile,Header* header ) { DEM_TRACE("Impl_or_loc","void Impl_or_loc::no_filename(char* ppfile,Header* header)"); #ifndef NOTRACE DemTrace demTraceEmptyMethod(__FILE__,__LINE__,"Impl_or_loc",form(" at %s , *** PREMATURELY TERMINATED *** ", this->get_type())); #endif } // Pp_location = + // File_name // - // *l. void Pp_location::no_filename( char* ppfile,Header* header ) { DEM_TRACE("Pp_location","void Pp_location::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers cerr << toolname << ": in file " << ppfile << ": "; header->g_print(cerr); cerr << ": cannot use file name to refer to a propagation pattern.\n" << endl; exit(1); // outgoing calls // suffix class wrappers // assignments for carrying out } // PCP_def_Amplist ~ PCP_def { PCP_def }. . void PCP_def_Amplist::no_filename( char* ppfile,Header* header ) { DEM_TRACE("PCP_def_Amplist","void PCP_def_Amplist::no_filename(char* ppfile,Header* header)"); // variables for carrying in and out // assignments for carrying in // prefix class wrappers // outgoing calls PCP_def_list_iterator next_PCP_def(*this); PCP_def* each_PCP_def; while ( each_PCP_def = next_PCP_def() ) { // repetition edge prefix wrappers each_PCP_def->no_filename( ppfile , header ); // repetition edge suffix wrappers } // suffix class wrappers // assignments for carrying out }