UIEventEmitterPtr UIKeyEventCollector::create_emitter() { UIKeyEventEmitterPtr emitter(new UIKeyEventEmitter(*this)); m_emitters.push_back(emitter); return m_emitters.back(); }
void join::make_pass() { delete mainLayout; delete nextb; delete le; update(); nextb=new QPushButton(); nextb->setIcon(QIcon(":next.png")); nextb->setIconSize(QSize(40,40)); nextb->setAutoFillBackground(true); nextb->setFixedSize(50,50); lab1=new QLabel(); le=new QLineEdit(); le1=new QLineEdit(); QPixmap *pix=new QPixmap(QSize(150,125)); pix->load(":pass.jpg"); lab1->setPixmap(*pix); mainLayout=new QVBoxLayout(); mainLayout->addWidget(le); mainLayout->addWidget(le1); lay1=new QHBoxLayout(); lay1->addWidget(lab1); lay1->addLayout(mainLayout); lay1->addWidget(nextb); le->setEchoMode(QLineEdit::Password); le1->setEchoMode(QLineEdit::Password); setFixedSize(350,170); setLayout(lay1); connect(nextb,SIGNAL(clicked()),this,SLOT(emitter())); }
inline std::string To_String::fallback_impl(AST_Node* n) { Emitter emitter(ctx); Inspect i(emitter); i.in_declaration = in_declaration; if (n) n->perform(&i); return i.get_buffer(); }
/** * Render this node to a string. * @param s The output string. * @throw std::exception An error occurred. */ void InspectMapNode::RenderToString(std::string &s) { try { yaml::Emitter emitter(s, false); RenderToYaml(emitter); } catch (yaml::EmitterExn &ex) { throw std::exception(ex); } }
census_run_result run_census_in_series::operator() (fs::path const& file ,mcenum_emission const emission ,std::vector<Input> const& cells ,Ledger & composite ) { Timer timer; census_run_result result; boost::shared_ptr<progress_meter> meter (create_progress_meter (cells.size() ,"Calculating all cells" ,progress_meter_mode(emission) ) ); ledger_emitter emitter(file, emission); result.seconds_for_output_ += emitter.initiate(); for(unsigned int j = 0; j < cells.size(); ++j) { if(!cell_should_be_ignored(cells[j])) { std::string const name(cells[j]["InsuredName"].str()); IllusVal IV(serial_file_path(file, name, j, "hastur").string()); IV.run(cells[j]); composite.PlusEq(*IV.ledger()); result.seconds_for_output_ += emitter.emit_cell (serial_file_path(file, name, j, "hastur") ,*IV.ledger() ); meter->dawdle(intermission_between_printouts(emission)); } if(!meter->reflect_progress()) { result.completed_normally_ = false; goto done; } } meter->culminate(); result.seconds_for_output_ += emitter.emit_cell (serial_file_path(file, "composite", -1, "hastur") ,composite ); result.seconds_for_output_ += emitter.finish(); done: double total_seconds = timer.stop().elapsed_seconds(); status() << Timer::elapsed_msec_str(total_seconds) << std::flush; result.seconds_for_calculations_ = total_seconds - result.seconds_for_output_; return result; }
vector<string> StreamSorter<Message>::streaming_merge(const vector<string>& temp_files_in, unordered_map<string, size_t>* messages_per_file) { // What are the names of the merged files we create? vector<string> temp_files_out; // We don't do this loop in parallel because the point of looping is to limit the total currently open files. for (size_t start_file = 0; start_file < temp_files_in.size(); start_file += max_fan_in) { // For each range of sufficiently few files, starting at start_file and running for file_count size_t file_count = min(max_fan_in, temp_files_in.size() - start_file); // Open up cursors into all the files. list<ifstream> temp_ifstreams; list<cursor_t> temp_cursors; open_all(vector<string>(&temp_files_out[start_file], &temp_files_out[start_file + file_count]), temp_ifstreams, temp_cursors); // Work out how many messages to expect size_t expected_messages = 0; if (messages_per_file != nullptr) { for (size_t i = start_file; i < start_file + file_count; i++) { expected_messages += messages_per_file->at(temp_files_in.at(i)); } } // Open an output file string out_file_name = temp_file::create(); ofstream out_stream(out_file_name); temp_files_out.push_back(out_file_name); // Make an output emitter emitter_t emitter(out_stream); // Merge the cursors into the emitter streaming_merge(temp_cursors, emitter, expected_messages); // The output file will be flushed and finished automatically when the emitter goes away. // Clean up the input files we used temp_cursors.clear(); temp_ifstreams.clear(); for (size_t i = start_file; i < file_count; i++) { temp_file::remove(temp_files_in.at(i)); } if (messages_per_file != nullptr) { // Save the total messages that should be in the created file, in case we need to do another pass (*messages_per_file)[out_file_name] = expected_messages; } } return temp_files_out; }
OutputBuffer Output::get_buffer(void) { Emitter emitter(opt); Inspect inspect(emitter); size_t size_nodes = top_nodes.size(); for (size_t i = 0; i < size_nodes; i++) { top_nodes[i]->perform(&inspect); inspect.append_mandatory_linefeed(); } // flush scheduled outputs // maybe omit semicolon if possible inspect.finalize(wbuf.buffer.size() == 0); // prepend buffer on top prepend_output(inspect.output()); // make sure we end with a linefeed if (!ends_with(wbuf.buffer, opt.linefeed)) { // if the output is not completely empty if (!wbuf.buffer.empty()) append_string(opt.linefeed); } // search for unicode char for(const char& chr : wbuf.buffer) { // skip all ascii chars // static cast to unsigned to handle `char` being signed / unsigned if (static_cast<unsigned>(chr) < 128) continue; // declare the charset if (output_style() != COMPRESSED) charset = "@charset \"UTF-8\";" + std::string(opt.linefeed); else charset = "\xEF\xBB\xBF"; // abort search break; } // add charset as first line, before comments and imports if (!charset.empty()) prepend_string(charset); return wbuf; }
OutputBuffer Output::get_buffer(void) { Emitter emitter(ctx); Inspect inspect(emitter); size_t size_nodes = top_nodes.size(); for (size_t i = 0; i < size_nodes; i++) { top_nodes[i]->perform(&inspect); inspect.append_mandatory_linefeed(); } // flush scheduled outputs inspect.finalize(); // prepend buffer on top prepend_output(inspect.output()); // make sure we end with a linefeed if (!ends_with(wbuf.buffer, ctx->linefeed)) { // if the output is not completely empty if (!wbuf.buffer.empty()) append_string(ctx->linefeed); } // search for unicode char for(const char& chr : wbuf.buffer) { // skip all ascii chars if (chr >= 0) continue; // declare the charset if (output_style() != SASS_STYLE_COMPRESSED) charset = "@charset \"UTF-8\";" + ctx->linefeed; else charset = "\xEF\xBB\xBF"; // abort search break; } // add charset as first line, before comments and imports if (!charset.empty()) prepend_string(charset); return wbuf; }
void StreamSorter<Message>::easy_sort(istream& stream_in, ostream& stream_out, StreamIndex<Message>* index_to) { std::vector<Message> sort_buffer; stream::for_each<Message>(stream_in, [&](Message &msg) { sort_buffer.push_back(msg); }); this->sort(sort_buffer); // Maintain our own group buffer at a higher scope than the emitter. vector<Message> group_buffer; { // Make an output emitter stream::ProtobufEmitter<Message> emitter(stream_out); if (index_to != nullptr) { emitter.on_message([&](const Message& m) { // Copy every message that is emitted. // TODO: Just compute indexing stats instead. group_buffer.push_back(m); }); emitter.on_group([&](int64_t start_vo, int64_t past_end_vo) { // On every group, tell the index to record the group stats, and clear the buffer. index_to->add_group(group_buffer, start_vo, past_end_vo); group_buffer.clear(); }); } for (auto& msg : sort_buffer) { // Feed in all the sorted messages emitter.write(std::move(msg)); } // Emitter destruction will terminate the file with an EOF marker } }
void test_emit (void) { pid_t pid; int status; pid = fork (); assert ( pid >= 0 ); if ( pid == 0 ) { /* child listens */ listener (mcast_ip, mcast_port, mcast_iface); exit (0); } else { /* parent emits */ sleep (1); emitter (mcast_ip, mcast_port, mcast_iface); /* then waits for child */ assert ( wait (&status) == pid ); assert ( status == 0 ); } }
census_run_result run_census_in_parallel::operator() (fs::path const& file ,mcenum_emission const emission ,std::vector<Input> const& cells ,Ledger & composite ) { Timer timer; census_run_result result; boost::shared_ptr<progress_meter> meter (create_progress_meter (cells.size() ,"Initializing all cells" ,progress_meter_mode(emission) ) ); ledger_emitter emitter(file, emission); std::vector<Input>::const_iterator ip; std::vector<boost::shared_ptr<AccountValue> > cell_values; std::vector<boost::shared_ptr<AccountValue> >::iterator i; std::vector<mcenum_run_basis> const& RunBases = composite.GetRunBases(); int j = 0; int const first_cell_inforce_year = value_cast<int>((*cells.begin())["InforceYear"].str()); int const first_cell_inforce_month = value_cast<int>((*cells.begin())["InforceMonth"].str()); cell_values.reserve(cells.size()); for(ip = cells.begin(); ip != cells.end(); ++ip, ++j) { // This condition need be written only once, here, because // subsequently 'cell_values' (which reflects the condition) // is iterated across instead of 'cells'. if(!cell_should_be_ignored(cells[j])) { { // Begin fenv_guard scope. fenv_guard fg; boost::shared_ptr<AccountValue> av(new AccountValue(*ip)); std::string const name(cells[j]["InsuredName"].str()); av->SetDebugFilename (serial_file_path(file, name, j, "hastur").string() ); cell_values.push_back(av); if(contains(av->yare_input_.Comments, "idiosyncrasyZ")) { av->Debugging = true; av->DebugPrintInit(); } if ( first_cell_inforce_year != av->yare_input_.InforceYear || first_cell_inforce_month != av->yare_input_.InforceMonth ) { fatal_error() << "Running census by month untested for inforce" << " with inforce duration varying across cells." << LMI_FLUSH ; } if(mce_solve_none != av->yare_input_.SolveType) { fatal_error() << "Running census by month: solves not permitted." << LMI_FLUSH ; } } // End fenv_guard scope. } if(!meter->reflect_progress()) { result.completed_normally_ = false; goto done; } } // End for. meter->culminate(); if(cell_values.empty()) { // Make sure it's safe to dereference cell_values[0] later. fatal_error() << "No cell with any lives was included in the composite." << LMI_FLUSH ; } for (std::vector<mcenum_run_basis>::const_iterator run_basis = RunBases.begin() ;run_basis != RunBases.end() ;++run_basis ) { // It seems somewhat anomalous to create and update a GUI // progress meter inside this critical calculation section, // because it is not entirely inconceivable that doing so // might affect the floating-point control word. However, // rogue msw dlls that improperly alter the control word // seem to do so when they are initially loaded, and any // such dll would already have been loaded to support the // progress meter used earlier in this function. { // Begin fenv_guard scope. fenv_guard fg; mcenum_gen_basis expense_and_general_account_basis; mcenum_sep_basis separate_account_basis; set_cloven_bases_from_run_basis (*run_basis ,expense_and_general_account_basis ,separate_account_basis ); // Calculate duration when the youngest life matures. int MaxYr = 0; for(i = cell_values.begin(); i != cell_values.end(); ++i) { (*i)->InitializeLife(*run_basis); MaxYr = std::max(MaxYr, (*i)->GetLength()); } meter = create_progress_meter (MaxYr - first_cell_inforce_year ,mc_str(*run_basis) ,progress_meter_mode(emission) ); // Variables to support tiering and experience rating. double const case_ibnr_months = cell_values[0]->ibnr_as_months_of_mortality_charges() ; double const case_experience_rating_amortization_years = cell_values[0]->experience_rating_amortization_years() ; double case_accum_net_mortchgs = 0.0; double case_accum_net_claims = 0.0; double case_k_factor = cell_values[0]->yare_input_.ExperienceRatingInitialKFactor; // Experience rating as implemented here uses either a special // scalar input rate, or the separate-account rate. Those // rates as entered might vary across cells, but there must be // only one rate: therefore, use the first cell's rate, and // extend its last element if it doesn't have enough values. std::vector<double> experience_reserve_rate; std::copy (cell_values[0]->yare_input_.SeparateAccountRate.begin() ,cell_values[0]->yare_input_.SeparateAccountRate.end() ,std::back_inserter(experience_reserve_rate) ); experience_reserve_rate.resize(MaxYr, experience_reserve_rate.back()); if(cell_values[0]->yare_input_.OverrideExperienceReserveRate) { experience_reserve_rate.assign (experience_reserve_rate.size() ,cell_values[0]->yare_input_.ExperienceReserveRate ); } for(int year = first_cell_inforce_year; year < MaxYr; ++year) { double experience_reserve_annual_u = 1.0 + experience_reserve_rate[year] ; for(i = cell_values.begin(); i != cell_values.end(); ++i) { // A cell must be initialized at the beginning of any // partial inforce year in which it's illustrated. if((*i)->PrecedesInforceDuration(year, 11)) { continue; } (*i)->Year = year; (*i)->CoordinateCounters(); (*i)->InitializeYear(); } // Process one month at a time for all cells. int const inforce_month = first_cell_inforce_year == year ? first_cell_inforce_month : 0 ; for(int month = inforce_month; month < 12; ++month) { double assets = 0.0; // Get total case assets prior to interest crediting because // those assets may determine the M&E charge. // Process transactions through monthly deduction. for(i = cell_values.begin(); i != cell_values.end(); ++i) { if((*i)->PrecedesInforceDuration(year, month)) { continue; } (*i)->Month = month; (*i)->CoordinateCounters(); (*i)->IncrementBOM(year, month, case_k_factor); assets += (*i)->GetSepAcctAssetsInforce(); } // Process transactions from int credit through end of month. for(i = cell_values.begin(); i != cell_values.end(); ++i) { if((*i)->PrecedesInforceDuration(year, month)) { continue; } (*i)->IncrementEOM(year, month, assets, (*i)->CumPmts); } } // Perform end of year calculations. // Project claims using the partial-mortality rate: // it's curtate, so the whole year's claims occur at // the end of the last month and no interest // adjustment is required. // // An off-anniversary inforce case generates a full // year's claims, which is consistent with curtate // mortality. double eoy_inforce_lives = 0.0; double years_net_claims = 0.0; double years_net_mortchgs = 0.0; double projected_net_mortchgs = 0.0; for(i = cell_values.begin(); i != cell_values.end(); ++i) { if((*i)->PrecedesInforceDuration(year, 11)) { continue; } (*i)->SetClaims(); (*i)->SetProjectedCoiCharge(); eoy_inforce_lives += (*i)->InforceLivesEoy(); (*i)->IncrementEOY(year); years_net_claims += (*i)->GetCurtateNetClaimsInforce(); years_net_mortchgs += (*i)->GetCurtateNetCoiChargeInforce(); projected_net_mortchgs += (*i)->GetProjectedCoiChargeInforce(); } // Calculate next year's k factor. Do this only for // current-expense bases, not as a speed optimization, // but rather because experience rating on other bases // is undefined. case_accum_net_claims *= experience_reserve_annual_u; case_accum_net_claims += years_net_claims; case_accum_net_mortchgs *= experience_reserve_annual_u; case_accum_net_mortchgs += years_net_mortchgs; // Presumably an admin system would maintain a scalar // reserve instead of tracking claims and mortality // charges separately, and accumulate it at interest more // frequently than once a year. // // Therefore, add inforce reserve here, to avoid crediting // a year's interest to it. Because only a scalar reserve // is captured, it must all be added to one side of the // reserve equation: the distinction between claims and // mortality charges is lost, but their difference is // preserved, so the resulting reserve is correct. // // The inforce reserve would reflect net claims already // paid as well as mortality charges already deducted for // any partial year. Therefore, although inforce YTD COI // charge is captured separately for adjusting IBNR, it // would be incorrect to add it here. if(first_cell_inforce_year == year) { case_accum_net_mortchgs += cell_values[0]->yare_input_.InforceNetExperienceReserve; } // Apportion experience-rating reserve uniformly across // inforce lives. Previously, it had been apportioned by // projected mortality charges; that proved unworkable // when a cell lapsed, matured, or failed to have a // nonzero NAAR due to a corridor factor of unity. To // guard against such problems, the apportioned reserve // is summed across cells and asserted materially to // equal the original total reserve. if ( cell_values[0]->yare_input_.UseExperienceRating && mce_gen_curr == expense_and_general_account_basis && 0.0 != eoy_inforce_lives ) { if(first_cell_inforce_year == year) { years_net_mortchgs += cell_values[0]->yare_input_.InforceYtdNetCoiCharge; } double case_ibnr = years_net_mortchgs * case_ibnr_months / 12.0 ; double case_net_mortality_reserve = case_accum_net_mortchgs - case_accum_net_claims - case_ibnr ; // Current net mortality charge can actually be zero, // e.g., when the corridor factor is unity. double denominator = case_experience_rating_amortization_years * projected_net_mortchgs ; if(0.0 == denominator) { case_k_factor = 1.0; } else { case_k_factor = std::max (0.0 ,1.0 - case_net_mortality_reserve / denominator ); } double case_net_mortality_reserve_checksum = 0.0; for(i = cell_values.begin(); i != cell_values.end(); ++i) { if((*i)->PrecedesInforceDuration(year, 11)) { continue; } case_net_mortality_reserve_checksum += (*i)->ApportionNetMortalityReserve ( case_net_mortality_reserve / eoy_inforce_lives ); } if (!materially_equal (case_net_mortality_reserve ,case_net_mortality_reserve_checksum ) ) { fatal_error() << "\nExperience-rating reserve discrepancy in year " << year << ": " << case_net_mortality_reserve << " != " << case_net_mortality_reserve_checksum << LMI_FLUSH ; } } if(!meter->reflect_progress()) { result.completed_normally_ = false; goto done; } } // End for year. meter->culminate(); for(i = cell_values.begin(); i != cell_values.end(); ++i) { (*i)->FinalizeLife(*run_basis); } } // End fenv_guard scope. } // End for. meter = create_progress_meter (cell_values.size() ,"Finalizing all cells" ,progress_meter_mode(emission) ); for(i = cell_values.begin(); i != cell_values.end(); ++i) { fenv_guard fg; (*i)->FinalizeLifeAllBases(); composite.PlusEq(*(*i)->ledger_from_av()); if(!meter->reflect_progress()) { result.completed_normally_ = false; goto done; } } meter->culminate(); result.seconds_for_output_ += emitter.initiate(); meter = create_progress_meter (cell_values.size() ,"Writing output for all cells" ,progress_meter_mode(emission) ); for(j = 0, i = cell_values.begin(); i != cell_values.end(); ++i, ++j) { std::string const name(cells[j]["InsuredName"].str()); result.seconds_for_output_ += emitter.emit_cell (serial_file_path(file, name, j, "hastur") ,*(*i)->ledger_from_av() ); meter->dawdle(intermission_between_printouts(emission)); if(!meter->reflect_progress()) { result.completed_normally_ = false; goto done; } } meter->culminate(); result.seconds_for_output_ += emitter.emit_cell (serial_file_path(file, "composite", -1, "hastur") ,composite ); result.seconds_for_output_ += emitter.finish(); done: double total_seconds = timer.stop().elapsed_seconds(); status() << Timer::elapsed_msec_str(total_seconds) << std::flush; result.seconds_for_calculations_ = total_seconds - result.seconds_for_output_; return result; }
void *get_vm_execute_java_method() { static void *addr_execute = 0; if(addr_execute) { return addr_execute; } const int entry_point = IN_REG0; //const int nargs = IN_REG1; //not used const int args = IN_REG2; const int double_result_addr = IN_REG3; //const int double_nargs = IN_REG4; //not used const int double_args = IN_REG5; const int thread_pointer = IN_REG6; const int thread_id = IN_REG7; const int saved_tp = 40; const int saved_tid = 41; const int old_pfs = 42; const int return_link = 43; const int saved_heap_base = 44; const int out0 = 45; tl::MemoryPool mem_pool; Merced_Code_Emitter emitter(mem_pool, 2, 0); emitter.disallow_instruction_exchange(); emitter.memory_type_is_unknown(); const int num_loc_regs = out0 - IN_REG0; const int num_out_regs = 10; emitter.ipf_alloc(old_pfs, 0, num_loc_regs, num_out_regs, 0); emitter.ipf_mfbr(return_link, BRANCH_RETURN_LINK_REG); // Save preserved registers used by VM for thread-local values emitter.ipf_mov(saved_tp, THREAD_PTR_REG); emitter.ipf_mov(saved_tid, THREAD_ID_REG); emitter.ipf_mov(saved_heap_base, HEAP_BASE_REG); emitter.ipf_mov(THREAD_PTR_REG, thread_pointer); emitter.ipf_mov(THREAD_ID_REG, thread_id); emit_mov_imm_compactor(emitter, HEAP_BASE_REG, (uint64)vm_get_heap_base_address()); /////// begin get args // First move int args to stacked registers // and fp args to f8..f15 // Issue two loads per cycle for(int i = 0; i < 8; i++) { emitter.ipf_ldf_inc_imm(float_mem_size_d, mem_ld_none, mem_none, 8 + i, double_args, 8); emitter.ipf_ld_inc_imm(int_mem_size_8, mem_ld_none, mem_none, out0 + i, args, 8); } // We should also: // - move arg9 and higher to the memory stack /////// end get args enforce_calling_conventions(&emitter); emitter.ipf_mtbr(SCRATCH_BRANCH_REG, entry_point); emitter.ipf_bricall(br_many, br_sptk, br_none, BRANCH_RETURN_LINK_REG, SCRATCH_BRANCH_REG); // Unconditionally save the fp result. // It is ignored if the signature doesn't expect an fp result emitter.ipf_stf(float_mem_size_d, mem_st_none, mem_none, double_result_addr, 8); emitter.ipf_mov(THREAD_PTR_REG, saved_tp); emitter.ipf_mov(THREAD_ID_REG, saved_tid); emitter.ipf_mov(HEAP_BASE_REG, saved_heap_base); emitter.ipf_mtap(AR_pfs, old_pfs); emitter.ipf_mtbr(BRANCH_RETURN_LINK_REG, return_link); emitter.ipf_brret(br_many, br_sptk, br_none, BRANCH_RETURN_LINK_REG); addr_execute = finalize_stub(emitter, "vm_execute_java"); return addr_execute; } // get_vm_execute_java_method
void StreamSorter<Message>::stream_sort(istream& stream_in, ostream& stream_out, StreamIndex<Message>* index_to) { // We want to work out the file size, if we can. size_t file_size = 0; { // Save our position auto here = stream_in.tellg(); // Go to the end stream_in.seekg(0, stream_in.end); // Get its position auto there = stream_in.tellg(); // Go back to where we were stream_in.seekg(here); if (stream_in.good()) { // We can seek in this stream. So how far until the end? file_size = there - here; } else { // It's entirely possible that none of that worked. So clear the error flags and leave the size at 0. stream_in.clear(); } } // Don't give an actual 0 to the progress code or it will NaN create_progress("break into sorted chunks", file_size == 0 ? 1 : file_size); // Eventually we put sorted chunks of data in temp files and put their names here vector<string> outstanding_temp_files; // This tracks the number of messages in each file, by file name unordered_map<string, size_t> messages_per_file; // This tracks the total messages observed on input size_t total_messages_read = 0; // This cursor will read in the input file. cursor_t input_cursor(stream_in); #pragma omp parallel shared(stream_in, input_cursor, outstanding_temp_files, messages_per_file, total_messages_read) { while(true) { vector<Message> thread_buffer; #pragma omp critical (input_cursor) { // Each thread fights for the file and the winner takes some data size_t buffered_message_bytes = 0; while (input_cursor.has_next() && buffered_message_bytes < max_buf_size) { // Until we run out of input messages or space, buffer each, recording its size. thread_buffer.emplace_back(std::move(input_cursor.take())); buffered_message_bytes += thread_buffer.back().ByteSizeLong(); } // Update the progress bar update_progress(stream_in.tellg()); } if (thread_buffer.empty()) { // No data was found break; } // Do a sort of the data we grabbed this->sort(thread_buffer); // Save it to a temp file. string temp_name = temp_file::create(); ofstream temp_stream(temp_name); // OK to save as one massive group here. // TODO: This write could also be in a thread. stream::write_buffered(temp_stream, thread_buffer, 0); #pragma omp critical (outstanding_temp_files) { // Remember the temp file name outstanding_temp_files.push_back(temp_name); // Remember the messages in the file, for progress purposes messages_per_file[temp_name] = thread_buffer.size(); // Remember how many messages we found in the total total_messages_read += thread_buffer.size(); } } } // Now we know the reader thmessages have taken care of the input, and all the data is in temp files. destroy_progress(); while (outstanding_temp_files.size() > max_fan_in) { // We can't merge them all at once, so merge subsets of them. outstanding_temp_files = streaming_merge(outstanding_temp_files, &messages_per_file); } // Now we can merge (and maybe index) the final layer of the tree. // Open up cursors into all the files. list<ifstream> temp_ifstreams; list<cursor_t> temp_cursors; open_all(outstanding_temp_files, temp_ifstreams, temp_cursors); // Maintain our own group buffer at a higher scope than the emitter. vector<Message> group_buffer; { // Make an output emitter emitter_t emitter(stream_out); if (index_to != nullptr) { emitter.on_message([&index_to,&group_buffer](const Message& m) { // Copy every message that is emitted. // TODO: Just compute indexing stats instead. group_buffer.push_back(m); }); emitter.on_group([&index_to,&group_buffer](int64_t start_vo, int64_t past_end_vo) { // On every group, tell the index to record the group stats, and clear the buffer. index_to->add_group(group_buffer, start_vo, past_end_vo); group_buffer.clear(); }); } // Merge the cursors into the emitter streaming_merge(temp_cursors, emitter, total_messages_read); } // Clean up temp_cursors.clear(); temp_ifstreams.clear(); for (auto& filename : outstanding_temp_files) { temp_file::remove(filename); } }
std::ostream& operator << (std::ostream& out, const Node& node) { Emitter emitter(out); emitter << node; return out; }
bool Jitx86Base::BackPatch(u32 emAddress, SContext* ctx) { u8* codePtr = reinterpret_cast<u8*>(ctx->CTX_PC); if (!IsInSpace(codePtr)) return false; // this will become a regular crash real soon after this auto it = m_back_patch_info.find(codePtr); if (it == m_back_patch_info.end()) { PanicAlert("BackPatch: no register use entry for address %p", codePtr); return false; } TrampolineInfo& info = it->second; u8* exceptionHandler = nullptr; if (jo.memcheck) { auto it2 = m_exception_handler_at_loc.find(codePtr); if (it2 != m_exception_handler_at_loc.end()) exceptionHandler = it2->second; } // In the trampoline code, we jump back into the block at the beginning // of the next instruction. The next instruction comes immediately // after the backpatched operation, or BACKPATCH_SIZE bytes after the start // of the backpatched operation, whichever comes last. (The JIT inserts NOPs // into the original code if necessary to ensure there is enough space // to insert the backpatch jump.) js.generatingTrampoline = true; js.trampolineExceptionHandler = exceptionHandler; // Generate the trampoline. const u8* trampoline = trampolines.GenerateTrampoline(info); js.generatingTrampoline = false; js.trampolineExceptionHandler = nullptr; u8* start = info.start; // Patch the original memory operation. XEmitter emitter(start); emitter.JMP(trampoline, true); // NOPs become dead code const u8* end = info.start + info.len; for (const u8* i = emitter.GetCodePtr(); i < end; ++i) emitter.INT3(); // Rewind time to just before the start of the write block. If we swapped memory // before faulting (eg: the store+swap was not an atomic op like MOVBE), let's // swap it back so that the swap can happen again (this double swap isn't ideal but // only happens the first time we fault). if (info.nonAtomicSwapStoreSrc != Gen::INVALID_REG) { u64* ptr = ContextRN(ctx, info.nonAtomicSwapStoreSrc); switch (info.accessSize << 3) { case 8: // No need to swap a byte break; case 16: *ptr = Common::swap16(static_cast<u16>(*ptr)); break; case 32: *ptr = Common::swap32(static_cast<u32>(*ptr)); break; case 64: *ptr = Common::swap64(static_cast<u64>(*ptr)); break; default: _dbg_assert_(DYNA_REC, 0); break; } } // This is special code to undo the LEA in SafeLoadToReg if it clobbered the address // register in the case where reg_value shared the same location as opAddress. if (info.offsetAddedToAddress) { u64* ptr = ContextRN(ctx, info.op_arg.GetSimpleReg()); *ptr -= static_cast<u32>(info.offset); } ctx->CTX_PC = reinterpret_cast<u64>(trampoline); return true; }
void partSys::initPS(){ Particle emitter(glm::vec3(0, 0, 0), Origin, glm::vec3(0, 0, 0), duration, bb, type); particles.push_back(emitter); }