void lower(VLS& env, syncvmret& inst, Vlabel b, size_t i) { switch (arch()) { case Arch::X64: // fall through case Arch::PPC64: env.unit.blocks[b].code[i] = copy2{inst.data, inst.type, rret_data(), rret_type()}; break; case Arch::ARM: // For ARM64 we need to clear the bits 8..31 from the type value. // That allows us to use the resulting register values in // type comparisons without the need for truncation there. // We must not touch bits 63..32 as they contain the AUX data. lower_impl(env.unit, b, i, [&] (Vout& v) { v << copy{inst.data, rret_data()}; v << andq{v.cns(0xffffffff000000ff), inst.type, rret_type(), v.makeReg()}; }); break; } }
void FileSystemArchiveTests::testListFileInfoNonRecursive() { FileSystemArchive arch(testPath, "FileSystem"); arch.load(); FileInfoListPtr vec = arch.listFileInfo(false); //CPPUNIT_ASSERT_EQUAL((size_t)2, vec->size()); //FileInfo& fi1 = vec->at(0); //CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.filename); //CPPUNIT_ASSERT_EQUAL(String("rootfile.txt"), fi1.basename); //CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi1.path); //CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.compressedSize); //CPPUNIT_ASSERT_EQUAL((size_t)130, fi1.uncompressedSize); //FileInfo& fi2 = vec->at(1); //CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.filename); //CPPUNIT_ASSERT_EQUAL(String("rootfile2.txt"), fi2.basename); //CPPUNIT_ASSERT_EQUAL(StringUtil::BLANK, fi2.path); //CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.compressedSize); //CPPUNIT_ASSERT_EQUAL((size_t)156, fi2.uncompressedSize); }
void FileSystemArchiveTests::testCreateAndRemoveFile() { FileSystemArchive arch("./", "FileSystem"); arch.load(); CPPUNIT_ASSERT(!arch.isReadOnly()); String fileName = "a_test_file.txt"; DataStreamPtr stream = arch.create(fileName); String testString = "Some text here"; size_t written = stream->write((void*)testString.c_str(), testString.size()); CPPUNIT_ASSERT_EQUAL(testString.size(), written); stream->close(); arch.remove(fileName); CPPUNIT_ASSERT(!arch.exists(fileName)); }
bool cmp_zero_impl(Env& env, const In& inst, Reg r, Vlabel b, size_t i) { if (env.use_counts[inst.sf] != 1) return false; auto const suitable_use = [&]{ // "cmp zero -> test" simplification is arch specific so it's considered an // opt-in optimization. if (arch() != Arch::X64) return false; auto const& code = env.unit.blocks[b].code; if (i + 1 >= code.size()) return false; CmpUseChecker c{inst.sf}; visitOperands(code[i+1], c); return c.cc_result == true && c.use_result == true; }(); if (!suitable_use) return false; return simplify_impl(env, b, i, [&] (Vout& v) { v << Out{r, r, inst.sf}; return 1; }); }
int prAsArchive(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; PyrArchiver<char*> arch(g); int err = arch.prepareToWriteArchive(a); if (err) return err; int32 size = arch.calcArchiveSize(); PyrInt8Array *obj = newPyrInt8Array(g->gc, size, 0, true); obj->size = size; arch.setStream((char*)obj->b); err = arch.writeArchive(); if (err == errNone) SetObject(a, obj); else SetNil(a); return err; }
extern "C" int Function_ChangeBinaryToBaseParticles(void * input_string, void * output_string, int ptCount) { std::string input((char*)input_string); std::stringstream in_stream; in_stream << "{\"value0\": \""; in_stream << input; in_stream << "\"}"; // std::cout << in_stream.str() << std::endl; cereal::JSONInputArchive arch(in_stream); std::vector<CWrongPtBase> particles; for (int i = 0; i < ptCount; ++i) { particles.push_back(CWrongPtBase()); } arch.loadBinaryValue(&particles[0], sizeof(CWrongPtBase) * ptCount); std::vector<CParticleBase> saveParticles; for (int i = 0; i < ptCount; ++i){ auto pt = CParticleBase(); pt.Coordinates = particles[i].Coordinates; CQuaternion newOrient; newOrient.W = particles[i].Rotation.W; newOrient.V = particles[i].Rotation.V; pt.SetRotation(CQuaternion(newOrient)); saveParticles.push_back(pt); } std::stringstream out_stream; cereal::JSONOutputArchive oarch(out_stream); oarch.saveBinaryValue(&saveParticles[0], sizeof(CParticleBase)*ptCount); std::string out_string = out_stream.str(); for(int i = 17; i < out_string.length()-1; i++) { ((char*)output_string)[i-17] = out_string[i]; } return strlen((char*)output_string); }
Vauto::~Vauto() { for (auto& b : unit().blocks) { if (!b.code.empty()) { // Found at least one nonempty block. Finish up. if (!main().closed()) main() << fallthru{}; // Prevent spurious printir traces. Trace::Bump bumper{Trace::printir, 10}; switch (arch()) { case Arch::X64: optimizeX64(unit(), abi(m_kind)); emitX64(unit(), m_text, nullptr); break; case Arch::ARM: finishARM(unit(), m_text, abi(m_kind), nullptr); break; } return; } } }
//filename and name must both be intact for this function to work //initialization from string buffer (e.g. file) - this is the old, slow version but is still used for initial save/load void Prefab::Init() { //if you broke here, check where this prefab came from, the old version requires it to have (most likely) come from available assets pool assert(!filename.empty()); std::ifstream ia(filename); if (ia.good()) { boost::archive::xml_iarchive arch(ia); //if you broke here, this prefab is already inited somehow assert(dormantObject == 0); dormantObject = new GameObject(); dormantObject->SetName("Dormant Prefab Object"); dormantObject->isDormant = true; arch >> BOOST_SERIALIZATION_NVP(*dormantObject); //security modifications - make sure this dormant object stays dormant dormantObject->myState = 0; }
FPInvOffset extract_spoff(TCA stub) { switch (arch()) { case Arch::X64: { DecodedInstruction instr(stub); // If it's not a lea, vasm optimized a lea{rvmfp, rvmsp} to a mov, so // the offset was 0. if (!instr.isLea()) return FPInvOffset{0}; auto const offBytes = safe_cast<int32_t>(instr.offset()); always_assert((offBytes % sizeof(Cell)) == 0); return FPInvOffset{-(offBytes / int32_t{sizeof(Cell)})}; } case Arch::ARM: not_implemented(); case Arch::PPC64: not_implemented(); } not_reached(); }
std::string show(PhysReg r) { switch (arch()) { case Arch::X64: return r.type() == PhysReg::GP ? reg::regname(Reg64(r)) : r.type() == PhysReg::SIMD ? reg::regname(RegXMM(r)) : /* r.type() == PhysReg::SF) ? */ reg::regname(RegSF(r)); case Arch::ARM: if (r.isSF()) return "SF"; return folly::to<std::string>( r.isGP() ? (vixl::Register(r).size() == vixl::kXRegSize ? 'x' : 'w') : (vixl::FPRegister(r).size() == vixl::kSRegSize ? 's' : 'd'), ((vixl::CPURegister)r).code() ); case Arch::PPC64: return r.type() == PhysReg::GP ? ppc64_asm::reg::regname(Reg64(r)) : r.type() == PhysReg::SIMD ? ppc64_asm::reg::regname(RegXMM(r)) : /* r.type() == PhysReg::SF) ? */ ppc64_asm::reg::regname(RegSF(r)); } not_reached(); }
void FileSystemArchiveTests::testFindFileInfoRecursive() { FileSystemArchive arch(testPath, "FileSystem"); arch.load(); FileInfoListPtr vec = arch.findFileInfo("*.material", true); CPPUNIT_ASSERT_EQUAL((size_t)4, vec->size()); FileInfo& fi3 = vec->at(0); CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file.material"), fi3.filename); CPPUNIT_ASSERT_EQUAL(String("file.material"), fi3.basename); CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi3.path); CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.compressedSize); CPPUNIT_ASSERT_EQUAL((size_t)0, fi3.uncompressedSize); FileInfo& fi4 = vec->at(1); CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/file2.material"), fi4.filename); CPPUNIT_ASSERT_EQUAL(String("file2.material"), fi4.basename); CPPUNIT_ASSERT_EQUAL(String("level1/materials/scripts/"), fi4.path); CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.compressedSize); CPPUNIT_ASSERT_EQUAL((size_t)0, fi4.uncompressedSize); FileInfo& fi5 = vec->at(2); CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file3.material"), fi5.filename); CPPUNIT_ASSERT_EQUAL(String("file3.material"), fi5.basename); CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi5.path); CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.compressedSize); CPPUNIT_ASSERT_EQUAL((size_t)0, fi5.uncompressedSize); FileInfo& fi6 = vec->at(3); CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/file4.material"), fi6.filename); CPPUNIT_ASSERT_EQUAL(String("file4.material"), fi6.basename); CPPUNIT_ASSERT_EQUAL(String("level2/materials/scripts/"), fi6.path); CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.compressedSize); CPPUNIT_ASSERT_EQUAL((size_t)0, fi6.uncompressedSize); }
int configurar() { std::string atr_puerto = PUERTO_AGENTE_ATR; std::string atr_nombre = HOST_AGENTE_ATR; std::string ruta = RUTA_CONFIG; ArchivoConfiguracion arch(ruta.c_str()); std::cout << "::::::Modo Configuracion::::::" << std::endl; std::string puerto; std::cout << "Puerto Actual: "; std::cout << arch.obtenerAtributo(atr_puerto); std::cout << std::endl; std::cout << "1) ingrese el puerto del host: "; if (!obtenerPuerto(puerto)) { std::cout << "No se configuro el agente." << std::endl; return 2; } std::string nombre_host; std::cout << std::endl << "Huesped Actual: \""<< arch.obtenerAtributo(atr_nombre); std::cout << "\"" << std::endl; std::cout << "2) ingrese el nombre del host: "; std::getline(std::cin, nombre_host); if (puerto.empty() == false) arch.setearAtributo(atr_puerto, puerto); if (nombre_host.empty() == false) arch.setearAtributo(atr_nombre, nombre_host); if (!nombre_host.empty() || !puerto.empty()) std::cout << "Configuracion realizada correctamente." << std::endl; return 0; }
bool InliningDecider::canInlineAt(SrcKey callSK, const Func* callee, const RegionDesc& region) const { if (!RuntimeOption::RepoAuthoritative || !RuntimeOption::EvalHHIREnableGenTimeInlining) { return false; } // If inlining was disabled... don't inline. if (m_disabled) return false; // TODO(#3331014): We have this hack until more ARM codegen is working. if (arch() == Arch::ARM) return false; // We can only inline at normal FCalls. if (callSK.op() != Op::FCall && callSK.op() != Op::FCallD) { return false; } // Don't inline from resumed functions. The inlining mechanism doesn't have // support for these---it has no way to redefine stack pointers relative to // the frame pointer, because in a resumed function the frame pointer points // into the heap instead of into the eval stack. if (callSK.resumed()) return false; // TODO(#4238160): Inlining into pseudomain callsites is still buggy. if (callSK.func()->isPseudoMain()) return false; if (!isCalleeInlinable(callSK, callee) || !checkNumArgs(callSK, callee) || !checkFPIRegion(callSK, callee, region)) { return false; } return true; }
const std::string rtems_arch_prefix () { return arch () + "-rtems" + version (); }
static void load_cc () { path::paths parts; std::string rtems_pkgconfig; std::string bsp; if (_path.empty ()) throw rld::error ("Not set", "RTEMS path"); bsp = rtems_arch_bsp (); parts.push_back ("lib"); parts.push_back ("pkgconfig"); rld::path::path_join (path (), parts, rtems_pkgconfig); if (!path::check_directory (rtems_pkgconfig)) throw rld::error ("Invalid RTEMS path", path ()); rld::path::path_join (rtems_pkgconfig, bsp + ".pc", rtems_pkgconfig); if (!path::check_file (rtems_pkgconfig)) throw rld::error ("RTEMS BSP not found", arch_bsp ()); if (rld::verbose () >= RLD_VERBOSE_INFO) std::cout << " rtems: " << _arch_bsp << ": " << rtems_pkgconfig << std::endl; pkgconfig::package pkg (rtems_pkgconfig); /* * Check the pc file matches what we ask for. */ std::string name; if (!pkg.get ("name", name)) throw rld::error ("RTEMS BSP no name in pkgconfig file", _arch_bsp); if (name != bsp) throw rld::error ("RTEMS BSP does not match the name in pkgconfig file", _arch_bsp); std::string flags; if (pkg.get ("CPPFLAGS", flags)) { rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cppflags); if (rld::verbose () >= RLD_VERBOSE_INFO) std::cout << " rtems: " << arch_bsp () << ": CPPFLAGS=" << rld::cc::get_flags (rld::cc::ft_cppflags) << std::endl; } if (pkg.get ("CFLAGS", flags)) { rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cflags); if (rld::verbose () >= RLD_VERBOSE_INFO) { std::cout << " rtems: " << arch_bsp () << ": CFLAGS=" << rld::cc::get_flags (rld::cc::ft_cflags) << std::endl; std::cout << " rtems: " << _arch_bsp << ": WARNINGS=" << rld::cc::get_flags (rld::cc::fg_warning_flags) << std::endl; std::cout << " rtems: " << arch_bsp () << ": INCLUDES=" << rld::cc::get_flags (rld::cc::fg_include_flags) << std::endl; std::cout << " rtems: " << arch_bsp () << ": MACHINES=" << rld::cc::get_flags (rld::cc::fg_machine_flags) << std::endl; std::cout << " rtems: " << arch_bsp () << ": SPECS=" << rld::cc::get_flags (rld::cc::fg_spec_flags) << std::endl; } } if (pkg.get ("CXXFLAGS", flags)) { rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_cxxflags); if (rld::verbose () >= RLD_VERBOSE_INFO) std::cout << " rtems: " << arch_bsp () << ": CXXFLAGS=" << rld::cc::get_flags (rld::cc::ft_cxxflags) << std::endl; } if (pkg.get ("LDFLAGS", flags)) { rld::cc::append_flags (flags, arch (), path (), rld::cc::ft_ldflags); if (rld::verbose () >= RLD_VERBOSE_INFO) std::cout << " rtems: " << arch_bsp () << ": LDFLAGS=" << rld::cc::get_flags (rld::cc::ft_ldflags) << std::endl; } rld::cc::set_exec_prefix (arch ()); }
inline static void toObj(Obj& mObj, const T& mValue) { arch(mObj, ssvs::getMBtnName(mValue)); }
MachOLayout<A>::MachOLayout(const void* machHeader, uint64_t offset, const char* path, ino_t inode, time_t modTime, uid_t uid) : fPath(path), fOffset(offset), fArchPair(0,0), fMTime(modTime), fInode(inode), fHasSplitSegInfo(false), fRootOwned(uid==0), fShareableLocation(false), fDynamicLookupLinkage(false), fMainExecutableLookupLinkage(false), fIsDylib(false), fHasDyldInfo(false), fDyldInfoExports(NULL) { fDylibID.name = NULL; fDylibID.currentVersion = 0; fDylibID.compatibilityVersion = 0; bzero(fUUID, sizeof(fUUID)); const macho_header<P>* mh = (const macho_header<P>*)machHeader; if ( mh->cputype() != arch() ) throw "Layout object is wrong architecture"; switch ( mh->filetype() ) { case MH_DYLIB: fIsDylib = true; break; case MH_BUNDLE: case MH_EXECUTE: case MH_DYLIB_STUB: case MH_DYLINKER: break; default: throw "file is not a mach-o final linked image"; } fFlags = mh->flags(); fFileType = mh->filetype(); fArchPair.arch = mh->cputype(); fArchPair.subtype = mh->cpusubtype(); const macho_dyld_info_command<P>* dyldInfo = NULL; const macho_symtab_command<P>* symbolTableCmd = NULL; const macho_dysymtab_command<P>* dynamicSymbolTableCmd = NULL; const macho_load_command<P>* const cmds = (macho_load_command<P>*)((uint8_t*)mh + sizeof(macho_header<P>)); const uint32_t cmd_count = mh->ncmds(); const macho_load_command<P>* cmd = cmds; for (uint32_t i = 0; i < cmd_count; ++i) { switch ( cmd->cmd() ) { case LC_ID_DYLIB: { macho_dylib_command<P>* dylib = (macho_dylib_command<P>*)cmd; fDylibID.name = strdup(dylib->name()); fDylibID.currentVersion = dylib->current_version(); fDylibID.compatibilityVersion = dylib->compatibility_version(); fNameFileOffset = dylib->name() - (char*)machHeader; fShareableLocation = ( (strncmp(fDylibID.name, "/usr/lib/", 9) == 0) || (strncmp(fDylibID.name, "/System/Library/", 16) == 0) ); } break; case LC_LOAD_DYLIB: case LC_LOAD_WEAK_DYLIB: case LC_REEXPORT_DYLIB: case LC_LOAD_UPWARD_DYLIB: { macho_dylib_command<P>* dylib = (macho_dylib_command<P>*)cmd; Library lib; lib.name = strdup(dylib->name()); lib.currentVersion = dylib->current_version(); lib.compatibilityVersion = dylib->compatibility_version(); lib.weakImport = ( cmd->cmd() == LC_LOAD_WEAK_DYLIB ); fLibraries.push_back(lib); } break; case LC_SEGMENT_SPLIT_INFO: fHasSplitSegInfo = true; break; case macho_segment_command<P>::CMD: { macho_segment_command<P>* segCmd = (macho_segment_command<P>*)cmd; fSegments.push_back(Segment(segCmd->vmaddr(), segCmd->vmsize(), segCmd->fileoff(), segCmd->filesize(), segCmd->initprot(), segCmd->segname())); } break; case LC_SYMTAB: symbolTableCmd = (macho_symtab_command<P>*)cmd; break; case LC_DYSYMTAB: dynamicSymbolTableCmd = (macho_dysymtab_command<P>*)cmd; break; case LC_DYLD_INFO: case LC_DYLD_INFO_ONLY: fHasDyldInfo = true; dyldInfo = (struct macho_dyld_info_command<P>*)cmd; break; case LC_UUID: { const macho_uuid_command<P>* uc = (macho_uuid_command<P>*)cmd; memcpy(&fUUID, uc->uuid(), 16); } break; } cmd = (const macho_load_command<P>*)(((uint8_t*)cmd)+cmd->cmdsize()); } fLowSegment = NULL; fLowExecutableSegment = NULL; fLowWritableSegment = NULL; fLowReadOnlySegment = NULL; fVMExecutableSize = 0; fVMWritablSize = 0; fVMReadOnlySize = 0; fVMSize = 0; const Segment* highSegment = NULL; for(std::vector<Segment>::const_iterator it = fSegments.begin(); it != fSegments.end(); ++it) { const Segment& seg = *it; if ( (fLowSegment == NULL) || (seg.address() < fLowSegment->address()) ) fLowSegment = &seg; if ( (highSegment == NULL) || (seg.address() > highSegment->address()) ) highSegment = &seg; if ( seg.executable() ) { if ( (fLowExecutableSegment == NULL) || (seg.address() < fLowExecutableSegment->address()) ) fLowExecutableSegment = &seg; fVMExecutableSize += seg.size(); } else if ( seg.writable()) { if ( (fLowWritableSegment == NULL) || (seg.address() < fLowWritableSegment->address()) ) fLowWritableSegment = &seg; fVMWritablSize += seg.size(); } else { if ( (fLowReadOnlySegment == NULL) || (seg.address() < fLowReadOnlySegment->address()) ) fLowReadOnlySegment = &seg; fVMReadOnlySize += seg.size(); } } if ( (highSegment != NULL) && (fLowSegment != NULL) ) fVMSize = (highSegment->address() + highSegment->size() - fLowSegment->address() + 4095) & (-4096); // scan undefines looking, for magic ordinals if ( (symbolTableCmd != NULL) && (dynamicSymbolTableCmd != NULL) ) { const macho_nlist<P>* symbolTable = (macho_nlist<P>*)((uint8_t*)machHeader + symbolTableCmd->symoff()); const uint32_t startUndefs = dynamicSymbolTableCmd->iundefsym(); const uint32_t endUndefs = startUndefs + dynamicSymbolTableCmd->nundefsym(); for (uint32_t i=startUndefs; i < endUndefs; ++i) { uint8_t ordinal = GET_LIBRARY_ORDINAL(symbolTable[i].n_desc()); if ( ordinal == DYNAMIC_LOOKUP_ORDINAL ) fDynamicLookupLinkage = true; else if ( ordinal == EXECUTABLE_ORDINAL ) fMainExecutableLookupLinkage = true; } } if ( dyldInfo != NULL ) { if ( dyldInfo->export_off() != 0 ) { fDyldInfoExports = (uint8_t*)machHeader + dyldInfo->export_off(); } } }
bool checkRegisters(const IRUnit& unit, const RegAllocInfo& regs) { assert(checkCfg(unit)); auto blocks = rpoSortCfg(unit); StateVector<Block, RegState> states(unit, RegState()); StateVector<Block, bool> reached(unit, false); for (auto* block : blocks) { RegState state = states[block]; for (IRInstruction& inst : *block) { if (inst.op() == Jmp) continue; // handled by Shuffle auto& inst_regs = regs[inst]; for (int i = 0, n = inst.numSrcs(); i < n; ++i) { auto const &rs = inst_regs.src(i); if (!rs.spilled()) { // hack - ignore rbx and rbp bool ignore_frame_regs; switch (arch()) { case Arch::X64: ignore_frame_regs = (rs.reg(0) == X64::rVmSp || rs.reg(0) == X64::rVmFp); break; case Arch::ARM: ignore_frame_regs = (rs.reg(0) == ARM::rVmSp || rs.reg(0) == ARM::rVmFp); break; } if (ignore_frame_regs) continue; } DEBUG_ONLY auto src = inst.src(i); assert(rs.numWords() == src->numWords() || (src->isConst() && rs.numWords() == 0)); DEBUG_ONLY auto allocated = rs.numAllocated(); if (allocated == 2) { if (rs.spilled()) { assert(rs.slot(0) != rs.slot(1)); } else { assert(rs.reg(0) != rs.reg(1)); } } for (unsigned i = 0, n = rs.numAllocated(); i < n; ++i) { assert(state.tmp(rs, i) == src); } } auto update = [&](SSATmp* tmp, const PhysLoc& loc) { for (unsigned i = 0, n = loc.numAllocated(); i < n; ++i) { state.tmp(loc, i) = tmp; } }; if (inst.op() == Shuffle) { checkShuffle(inst, regs); for (unsigned i = 0; i < inst.numSrcs(); ++i) { update(inst.src(i), inst.extra<Shuffle>()->dests[i]); } } else { for (unsigned i = 0; i < inst.numDsts(); ++i) { update(inst.dst(i), inst_regs.dst(i)); } } } // State contains the PhysLoc->SSATmp reverse mappings at block end; // propagate the state to succ auto updateEdge = [&](Block* succ) { if (!reached[succ]) { states[succ] = state; } else { states[succ].merge(state); } }; if (auto* next = block->next()) updateEdge(next); if (auto* taken = block->taken()) updateEdge(taken); } return true; }
void lower_vcall(Vunit& unit, Inst& inst, Vlabel b, size_t i) { auto& blocks = unit.blocks; auto const& vinstr = blocks[b].code[i]; auto const is_vcall = vinstr.op == Vinstr::vcall; auto const vcall = vinstr.vcall_; auto const vinvoke = vinstr.vinvoke_; // We lower vinvoke in two phases, and `inst' is overwritten after the first // phase. We need to save any of its parameters that we care about in the // second phase ahead of time. auto const& vargs = unit.vcallArgs[inst.args]; auto const dests = unit.tuples[inst.d]; auto const destType = inst.destType; auto const scratch = unit.makeScratchBlock(); SCOPE_EXIT { unit.freeScratchBlock(scratch); }; Vout v(unit, scratch, vinstr.origin); int32_t const adjust = (vargs.stkArgs.size() & 0x1) ? sizeof(uintptr_t) : 0; if (adjust) v << lea{rsp()[-adjust], rsp()}; // Push stack arguments, in reverse order. for (int i = vargs.stkArgs.size() - 1; i >= 0; --i) { v << push{vargs.stkArgs[i]}; } // Get the arguments in the proper registers. RegSet argRegs; bool needsCopy = false; auto doArgs = [&] (const VregList& srcs, PhysReg (*r)(size_t)) { VregList argDests; for (size_t i = 0, n = srcs.size(); i < n; ++i) { auto const reg = r(i); argDests.push_back(reg); argRegs |= reg; } if (argDests.size()) { v << copyargs{v.makeTuple(srcs), v.makeTuple(std::move(argDests))}; } }; switch (arch()) { case Arch::X64: case Arch::PPC64: doArgs(vargs.args, rarg); break; case Arch::ARM: if (vargs.indirect) { if (vargs.args.size() > 0) { // First arg is a pointer to storage for the return value. v << copy{vargs.args[0], rret_indirect()}; VregList rem(vargs.args.begin() + 1, vargs.args.end()); doArgs(rem, rarg); needsCopy = true; } } else { doArgs(vargs.args, rarg); } } doArgs(vargs.simdArgs, rarg_simd); // Emit the appropriate call instruction sequence. emitCall(v, inst.call, argRegs); // Handle fixup and unwind information. if (inst.fixup.isValid()) { v << syncpoint{inst.fixup}; } if (!is_vcall) { auto& targets = vinvoke.targets; v << unwind{{targets[0], targets[1]}}; // Insert an lea fixup for any stack args at the beginning of the catch // block. if (auto rspOffset = ((vargs.stkArgs.size() + 1) & ~1) * sizeof(uintptr_t)) { auto& taken = unit.blocks[targets[1]].code; assertx(taken.front().op == Vinstr::landingpad || taken.front().op == Vinstr::jmp); Vinstr vi { lea{rsp()[rspOffset], rsp()} }; vi.origin = taken.front().origin; if (taken.front().op == Vinstr::jmp) { taken.insert(taken.begin(), vi); } else { taken.insert(taken.begin() + 1, vi); } } // Write out the code so far to the end of b. Remaining code will be // emitted to the next block. vector_splice(blocks[b].code, i, 1, blocks[scratch].code); } else if (vcall.nothrow) { v << nothrow{}; } // Copy back the indirect result pointer into the return register. if (needsCopy) { v << copy{rret_indirect(), rret(0)}; } // For vinvoke, `inst' is no longer valid after this point. // Copy the call result to the destination register(s). switch (destType) { case DestType::TV: static_assert(offsetof(TypedValue, m_data) == 0, ""); static_assert(offsetof(TypedValue, m_type) == 8, ""); if (dests.size() == 2) { v << copy2{rret(0), rret(1), dests[0], dests[1]}; } else { // We have cases where we statically know the type but need the value // from native call. Even if the type does not really need a register // (e.g., InitNull), a Vreg is still allocated in assignRegs(), so the // following assertion holds. assertx(dests.size() == 1); v << copy{rret(0), dests[0]}; } break; case DestType::SIMD: static_assert(offsetof(TypedValue, m_data) == 0, ""); static_assert(offsetof(TypedValue, m_type) == 8, ""); assertx(dests.size() == 1); pack2(v, rret(0), rret(1), dests[0]); break; case DestType::SSA: case DestType::Byte: assertx(dests.size() == 1); assertx(dests[0].isValid()); // Copy the single-register result to dests[0]. v << copy{rret(0), dests[0]}; break; case DestType::Dbl: // Copy the single-register result to dests[0]. assertx(dests.size() == 1); assertx(dests[0].isValid()); v << copy{rret_simd(0), dests[0]}; break; case DestType::None: assertx(dests.empty()); break; } if (vargs.stkArgs.size() > 0) { auto const delta = safe_cast<int32_t>( vargs.stkArgs.size() * sizeof(uintptr_t) + adjust ); v << lea{rsp()[delta], rsp()}; } // Insert new instructions to the appropriate block. if (is_vcall) { vector_splice(blocks[b].code, i, 1, blocks[scratch].code); } else { vector_splice(blocks[vinvoke.targets[0]].code, 0, 0, blocks[scratch].code); } }
static bool execSdkManager(const char *javaPath, const char *toolsDir, const char *tmpDir, const char *lpCmdLine) { SetLastError(0); // Which java binary to call. // The default is to use java.exe to automatically dump stdout in // the parent console. CPath javaExecPath(javaPath); // Attach to the parent console, if there's one. if (AttachConsole(-1) == 0) { // This can fail with ERROR_ACCESS_DENIED if the process is already // attached to the parent console. That means there's a console so // we want to keep invoking java.exe to get stdout into it. // // This also fails if there is no parent console, in which // it means this was invoked not from a shell. It's a good // signal we don't want a new console to show up so we'll // switch to javaw.exe instead, if available. if (GetLastError() != ERROR_ACCESS_DENIED) { SetLastError(0); javaExecPath.replaceName("java.exe", "javaw.exe"); // Only accept it if we can actually find the exec PVOID oldWow64Value = disableWow64FsRedirection(); if (!javaExecPath.fileExists()) { javaExecPath.set(javaPath); } revertWow64FsRedirection(&oldWow64Value); } } // Check whether the underlying system is x86 or x86_64. // We use GetSystemInfo which will see the one masqueraded by Wow64. // (to get the real info, we would use GetNativeSystemInfo instead.) SYSTEM_INFO sysInfo; GetSystemInfo(&sysInfo); CString arch("x86"); if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) { arch.set("x86_64"); } else if (sysInfo.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL) { // Skip this. We'll just assume x86 and let it fail later. // Keep this line for debugging purposes: // displayLastError("Unknown Processor Architecture: %d", sysInfo.wProcessorArchitecture); } // Now build the command line. // Note that we pass the absolute javaExecPath both to CreateProcess (via execNoWait) // and we set it as argv[0] in the command line just for the show. // Important: for the classpath to be able to contain "lib\\sdkmanager.jar", etc., // we need to set the toolsDir as the *temp* directory in execNoWait. // It's important to not use toolsDir otherwise it would lock that diretory. CString cmdLine; cmdLine.setf("\"%s\" " // javaPath "-Dcom.android.sdkmanager.toolsdir=\"%s\" " // toolsDir "-Dcom.android.sdkmanager.workdir=\"%s\" " // workDir==toolsdir "-classpath \"lib\\sdkmanager.jar;lib\\swtmenubar.jar;lib\\%s\\swt.jar\" " // arch "com.android.sdkmanager.Main " "%s", // extra parameters javaExecPath.baseName(), toolsDir, tmpDir, arch.cstr(), lpCmdLine); // Tip: to connect the Java debugging to a running process, add this to the Java command line: // "-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000" if (gDebug) msgBox("Executing: %s", cmdLine.cstr()); if (!execNoWait(javaExecPath.cstr(), cmdLine.cstr(), tmpDir)) { displayLastError("Failed to run %s", cmdLine.cstr()); return false; } return true; }
void lower_vcall(Vunit& unit, Inst& inst, Vlabel b, size_t i) { auto& blocks = unit.blocks; auto const& vinstr = blocks[b].code[i]; auto const is_vcall = vinstr.op == Vinstr::vcall; auto const vcall = vinstr.vcall_; auto const vinvoke = vinstr.vinvoke_; // We lower vinvoke in two phases, and `inst' is overwritten after the first // phase. We need to save any of its parameters that we care about in the // second phase ahead of time. auto const& vargs = unit.vcallArgs[inst.args]; auto const dests = unit.tuples[inst.d]; auto const destType = inst.destType; auto const scratch = unit.makeScratchBlock(); SCOPE_EXIT { unit.freeScratchBlock(scratch); }; Vout v(unit, scratch, vinstr.irctx()); // Push stack arguments, in reverse order. Push in pairs without padding // except for the last argument (pushed first) which should be padded if // there are an odd number of arguments. auto numArgs = vargs.stkArgs.size(); int32_t const adjust = (numArgs & 0x1) ? sizeof(uintptr_t) : 0; if (adjust) { // Using InvalidReg below fails SSA checks and simplify pass, so just // push the arg twice. It's on the same cacheline and will actually // perform faster than an explicit lea. v << pushp{vargs.stkArgs[numArgs - 1], vargs.stkArgs[numArgs - 1]}; --numArgs; } for (auto i2 = numArgs; i2 >= 2; i2 -= 2) { v << pushp{vargs.stkArgs[i2 - 1], vargs.stkArgs[i2 - 2]}; } // Get the arguments in the proper registers. RegSet argRegs; auto doArgs = [&] (const VregList& srcs, PhysReg (*r)(size_t)) { VregList argDests; for (size_t i2 = 0, n = srcs.size(); i2 < n; ++i2) { auto const reg = r(i2); argDests.push_back(reg); argRegs |= reg; } if (argDests.size()) { v << copyargs{v.makeTuple(srcs), v.makeTuple(std::move(argDests))}; } }; doArgs(vargs.indRetArgs, rarg_ind_ret); doArgs(vargs.args, rarg); doArgs(vargs.simdArgs, rarg_simd); // Emit the appropriate call instruction sequence. emitCall(v, inst.call, argRegs); // Handle fixup and unwind information. if (inst.fixup.isValid()) { v << syncpoint{inst.fixup}; } if (!is_vcall) { auto& targets = vinvoke.targets; v << unwind{{targets[0], targets[1]}}; // Insert an lea fixup for any stack args at the beginning of the catch // block. if (auto rspOffset = ((vargs.stkArgs.size() + 1) & ~1) * sizeof(uintptr_t)) { auto& taken = unit.blocks[targets[1]].code; assertx(taken.front().op == Vinstr::landingpad || taken.front().op == Vinstr::jmp); Vinstr vi { lea{rsp()[rspOffset], rsp()}, taken.front().irctx() }; if (taken.front().op == Vinstr::jmp) { taken.insert(taken.begin(), vi); } else { taken.insert(taken.begin() + 1, vi); } } // Write out the code so far to the end of b. Remaining code will be // emitted to the next block. vector_splice(blocks[b].code, i, 1, blocks[scratch].code); } else if (vcall.nothrow) { v << nothrow{}; } // For vinvoke, `inst' is no longer valid after this point. // Copy the call result to the destination register(s). switch (destType) { case DestType::TV: static_assert(offsetof(TypedValue, m_data) == 0, ""); static_assert(offsetof(TypedValue, m_type) == 8, ""); if (dests.size() == 2) { switch (arch()) { case Arch::X64: // fall through case Arch::PPC64: v << copy2{rret(0), rret(1), dests[0], dests[1]}; break; case Arch::ARM: // For ARM64 we need to clear the bits 8..31 from the type value. // That allows us to use the resulting register values in // type comparisons without the need for truncation there. // We must not touch bits 63..32 as they contain the AUX data. v << copy{rret(0), dests[0]}; v << andq{v.cns(0xffffffff000000ff), rret(1), dests[1], v.makeReg()}; break; } } else { // We have cases where we statically know the type but need the value // from native call. Even if the type does not really need a register // (e.g., InitNull), a Vreg is still allocated in assignRegs(), so the // following assertion holds. assertx(dests.size() == 1); v << copy{rret(0), dests[0]}; } break; case DestType::SIMD: static_assert(offsetof(TypedValue, m_data) == 0, ""); static_assert(offsetof(TypedValue, m_type) == 8, ""); assertx(dests.size() == 1); pack2(v, rret(0), rret(1), dests[0]); break; case DestType::SSA: case DestType::Byte: assertx(dests.size() == 1); assertx(dests[0].isValid()); // Copy the single-register result to dests[0]. v << copy{rret(0), dests[0]}; break; case DestType::SSAPair: assertx(dests.size() == 2); assertx(dests[0].isValid()); assertx(dests[1].isValid()); // Copy the result pair to dests. v << copy2{rret(0), rret(1), dests[0], dests[1]}; break; case DestType::Dbl: // Copy the single-register result to dests[0]. assertx(dests.size() == 1); assertx(dests[0].isValid()); v << copy{rret_simd(0), dests[0]}; break; case DestType::Indirect: // Already asserted above break; case DestType::None: assertx(dests.empty()); break; } if (vargs.stkArgs.size() > 0) { auto const delta = safe_cast<int32_t>( vargs.stkArgs.size() * sizeof(uintptr_t) + adjust ); v << lea{rsp()[delta], rsp()}; } // Insert new instructions to the appropriate block. if (is_vcall) { vector_splice(blocks[b].code, i, 1, blocks[scratch].code); } else { vector_splice(blocks[vinvoke.targets[0]].code, 0, 0, blocks[scratch].code); } }
extern "C" void Function_GetChainOrientationProbability(char ** input_string, int*_ptCount, double* _separationCutOff, int* corr_counts_out, double* corr_lengths_out, double* _systemSize) { int ptCount = _ptCount[0]; double separationCutOff = _separationCutOff[0]; double systemSize = _systemSize[0]; std::string input(*input_string); std::stringstream in_stream; in_stream << "{\"value0\": \""; in_stream << input; in_stream << "\"}"; cereal::JSONInputArchive arch(in_stream); std::vector<CParticleBase> particles; for (int i = 0; i < ptCount; ++i) { particles.push_back(CParticleBase()); } arch.loadBinaryValue(&particles[0], sizeof(CParticleBase) * ptCount); bool chain_1; bool chain_2; int chainLength = 0; for (int i = 0; i < particles.size(); i++) { auto& pt = particles[i]; chain_1 = pt.GetOrientation().Z > 0; auto& pt_next = particles[get_next(i, ptCount)]; auto cosTheta = pt.GetOrientation().Z; auto cosTheta_next = pt_next.GetOrientation().Z; chain_2 = cosTheta_next > 0; if((pt.GetDistanceRight(pt_next, systemSize).GetLength() <= separationCutOff) && (cosTheta * cosTheta_next >= 0)){ chainLength++; } else { // rr, lr, rl, ll CYukawaDipolePt pt1 = CYukawaDipolePt(1000, 10, systemSize); CYukawaDipolePt pt2 = CYukawaDipolePt(1000, 10, systemSize); pt1.SetRotation(pt.GetRotation()); pt2.SetRotation(pt_next.GetRotation()); pt1.Coordinates = pt.Coordinates; pt2.Coordinates = pt_next.Coordinates; if (chain_1 && chain_2) { corr_counts_out[0]++; corr_lengths_out[0] += pt.GetDistanceRight(pt_next, systemSize).GetLength(); corr_lengths_out[4] += pt1.GetPotentialEnergy1D(pt2, pt1.GetDistanceRight(pt2, systemSize)); } if (!chain_1 && chain_2) { corr_counts_out[1]++; corr_lengths_out[1] += pt.GetDistanceRight(pt_next, systemSize).GetLength(); corr_lengths_out[5] += pt1.GetPotentialEnergy1D(pt2, pt1.GetDistanceRight(pt2, systemSize)); } if (chain_1 && !chain_2) { corr_counts_out[2]++; corr_lengths_out[2] += pt.GetDistanceRight(pt_next, systemSize).GetLength(); corr_lengths_out[6] += pt1.GetPotentialEnergy1D(pt2, pt1.GetDistanceRight(pt2, systemSize)); } if (!chain_1 && !chain_2) { corr_counts_out[3]++; corr_lengths_out[3] += pt.GetDistanceRight(pt_next, systemSize).GetLength(); corr_lengths_out[7] += pt1.GetPotentialEnergy1D(pt2, pt1.GetDistanceRight(pt2, systemSize)); } if (chain_1) { corr_counts_out[4]++; } else { corr_counts_out[5]++; } corr_counts_out[6] += chainLength; chainLength = 0; } } }
extern "C" void Function_GetChainOrientationProbabilityTest(char ** input_string, int*_ptCount, double* _separationCutOff, int* corr_counts_out, double* _systemSize) { int ptCount = _ptCount[0]; double separationCutOff = _separationCutOff[0]; double systemSize = _systemSize[0]; std::string input(*input_string); std::stringstream in_stream; in_stream << "{\"value0\": \""; in_stream << input; in_stream << "\"}"; cereal::JSONInputArchive arch(in_stream); std::vector<CParticleBase> particles; for (int i = 0; i < ptCount; ++i) { particles.push_back(CParticleBase()); } arch.loadBinaryValue(&particles[0], sizeof(CParticleBase) * ptCount); particles = std::vector<CParticleBase>(); double displ = 0; for(int i = 0; i < 10; i++){ auto pt = CParticleBase(); pt.Coordinates = i*0.9 + displ; particles.push_back(pt); } // displ = 12; // for(int i = 0; i < 10; i++){ // auto pt = CParticleBase(); // pt.Coordinates = i*0.9 + displ; // // particles.push_back(pt); // } // // displ = 24; // for(int i = 0; i < 10; i++){ // auto pt = CParticleBase(); // pt.Coordinates = i*0.9 + displ; // pt.Rotation = CQuaternion(M_PI, CVector(0, 1, 0)); // particles.push_back(pt); // } // // displ = 36; for(int i = 0; i < 10; i++){ auto pt = CParticleBase(); pt.Coordinates = i*0.9 + displ; pt.SetRotation(CQuaternion(M_PI, CVector(0, 1, 0))); particles.push_back(pt); } displ = 48; for(int i = 0; i < 10; i++){ auto pt = CParticleBase(); pt.Coordinates = i*0.9 + displ; pt.SetRotation(CQuaternion(M_PI, CVector(0, 1, 0))); particles.push_back(pt); } bool chain_1 = particles[0].GetOrientation().Z > 0; bool chain_2 = true; int chainLength = 0; for (int i = 0; i < particles.size(); i++) { auto& pt = particles[i]; auto& pt_next = particles[get_next(i, ptCount)]; auto cosTheta = pt.GetOrientation().Z; auto cosTheta_next = pt_next.GetOrientation().Z; chain_2 = cosTheta_next > 0; if(pt.GetDistanceRight(pt_next, systemSize).GetLength() <= separationCutOff && cosTheta * cosTheta_next >= 0){ chainLength++; } else { // ll, rl, lr, rr if (chain_1 && chain_2) corr_counts_out[3]++; if (!chain_1 && chain_2) corr_counts_out[2]++; if (chain_1 && !chain_2) corr_counts_out[1]++; if (!chain_1 && !chain_2) corr_counts_out[0]++; if (chain_1) { corr_counts_out[4]++; } else { corr_counts_out[5]++; } corr_counts_out[6] += chainLength; chainLength = 0; chain_1 = chain_2; } } }
int WINAPI WinMain(HINSTANCE instance, HINSTANCE, LPSTR cmdLine, int nCmdShow) { CArch arch(instance); CLOG; CArgs args; s_instance = instance; // if "/uninstall" is on the command line then just stop and // uninstall the service and quit. this is the only option // but we ignore any others. if (CString(cmdLine).find("/uninstall") != CString::npos) { CAutoStart::uninstallDaemons(false); CAutoStart::uninstallDaemons(true); return 0; } // register main window (dialog) class WNDCLASSEX classInfo; classInfo.cbSize = sizeof(classInfo); classInfo.style = CS_HREDRAW | CS_VREDRAW; classInfo.lpfnWndProc = &mainWndProc; classInfo.cbClsExtra = 0; classInfo.cbWndExtra = DLGWINDOWEXTRA; classInfo.hInstance = instance; classInfo.hIcon = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SYNERGY), IMAGE_ICON, 32, 32, LR_SHARED); classInfo.hCursor = LoadCursor(NULL, IDC_ARROW); classInfo.hbrBackground = reinterpret_cast<HBRUSH>(COLOR_3DFACE + 1); classInfo.lpszMenuName = NULL; classInfo.lpszClassName = s_mainClass; classInfo.hIconSm = (HICON)LoadImage(instance, MAKEINTRESOURCE(IDI_SYNERGY), IMAGE_ICON, 16, 16, LR_SHARED); RegisterClassEx(&classInfo); // create main window HWND mainWindow = CreateDialog(s_instance, MAKEINTRESOURCE(IDD_MAIN), 0, NULL); // prep windows initMainWindow(mainWindow); s_globalOptions = new CGlobalOptions(mainWindow, &ARG->m_config); s_advancedOptions = new CAdvancedOptions(mainWindow, &ARG->m_config); s_screensLinks = new CScreensLinks(mainWindow, &ARG->m_config); // show window ShowWindow(mainWindow, nCmdShow); // main loop MSG msg; bool done = false; do { switch (GetMessage(&msg, NULL, 0, 0)) { case -1: // error break; case 0: // quit done = true; break; default: if (!IsDialogMessage(mainWindow, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } break; } } while (!done); return msg.wParam; }
int main() { Archive arch({Zip}); arch.archive(std::cout, "text"); }
bool ReadInstallationInfo(std::string &distName, std::string &configName, std::string &bankName) { // There is a 1:1 match between archNames and distNames. // // Architecture names that match VisIt's architecture directories. These are the // directory names that you'd find in /usr/local/apps/visit/<ver> // static const char *archNames[] = { "linux-intel", "linux-intel", "linux-x86_64", "linux-x86_64", "linux-ia64", "linux-ia64", "darwin-i386", "darwin-x86_64", // Deprecated "darwin-ppc", "sun4-sunos5-sparc", "ibm-aix-pwr", "ibm-aix-pwr64", "sgi-irix6-mips2", "dec-osf1-alpha", }; #define NARCH (sizeof(archNames) / sizeof(const char *)) // // Names that match VisIt's distribution names. These are used in the filenames // that contain a VisIt distribution: e.g. visit1_10_1.darwin-i386.tar.gz // static const char *distNames[] = { "linux_rhel3", "linux-ellipse", "linux-x86_64", "linux-x86_64-fedora4", "linux-ia64", "linux-altix", "darwin-i386", "darwin-x86_64", // Deprecated "darwin-ppc", "sunos5", "aix", "aix64", "irix6", "osf1", }; // // Try and determine the platform that should be downloaded. // std::string archHome = Environment::get("VISITARCHHOME"); bool platformDetermined = false; if(!archHome.empty()) { std::string arch(archHome); // Try and read the .installinfo file that tells us just how VisIt // was installed. That way we can be sure that we pick up the right // Linux or AIX installation. std::string installinfo(archHome); if(installinfo[installinfo.length()-1] != '/') installinfo += "/"; installinfo += ".installinfo"; FILE *fp = fopen(installinfo.c_str(), "rt"); if(fp != NULL) { int fver = 0; if(fscanf(fp, "%d;", &fver) == 1) { char str[200]; for(int i = 0; i < 3; ++i) { int j = 0; for(; j < 200-1; ++j) { str[j] = (char)fgetc(fp); if(str[j] == ';' || str[j] < ' ') break; } str[j] = '\0'; if(j >= 1) { if(i == 0) configName = str; else if(i == 1) bankName = str; else { distName = str; platformDetermined = true; } } else { // error break; } } } fclose(fp); } // We could not open the .installinfo file so let's try and // determine the distName based on the archNames. if(!platformDetermined) { size_t lastSlash = arch.rfind("/"); if(lastSlash != std::string::npos) { arch = arch.substr(lastSlash+1, arch.length() - lastSlash - 1); for(size_t i = 0; i < NARCH; ++i) { if(arch == archNames[i]) { platformDetermined = true; distName = distNames[i]; break; } } } } #ifdef __APPLE__ if(!platformDetermined) { if(sizeof(long) == 8) distName = "darwin-x86_64"; else distName = "darwin-i386"; platformDetermined = true; } #endif } return platformDetermined; }
ZipArchive Decompress::decompressAllFiles() { poco_assert (_mapping.empty()); ZipArchive arch(_in, *this); return arch; }
void UnixMakefileGenerator::processPrlFiles() { QList<QMakeLocalFileName> libdirs, frameworkdirs; frameworkdirs.append(QMakeLocalFileName("/System/Library/Frameworks")); const QString lflags[] = { "QMAKE_LIBDIR_FLAGS", "QMAKE_FRAMEWORKPATH_FLAGS", "QMAKE_LFLAGS", "QMAKE_LIBS", QString() }; for(int i = 0; !lflags[i].isNull(); i++) { QStringList &l = project->values(lflags[i]); for(int lit = 0; lit < l.size(); ++lit) { QString opt = l.at(lit).trimmed(); if(opt.startsWith("-")) { if(opt.startsWith("-L")) { QMakeLocalFileName l(opt.right(opt.length()-2)); if(!libdirs.contains(l)) libdirs.append(l); } else if(opt.startsWith("-l")) { QString lib = opt.right(opt.length() - 2); for(int dep_i = 0; dep_i < libdirs.size(); ++dep_i) { const QMakeLocalFileName &lfn = libdirs[dep_i]; if(!project->isActiveConfig("compile_libtool")) { //give them the .libs.. QString la = lfn.local() + Option::dir_sep + project->values("QMAKE_PREFIX_SHLIB").first() + lib + Option::libtool_ext; if(exists(la) && QFile::exists(lfn.local() + Option::dir_sep + ".libs")) { QString dot_libs = lfn.real() + Option::dir_sep + ".libs"; l.append("-L" + dot_libs); libdirs.append(QMakeLocalFileName(dot_libs)); } } QString prl = lfn.local() + Option::dir_sep + project->values("QMAKE_PREFIX_SHLIB").first() + lib; if(!project->isEmpty("QMAKE_" + lib.toUpper() + "_SUFFIX")) prl += project->first("QMAKE_" + lib.toUpper() + "_SUFFIX"); if(processPrlFile(prl)) { if(prl.startsWith(lfn.local())) prl.replace(0, lfn.local().length(), lfn.real()); opt = linkLib(prl, lib); break; } } } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F")) { QMakeLocalFileName f(opt.right(opt.length()-2)); if(!frameworkdirs.contains(f)) frameworkdirs.append(f); } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) { if(opt.length() > 11) opt = opt.mid(11); else opt = l.at(++lit); opt = opt.trimmed(); const QList<QMakeLocalFileName> dirs = frameworkdirs + libdirs; for(int dep_i = 0; dep_i < dirs.size(); ++dep_i) { QString prl = dirs[dep_i].local() + "/" + opt + ".framework/" + opt + Option::prl_ext; if(processPrlFile(prl)) break; } } } else if(!opt.isNull()) { QString lib = opt; processPrlFile(lib); #if 0 if(ret) opt = linkLib(lib, ""); #endif if(!opt.isEmpty()) l.replaceInStrings(lib, opt); } QStringList &prl_libs = project->values("QMAKE_CURRENT_PRL_LIBS"); if(!prl_libs.isEmpty()) { for(int prl = 0; prl < prl_libs.size(); ++prl) l.insert(lit+prl+1, prl_libs.at(prl)); prl_libs.clear(); } } //merge them into a logical order if(!project->isActiveConfig("no_smart_library_merge") && !project->isActiveConfig("no_lflags_merge")) { QHash<QString, QStringList> lflags; for(int lit = 0; lit < l.size(); ++lit) { QString arch("default"); QString opt = l.at(lit).trimmed(); if(opt.startsWith("-")) { if (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-Xarch")) { if (opt.length() > 7) { arch = opt.mid(7); opt = l.at(++lit); } } if(opt.startsWith("-L") || (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-F"))) { if(!lflags[arch].contains(opt)) lflags[arch].append(opt); } else if(opt.startsWith("-l") || opt == "-pthread") { // Make sure we keep the dependency-order of libraries if (lflags[arch].contains(opt)) lflags[arch].removeAll(opt); lflags[arch].append(opt); } else if(Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-framework")) { if(opt.length() > 11) opt = opt.mid(11); else { opt = l.at(++lit); if (Option::target_mode == Option::TARG_MACX_MODE && opt.startsWith("-Xarch")) opt = l.at(++lit); // The user has done the right thing and prefixed each part } bool found = false; for(int x = 0; x < lflags[arch].size(); ++x) { QString xf = lflags[arch].at(x); if(xf.startsWith("-framework")) { QString framework; if(xf.length() > 11) framework = xf.mid(11); else framework = lflags[arch].at(++x); if(framework == opt) { found = true; break; } } } if(!found) { lflags[arch].append("-framework"); lflags[arch].append(opt); } } else { lflags[arch].append(opt); } } else if(!opt.isNull()) { if(!lflags[arch].contains(opt)) lflags[arch].append(opt); } } l = lflags.take("default"); // Process architecture specific options (Xarch) QHash<QString, QStringList>::const_iterator archIterator = lflags.constBegin(); while (archIterator != lflags.constEnd()) { const QStringList archOptions = archIterator.value(); for (int i = 0; i < archOptions.size(); ++i) { l.append(QLatin1String("-Xarch_") + archIterator.key()); l.append(archOptions.at(i)); } ++archIterator; } } } }
int main() { std::cout << "[moeoFitDivBoundedArchive]\t=>\t"; // objective vectors ObjectiveVector obj0, obj1, obj2, obj3, obj4, obj5, obj6; obj0[0] = 2; obj0[1] = 5; obj1[0] = 3; obj1[1] = 3; obj2[0] = 4; obj2[1] = 1; obj3[0] = 5; obj3[1] = 5; obj4[0] = 5; obj4[1] = 1; obj5[0] = 3; obj5[1] = 8; obj6[0] = 2.5; obj6[1] = 3.5; // population eoPop < Solution > pop; pop.resize(6); pop[0].objectiveVector(obj0); pop[1].objectiveVector(obj1); pop[2].objectiveVector(obj2); pop[3].objectiveVector(obj3); pop[4].objectiveVector(obj4); pop[5].objectiveVector(obj5); moeoDummyFitnessAssignment < Solution > fitness; moeoDummyDiversityAssignment < Solution > diversity; moeoFitnessThenDiversityComparator < Solution > indiComparator; moeoParetoObjectiveVectorComparator < ObjectiveVector > comparator; // archive moeoFitDivBoundedArchive< Solution > arch(indiComparator, comparator, fitness, diversity, 50); moeoFitDivBoundedArchive< Solution > arch2(indiComparator, fitness, diversity, 2); //test archive arch(pop); assert(arch.size()==3); arch2(pop); assert(arch2.size()==2); pop.resize(7); pop[6].objectiveVector(obj6); arch2(pop[6]); assert(arch2.size()==2); obj6[0] = 0; obj6[1] = 0; pop[6].objectiveVector(obj6); arch2(pop[6]); assert(arch2.size()==1); std::cout << "OK" << std::endl; return EXIT_SUCCESS; }
bool LibArchiveInterface::copyFiles(const QVariantList& files, const QString& destinationDirectory, ExtractionOptions options) { kDebug() << "Changing current directory to " << destinationDirectory; QDir::setCurrent(destinationDirectory); const bool extractAll = files.isEmpty(); const bool preservePaths = options.value(QLatin1String( "PreservePaths" )).toBool(); QString rootNode = options.value(QLatin1String("RootNode"), QVariant()).toString(); if ((!rootNode.isEmpty()) && (!rootNode.endsWith(QLatin1Char('/')))) { rootNode.append(QLatin1Char('/')); } ArchiveRead arch(archive_read_new()); if (!(arch.data())) { return false; } if (archive_read_support_compression_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_support_format_all(arch.data()) != ARCHIVE_OK) { return false; } if (archive_read_open_filename(arch.data(), QFile::encodeName(filename()), 10240) != ARCHIVE_OK) { emit error(i18nc("@info", "Could not open the archive <filename>%1</filename>, libarchive cannot handle it.", filename())); return false; } ArchiveWrite writer(archive_write_disk_new()); if (!(writer.data())) { return false; } archive_write_disk_set_options(writer.data(), extractionFlags()); int entryNr = 0; int totalCount = 0; if (extractAll) { if (!m_cachedArchiveEntryCount) { emit progress(0); //TODO: once information progress has been implemented, send //feedback here that the archive is being read kDebug() << "For getting progress information, the archive will be listed once"; m_emitNoEntries = true; list(); m_emitNoEntries = false; } totalCount = m_cachedArchiveEntryCount; } else { totalCount = files.size(); } m_currentExtractedFilesSize = 0; bool overwriteAll = false; // Whether to overwrite all files bool skipAll = false; // Whether to skip all files struct archive_entry *entry; QString fileBeingRenamed; while (archive_read_next_header(arch.data(), &entry) == ARCHIVE_OK) { fileBeingRenamed.clear(); // retry with renamed entry, fire an overwrite query again // if the new entry also exists retry: const bool entryIsDir = S_ISDIR(archive_entry_mode(entry)); //we skip directories if not preserving paths if (!preservePaths && entryIsDir) { archive_read_data_skip(arch.data()); continue; } //entryName is the name inside the archive, full path QString entryName = QDir::fromNativeSeparators(QFile::decodeName(archive_entry_pathname(entry))); if (entryName.startsWith(QLatin1Char( '/' ))) { //for now we just can't handle absolute filenames in a tar archive. //TODO: find out what to do here!! emit error(i18n("This archive contains archive entries with absolute paths, which are not yet supported by ark.")); return false; } if (files.contains(entryName) || entryName == fileBeingRenamed || extractAll) { // entryFI is the fileinfo pointing to where the file will be // written from the archive QFileInfo entryFI(entryName); //kDebug() << "setting path to " << archive_entry_pathname( entry ); const QString fileWithoutPath(entryFI.fileName()); //if we DON'T preserve paths, we cut the path and set the entryFI //fileinfo to the one without the path if (!preservePaths) { //empty filenames (ie dirs) should have been skipped already, //so asserting Q_ASSERT(!fileWithoutPath.isEmpty()); archive_entry_copy_pathname(entry, QFile::encodeName(fileWithoutPath).constData()); entryFI = QFileInfo(fileWithoutPath); //OR, if the commonBase has been set, then we remove this //common base from the filename } else if (!rootNode.isEmpty()) { kDebug() << "Removing" << rootNode << "from" << entryName; const QString truncatedFilename(entryName.remove(0, rootNode.size())); archive_entry_copy_pathname(entry, QFile::encodeName(truncatedFilename).constData()); entryFI = QFileInfo(truncatedFilename); } //now check if the file about to be written already exists if (!entryIsDir && entryFI.exists()) { if (skipAll) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (!overwriteAll && !skipAll) { Kerfuffle::OverwriteQuery query(entryName); emit userQuery(&query); query.waitForResponse(); if (query.responseCancelled()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); break; } else if (query.responseSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); continue; } else if (query.responseAutoSkip()) { archive_read_data_skip(arch.data()); archive_entry_clear(entry); skipAll = true; continue; } else if (query.responseRename()) { const QString newName(query.newFilename()); fileBeingRenamed = newName; archive_entry_copy_pathname(entry, QFile::encodeName(newName).constData()); goto retry; } else if (query.responseOverwriteAll()) { overwriteAll = true; } } } //if there is an already existing directory: if (entryIsDir && entryFI.exists()) { if (entryFI.isWritable()) { kDebug(1601) << "Warning, existing, but writable dir"; } else { kDebug(1601) << "Warning, existing, but non-writable dir. skipping"; archive_entry_clear(entry); archive_read_data_skip(arch.data()); continue; } } int header_response; kDebug() << "Writing " << fileWithoutPath << " to " << archive_entry_pathname(entry); if ((header_response = archive_write_header(writer.data(), entry)) == ARCHIVE_OK) { //if the whole archive is extracted and the total filesize is //available, we use partial progress copyData(arch.data(), writer.data(), (extractAll && m_extractedFilesSize)); } else if (header_response == ARCHIVE_WARN) { kDebug() << "Warning while writing " << entryName; } else { kDebug() << "Writing header failed with error code " << header_response << "While attempting to write " << entryName; } //if we only partially extract the archive and the number of //archive entries is available we use a simple progress based on //number of items extracted if (!extractAll && m_cachedArchiveEntryCount) { ++entryNr; emit progress(float(entryNr) / totalCount); } archive_entry_clear(entry); } else { archive_read_data_skip(arch.data()); } } return archive_read_close(arch.data()) == ARCHIVE_OK; }