void generate_entry( FILE *file, struct function *f, char *entry ) { fprintf(file,"extern \"C\" %s %s( %s )\n{\n",type_string(f->type),entry,param_string(f->params)); fprintf(file,"\t%s (*fptr)(%s);\n",type_string(f->type),param_string(f->params)); if(!is_void(f->type)) { fprintf(file,"\t%s result;\n",type_string(f->type)); } write_vararg_decls( file, f->params ); fprintf(file,"\tbypass_layer_init();\n"); // PZK 8/7/07: changed int to intptr_t for 64-bit compatibility fprintf(file,"\tfptr = (%s(*)(%s)) layer_lookup( \"bypass_agent_action_%s\", \"%s\", (intptr_t) %s );\n",type_string(f->type),param_string(f->params),f->name->text,entry,entry); fprintf(file,"\tif(!fptr) fptr = %s;\n",entry); fprintf(file,"\tlayer_descend();\n"); if(!is_void(f->type)) { fprintf(file,"\tresult = "); } else { fprintf(file,"\t"); } fprintf(file,"(*fptr) ( %s );\n",arg_string(f->params)); fprintf(file,"\tlayer_ascend();\n"); if(!is_void(f->type)) { fprintf(file,"\treturn result;\n"); } /* special case: a switch for _exit() or exit() must fall back on a fatal message */ if(!strcmp(f->name->text,"exit") || !strcmp(f->name->text,"_exit") ) { fprintf(file,"\tbypass_fatal(\"exit() returned without exiting!\");\n"); } fprintf(file,"}\n\n"); }
void printTreeNode(TreeNode* treeNode){ char *name = getNodeKindString(treeNode->nodekind); int isTerm = isTerminal(treeNode->nodekind); if (isTerm) printf("<%s>[%s]{%d}(%s)\n", name, treeNode->tokenString, treeNode->lineno, type_string(treeNode->type)); else printf("%s(%s)\n", name,type_string(treeNode->type)); }
ostream& single_star::print_star_story(ostream& s, int short_output) // default = 0 { put_story_header(s, STAR_ID); if (short_output) { // If we were to handle short output in the Star part of // the output stream, this is where it should be done. // However, for now it is simpler to handle all stellar // quantities in the Dyn output (in hdyn_io). #if 0 put_string(s, " S = ", type_short_string(get_element_type())); put_real_number(s, " T = ", temperature()); put_real_number(s, " L = ", get_luminosity()); #endif } else { put_string(s, " Type = ", type_string(get_element_type())); if (get_spec_type(Accreting)==Accreting) put_string(s, " Class = ", type_string(get_spec_type(Accreting))); put_real_number(s, " T_cur = ", get_current_time()); if (get_current_time()!=get_relative_age()) put_real_number(s, " T_rel = ", get_relative_age()); put_real_number(s, " M_rel = ", get_relative_mass()); put_real_number(s, " M_env = ", get_envelope_mass()); put_real_number(s, " M_core = ", get_core_mass()); put_real_number(s, " T_eff = ", temperature()); put_real_number(s, " L_eff = ", get_luminosity()); // Extra output for stars with CO cores if (star_with_COcore()) { put_real_number(s, " M_COcore = ", get_COcore_mass()); } // Extra output for radio- and X-ray pulsars. if (get_element_type()==Xray_Pulsar || get_element_type()==Radio_Pulsar || get_element_type()==Neutron_Star) { put_real_number(s, " P_rot = ", get_rotation_period()); put_real_number(s, " B_fld = ", get_magnetic_field()); } if (star_story) put_story_contents(s, *star_story); } put_story_footer(s, STAR_ID); return s; }
void single_star::first_roche_lobe_contact_story(stellar_type accretor) { char info_line[MAX_STORY_LINE_LENGTH]; real time = get_current_time(); sprintf(info_line, "%s_%s_%s_RLOF_to_%s_at_time = %6.2f", type_string(get_element_type()), type_string(get_spectral_class(temperature())), type_string(get_luminosity_class(temperature(), luminosity)), type_string(accretor), time); add_story_line(get_node()->get_log_story(), info_line); }
void report_fds(aClient *cptr) { int i; char *name, *blocking; for(i = 0; i < MAXCONNECTIONS; i++) { if(fd_list[i].type == FDT_NONE) continue; if(fd_list[i].type == FDT_CLIENT || fd_list[i].type == FDT_AUTH) { aClient *cptr = (aClient *) fd_list[i].value; int hide = (IsConnecting(cptr) || IsHandshake(cptr) || IsServer(cptr)) ? HIDEME : 0; name = get_client_name(cptr, hide); blocking = (cptr->flags & FLAGS_BLOCKED) ? "BLOCKED" : "_"; } else { name = "-"; blocking = "-"; } sendto_one(&me, cptr, ":%s %d %s :%d - %s [%s] %s %s", me.name, RPL_STATSDEBUG, cptr->name, i, type_string(fd_list[i].type), flags_string(fd_list[i].flags), name, blocking); } }
/*- -- net:dump() Write summary of protocol blocks to stdout. */ static int lnet_dump(lua_State* L) { libnet_t* ud = checkudata(L); libnet_pblock_t* p = ud->protocol_blocks; int strings = 0; while(p) { /* h_len is header length for checksumming? "chksum length"? */ char str[1024]; sprintf(str, "tag %d flags %d type %s/%#x buf %p b_len %2u h_len %2u copied %u prev %d next %d\n", p->ptag, p->flags, type_string(p->type), p->type, p->buf, p->b_len, p->h_len, p->copied, p->prev ? p->prev->ptag : -1, p->next ? p->next->ptag : -1 ); lua_pushstring(L, str); p = p->next; strings++; } lua_pushfstring(L, "link_offset %d aligner %d total_size %d nblocks %d\n", ud->link_offset, ud->aligner, ud->total_size, ud->n_pblocks); strings++; lua_concat(L, strings); return 1; }
void SuperFamicomCartridge::write_hash(netnode & node) const { node.hashset("rom_size", rom_size); node.hashset("ram_size", ram_size); node.hashset("firmware_appended", firmware_appended ? 1 : 0); node.hashset("header_offset", header_offset); node.hashset("type", type_string()); node.hashset("region", region_string()); node.hashset("mapper", mapper_string()); node.hashset("dsp1_mapper", dsp1_mapper_string()); node.hashset("has_bsx_slot", has_bsx_slot ? 1 : 0); node.hashset("has_superfx", has_superfx ? 1 : 0); node.hashset("has_sa1", has_sa1 ? 1 : 0); node.hashset("has_sharprtc", has_sharprtc ? 1 : 0); node.hashset("has_epsonrtc", has_epsonrtc ? 1 : 0); node.hashset("has_sdd1", has_sdd1 ? 1 : 0); node.hashset("has_spc7110", has_spc7110 ? 1 : 0); node.hashset("has_cx4", has_cx4 ? 1 : 0); node.hashset("has_dsp1", has_dsp1 ? 1 : 0); node.hashset("has_dsp2", has_dsp2 ? 1 : 0); node.hashset("has_dsp3", has_dsp3 ? 1 : 0); node.hashset("has_dsp4", has_dsp4 ? 1 : 0); node.hashset("has_obc1", has_obc1 ? 1 : 0); node.hashset("has_st010", has_st010 ? 1 : 0); node.hashset("has_st011", has_st011 ? 1 : 0); node.hashset("has_st018", has_st018 ? 1 : 0); }
static int lnet_dump(lua_State* L) { libnet_t** ud = luaL_checkudata(L, 1, L_NET_REGID); luaL_argcheck(L, *ud, 1, "net has been destroyed"); libnet_pblock_t* p = (*ud)->protocol_blocks; int strings = 0; while(p) { /* h_len is header length for checksumming? "chksum length"? */ char str[1024]; sprintf(str, "tag %d flags %d type %s/%#x buf %p b_len %2u h_len %2u ip_offset %2u, copied %u\n", p->ptag, p->flags, type_string(p->type), p->type, p->buf, p->b_len, p->h_len, p->ip_offset, p->copied); lua_pushstring(L, str); p = p->next; strings++; } lua_pushfstring(L, "link_offset %d aligner %d total_size %d nblocks %d\n", (*ud)->link_offset, (*ud)->aligner, (*ud)->total_size, (*ud)->n_pblocks); strings++; lua_concat(L, strings); return 1; }
TypeErrorException(NativeAccessor& accessor, StringData object_type, Property const& prop, ValueType value) : std::invalid_argument(util::format("%1.%2 must be of type '%3', got '%4' (%5)", object_type, prop.name, type_string(prop), accessor.typeof(value), accessor.print(value))) {}
real hyper_giant::add_mass_to_accretor(const real mdot) { if (mdot<0) { cerr << "hyper_giant::add_mass_to_accretor(mdot=" << mdot << ")"<<endl; cerr << "mdot (" << mdot << ") smaller than zero!" << endl; return 0; } adjust_accretor_age(mdot); if (relative_mass<get_total_mass() + mdot) relative_mass = get_total_mass() + mdot; envelope_mass += mdot; // Wind mass loss for massive stars (SPZ:July 1998) if (relative_mass >= cnsts.parameters(massive_star_mass_limit)) { cerr << type_string(get_element_type()) << " wind treatment for stars with M >=" << cnsts.parameters(massive_star_mass_limit) << " for " << identity << endl << " M = " << get_total_mass() << " [Msun] " << " Mdot = " << wind_constant << " [Msun/Myr] " << endl; } set_spec_type(Accreting); return mdot; }
char * ftype_string( struct function *f ) { char *buffer = malloc(STRING_BUFFER_SIZE*10); sprintf(buffer,"%s (*)(%s)", type_string(f->type), param_string(f->params)); return buffer; }
void Dbck_options:: print(FILE *f) const { fprintf(f,"%s <\n",type_string()); fprintf(f,"\nDirectories:\n"); dbdirectories()->print(_tt_string_print,f); fprintf(f,"\n"); if (_sel_filename_p) { fprintf(f,catgets(_ttcatd, 6, 7, "Select by filename: %s\n"), (char *)_sel_filename); } if (_sel_objid_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 8, "Select by objid key:")); _sel_objid_key->print(f); fprintf(f,"\n"); } if (_sel_type_p) { fprintf(f,catgets(_ttcatd, 6, 9, "Select by type: %s\n"), (char *)_sel_type); } if (_diag_badform_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 10, "Diagnose badly formed entities\n")); } if (_diag_exist_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 11, "Diagnose references to " "non-existent entities\n")); } if (_disp_id_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 12, "Display ids\n")); } if (_disp_mand_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 13, "Display mandatory data\n")); } if (_disp_prop_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 14, "Display properties and values data\n")); } if (_repair_netisam_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 15, "Invoke NetISAM isrepair() function before " "inspecting\n")); } if (_repair_type_p) { fprintf(f,catgets(_ttcatd, 6, 16, "Repair by setting to type: %s\n"), (char *)_repair_type); } if (_repair_delete_p) { fprintf(f, "%s", catgets(_ttcatd, 6, 17, "Repair by deleting\n")); } fprintf(f,catgets(_ttcatd, 6, 18, "Debugging printout level %d\n"), _debug_level); }
void write_static_call( FILE *file, struct function *f ) { fprintf(file,"\t\t\textern %s %s (%s);\n",type_string(f->type),upper_string(pattern_complete(f->options->local_name->text,f->name->text)),param_string(f->params)); if(!is_void(f->type)) { fprintf(file,"\t\t\tresult = "); } else { fprintf(file,"\t\t\t"); } fprintf(file,"%s( %s );\n",upper_string(pattern_complete(f->options->local_name->text,f->name->text)),arg_string(f->params)); }
void single_star::star_transformation_story(stellar_type new_type) { char info_line[MAX_STORY_LINE_LENGTH]; stellar_type old_type = get_element_type(); real time = get_current_time(); sprintf(info_line, "%s_to_%s_at_time = %6.2f", type_string(old_type), type_string(new_type), time); add_story_line(get_node()->get_log_story(), info_line); // cerr output for debugging! cerr << endl << get_node()->format_label() << " " << info_line << " Myr (old mass = " << get_total_mass() << ")" << endl; if(is_binary_component()) { #if 0 // This should be fixed some time SPZ:26/02/03 if(get_binary()->obtain_binary_type() == Merged) { cerr << "binary is merged." << endl; } else if(get_binary()->obtain_binary_type() == Disrupted) { cerr << "binary is disrupted, other component: " << endl << type_string(get_companion()->get_element_type()) << endl; } else { cerr << "binary companion: " << type_string(get_companion()->get_element_type()) << endl; } #endif cerr << "binary companion: " << type_string(get_companion()->get_element_type()) << endl; cerr << "parent: " << get_node()->get_parent()->format_label() << endl; } }
int Trick::DataRecordGroup::write_header() { unsigned int jj ; std::string header_name ; std::fstream out_stream ; /*! create the header file used by the GUIs */ header_name = output_dir + "/log_" + group_name + ".header" ; out_stream.open(header_name.c_str(), std::fstream::out ) ; if ( ! out_stream || ! out_stream.good() ) { #ifndef _DMTCP message_publish(MSG_ERROR, "Can't open Data Record file %s.\n", header_name.c_str()) ; #endif return -1; } /* Header file first line is created in format specific header */ out_stream << "log_" << group_name ; format_specific_header(out_stream) ; /* Output the file name, variable size, units, and variable name * to the rest of recorded data header file. * (e.g. file_name C_type units sim_name) * Note: "sys.exec.out.time" should be the first variable in the buffer. */ for (jj = 0; jj < rec_buffer.size() ; jj++) { /*! recording single data item */ out_stream << "log_" << group_name << "\t" << type_string(rec_buffer[jj]->ref->attr->type, rec_buffer[jj]->ref->attr->size) << "\t" << std::setw(6) ; if ( rec_buffer[jj]->ref->attr->mods & TRICK_MODS_UNITSDASHDASH ) { out_stream << "--" ; } else { out_stream << rec_buffer[jj]->ref->attr->units ; } out_stream << "\t" << rec_buffer[jj]->ref->reference << std::endl ; } // Send all unwritten characters in the buffer to its output/file. out_stream.flush() ; out_stream.close() ; return(0) ; }
void write_vararg_decls( FILE *file, struct param *p ) { struct param *q=0; /* Skip to the first vararg (if any) */ while(1) { if(!p) return; if(p->is_vararg) break; q=p; p = p->next; } /* Now, q is null or points to the param previous to p. */ if(!q) { fprintf(stderr,"*** At least one regular parameter must precede any variable parameters.\n"); return; } /* Begin the vararg traversal */ fprintf(file,"\tva_list bypass_arglist;\n"); fprintf(file,"\tva_start(bypass_arglist,%s);\n",q->name->text); /* For each remaining parameter, declare storage and extract it */ for( ; p; p=p->next ) { fprintf(file,"\t%s\t%s;\n",type_string(p->type),p->name->text); fprintf(file,"\t%s = va_arg(bypass_arglist,%s);\n",p->name->text,type_string(p->type)); } /* Done with the traversal */ fprintf(file,"\tva_end(bypass_arglist);\n"); }
static int list_op(const char *input_dir) { AVIODirEntry *entry = NULL; AVIODirContext *ctx = NULL; int cnt, ret; char filemode[4], uid_and_gid[20]; if ((ret = avio_open_dir(&ctx, input_dir, NULL)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot open directory: %s.\n", av_err2str(ret)); goto fail; } cnt = 0; for (;;) { if ((ret = avio_read_dir(ctx, &entry)) < 0) { av_log(NULL, AV_LOG_ERROR, "Cannot list directory: %s.\n", av_err2str(ret)); goto fail; } if (!entry) break; if (entry->filemode == -1) { snprintf(filemode, 4, "???"); } else { snprintf(filemode, 4, "%3"PRIo64, entry->filemode); } snprintf(uid_and_gid, 20, "%"PRId64"(%"PRId64")", entry->user_id, entry->group_id); if (cnt == 0) av_log(NULL, AV_LOG_INFO, "%-9s %12s %30s %10s %s %16s %16s %16s\n", "TYPE", "SIZE", "NAME", "UID(GID)", "UGO", "MODIFIED", "ACCESSED", "STATUS_CHANGED"); av_log(NULL, AV_LOG_INFO, "%-9s %12"PRId64" %30s %10s %s %16"PRId64" %16"PRId64" %16"PRId64"\n", type_string(entry->type), entry->size, entry->name, uid_and_gid, filemode, entry->modification_timestamp, entry->access_timestamp, entry->status_change_timestamp); avio_free_directory_entry(&entry); cnt++; }; fail: avio_close_dir(&ctx); return ret; }
void Event::print(std::ostream& os) const { std::string type_string("Invalid event"); switch (type_) { case START: type_string = "Start event"; break; case END: type_string = "End event"; break; case INTERSECTION: type_string = "Intersection event"; break; default: break; } os << type_string << " at " << position_ ; }
void generate_shadow_action( FILE *file, struct function *f ) { fprintf(file,"static %s bypass_shadow_action_%s( %s )\n{\n",type_string(f->type),f->name->text,param_string_noconst(f->params)); write_vararg_decls(file,f->params); if(f->shadow_action) { fprintf(file,"%s\n",f->shadow_action->text ); } else { if(!is_void(f->type)) { fprintf(file,"\treturn "); } fprintf(file,"%s( %s );\n",f->name->text,arg_string_noconst(f->params)); } fprintf(file,"\n}\n\n"); }
real hyper_giant::add_mass_to_accretor(real mdot, const real dt) { real m_tot = get_total_mass(); if (mdot<0) { /* error << "hyper_giant::add_mass_to_accretor(mdot=" << mdot << ")"<<endl; error << "mdot (" << mdot << ") smaller than zero!" << endl; error << "Action: proceed!" << endl; */ } mdot = accretion_limit(mdot, dt); adjust_accretor_age(mdot); if (relative_mass<get_total_mass() + mdot) relative_mass = get_total_mass() + mdot; envelope_mass += mdot; // Wind mass loss for massive stars (SPZ:July 1998) if (relative_mass >= cnsts.parameters(massive_star_mass_limit)) { // Mass loss constant in time. wind_constant = envelope_mass/(next_update_age-relative_age); wind_constant = max(wind_constant, 0.); cerr << type_string(get_element_type()) << " wind treatment for stars with M >=" << cnsts.parameters(massive_star_mass_limit) << " for " << identity << endl << " M = " << get_total_mass() << " [Msun] " << " Mdot = " << wind_constant << " [Msun/Myr] " << endl; } set_spec_type(Accreting); return mdot; }
bool BrowserWrapper::IsHtmlPage(IHTMLDocument2* doc) { CComBSTR type; if (!SUCCEEDED(doc->get_mimeType(&type))) { return false; } std::wstring document_type_key_name(L""); if (this->factory_.GetRegistryValue(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice", L"Progid", &document_type_key_name)) { // Look for the user-customization under Vista/Windows 7 first. If it's // IE, set the document friendly name lookup key to 'htmlfile'. If not, // set it to blank so that we can look up the proper HTML type. if (document_type_key_name == L"IE.HTTP") { document_type_key_name = L"htmlfile"; } else { document_type_key_name = L""; } } if (document_type_key_name == L"") { // To be technically correct, we should look up the extension specified // for the text/html MIME type first (located in the "Extension" value // of HKEY_CLASSES_ROOT\MIME\Database\Content Type\text/html), but that // should always resolve to ".htm" anyway. From the extension, we can // find the browser-specific subkey of HKEY_CLASSES_ROOT, the default // value of which should contain the browser-specific friendly name of // the MIME type for HTML documents, which is what // IHTMLDocument2::get_mimeType() returns. if (!this->factory_.GetRegistryValue(HKEY_CLASSES_ROOT, L".htm", L"", &document_type_key_name)) { return false; } } std::wstring mime_type_name; if (!this->factory_.GetRegistryValue(HKEY_CLASSES_ROOT, document_type_key_name, L"", &mime_type_name)) { return false; } std::wstring type_string((BSTR)type); return type_string == mime_type_name; }
int main (int argc, char **argv) { /* int i;*/ progname = *argv; for (;;) { switch (getopt (argc, argv, "vd")) { case EOF: break; case 'v': ++verbose; continue; case 'd': ++debug; continue; default: usage (); } break; } argc -= optind; argv += optind; if (argc > 0) usage (); audio_init_input (); pause (); #if 0 /* Play args. */ for (i=0; i<argc; ++i) { space_seen = 1; type_string (argv[i]); type_char (' '); } #endif return (0); }
void generate_agent_action( FILE *file, struct function *f ) { fprintf(file,"extern \"C\" %s bypass_agent_action_%s( %s )\n{\n",type_string(f->type),f->name->text,param_string(f->params)); write_vararg_decls(file,f->params); if(f->agent_action) { fprintf(file,"\t%s\n",f->agent_action->text ); } else { if(!is_void(f->type)) { fprintf(file,"\treturn "); } fprintf(file,"bypass_shadow_%s( %s );\n",pattern_complete(f->options->remote_name->text,f->name->text),arg_string_noconst(f->params)); } fprintf(file,"\n}\n\n"); if( f->options->instead ) { generate_agent_action( file, f->options->instead ); } }
void write_dynamic_call( FILE *file, struct function *f ) { /* Declare a library handle, open it if needed */ fprintf(file,"\t\t\tstatic void *handle = 0;\n"); fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.so\");\n",f->options->library->text); fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.sl\");\n",f->options->library->text); fprintf(file,"\t\t\tif(!handle) handle = bypass_library_open(\"%s.so.6\");\n",f->options->library->text); fprintf(file,"\t\t\tif(!handle) bypass_call_error(BYPASS_CALL_%s,\"can't find library\");\n\n",f->name->text); /* Declare a function pointer, look it up if needed */ fprintf(file,"\t\t\tstatic %s (*fptr)( %s ) = 0;\n",type_string(f->type),param_string(f->params)); fprintf(file,"\t\t\tif(!fptr) fptr = (%s(*)(%s)) bypass_library_lookup(handle,\"%s\");\n",type_string(f->type),param_string(f->params),pattern_complete(f->options->local_name->text,f->name->text)); fprintf(file,"\t\t\tif(!fptr) bypass_call_error(BYPASS_CALL_%s,\"can't find procedure in library\");\n",f->name->text); /* Otherwise, invoke the function */ if(!is_void(f->type)) { fprintf(file,"\t\t\tresult = "); } else { fprintf(file,"\t\t\t"); } fprintf(file,"fptr( %s );\n",arg_string(f->params)); }
char *param_string( struct param *p ) { char *buffer = malloc(STRING_BUFFER_SIZE*10); if(!p) { strcpy(buffer,"void"); return buffer; } for( buffer[0]=0; p!=0; p=p->next) { strcat(buffer,type_string(p->type)); strcat(buffer," "); strcat(buffer,p->name->text); if(p->next) { strcat(buffer,", "); if(p->next->is_vararg) { strcat(buffer,"..."); break; } } } return buffer; }
std::string generator_opencl::co(const node& n) { switch (n.type) { case node::entry_point: return "p"; case node::const_var: return std::to_string(n.aux_var); case node::const_bool: return std::to_string(n.aux_bool); case node::const_str: throw std::runtime_error("string encountered"); case node::rotate: return "p_rotate" + pl(n); case node::rotate3: return "p_rotate3(" + co(n.input[0]) + ", (double3)(" + co(n.input[1]) + "," + co(n.input[2]) + "," + co(n.input[3]) + "), " + co(n.input[4]) + ")"; case node::scale: case node::scale3: return "(" + co(n.input[0]) + "/" + co(n.input[1]) + ")"; case node::shift: return "(" + co(n.input[0]) + "+(double2)(" + co(n.input[1]) + "," + co(n.input[2]) + "))"; case node::shift3: return "(" + co(n.input[0]) + "+(double3)(" + co(n.input[1]) + "," + co(n.input[2]) + "," + co(n.input[3]) + "))"; case node::swap: return "p_swap" + pl(n); case node::map: { std::string func_name{std::string("ip_map") + std::to_string(count_++)}; std::stringstream func_body; func_body << "inline double2 " << func_name << " (const double2 p) { return (double2)(" << co(n.input[1]) << ", " << co(n.input[2]) << "); }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + ")"; } case node::map3: { std::string func_name{"ip_map3" + std::to_string(count_++)}; std::stringstream func_body; func_body << "inline double3 " << func_name << " (const double3 p) { return (double3)(" << co(n.input[1]) << ", " << co(n.input[2]) << ", " << co(n.input[3]) << "); }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + ")"; } case node::turbulence: { std::string func_name("ip_turb" + std::to_string(count_++)); std::stringstream func_body; func_body << "inline double2 " << func_name << " (const double2 p) { return (double2)(" << "p.x+(" << co(n.input[1]) << "), " << "p.y+(" << co(n.input[2]) << ")); }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + ")"; } case node::turbulence3: { std::string func_name("ip_turb3" + std::to_string(count_++)); std::stringstream func_body; func_body << "inline double3 " << func_name << " (const double3 p) { return (double3)(" << "p.x+(" << co(n.input[1]) << "), " << "p.y+(" << co(n.input[2]) << "), " << "p.z+(" << co(n.input[3]) << ")); }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + ")"; } case node::worley: { std::string func_name("ip_worley" + std::to_string(count_++)); std::stringstream func_body; func_body << "inline double " << func_name << " (const double2 q, uint seed) { " << " double2 p = p_worley(q, seed);" << " return " << co(n.input[1]) << "; }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + "," + co(n.input[2]) + ")"; } case node::worley3: { std::string func_name("ip_worley3" + std::to_string(count_++)); std::stringstream func_body; func_body << "inline double " << func_name << " (const double3 q, uint seed) { " << " double3 p = p_worley3(q, seed);" << " return " << co(n.input[1]) << "; }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + "," + co(n.input[2]) + ")"; } case node::voronoi: { std::string func_name("ip_voronoi" + std::to_string(count_++)); std::stringstream func_body; func_body << "inline double " << func_name << " (const double2 q, uint seed) { " << " double2 p = p_voronoi(q, seed);" << " return " << co(n.input[1]) << "; }" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + "," + co(n.input[2]) + ")"; } case node::angle: return "p_angle" + pl(n); case node::chebyshev: return "p_chebyshev" + pl(n); case node::chebyshev3: return "p_chebyshev3" + pl(n); case node::checkerboard: return "p_checkerboard" + pl(n); case node::checkerboard3: return "p_checkerboard3" + pl(n); case node::distance: case node::distance3: return "length" + pl(n); case node::manhattan: return "p_manhattan" + pl(n); case node::manhattan3: return "p_manhattan3" + pl(n); case node::perlin: return "p_perlin" + pl(n); case node::perlin3: return "p_perlin3" + pl(n); case node::simplex: return "p_simplex" + pl(n); case node::simplex3: return "p_simplex3" + pl(n); case node::opensimplex: return "p_opensimplex" + pl(n); case node::opensimplex3: return "p_opensimplex3" + pl(n); case node::x: return co(n.input[0]) + ".x"; case node::y: return co(n.input[0]) + ".y"; case node::z: return co(n.input[0]) + ".z"; case node::xy: return co(n.input[0]) + ".xy"; case node::zplane: return "(double3)(" + co(n.input[0]) + "," + co(n.input[1]) + ")"; case node::add: return "(" + co(n.input[0]) + "+" + co(n.input[1]) + ")"; case node::sub: return "(" + co(n.input[0]) + "-" + co(n.input[1]) + ")"; case node::mul: return "(" + co(n.input[0]) + "*" + co(n.input[1]) + ")"; case node::div: return "(" + co(n.input[0]) + "/" + co(n.input[1]) + ")"; case node::abs: return "fabs" + pl(n); case node::blend: return "p_blend" + pl(n); case node::cos: return "cospi" + pl(n); case node::min: return "fmin" + pl(n); case node::max: return "fmax" + pl(n); case node::neg: return "-" + co(n.input[0]); case node::pow: { if (n.input[1].is_const) { double exp(std::floor(n.input[1].aux_var)); if (std::abs(exp - n.input[1].aux_var) < 1e-9) return "pown(" + co(n.input[0]) + "," + std::to_string((int)exp) + ")"; } return "pow" + pl(n); } case node::round: return "round" + pl(n); case node::saw: return "p_saw" + pl(n); case node::sin: return "sinpi" + pl(n); case node::sqrt: return "sqrt" + pl(n); case node::tan: return "tanpi" + pl(n); case node::band: return co(n.input[0]) + "&&" + co(n.input[1]); case node::bor: return co(n.input[0]) + "||" + co(n.input[1]); case node::bxor: return "((" + co(n.input[0]) + ")!=(" + co(n.input[1]) + "))"; case node::bnot: return "!" + co(n.input[0]); case node::is_equal: return co(n.input[0]) + "==" + co(n.input[1]); case node::is_greaterthan: return co(n.input[0]) + ">" + co(n.input[1]); case node::is_gte: return co(n.input[0]) + ">=" + co(n.input[1]); case node::is_lessthan: return co(n.input[0]) + "<" + co(n.input[1]); case node::is_lte: return co(n.input[0]) + "<=" + co(n.input[1]); case node::is_in_circle: return "p_is_in_circle" + pl(n); case node::is_in_rectangle: return "p_is_in_rectangle" + pl(n); case node::then_else: return "(" + co(n.input[0]) + ")?(" + co(n.input[1]) + "):(" + co(n.input[2]) + ")"; case node::fractal: { assert(n.input.size() == 5); if (!n.input[2].is_const) throw std::runtime_error( "fractal octave count must be a constexpr"); int octaves(std::min<int>(n.input[2].aux_var, OPENCL_OCTAVES_LIMIT)); std::string func_name("ip_fractal_" + std::to_string(count_++)); std::stringstream func_body; func_body << "double " << func_name << " (double2 p, const double lac, const double per) {" << "double result = 0.0; double div = 0.0; double step = 1.0;" << "for(int i = 0; i < " << octaves << "; ++i)" << "{" << " result += " << co(n.input[1]) << " * step;" << " div += step;" << " step *= per;" << " p *= lac;" << " p.x += 12345.0;" << "}" << "return result / div;" << "}"; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + "," + co(n.input[3]) + "," + co(n.input[4]) + ")"; } case node::fractal3: { assert(n.input.size() == 5); if (!n.input[2].is_const) throw std::runtime_error( "fractal octave count must be a constexpr"); int octaves = std::min<int>(n.input[2].aux_var, OPENCL_OCTAVES_LIMIT); std::string func_name{"ip_fractal3_" + std::to_string(count_++)}; std::stringstream func_body; func_body << "double " << func_name << " (double3 p, const double lac, const double per) {" << "double result = 0.0; double div = 0.0; double step = 1.0;" << "for(int i = 0; i < " << octaves << "; ++i)" << "{" << " result += " << co(n.input[1]) << " * step;" << " div += step;" << " step *= per;" << " p *= lac;" << " p.x += 12345.0;" << "}" << "return result / div;" << "}"; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + "," + co(n.input[3]) + "," + co(n.input[4]) + ")"; } case node::lambda_: { assert(n.input.size() == 2); std::string func_name{"ip_lambda_" + std::to_string(count_++)}; std::string type{type_string(n.input[0])}; std::stringstream func_body; func_body << "double " << func_name << " (" << type << " p) {" << "return " << co(n.input[1]) << ";}" << std::endl; functions_.emplace_back(func_body.str()); return func_name + "(" + co(n.input[0]) + ")"; } case node::external_: throw std::runtime_error("OpenCL @external not implemented yet"); case node::curve_linear: throw std::runtime_error("OpenCL curve_linear not implemented yet"); case node::curve_spline: throw std::runtime_error("OpenCL curve_spline not implemented yet"); case node::png_lookup: throw std::runtime_error("OpenCL png_lookup not implemented yet"); default: throw std::runtime_error("function not implemented in OpenCL yet"); } return std::string(); }
// ------------------------------------------------------------------ // ciMetadata::print // // Print debugging output about this ciMetadata. // // Implementation note: dispatch to the virtual print_impl behavior // for this ciObject. void ciMetadata::print(outputStream* st) { st->print("<%s", type_string()); GUARDED_VM_ENTRY(print_impl(st);)
void generate_sender_prototype( FILE *file, struct function *f ) { fprintf(file,"extern \"C\" %s bypass_shadow_%s( %s );\n",type_string(f->type),f->name->text,param_string_noconst(f->params)); }
int test() { int retval = EXIT_SUCCESS; std::cout << std::endl; std::cout << "-----------------------------------------------" << std::endl; std::cout << std::endl; std::cout << "Conversion test from " << type_string(FromNumericT()) << " to " << type_string(ToNumericT()) << std::endl; std::cout << std::endl; std::size_t full_size1 = 578; std::size_t small_size1 = full_size1 / 4; std::size_t full_size2 = 687; std::size_t small_size2 = full_size2 / 4; // // Set up STL objects // std::vector<FromNumericT> std_src(full_size1 * full_size2); std::vector<std::vector<FromNumericT> > std_src2(full_size1, std::vector<FromNumericT>(full_size2)); std::vector<std::vector<FromNumericT> > std_src_small(small_size1, std::vector<FromNumericT>(small_size2)); std::vector<ToNumericT> std_dest(std_src.size()); for (std::size_t i=0; i<full_size1; ++i) for (std::size_t j=0; j<full_size2; ++j) { std_src[i * full_size2 + j] = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j); std_src2[i][j] = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j); if (i < small_size1 && j < small_size2) std_src_small[i][j] = FromNumericT(1.0) + FromNumericT(i) + FromNumericT(j); } // // Set up ViennaCL objects // viennacl::matrix<FromNumericT, LayoutT> vcl_src(full_size1, full_size2); viennacl::matrix<ToNumericT, LayoutT> vcl_dest(full_size1, full_size2); viennacl::copy(std_src2, vcl_src); viennacl::matrix<FromNumericT, LayoutT> vcl_src_small(small_size1, small_size2); viennacl::copy(std_src_small, vcl_src_small); viennacl::matrix<ToNumericT, LayoutT> vcl_dest_small(small_size1, small_size2); std::size_t r11_start = 1 + full_size1 / 4; std::size_t r11_stop = r11_start + small_size1; viennacl::range vcl_r11(r11_start, r11_stop); std::size_t r12_start = 2 * full_size1 / 4; std::size_t r12_stop = r12_start + small_size1; viennacl::range vcl_r12(r12_start, r12_stop); std::size_t r21_start = 2 * full_size2 / 4; std::size_t r21_stop = r21_start + small_size2; viennacl::range vcl_r21(r21_start, r21_stop); std::size_t r22_start = 1 + full_size2 / 4; std::size_t r22_stop = r22_start + small_size2; viennacl::range vcl_r22(r22_start, r22_stop); viennacl::matrix_range< viennacl::matrix<FromNumericT, LayoutT> > vcl_range_src(vcl_src, vcl_r11, vcl_r21); viennacl::matrix_range< viennacl::matrix<ToNumericT, LayoutT> > vcl_range_dest(vcl_dest, vcl_r12, vcl_r22); std::size_t s11_start = 1 + full_size1 / 5; std::size_t s11_inc = 3; std::size_t s11_size = small_size1; viennacl::slice vcl_s11(s11_start, s11_inc, s11_size); std::size_t s12_start = 2 * full_size1 / 5; std::size_t s12_inc = 2; std::size_t s12_size = small_size1; viennacl::slice vcl_s12(s12_start, s12_inc, s12_size); std::size_t s21_start = 1 + full_size2 / 5; std::size_t s21_inc = 3; std::size_t s21_size = small_size2; viennacl::slice vcl_s21(s21_start, s21_inc, s21_size); std::size_t s22_start = 2 * full_size2 / 5; std::size_t s22_inc = 2; std::size_t s22_size = small_size2; viennacl::slice vcl_s22(s22_start, s22_inc, s22_size); viennacl::matrix_slice< viennacl::matrix<FromNumericT, LayoutT> > vcl_slice_src(vcl_src, vcl_s11, vcl_s21); viennacl::matrix_slice< viennacl::matrix<ToNumericT, LayoutT> > vcl_slice_dest(vcl_dest, vcl_s12, vcl_s22); // // Now start running tests for vectors, ranges and slices: // std::cout << " ** vcl_src = matrix, vcl_dest = matrix **" << std::endl; retval = test(std_src, 0, 1, full_size1, 0, 1, full_size2, full_size2, std_dest, 0, 1, full_size1, 0, 1, full_size2, full_size2, vcl_src, vcl_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = matrix, vcl_dest = range **" << std::endl; retval = test(std_src, 0, 1, small_size1, 0, 1, small_size2, full_size2, std_dest, r12_start, 1, r12_stop - r12_start, r22_start, 1, r22_stop - r22_start, full_size2, vcl_src_small, vcl_range_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = matrix, vcl_dest = slice **" << std::endl; retval = test(std_src, 0, 1, small_size1, 0, 1, small_size2, full_size2, std_dest, s12_start, s12_inc, s12_size, s22_start, s22_inc, s22_size, full_size2, vcl_src_small, vcl_slice_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; /////// std::cout << " ** vcl_src = range, vcl_dest = matrix **" << std::endl; retval = test(std_src, r11_start, 1, r11_stop - r11_start, r21_start, 1, r21_stop - r21_start, full_size2, std_dest, 0, 1, small_size1, 0, 1, small_size2, full_size2, vcl_range_src, vcl_dest_small); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = range, vcl_dest = range **" << std::endl; retval = test(std_src, r11_start, 1, r11_stop - r11_start, r21_start, 1, r21_stop - r21_start, full_size2, std_dest, r12_start, 1, r12_stop - r12_start, r22_start, 1, r22_stop - r22_start, full_size2, vcl_range_src, vcl_range_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = range, vcl_dest = slice **" << std::endl; retval = test(std_src, r11_start, 1, r11_stop - r11_start, r21_start, 1, r21_stop - r21_start, full_size2, std_dest, s12_start, s12_inc, s12_size, s22_start, s22_inc, s22_size, full_size2, vcl_range_src, vcl_slice_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; /////// std::cout << " ** vcl_src = slice, vcl_dest = matrix **" << std::endl; retval = test(std_src, s11_start, s11_inc, s11_size, s21_start, s21_inc, s21_size, full_size2, std_dest, 0, 1, small_size1, 0, 1, small_size2, full_size2, vcl_slice_src, vcl_dest_small); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = slice, vcl_dest = range **" << std::endl; retval = test(std_src, s11_start, s11_inc, s11_size, s21_start, s21_inc, s21_size, full_size2, std_dest, r12_start, 1, r12_stop - r12_start, r22_start, 1, r22_stop - r22_start, full_size2, vcl_slice_src, vcl_range_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; std::cout << " ** vcl_src = slice, vcl_dest = slice **" << std::endl; retval = test(std_src, s11_start, s11_inc, s11_size, s21_start, s21_inc, s21_size, full_size2, std_dest, s12_start, s12_inc, s12_size, s22_start, s22_inc, s22_size, full_size2, vcl_slice_src, vcl_slice_dest); if (retval != EXIT_SUCCESS) return EXIT_FAILURE; return EXIT_SUCCESS; }
void generate_switch_prototype( FILE *file, struct function *f ) { fprintf(file,"extern \"C\" %s %s( %s );\n",type_string(f->type),f->name->text,param_string(f->params)); }