From: Gabe Black Date: Thu, 21 Jan 2021 07:14:24 +0000 (-0800) Subject: sim: Stop "using namespace std" X-Git-Tag: develop-gem5-snapshot~248 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=592b075fc80a7f07fc7a652deb27f0e5b1c03c15;p=gem5.git sim: Stop "using namespace std" Change-Id: Ic641cb82a069ccb2b185d74a3b49a96b27111035 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/39537 Reviewed-by: Gabe Black Maintainer: Gabe Black Tested-by: kokoro --- diff --git a/src/sim/core.cc b/src/sim/core.cc index ace699a3c..928e6c8d2 100644 --- a/src/sim/core.cc +++ b/src/sim/core.cc @@ -39,8 +39,6 @@ #include "base/output.hh" #include "sim/eventq.hh" -using namespace std; - namespace Gem5Internal { @@ -125,7 +123,7 @@ setClockFrequency(Tick tps) Tick getClockFrequency() { return _ticksPerSecond; } void -setOutputDir(const string &dir) +setOutputDir(const std::string &dir) { simout.setDirectory(dir); } @@ -159,6 +157,6 @@ doExitCleanup() exitCallbacks().process(); exitCallbacks().clear(); - cout.flush(); + std::cout.flush(); } diff --git a/src/sim/debug.cc b/src/sim/debug.cc index b2b3d456b..4144cafc1 100644 --- a/src/sim/debug.cc +++ b/src/sim/debug.cc @@ -40,8 +40,6 @@ #include "sim/sim_exit.hh" #include "sim/system.hh" -using namespace std; - // // Debug event: place a breakpoint on the process function and // schedule the event to break at a particular cycle diff --git a/src/sim/eventq.cc b/src/sim/eventq.cc index adce51ef5..3e99683e1 100644 --- a/src/sim/eventq.cc +++ b/src/sim/eventq.cc @@ -43,8 +43,6 @@ #include "debug/Checkpoint.hh" #include "sim/core.hh" -using namespace std; - Tick simQuantum = 0; // @@ -54,7 +52,7 @@ Tick simQuantum = 0; // cycle, before the pipeline simulation is performed. // uint32_t numMainEventQueues = 0; -vector mainEventQueue; +std::vector mainEventQueue; __thread EventQueue *_curEventQueue = NULL; bool inParallelMode = false; @@ -419,7 +417,7 @@ Event::dump() const } } -EventQueue::EventQueue(const string &n) +EventQueue::EventQueue(const std::string &n) : objName(n), head(NULL), _curTick(0) { } diff --git a/src/sim/init.cc b/src/sim/init.cc index 73d4dbd70..6abb0e1b5 100644 --- a/src/sim/init.cc +++ b/src/sim/init.cc @@ -65,7 +65,6 @@ #endif -using namespace std; namespace py = pybind11; // The python library is totally messed up with respect to constness, @@ -81,16 +80,16 @@ EmbeddedPython::EmbeddedPython(const char *filename, const char *abspath, { // if we've added the importer keep track of it because we need it // to bootstrap. - if (string(modpath) == string("importer")) + if (std::string(modpath) == std::string("importer")) importer = this; else getList().push_back(this); } -list & +std::list & EmbeddedPython::getList() { - static list the_list; + static std::list the_list; return the_list; } @@ -142,8 +141,8 @@ EmbeddedPython::initAll() // Load the rest of the embedded python files into the embedded // python importer - list::iterator i = getList().begin(); - list::iterator end = getList().end(); + std::list::iterator i = getList().begin(); + std::list::iterator end = getList().end(); for (; i != end; ++i) if (!(*i)->addModule()) return 1; diff --git a/src/sim/init_signals.cc b/src/sim/init_signals.cc index 305f0cfaa..db82682bd 100644 --- a/src/sim/init_signals.cc +++ b/src/sim/init_signals.cc @@ -61,8 +61,6 @@ #include "sim/core.hh" #include "sim/eventq.hh" -using namespace std; - // Use an separate stack for fatal signal handlers static uint8_t fatalSigStack[2 * SIGSTKSZ]; @@ -146,7 +144,8 @@ abortHandler(int sigtype) { const EventQueue *const eq(curEventQueue()); if (eq) { - ccprintf(cerr, "Program aborted at tick %llu\n", eq->getCurTick()); + ccprintf(std::cerr, "Program aborted at tick %llu\n", + eq->getCurTick()); } else { STATIC_ERR("Program aborted\n\n"); } diff --git a/src/sim/process.cc b/src/sim/process.cc index 409b48afc..1ae8d4096 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -67,7 +67,6 @@ #include "sim/syscall_desc.hh" #include "sim/system.hh" -using namespace std; using namespace TheISA; namespace @@ -127,7 +126,8 @@ Process::Process(const ProcessParams ¶ms, EmulationPageTable *pTable, _gid(params.gid), _egid(params.egid), _pid(params.pid), _ppid(params.ppid), _pgid(params.pgid), drivers(params.drivers), - fds(make_shared(params.input, params.output, params.errout)), + fds(std::make_shared( + params.input, params.output, params.errout)), childClearTID(0), ADD_STAT(numSyscalls, "Number of system calls") { @@ -189,7 +189,7 @@ Process::clone(ThreadContext *otc, ThreadContext *ntc, * Duplicate the process memory address space. The state needs to be * copied over (rather than using pointers to share everything). */ - typedef std::vector> MapVec; + typedef std::vector> MapVec; MapVec mappings; pTable->getMappings(&mappings); diff --git a/src/sim/pseudo_inst.cc b/src/sim/pseudo_inst.cc index 0079ebd00..9b51b9fc0 100644 --- a/src/sim/pseudo_inst.cc +++ b/src/sim/pseudo_inst.cc @@ -69,7 +69,6 @@ #include "sim/stats.hh" #include "sim/system.hh" -using namespace std; using namespace Stats; namespace PseudoInst @@ -203,13 +202,13 @@ loadsymbol(ThreadContext *tc) { DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n"); - const string &filename = tc->getCpuPtr()->system->params().symbolfile; + const std::string &filename = tc->getCpuPtr()->system->params().symbolfile; if (filename.empty()) { return; } std::string buffer; - ifstream file(filename.c_str()); + std::ifstream file(filename.c_str()); if (!file) fatal("file error: Can't open symbol table file %s\n", filename); @@ -220,17 +219,17 @@ loadsymbol(ThreadContext *tc) if (buffer.empty()) continue; - string::size_type idx = buffer.find(' '); - if (idx == string::npos) + std::string::size_type idx = buffer.find(' '); + if (idx == std::string::npos) continue; - string address = "0x" + buffer.substr(0, idx); + std::string address = "0x" + buffer.substr(0, idx); eat_white(address); if (address.empty()) continue; // Skip over letter and space - string symbol = buffer.substr(idx + 3); + std::string symbol = buffer.substr(idx + 3); eat_white(symbol); if (symbol.empty()) continue; @@ -278,11 +277,11 @@ initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2) // concatenate them in the key character buffer const int len = 2 * sizeof(uint64_t) + 1; char key[len]; - memset(key, '\0', len); + std::memset(key, '\0', len); std::array key_regs = {{ key_str1, key_str2 }}; key_regs = letoh(key_regs); - memcpy(key, key_regs.data(), sizeof(key_regs)); + std::memcpy(key, key_regs.data(), sizeof(key_regs)); // Check key parameter to figure out what to return. const std::string key_str(key); @@ -359,7 +358,7 @@ readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n", vaddr, len, offset); - const string &file = tc->getSystemPtr()->params().readfile; + const std::string &file = tc->getSystemPtr()->params().readfile; if (file.empty()) { return ULL(0); } @@ -410,10 +409,11 @@ writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, // do not truncate file if offset is non-zero // (ios::in flag is required as well to keep the existing data // intact, otherwise existing data will be zeroed out.) - out = simout.open(filename, ios::in | ios::out | ios::binary, true); + out = simout.open(filename, + std::ios::in | std::ios::out | std::ios::binary, true); } - ostream *os(out->stream()); + std::ostream *os(out->stream()); if (!os) panic("could not open file %s\n", filename); diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index a563332a1..e81f49dc7 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -65,8 +65,6 @@ // For stat reset hack #include "sim/stat_control.hh" -using namespace std; - int ckptMaxCount = 0; int ckptCount = 0; int ckptPrevCount = -1; @@ -183,14 +181,14 @@ Serializable::unserializeSection(CheckpointIn &cp, const char *name) } void -Serializable::serializeAll(const string &cpt_dir) +Serializable::serializeAll(const std::string &cpt_dir) { - string dir = CheckpointIn::setDir(cpt_dir); + std::string dir = CheckpointIn::setDir(cpt_dir); if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST) fatal("couldn't mkdir %s\n", dir); - string cpt_file = dir + CheckpointIn::baseFilename; - ofstream outstream(cpt_file.c_str()); + std::string cpt_file = dir + CheckpointIn::baseFilename; + std::ofstream outstream(cpt_file.c_str()); time_t t = time(NULL); if (!outstream.is_open()) fatal("Unable to open file %s for writing\n", cpt_file.c_str()); @@ -246,30 +244,31 @@ Serializable::currentSection() const char *CheckpointIn::baseFilename = "m5.cpt"; -string CheckpointIn::currentDirectory; +std::string CheckpointIn::currentDirectory; -string -CheckpointIn::setDir(const string &name) +std::string +CheckpointIn::setDir(const std::string &name) { // use csprintf to insert curTick() into directory name if it // appears to have a format placeholder in it. - currentDirectory = (name.find("%") != string::npos) ? + currentDirectory = (name.find("%") != std::string::npos) ? csprintf(name, curTick()) : name; if (currentDirectory[currentDirectory.size() - 1] != '/') currentDirectory += "/"; return currentDirectory; } -string +std::string CheckpointIn::dir() { return currentDirectory; } -CheckpointIn::CheckpointIn(const string &cpt_dir, SimObjectResolver &resolver) +CheckpointIn::CheckpointIn(const std::string &cpt_dir, + SimObjectResolver &resolver) : db(new IniFile), objNameResolver(resolver), _cptDir(setDir(cpt_dir)) { - string filename = getCptDir() + "/" + CheckpointIn::baseFilename; + std::string filename = getCptDir() + "/" + CheckpointIn::baseFilename; if (!db->load(filename)) { fatal("Can't load checkpoint file '%s'\n", filename); } @@ -289,7 +288,7 @@ CheckpointIn::~CheckpointIn() * we are looking in. */ bool -CheckpointIn::entryExists(const string §ion, const string &entry) +CheckpointIn::entryExists(const std::string §ion, const std::string &entry) { return db->entryExists(section, entry); } @@ -304,7 +303,8 @@ CheckpointIn::entryExists(const string §ion, const string &entry) * the value, given the section . */ bool -CheckpointIn::find(const string §ion, const string &entry, string &value) +CheckpointIn::find(const std::string §ion, const std::string &entry, + std::string &value) { return db->find(section, entry, value); } @@ -319,10 +319,10 @@ CheckpointIn::find(const string §ion, const string &entry, string &value) * */ bool -CheckpointIn::findObj(const string §ion, const string &entry, +CheckpointIn::findObj(const std::string §ion, const std::string &entry, SimObject *&value) { - string path; + std::string path; if (!db->find(section, entry, path)) return false; @@ -332,7 +332,7 @@ CheckpointIn::findObj(const string §ion, const string &entry, } bool -CheckpointIn::sectionExists(const string §ion) +CheckpointIn::sectionExists(const std::string §ion) { return db->sectionExists(section); } @@ -345,16 +345,16 @@ CheckpointIn::visitSection(const std::string §ion, } void -objParamIn(CheckpointIn &cp, const string &name, SimObject * ¶m) +objParamIn(CheckpointIn &cp, const std::string &name, SimObject * ¶m) { - const string §ion(Serializable::currentSection()); + const std::string §ion(Serializable::currentSection()); if (!cp.findObj(section, name, param)) { fatal("Can't unserialize '%s:%s'\n", section, name); } } void -debug_serialize(const string &cpt_dir) +debug_serialize(const std::string &cpt_dir) { Serializable::serializeAll(cpt_dir); } diff --git a/src/sim/sim_events.cc b/src/sim/sim_events.cc index 5888ea06f..af516d382 100644 --- a/src/sim/sim_events.cc +++ b/src/sim/sim_events.cc @@ -50,8 +50,6 @@ #include "sim/sim_exit.hh" #include "sim/stats.hh" -using namespace std; - GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when, const std::string &_cause, int c, Tick r) diff --git a/src/sim/sim_object.cc b/src/sim/sim_object.cc index 58780b2d7..17dbd1da5 100644 --- a/src/sim/sim_object.cc +++ b/src/sim/sim_object.cc @@ -35,9 +35,6 @@ #include "debug/Checkpoint.hh" #include "sim/probe/probe.hh" -using namespace std; - - //////////////////////////////////////////////////////////////////////// // // SimObject member definitions @@ -148,7 +145,7 @@ SimObject::serializeAll(CheckpointOut &cp) // static function: flag which objects should have the debugger break // void -SimObject::debugObjectBreak(const string &objs) +SimObject::debugObjectBreak(const std::string &objs) { SimObjectList::const_iterator i = simObjectList.begin(); SimObjectList::const_iterator end = simObjectList.end(); diff --git a/src/sim/stat_control.cc b/src/sim/stat_control.cc index 8189bfe34..a78e69c40 100644 --- a/src/sim/stat_control.cc +++ b/src/sim/stat_control.cc @@ -54,8 +54,6 @@ #include "base/time.hh" #include "sim/global_event.hh" -using namespace std; - namespace Stats { GlobalEvent *dumpEvent; diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index fd5699ce1..c85d89317 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -53,7 +53,6 @@ #include "sim/syscall_desc.hh" #include "sim/system.hh" -using namespace std; using namespace TheISA; void @@ -321,7 +320,7 @@ _llseekFunc(SyscallDesc *desc, ThreadContext *tc, return -errno; // Assuming that the size of loff_t is 64 bits on the target platform BufferArg result_buf(result_ptr, sizeof(result)); - memcpy(result_buf.bufferPtr(), &result, sizeof(result)); + std::memcpy(result_buf.bufferPtr(), &result, sizeof(result)); result_buf.copyOut(tc->getVirtProxy()); return 0; } @@ -368,7 +367,7 @@ getcwdFunc(SyscallDesc *desc, ThreadContext *tc, BufferArg buf(buf_ptr, size); // Is current working directory defined? - string cwd = p->tgtCwd; + std::string cwd = p->tgtCwd; if (!cwd.empty()) { if (cwd.length() >= size) { // Buffer too small @@ -393,7 +392,7 @@ SyscallReturn readlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr buf_ptr, size_t bufsiz) { - string path; + std::string path; auto p = tc->getProcessPtr(); if (!tc->getVirtProxy().tryReadString(path, pathname)) @@ -450,7 +449,7 @@ readlinkFunc(SyscallDesc *desc, ThreadContext *tc, SyscallReturn unlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname) { - string path; + std::string path; auto p = tc->getProcessPtr(); if (!tc->getVirtProxy().tryReadString(path, pathname)) @@ -466,8 +465,8 @@ SyscallReturn linkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname) { - string path; - string new_path; + std::string path; + std::string new_path; auto p = tc->getProcessPtr(); auto &virt_mem = tc->getVirtProxy(); @@ -487,8 +486,8 @@ SyscallReturn symlinkFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, Addr new_pathname) { - string path; - string new_path; + std::string path; + std::string new_path; auto p = tc->getProcessPtr(); auto &virt_mem = tc->getVirtProxy(); @@ -523,11 +522,11 @@ renameFunc(SyscallDesc *desc, ThreadContext *tc, Addr oldpath, Addr newpath) { auto p = tc->getProcessPtr(); - string old_name; + std::string old_name; if (!tc->getVirtProxy().tryReadString(old_name, oldpath)) return -EFAULT; - string new_name; + std::string new_name; if (!tc->getVirtProxy().tryReadString(new_name, newpath)) return -EFAULT; @@ -542,7 +541,7 @@ renameFunc(SyscallDesc *desc, ThreadContext *tc, Addr oldpath, Addr newpath) SyscallReturn truncateFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, off_t length) { - string path; + std::string path; auto p = tc->getProcessPtr(); if (!tc->getVirtProxy().tryReadString(path, pathname)) @@ -574,7 +573,7 @@ truncate64Func(SyscallDesc *desc, ThreadContext *tc, Addr pathname, int64_t length) { auto process = tc->getProcessPtr(); - string path; + std::string path; if (!tc->getVirtProxy().tryReadString(path, pathname)) return -EFAULT; @@ -624,7 +623,7 @@ SyscallReturn chownFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, uint32_t owner, uint32_t group) { - string path; + std::string path; auto p = tc->getProcessPtr(); if (!tc->getVirtProxy().tryReadString(path, pathname)) @@ -998,7 +997,7 @@ SyscallReturn accessFunc(SyscallDesc *desc, ThreadContext *tc, Addr pathname, mode_t mode) { - string path; + std::string path; auto p = tc->getProcessPtr(); if (!tc->getVirtProxy().tryReadString(path, pathname)) return -EFAULT; diff --git a/src/sim/syscall_emul.hh b/src/sim/syscall_emul.hh index 79cd35a6d..581e8dbce 100644 --- a/src/sim/syscall_emul.hh +++ b/src/sim/syscall_emul.hh @@ -372,8 +372,6 @@ SyscallReturn futexFunc(SyscallDesc *desc, ThreadContext *tc, Addr uaddr, int op, int val, int timeout, Addr uaddr2, int val3) { - using namespace std; - auto process = tc->getProcessPtr(); /* diff --git a/src/sim/system.cc b/src/sim/system.cc index 80aa2fb57..f2f10bc82 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -71,10 +71,9 @@ #include "sim/full_system.hh" #include "sim/redirect_path.hh" -using namespace std; using namespace TheISA; -vector System::systemList; +std::vector System::systemList; void System::Threads::Thread::resume() @@ -484,7 +483,7 @@ System::regStats() for (uint32_t j = 0; j < numWorkIds ; j++) { workItemStats[j] = new Stats::Histogram(this); - stringstream namestr; + std::stringstream namestr; ccprintf(namestr, "work_item_type%d", j); workItemStats[j]->init(20) .name(name() + "." + namestr.str()) @@ -513,16 +512,17 @@ System::workItemEnd(uint32_t tid, uint32_t workid) void System::printSystems() { - ios::fmtflags flags(cerr.flags()); + std::ios::fmtflags flags(std::cerr.flags()); - vector::iterator i = systemList.begin(); - vector::iterator end = systemList.end(); + std::vector::iterator i = systemList.begin(); + std::vector::iterator end = systemList.end(); for (; i != end; ++i) { System *sys = *i; - cerr << "System " << sys->name() << ": " << hex << sys << endl; + std::cerr << "System " << sys->name() << ": " << std::hex << sys + << std::endl; } - cerr.flags(flags); + std::cerr.flags(flags); } void