summaryrefslogtreecommitdiff
path: root/base
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2003-11-04 17:43:41 -0500
committerNathan Binkert <binkertn@umich.edu>2003-11-04 17:43:41 -0500
commit247984bc22442c5871bc2f19285bccc730dcd578 (patch)
tree0db8e022406c1983bf5ad10d4387923b94010e3c /base
parenta7635fa6ef488b8e44b127c40ab2a6818620145e (diff)
downloadgem5-247984bc22442c5871bc2f19285bccc730dcd578.tar.xz
A little bit of code here and there to get more access to
what the console output is. base/circlebuf.hh: base/circlebuf.cc: add stuff to spit to an ostream prepend _ in front of protected member variables formatting dev/console.hh: dev/console.cc: Add DPRINTF to spit out the lines of console data dev/console.cc: little hack to append name() to the file so that we can easily get multiple output files. dev/console.hh: TRACING_ON == 1 not defined(TRACING_ON) --HG-- extra : convert_revision : bbe80715fb97ee4c4ed6b484955ef71289f09fc9
Diffstat (limited to 'base')
-rw-r--r--base/circlebuf.cc212
-rw-r--r--base/circlebuf.hh43
2 files changed, 142 insertions, 113 deletions
diff --git a/base/circlebuf.cc b/base/circlebuf.cc
index 77da26da6..7bd488ef8 100644
--- a/base/circlebuf.cc
+++ b/base/circlebuf.cc
@@ -40,148 +40,174 @@
using namespace std;
CircleBuf::CircleBuf(int l)
- : rollover(false), buflen(l), size(0), start(0), stop(0)
-{ buf = new char[buflen]; }
+ : _rollover(false), _buflen(l), _size(0), _start(0), _stop(0)
+{
+ _buf = new char[_buflen];
+}
CircleBuf::~CircleBuf()
-{ if (buf) delete [] buf; }
+{
+ if (_buf)
+ delete [] _buf;
+}
void
CircleBuf::dump()
{
- cprintf("start = %10d, stop = %10d, buflen = %10d\n", start, stop, buflen);
- fflush(stdout);
- ::write(STDOUT_FILENO, buf, buflen);
- ::write(STDOUT_FILENO, "<\n", 2);
+ cprintf("start = %10d, stop = %10d, buflen = %10d\n",
+ _start, _stop, _buflen);
+ fflush(stdout);
+ ::write(STDOUT_FILENO, _buf, _buflen);
+ ::write(STDOUT_FILENO, "<\n", 2);
}
void
CircleBuf::flush()
{
- start = 0;
- stop = 0;
- rollover = false;
+ _start = 0;
+ _stop = 0;
+ _rollover = false;
}
void
CircleBuf::read(char *b, int len)
{
- size -= len;
- if (size < 0)
- size = 0;
-
- if (stop > start) {
- len = min(len, stop - start);
- memcpy(b, buf + start, len);
- start += len;
- }
- else {
- int endlen = buflen - start;
- if (endlen > len) {
- memcpy(b, buf + start, len);
- start += len;
+ _size -= len;
+ if (_size < 0)
+ _size = 0;
+
+ if (_stop > _start) {
+ len = min(len, _stop - _start);
+ memcpy(b, _buf + _start, len);
+ _start += len;
}
else {
- memcpy(b, buf + start, endlen);
- start = min(len - endlen, stop);
- memcpy(b + endlen, buf, start);
+ int endlen = _buflen - _start;
+ if (endlen > len) {
+ memcpy(b, _buf + _start, len);
+ _start += len;
+ }
+ else {
+ memcpy(b, _buf + _start, endlen);
+ _start = min(len - endlen, _stop);
+ memcpy(b + endlen, _buf, _start);
+ }
}
- }
}
void
CircleBuf::read(int fd, int len)
{
- size -= len;
- if (size < 0)
- size = 0;
-
- if (stop > start) {
- len = min(len, stop - start);
- ::write(fd, buf + start, len);
- start += len;
- }
- else {
- int endlen = buflen - start;
- if (endlen > len) {
- ::write(fd, buf + start, len);
- start += len;
+ _size -= len;
+ if (_size < 0)
+ _size = 0;
+
+ if (_stop > _start) {
+ len = min(len, _stop - _start);
+ ::write(fd, _buf + _start, len);
+ _start += len;
}
else {
- ::write(fd, buf + start, endlen);
- start = min(len - endlen, stop);
- ::write(fd, buf, start);
+ int endlen = _buflen - _start;
+ if (endlen > len) {
+ ::write(fd, _buf + _start, len);
+ _start += len;
+ }
+ else {
+ ::write(fd, _buf + _start, endlen);
+ _start = min(len - endlen, _stop);
+ ::write(fd, _buf, _start);
+ }
}
- }
}
void
CircleBuf::read(int fd)
{
- size = 0;
+ _size = 0;
+
+ if (_stop > _start) {
+ ::write(fd, _buf + _start, _stop - _start);
+ }
+ else {
+ ::write(fd, _buf + _start, _buflen - _start);
+ ::write(fd, _buf, _stop);
+ }
+
+ _start = _stop;
+}
+
+void
+CircleBuf::read(ostream &out)
+{
+ _size = 0;
- if (stop > start) {
- ::write(fd, buf + start, stop - start);
- }
- else {
- ::write(fd, buf + start, buflen - start);
- ::write(fd, buf, stop);
- }
+ if (_stop > _start) {
+ out.write(_buf + _start, _stop - _start);
+ }
+ else {
+ out.write(_buf + _start, _buflen - _start);
+ out.write(_buf, _stop);
+ }
- start = stop;
+ _start = _stop;
}
void
CircleBuf::readall(int fd)
{
- if (rollover)
- ::write(fd, buf + stop, buflen - stop);
+ if (_rollover)
+ ::write(fd, _buf + _stop, _buflen - _stop);
- ::write(fd, buf, stop);
- start = stop;
+ ::write(fd, _buf, _stop);
+ _start = _stop;
}
void
CircleBuf::write(char b)
-{ write(&b, 1); }
+{
+ write(&b, 1);
+}
void
CircleBuf::write(const char *b)
-{ write(b, strlen(b)); }
+{
+ write(b, strlen(b));
+}
void
CircleBuf::write(const char *b, int len)
{
- if (len <= 0)
- return;
-
- size += len;
- if (size > buflen)
- size = buflen;
-
- int old_start = start;
- int old_stop = stop;
-
- if (len >= buflen) {
- start = 0;
- stop = buflen;
- rollover = true;
- memcpy(buf, b + (len - buflen), buflen);
- return;
- }
-
- if (stop + len <= buflen) {
- memcpy(buf + stop, b, len);
- stop += len;
- } else {
- int end_len = buflen - old_stop;
- stop = len - end_len;
- memcpy(buf + old_stop, b, end_len);
- memcpy(buf, b + end_len, stop);
- rollover = true;
- }
-
- if (old_start > old_stop && old_start < stop ||
- old_start < old_stop && stop < old_stop)
- start = stop + 1;
+ if (len <= 0)
+ return;
+
+ _size += len;
+ if (_size > _buflen)
+ _size = _buflen;
+
+ int old_start = _start;
+ int old_stop = _stop;
+
+ if (len >= _buflen) {
+ _start = 0;
+ _stop = _buflen;
+ _rollover = true;
+ memcpy(_buf, b + (len - _buflen), _buflen);
+ return;
+ }
+
+ if (_stop + len <= _buflen) {
+ memcpy(_buf + _stop, b, len);
+ _stop += len;
+ } else {
+ int end_len = _buflen - old_stop;
+ _stop = len - end_len;
+ memcpy(_buf + old_stop, b, end_len);
+ memcpy(_buf, b + end_len, _stop);
+ _rollover = true;
+ }
+
+ if (old_start > old_stop && old_start < _stop ||
+ old_start < old_stop && _stop < old_stop)
+ _start = _stop + 1;
}
diff --git a/base/circlebuf.hh b/base/circlebuf.hh
index e0abed31c..168158bb7 100644
--- a/base/circlebuf.hh
+++ b/base/circlebuf.hh
@@ -29,31 +29,34 @@
#ifndef __CIRCLEBUF_HH__
#define __CIRCLEBUF_HH__
+#include <iosfwd>
class CircleBuf
{
-protected:
- char *buf;
- bool rollover;
- int buflen;
- int size;
- int start;
- int stop;
+ protected:
+ char *_buf;
+ bool _rollover;
+ int _buflen;
+ int _size;
+ int _start;
+ int _stop;
-public:
- explicit CircleBuf(int l);
- ~CircleBuf();
+ public:
+ explicit CircleBuf(int l);
+ ~CircleBuf();
- bool empty() { return size == 0; }
- void dump();
- void flush();
- void read(char *b, int len);
- void read(int fd, int len);
- void read(int fd);
- void readall(int fd);
- void write(char b);
- void write(const char *b);
- void write(const char *b, int len);
+ bool empty() const { return _size == 0; }
+ int size() const { return _size; }
+ void dump();
+ void flush();
+ void read(char *b, int len);
+ void read(int fd, int len);
+ void read(int fd);
+ void read(std::ostream &out);
+ void readall(int fd);
+ void write(char b);
+ void write(const char *b);
+ void write(const char *b, int len);
};
#endif // __CIRCLEBUF_HH__