aboutsummaryrefslogtreecommitdiff
path: root/riscv
diff options
context:
space:
mode:
authorAndrew Waterman <andrew@sifive.com>2021-09-17 19:36:11 -0700
committerAndrew Waterman <andrew@sifive.com>2021-09-17 19:36:11 -0700
commit3c3c0eaa861f177ece2b5a5756043c6c7b862a47 (patch)
tree3a2150f660eb3f1961c7b6c7291bffb7682fdcab /riscv
parent22affb92b73a383115d22b0c85da1564e09a7f7b (diff)
downloadspike-3c3c0eaa861f177ece2b5a5756043c6c7b862a47.zip
spike-3c3c0eaa861f177ece2b5a5756043c6c7b862a47.tar.gz
spike-3c3c0eaa861f177ece2b5a5756043c6c7b862a47.tar.bz2
Don't use "using"
Diffstat (limited to 'riscv')
-rw-r--r--riscv/interactive.cc120
-rw-r--r--riscv/processor.cc43
-rw-r--r--riscv/processor.h5
-rw-r--r--riscv/sim.cc4
-rw-r--r--riscv/sim.h26
5 files changed, 82 insertions, 116 deletions
diff --git a/riscv/interactive.cc b/riscv/interactive.cc
index 31ac77d..e0ed045 100644
--- a/riscv/interactive.cc
+++ b/riscv/interactive.cc
@@ -20,16 +20,6 @@
#include <algorithm>
#include <math.h>
-using std::ostream;
-using std::cerr;
-using std::hex;
-using std::dec;
-using std::setfill;
-using std::left;
-using std::right;
-using std::setw;
-using std::endl;
-
#define MAX_CMD_STR 40 // maximum possible size of a command line
#define STR_(X) #X // these definitions allow to use a macro as a string
@@ -76,52 +66,52 @@ static std::string readline(int fd)
#ifdef HAVE_BOOST_ASIO
// read input command string
-std::string sim_t::rin(streambuf *bout_ptr) {
+std::string sim_t::rin(boost::asio::streambuf *bout_ptr) {
std::string s;
if (acceptor_ptr) { // if we are listening, get commands from socket
try {
- socket_ptr = new tcp::socket(*io_service_ptr);
+ socket_ptr = new boost::asio::ip::tcp::socket(*io_service_ptr);
acceptor_ptr->accept(*socket_ptr); // wait for someone to open connection
boost::asio::streambuf buf;
boost::asio::read_until(*socket_ptr, buf, "\n"); // wait for command
- s = buffer_cast<const char*>(buf.data());
- erase_all(s, "\r"); // get rid off any cr and lf
- erase_all(s, "\n");
+ s = boost::asio::buffer_cast<const char*>(buf.data());
+ boost::erase_all(s, "\r"); // get rid off any cr and lf
+ boost::erase_all(s, "\n");
// The socket client is a web server and it appends the IP of the computer
// that sent the command from its web browser.
// For now, erase the IP if it is there.
- regex re(" ((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
- "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$");
- s = regex_replace(s, re, (std::string)"");
+ boost::regex re(" ((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}"
+ "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])$");
+ s = boost::regex_replace(s, re, (std::string)"");
// TODO: check the IP against the IP used to upload RISC-V source files
} catch (std::exception& e) {
- cerr << e.what() << endl;
+ std::cerr << e.what() << std::endl;
}
// output goes to socket
sout_.rdbuf(bout_ptr);
} else { // if we are not listening on a socket, get commands from terminal
- cerr << ": " << std::flush;
+ std::cerr << ": " << std::flush;
s = readline(2); // 2 is stderr, but when doing reads it reverts to stdin
// output goes to stderr
- sout_.rdbuf(cerr.rdbuf());
+ sout_.rdbuf(std::cerr.rdbuf());
}
return s;
}
// write sout_ to socket (via bout)
-void sim_t::wout(streambuf *bout_ptr) {
+void sim_t::wout(boost::asio::streambuf *bout_ptr) {
if (!cmd_file && acceptor_ptr) { // only if we are not getting command inputs from a file
// and if a socket has been created
try {
boost::system::error_code ignored_error;
- boost::asio::write(*socket_ptr, *bout_ptr, transfer_all(), ignored_error);
+ boost::asio::write(*socket_ptr, *bout_ptr, boost::asio::transfer_all(), ignored_error);
socket_ptr->close(); // close the socket after each command input/ouput
// This is need to in order to make the socket interface
// acessible by HTTP GET via a socket client in a web server.
} catch (std::exception& e) {
- cerr << e.what() << endl;
+ std::cerr << e.what() << std::endl;
}
}
}
@@ -155,7 +145,7 @@ void sim_t::interactive()
while (!done())
{
#ifdef HAVE_BOOST_ASIO
- streambuf bout; // socket output
+ boost::asio::streambuf bout; // socket output
#endif
std::string s;
char cmd_str[MAX_CMD_STR+1]; // only used for following fscanf
@@ -164,14 +154,14 @@ void sim_t::interactive()
// up to MAX_CMD_STR characters before \n, skipping \n
s = cmd_str;
// while we get input from file, output goes to stderr
- sout_.rdbuf(cerr.rdbuf());
+ sout_.rdbuf(std::cerr.rdbuf());
} else {
// when there are no commands left from file or if there was no file from the beginning
cmd_file = NULL; // mark file pointer as being not valid, so any method can test this easily
#ifdef HAVE_BOOST_ASIO
s = rin(&bout); // get command string from socket or terminal
#else
- cerr << ": " << std::flush;
+ std::cerr << ": " << std::flush;
s = readline(2); // 2 is stderr, but when doing reads it reverts to stdin
#endif
}
@@ -193,16 +183,16 @@ void sim_t::interactive()
while (ss >> tmp)
args.push_back(tmp);
- ostream out(sout_.rdbuf());
+ std::ostream out(sout_.rdbuf());
try
{
if (funcs.count(cmd))
(this->*funcs[cmd])(cmd, args);
else
- out << "Unknown command " << cmd << endl;
+ out << "Unknown command " << cmd << std::endl;
} catch(trap_t& t) {
- out << "Bad or missing arguments for command " << cmd << endl;
+ out << "Bad or missing arguments for command " << cmd << std::endl;
}
#ifdef HAVE_BOOST_ASIO
wout(&bout); // socket output, if required
@@ -213,7 +203,7 @@ void sim_t::interactive()
void sim_t::interactive_help(const std::string& cmd, const std::vector<std::string>& args)
{
- ostream out(sout_.rdbuf());
+ std::ostream out(sout_.rdbuf());
out <<
"Interactive commands:\n"
"reg <core> [reg] # Display [reg] (all if omitted) in <core>\n"
@@ -240,7 +230,7 @@ void sim_t::interactive_help(const std::string& cmd, const std::vector<std::stri
"help # This screen!\n"
"h Alias for help\n"
"Note: Hitting enter is the same as: run 1"
- << endl;
+ << std::endl;
}
void sim_t::interactive_run_noisy(const std::string& cmd, const std::vector<std::string>& args)
@@ -261,8 +251,8 @@ void sim_t::interactive_run(const std::string& cmd, const std::vector<std::strin
for (size_t i = 0; i < steps && !ctrlc_pressed && !done(); i++)
step(1);
- ostream out(sout_.rdbuf());
- if (!noisy) out << ":" << endl;
+ std::ostream out(sout_.rdbuf());
+ if (!noisy) out << ":" << std::endl;
}
void sim_t::interactive_quit(const std::string& cmd, const std::vector<std::string>& args)
@@ -287,9 +277,9 @@ void sim_t::interactive_pc(const std::string& cmd, const std::vector<std::string
processor_t *p = get_core(args[0]);
int max_xlen = p->get_max_xlen();
- ostream out(sout_.rdbuf());
- out << hex << setfill('0') << "0x" << setw(max_xlen/4)
- << zext(get_pc(args), max_xlen) << endl;
+ std::ostream out(sout_.rdbuf());
+ out << std::hex << std::setfill('0') << "0x" << std::setw(max_xlen/4)
+ << zext(get_pc(args), max_xlen) << std::endl;
}
reg_t sim_t::get_reg(const std::vector<std::string>& args)
@@ -354,33 +344,33 @@ void sim_t::interactive_vreg(const std::string& cmd, const std::vector<std::stri
const int elen = (int)(p->VU.get_elen()) >> 3;
const int num_elem = vlen/elen;
- ostream out(sout_.rdbuf());
- out << dec << "VLEN=" << (vlen << 3) << " bits; ELEN=" << (elen << 3) << " bits" << endl;
+ std::ostream out(sout_.rdbuf());
+ out << std::dec << "VLEN=" << (vlen << 3) << " bits; ELEN=" << (elen << 3) << " bits" << std::endl;
for (int r = rstart; r < rend; ++r) {
- out << setfill (' ') << left << setw(4) << vr_name[r] << right << ": ";
+ out << std::setfill (' ') << std::left << std::setw(4) << vr_name[r] << std::right << ": ";
for (int e = num_elem-1; e >= 0; --e){
uint64_t val;
switch(elen){
case 8:
val = P.VU.elt<uint64_t>(r, e);
- out << dec << "[" << e << "]: 0x" << hex << setfill ('0') << setw(16) << val << " ";
+ out << std::dec << "[" << e << "]: 0x" << std::hex << std::setfill ('0') << std::setw(16) << val << " ";
break;
case 4:
val = P.VU.elt<uint32_t>(r, e);
- out << dec << "[" << e << "]: 0x" << hex << setfill ('0') << setw(8) << (uint32_t)val << " ";
+ out << std::dec << "[" << e << "]: 0x" << std::hex << std::setfill ('0') << std::setw(8) << (uint32_t)val << " ";
break;
case 2:
val = P.VU.elt<uint16_t>(r, e);
- out << dec << "[" << e << "]: 0x" << hex << setfill ('0') << setw(8) << (uint16_t)val << " ";
+ out << std::dec << "[" << e << "]: 0x" << std::hex << std::setfill ('0') << std::setw(8) << (uint16_t)val << " ";
break;
case 1:
val = P.VU.elt<uint8_t>(r, e);
- out << dec << "[" << e << "]: 0x" << hex << setfill ('0') << setw(8) << (int)(uint8_t)val << " ";
+ out << std::dec << "[" << e << "]: 0x" << std::hex << std::setfill ('0') << std::setw(8) << (int)(uint8_t)val << " ";
break;
}
}
- out << endl;
+ out << std::endl;
}
}
@@ -393,22 +383,22 @@ void sim_t::interactive_reg(const std::string& cmd, const std::vector<std::strin
processor_t *p = get_core(args[0]);
int max_xlen = p->get_max_xlen();
- ostream out(sout_.rdbuf());
- out << hex;
+ std::ostream out(sout_.rdbuf());
+ out << std::hex;
if (args.size() == 1) {
// Show all the regs!
for (int r = 0; r < NXPR; ++r) {
- out << setfill(' ') << setw(4) << xpr_name[r]
- << ": 0x" << setfill('0') << setw(max_xlen/4)
+ out << std::setfill(' ') << std::setw(4) << xpr_name[r]
+ << ": 0x" << std::setfill('0') << std::setw(max_xlen/4)
<< zext(p->get_state()->XPR[r], max_xlen);
if ((r + 1) % 4 == 0)
- out << endl;
+ out << std::endl;
}
} else {
- out << "0x" << setfill('0') << setw(max_xlen/4)
- << zext(get_reg(args), max_xlen) << endl;
+ out << "0x" << std::setfill('0') << std::setw(max_xlen/4)
+ << zext(get_reg(args), max_xlen) << std::endl;
}
}
@@ -423,8 +413,8 @@ void sim_t::interactive_freg(const std::string& cmd, const std::vector<std::stri
{
freg_t r = get_freg(args);
- ostream out(sout_.rdbuf());
- out << hex << "0x" << setfill ('0') << setw(16) << r.v[1] << setw(16) << r.v[0] << endl;
+ std::ostream out(sout_.rdbuf());
+ out << std::hex << "0x" << std::setfill ('0') << std::setw(16) << r.v[1] << std::setw(16) << r.v[0] << std::endl;
}
void sim_t::interactive_fregh(const std::string& cmd, const std::vector<std::string>& args)
@@ -432,8 +422,8 @@ void sim_t::interactive_fregh(const std::string& cmd, const std::vector<std::str
fpr f;
f.r = freg(f16_to_f32(f16(get_freg(args))));
- ostream out(sout_.rdbuf());
- out << dec << (isBoxedF32(f.r) ? (double)f.s : NAN) << endl;
+ std::ostream out(sout_.rdbuf());
+ out << (isBoxedF32(f.r) ? (double)f.s : NAN) << std::endl;
}
void sim_t::interactive_fregs(const std::string& cmd, const std::vector<std::string>& args)
@@ -441,8 +431,8 @@ void sim_t::interactive_fregs(const std::string& cmd, const std::vector<std::str
fpr f;
f.r = get_freg(args);
- ostream out(sout_.rdbuf());
- out << dec << (isBoxedF32(f.r) ? (double)f.s : NAN) << endl;
+ std::ostream out(sout_.rdbuf());
+ out << (isBoxedF32(f.r) ? (double)f.s : NAN) << std::endl;
}
void sim_t::interactive_fregd(const std::string& cmd, const std::vector<std::string>& args)
@@ -450,8 +440,8 @@ void sim_t::interactive_fregd(const std::string& cmd, const std::vector<std::str
fpr f;
f.r = get_freg(args);
- ostream out(sout_.rdbuf());
- out << dec << (isBoxedF64(f.r) ? f.d : NAN) << endl;
+ std::ostream out(sout_.rdbuf());
+ out << (isBoxedF64(f.r) ? f.d : NAN) << std::endl;
}
reg_t sim_t::get_mem(const std::vector<std::string>& args)
@@ -495,9 +485,9 @@ void sim_t::interactive_mem(const std::string& cmd, const std::vector<std::strin
{
int max_xlen = procs[0]->get_max_xlen();
- ostream out(sout_.rdbuf());
- out << hex << "0x" << setfill('0') << setw(max_xlen/4)
- << zext(get_mem(args), max_xlen) << endl;
+ std::ostream out(sout_.rdbuf());
+ out << std::hex << "0x" << std::setfill('0') << std::setw(max_xlen/4)
+ << zext(get_mem(args), max_xlen) << std::endl;
}
void sim_t::interactive_str(const std::string& cmd, const std::vector<std::string>& args)
@@ -516,13 +506,13 @@ void sim_t::interactive_str(const std::string& cmd, const std::vector<std::strin
reg_t addr = strtol(addr_str.c_str(),NULL,16);
- ostream out(sout_.rdbuf());
+ std::ostream out(sout_.rdbuf());
char ch;
while((ch = mmu->load_uint8(addr++)))
out << ch;
- out << endl;
+ out << std::endl;
}
void sim_t::interactive_until_silent(const std::string& cmd, const std::vector<std::string>& args)
diff --git a/riscv/processor.cc b/riscv/processor.cc
index 0aa0d83..5ab3c27 100644
--- a/riscv/processor.cc
+++ b/riscv/processor.cc
@@ -20,19 +20,12 @@
#include <string>
#include <algorithm>
-using std::stringstream;
-using std::hex;
-using std::dec;
-using std::setfill;
-using std::setw;
-using std::endl;
-
#undef STATE
#define STATE state
processor_t::processor_t(const char* isa, const char* priv, const char* varch,
simif_t* sim, uint32_t id, bool halt_on_reset,
- FILE* log_file, ostream& sout_)
+ FILE* log_file, std::ostream& sout_)
: debug(false), halt_request(HR_NONE), sim(sim), id(id), xlen(0),
histogram_enabled(false), log_commits_enabled(false),
log_file(log_file), sout_(sout_.rdbuf()), halt_on_reset(halt_on_reset),
@@ -747,10 +740,10 @@ void processor_t::enter_debug_mode(uint8_t cause)
state.pc = DEBUG_ROM_ENTRY;
}
-void processor_t::debug_output_log(stringstream *s)
+void processor_t::debug_output_log(std::stringstream *s)
{
if (log_file==stderr) {
- ostream out(sout_.rdbuf());
+ std::ostream out(sout_.rdbuf());
out << s->str(); // handles command line options -d -s -l
} else {
fputs(s->str().c_str(), log_file); // handles command line option --log
@@ -760,14 +753,14 @@ void processor_t::debug_output_log(stringstream *s)
void processor_t::take_trap(trap_t& t, reg_t epc)
{
if (debug) {
- stringstream s; // first put everything in a string, later send it to output
- s << "core " << dec << setfill(' ') << setw(3) << id
+ std::stringstream s; // first put everything in a string, later send it to output
+ s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
<< ": exception " << t.name() << ", epc 0x"
- << hex << setfill('0') << setw(max_xlen/4) << zext(epc, max_xlen) << endl;
+ << std::hex << std::setfill('0') << std::setw(max_xlen/4) << zext(epc, max_xlen) << std::endl;
if (t.has_tval())
- s << "core " << dec << setfill(' ') << setw(3) << id
- << ": tval 0x" << hex << setfill('0') << setw(max_xlen/4)
- << zext(t.get_tval(), max_xlen) << endl;
+ s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
+ << ": tval 0x" << std::hex << std::setfill('0') << std::setw(max_xlen/4)
+ << zext(t.get_tval(), max_xlen) << std::endl;
debug_output_log(&s);
}
@@ -866,26 +859,26 @@ void processor_t::disasm(insn_t insn)
{
uint64_t bits = insn.bits() & ((1ULL << (8 * insn_length(insn.bits()))) - 1);
if (last_pc != state.pc || last_bits != bits) {
- stringstream s; // first put everything in a string, later send it to output
+ std::stringstream s; // first put everything in a string, later send it to output
#ifdef RISCV_ENABLE_COMMITLOG
const char* sym = get_symbol(state.pc);
if (sym != nullptr)
{
- s << "core " << dec << setfill(' ') << setw(3) << id
- << ": >>>> " << sym << endl;
+ s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
+ << ": >>>> " << sym << std::endl;
}
#endif
if (executions != 1) {
- s << "core " << dec << setfill(' ') << setw(3) << id
- << ": Executed " << executions << " times" << endl;
+ s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
+ << ": Executed " << executions << " times" << std::endl;
}
- s << "core " << dec << setfill(' ') << setw(3) << id
- << hex << ": 0x" << setfill('0') << setw(max_xlen/4)
- << zext(state.pc, max_xlen) << " (0x" << setw(8) << bits << ") "
- << disassembler->disassemble(insn) << endl;
+ s << "core " << std::dec << std::setfill(' ') << std::setw(3) << id
+ << std::hex << ": 0x" << std::setfill('0') << std::setw(max_xlen/4)
+ << zext(state.pc, max_xlen) << " (0x" << std::setw(8) << bits << ") "
+ << disassembler->disassemble(insn) << std::endl;
debug_output_log(&s);
diff --git a/riscv/processor.h b/riscv/processor.h
index 1b11820..3a240f8 100644
--- a/riscv/processor.h
+++ b/riscv/processor.h
@@ -15,9 +15,6 @@
#include "entropy_source.h"
#include "csrs.h"
-using std::ostream;
-using std::stringstream;
-
class processor_t;
class mmu_t;
typedef reg_t (*insn_func_t)(processor_t*, insn_t, reg_t);
@@ -499,7 +496,7 @@ private:
void enter_debug_mode(uint8_t cause);
- void debug_output_log(stringstream *s); // either output to interactive user or write to log file
+ void debug_output_log(std::stringstream *s); // either output to interactive user or write to log file
friend class mmu_t;
friend class clint_t;
diff --git a/riscv/sim.cc b/riscv/sim.cc
index 042d0f0..1ec6a9f 100644
--- a/riscv/sim.cc
+++ b/riscv/sim.cc
@@ -38,7 +38,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch,
const char *log_path,
bool dtb_enabled, const char *dtb_file,
#ifdef HAVE_BOOST_ASIO
- io_service *io_service_ptr, tcp::acceptor *acceptor_ptr, // option -s
+ boost::asio::io_service *io_service_ptr, boost::asio::ip::tcp::acceptor *acceptor_ptr, // option -s
#endif
FILE *cmd_file) // needed for command line option --cmd
: htif_t(args),
@@ -68,7 +68,7 @@ sim_t::sim_t(const char* isa, const char* priv, const char* varch,
{
signal(SIGINT, &handle_signal);
- sout_.rdbuf(cerr.rdbuf()); // debug output goes to stderr by default
+ sout_.rdbuf(std::cerr.rdbuf()); // debug output goes to stderr by default
for (auto& x : mems)
bus.add_device(x.first, x.second);
diff --git a/riscv/sim.h b/riscv/sim.h
index 714b766..2a580f9 100644
--- a/riscv/sim.h
+++ b/riscv/sim.h
@@ -9,16 +9,6 @@
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <boost/asio.hpp>
-// namespace boost::asio does not work for all environments
-using boost::asio::ip::tcp;
-using boost::asio::io_service;
-using boost::asio::streambuf;
-// using boost::asio::write does not work either
-using boost::asio::transfer_all;
-using boost::asio::buffer_cast;
-using boost::erase_all;
-using boost::regex;
-using boost::regex_replace;
#endif
#include "debug_module.h"
@@ -34,10 +24,6 @@ using boost::regex_replace;
#include <memory>
#include <sys/types.h>
-using std::ostream;
-using std::string;
-using std::cerr;
-
class mmu_t;
class remote_bitbang_t;
@@ -54,7 +40,7 @@ public:
const debug_module_config_t &dm_config, const char *log_path,
bool dtb_enabled, const char *dtb_file,
#ifdef HAVE_BOOST_ASIO
- io_service *io_service_ptr_ctor, tcp::acceptor *acceptor_ptr_ctor, // option -s
+ boost::asio::io_service *io_service_ptr_ctor, boost::asio::ip::tcp::acceptor *acceptor_ptr_ctor, // option -s
#endif
FILE *cmd_file); // needed for command line option --cmd
~sim_t();
@@ -106,12 +92,12 @@ private:
#ifdef HAVE_BOOST_ASIO
// the following are needed for command socket interface
boost::asio::io_service *io_service_ptr;
- tcp::acceptor *acceptor_ptr;
- tcp::socket *socket_ptr;
- string rin(streambuf *bout_ptr); // read input command string
- void wout(streambuf *bout_ptr); // write output to socket
+ boost::asio::ip::tcp::acceptor *acceptor_ptr;
+ boost::asio::ip::tcp::socket *socket_ptr;
+ std::string rin(boost::asio::streambuf *bout_ptr); // read input command string
+ void wout(boost::asio::streambuf *bout_ptr); // write output to socket
#endif
- ostream sout_; // used for socket and terminal interface
+ std::ostream sout_; // used for socket and terminal interface
processor_t* get_core(const std::string& i);
void step(size_t n); // step through simulation