summaryrefslogtreecommitdiff
path: root/src/storage/dram.cc
diff options
context:
space:
mode:
authorSiddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com>2025-03-11 11:28:25 -0400
committerGitHub <noreply@github.com>2025-03-11 11:28:25 -0400
commite24e3cd4d296599b9ef1b705846b1c868148b0fd (patch)
tree25646d98b4bfcf4b9a664eabfc2651c481984c1d /src/storage/dram.cc
parent357e7fb37caf58cdfcdf85f7553db9378ff16e0c (diff)
parentfde996690d77b81e445450671a0723f837de4eb3 (diff)
Merge pull request #23 from bdunahu/bdunahu
Memory simulator CLI function implementation
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r--src/storage/dram.cc28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc
index 441f10b..e755c2a 100644
--- a/src/storage/dram.cc
+++ b/src/storage/dram.cc
@@ -2,6 +2,10 @@
#include "definitions.h"
#include "response.h"
#include <algorithm>
+#include <bits/stdc++.h>
+#include <bitset>
+#include <iostream>
+#include <iterator>
Dram::Dram(int lines, int delay)
{
@@ -70,3 +74,27 @@ Response Dram::read(
return r;
}
+
+std::ostream &operator<<(std::ostream &os, const Dram &d)
+{
+ const auto default_flags = std::cout.flags();
+ const auto default_fill = std::cout.fill();
+
+ std::vector<std::array<signed int, LINE_SIZE>> data = d.view(0, MEM_SIZE);
+
+ os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX"
+ << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA"
+ << std::endl;
+ for (int i = 0; i < MEM_SIZE; ++i) {
+ os << " 0b" << std::setw(MEM_SPEC) << std::bitset<MEM_SPEC>(i) << " | ";
+ for (int j = 0; j < LINE_SIZE; ++j) {
+ os << "0x" << std::setfill('0') << std::setw(8) << std::hex
+ << data.at(i).at(j) << ' ';
+ }
+ os << std::endl;
+ }
+
+ std::cout.flags(default_flags);
+ std::cout.fill(default_fill);
+ return os;
+}