diff options
author | bd <bdunahu@operationnull.com> | 2025-03-10 22:07:36 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-03-10 22:07:36 -0400 |
commit | 85078b99e4cf652fcbd5f4d36b061674a2fe8aa6 (patch) | |
tree | 1e3097ec91c7fcd7fc9d00f912b46814900201f0 /src/storage/dram.cc | |
parent | 25d6d41af95cc2a2db3ba2651e5d784413c7058f (diff) |
overload << operator for dram
Diffstat (limited to 'src/storage/dram.cc')
-rw-r--r-- | src/storage/dram.cc | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/storage/dram.cc b/src/storage/dram.cc index 441f10b..5c6d719 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -1,7 +1,11 @@ #include "dram.h" #include "definitions.h" #include "response.h" +#include <bits/stdc++.h> #include <algorithm> +#include <bitset> +#include <iostream> +#include <iterator> Dram::Dram(int lines, int delay) { @@ -70,3 +74,28 @@ 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); + + cout << data.capacity(); + os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX" + << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << '\n'; + 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 << '\n'; + } + + std::cout.flags(default_flags); + std::cout.fill(default_fill); + return os; +} |