code *nteh_monitor_epilog(regm_t retregs) { /* * CALL _d_monitor_epilog * POP FS:__except_list */ assert(config.exe == EX_WIN32); // BUG: figure out how to implement for other EX's Symbol *s = getRtlsym(RTLSYM_MONITOR_EPILOG); //desregs = ~s->Sregsaved & ALLREGS; regm_t desregs = 0; code *cs1; code *cs2; gensaverestore(retregs& desregs,&cs1,&cs2); CodeBuilder cdb(getregs(desregs)); cdb.gencs(0xE8,0,FLfunc,s); // CALL __d_monitor_epilog CodeBuilder cdb1(cs1); CodeBuilder cdb2(cs2); cdb1.append(cdb, cdb2); code cs; cs.Iop = 0x8F; cs.Irm = modregrm(0,0,BPRM); cs.Iflags = CFfs; cs.Irex = 0; cs.IFL1 = FLextern; cs.IEVsym1 = getRtlsym(RTLSYM_EXCEPT_LIST); cs.IEVoffset1 = 0; cdb1.gen(&cs); // POP FS:__except_list return cdb1.finish(); }
dp::rix::core::ContainerSharedHandle BufferManagerOffset::allocationGetBufferContainer( AllocationHandle allocation ) { AllocationImplHandle allocationImpl = dp::rix::core::handleCast<AllocationImpl>(allocation); dp::rix::core::ContainerSharedHandle container = getRenderer()->containerCreate( m_descriptor ); dp::rix::core::ContainerDataBuffer cdb( allocationImpl->m_chunk->m_buffer, allocationImpl->m_blockIndex * getAlignedBlockSize(), getBlockSize() ); getRenderer()->containerSetData( container, m_entry, cdb ); return container; }
code *nteh_unwind(regm_t retregs,unsigned index) { code cs; regm_t desregs; int reg; int local_unwind; // Shouldn't this always be CX? #if SCPP reg = AX; #else reg = CX; #endif #if MARS local_unwind = RTLSYM_D_LOCAL_UNWIND2; #else local_unwind = RTLSYM_LOCAL_UNWIND2; #endif desregs = (~getRtlsym(local_unwind)->Sregsaved & (ALLREGS)) | mask[reg]; code *cs1; code *cs2; gensaverestore(retregs & desregs,&cs1,&cs2); CodeBuilder cdb(getregs(desregs)); cs.Iop = 0x8D; cs.Irm = modregrm(2,reg,BPRM); cs.Iflags = 0; cs.Irex = 0; cs.IFL1 = FLconst; // EBP offset of __context.prev cs.IEV1.Vint = nteh_EBPoffset_prev(); cdb.gen(&cs); // LEA ECX,contextsym cdb.genc2(0x68,0,index); // PUSH index cdb.gen1(0x50 + reg); // PUSH ECX #if MARS //cdb.gencs(0xB8+AX,0,FLextern,nteh_scopetable()); // MOV EAX,&scope_table cdb.gencs(0x68,0,FLextern,nteh_scopetable()); // PUSH &scope_table cdb.gencs(0xE8,0,FLfunc,getRtlsym(local_unwind)); // CALL __d_local_unwind2() cdb.append(cod3_stackadj(NULL, -12)); #else cdb.gencs(0xE8,0,FLfunc,getRtlsym(local_unwind)); // CALL __local_unwind2() cdb.append(cod3_stackadj(NULL, -8)); #endif CodeBuilder cdb1(cs1); CodeBuilder cdb2(cs2); cdb1.append(cdb, cdb2); return cdb1.finish(); }
void* ClangCompilationDbThread::Entry() { CL_DEBUG("ClangCompilationDbThread: Started"); wxString filename; while ( !TestDestroy() ) { if ( m_queue.ReceiveTimeout( 50, filename ) == wxMSGQUEUE_NO_ERROR ) { // success // Process the file CL_DEBUG("ClangCompilationDbThread: Processing file " + filename); CompilationDatabase cdb(filename); cdb.Initialize(); CL_DEBUG("ClangCompilationDbThread: Processing file " + filename + "... done"); } } CL_DEBUG("ClangCompilationDbThread: Going down"); return NULL; }
code *linux_unwind(regm_t retregs,unsigned index) { int i; regm_t desregs; int reg; int local_unwind; // Shouldn't this always be CX? #if SCPP reg = AX; #else reg = CX; #endif #if MARS local_unwind = RTLSYM_D_LOCAL_UNWIND2; #else local_unwind = RTLSYM_LOCAL_UNWIND2; #endif desregs = (~getRtlsym(local_unwind)->Sregsaved & (ALLREGS)) | mask[reg]; code *cs1; code *cs2; gensaverestore(retregs & desregs,&cs1,&cs2); CodeBuilder cdb(getregs(desregs)); cdb.genc2(0x68,0,index); // PUSH index #if MARS // cdb.gencs(0x68,0,FLextern,nteh_scopetable()); // PUSH &scope_table cdb.gencs(0xE8,0,FLfunc,getRtlsym(local_unwind)); // CALL __d_local_unwind2() cdb.append(cod3_stackadj(NULL, -4)); #else cdb.gencs(0xE8,0,FLfunc,getRtlsym(local_unwind)); // CALL __local_unwind2() cdb.append(cod3_stackadj(NULL, -8)); #endif CodeBuilder cdb1(cs1); CodeBuilder cdb2(cs2); cdb1.append(cdb, cdb2); return cdb1.finish(); }
//每个装饰对象的实现和如何使用这个对象分离开 //每个装饰对象只关心自己的功能,不需要关心如 //何被添加到对象链当中(由客户程序决定) // void DecoratorShow(Component* pc) { ConcreteDecoratorA cda(pc); ConcreteDecoratorB cdb(&cda); cdb.Operation(); }
void BSpline::compute( int pointIndex /*= -1*/ ) { int n = m_controlPoints.size()+m_degree+1; int max = n - m_degree - 1; if((int)m_controlPoints.size() > m_controlPointsC) { printf("\n"); m_knot.clear(); for ( int i = -m_degree-1, j=m_controlPoints.size(); i < j; i ++ ) { float knot = ( i + 1 )/(float)( j - m_degree); m_knot.push_back(knot);//clamp(knot,0,1)); printf("%f ",knot); } printf("\n"); } if((int)m_controlPoints.size() <= m_degree) return; if(pointIndex < 0|| (int)m_controlPoints.size() > m_controlPointsC || !m_localUpdate) { // ok Update all points //m_computedPoints.clear(); /*for ( int i = 0; i <= m_degree; i ++ ) { knots.push_back( 0.0f ); printf("0.0 "); }*/ int max = n - m_degree - 1; if((int)m_controlPoints.size() > m_controlPointsC) { if(_points != NULL) delete[] _points; _points = new vec2[(m_degree+1)*(max+1)]; } //_points = new vec2[(m_degree+1)*(max+1)]; //_points = new vec2[(m_degree+1)*(max+1)]; int m = 10*(int)m_controlPoints.size(); float range = m_knot[m_knot.size()-1]-m_knot[0]; float p = 1.0f/m; /*for(int r = m_degree; r < n-m_degree-1; r++) {*/ float r = (float)m_degree; for(int i = 0; i <= m; i++) { while(m_knot[(int)r+1] < i*p) r++; if((int)m_computedPoints.size() < i+1) m_computedPoints.push_back(cdb(_points,m_knot,n,i*p,(int)r)); else m_computedPoints[i] = (cdb(_points,m_knot,n,i*p,(int)r)); } /*}*/ //delete _points; }else { int max = n - m_degree - 1; int m = 10*m_controlPoints.size(); float p = 1.0f/m; int _min = _clamp<int>(pointIndex,m_degree,m_knot.size()-1); int _max = _clamp<int>(pointIndex+m_degree+1,m_degree,m_knot.size()-1); float b = m_knot[_min]; float e = m_knot[_max]; int i = (int)_clamp<float>(round((float)(b/p)),0,(float)m); m = (int)_clamp<float>(round((float)(e/p)),0,(float)m); float r = (float)m_degree; for(; i <= m; i++) { while(m_knot[(int)r+1] < i*p) r++; if((int)m_computedPoints.size() < i+1) m_computedPoints.push_back(cdb(_points,m_knot,n,i*p,(int)r)); else m_computedPoints[i] = (cdb(_points,m_knot,n,i*p,(int)r)); } } }
int main(int argc, char *argv[]) { if(argc!=2) { std::cerr<<"Usage: "<<argv[0]<<" [Parameters_file]"<<std::endl; return -1; } bool SyncNorm = true; logger.Rename("logs_Seed2Cor/Test"); try { /* Initialize the CC Database with the input parameter file */ CCDatabase cdb( argv[1] ); //const CCPARAM& cdbParams = cdb.GetParams(); /* check total memory available */ float MemTotal = memo.MemTotal(); logger.Hold( INFO, "Estimated total memory = "+std::to_string(MemTotal)+" Mb", FuncName ); logger.flush(); /* iterate through the database and handle all possible events */ #pragma omp parallel { // parallel region S while( 1 ) { // main loop //int ithread = omp_get_thread_num(); /* dynamically assign events to threads, one at a time */ bool got; std::vector<DailyInfo> dinfoV; #pragma omp critical(cdb) { // critical S got = cdb.GetRec_AllCH(dinfoV); cdb.NextEvent(); } // critical E if( !got ) break; try { // handle current event //std::vector<SacRec> sacV; std::deque<SacRec> sacV; //sacV.reserve(dinfoV.size()); std::vector<std::stringstream> reportV( dinfoV.size() ); /* seed to fsac */ for( int ich=0; ich<dinfoV.size(); ich++ ) { auto& dinfo = dinfoV[ich]; /* daily info from the database */ logger.Hold( INFO, dinfo.seedname + " " + dinfo.staname + " " + dinfo.chname, FuncName ); /* stringstream for reporting */ auto& report = reportV[ich]; //std::cerr<<"memory consumed @1 = "<<memo.MemConsumed()<<" Mb (ithread = "<<ithread<<")"<<std::endl; /* extract the original sac from seed */ float gapfrac; SacRec sac( report ); sac.SetMaxMemForParallel( MemTotal * dinfo.memomax * 0.8 / omp_get_num_threads() ); SeedRec seedcur( dinfo.seedname, dinfo.rdsexe, report ); if( ! seedcur.ExtractSac( dinfo.staname, dinfo.netname, dinfo.chname, dinfo.sps, dinfo.rec_outname, dinfo.resp_outname, gapfrac, sac ) ) { sacV.push_back( std::move(sac) ); //sacV.push_back( SacRec() ); continue; } sac.Write( dinfo.osac_outname ); /* remove response and cut */ sac.RmRESP( dinfo.resp_outname, dinfo.perl*0.8, dinfo.perh*1.3, dinfo.evrexe ); char evtime[15]; sprintf( evtime, "%04d%02d%02d000000\0", dinfo.year, dinfo.month, dinfo.day ); sac.ZoomToEvent( evtime, -12345., -12345., dinfo.t1, dinfo.tlen ); sac.Write( dinfo.fsac_outname ); //sac.WriteHD("/usr/temp.SAC"); sacV.push_back( std::move(sac) ); } /* time-domain normalization */ TNormAll( sacV, dinfoV, SyncNorm ); /* fre-domain normalization */ // convert sacs to am&ph and store ams in sacV for( int isac=0; isac<sacV.size(); isac++ ) { auto& dinfo = dinfoV[isac]; auto& sac = sacV[isac]; if( ! sac.sig ) continue; SacRec sac_am, sac_ph; sac.ToAmPh( sac_am, sac_ph ); sac = std::move(sac_am); //sac = sac_am; sac_ph.Write( dinfo.fsac_outname + ".ph" ); } // normalize FNormAll( sacV, dinfoV, SyncNorm ); // write am for( int isac=0; isac<sacV.size(); isac++ ) { auto& dinfo = dinfoV[isac]; auto& sac = sacV[isac]; if( ! sac.sig ) continue; sac.Write( dinfo.fsac_outname + ".am" ); } /* log if any warning */ for( const auto& report : reportV ) { std::string warning = report.str(); if( ! warning.empty() ) logger.Hold( WARNING, "\n" + warning, FuncName ); logger.flush(); } // for dinfo } catch ( std::exception& e ) { logger.Hold( ERROR, e.what(), FuncName ); } // current event done } // main while loop } // parallel region E logger.Hold( INFO, "All threads finished.", FuncName ); } catch ( std::exception& e ) { logger.Hold(FATAL, e.what(), FuncName); return -2; } catch (...) { logger.Hold(FATAL, "unknown exception", FuncName); return -2; } return 0; }