From e8fbf581f70a899a26f71e4b2220dccd1b986ed8 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 10 Mar 2025 22:07:36 -0400 Subject: overload << operator for dram --- inc/dram.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'inc/dram.h') diff --git a/inc/dram.h b/inc/dram.h index 20221b7..e8d3573 100644 --- a/inc/dram.h +++ b/inc/dram.h @@ -1,5 +1,7 @@ #ifndef DRAM_H #define DRAM_H +#include "definitions.h" +#include #include class Dram : public Storage @@ -16,9 +18,12 @@ class Dram : public Storage ~Dram(); Response write(Accessor accessor, signed int data, int address) override; - Response read(Accessor accessor, int address, std::array& data) override; + Response read( + Accessor accessor, + int address, + std::array &data) override; - private: + private: /** * Helper for `write`. */ @@ -26,8 +31,9 @@ class Dram : public Storage /** * Helper for `read`. */ - void do_read(std::array& data_line, int address); + void do_read(std::array &data_line, int address); }; -#endif /* DRAM_H_INCLUDED */ +std::ostream &operator<<(std::ostream &os, const Dram &d); +#endif /* DRAM_H_INCLUDED */ -- cgit v1.2.3 From acb0bc357a9dfe6d89321d127b72693031435e65 Mon Sep 17 00:00:00 2001 From: bd Date: Tue, 11 Mar 2025 10:50:11 -0400 Subject: fix namespace issues with match function --- inc/dram.h | 2 +- src/cli/cli.cc | 42 +++++++++++++++++++++++++++++------------- src/main.cc | 3 --- src/storage/cache.cc | 4 ++-- src/storage/dram.cc | 10 +++++----- 5 files changed, 37 insertions(+), 24 deletions(-) (limited to 'inc/dram.h') diff --git a/inc/dram.h b/inc/dram.h index e8d3573..2d4088f 100644 --- a/inc/dram.h +++ b/inc/dram.h @@ -1,8 +1,8 @@ #ifndef DRAM_H #define DRAM_H #include "definitions.h" +#include "storage.h" #include -#include class Dram : public Storage { diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 033849e..0729e00 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -82,6 +82,9 @@ void Cli::help() << std::endl << " [s]tore
- Stores data into memory at " "specified address. Acessor must be one of: [f]etch, [m]em" + << " [p]eek - side door function that " + "peeks the current status of the entire memory subsystem" + << std::endl << std::endl << " [c]ycle - manually advances the clock" << std::endl << " [f]orce - advances the clock until one operation reports " @@ -91,19 +94,30 @@ void Cli::help() "configuration and " "cycles" << std::endl - << " [p]eek - side door function that " - "peeks the current status of the entire memory subsystem" - << std::endl - << " [h]elp - Prints this help text" << std::endl - << " [q]uit - Quits the program" << std::endl; + << " [h]elp - prints this help text" << std::endl + << " [q]uit - quits the program" << std::endl; } -void Cli::load(Accessor accessor, int address) { ; } +void Cli::load(Accessor accessor, int address) +{ + const auto default_flags = std::cout.flags(); + const auto default_fill = std::cout.fill(); + + signed int data; + // Response r = this->cache->read_word(accessor, address, data); + // std::cout << r << " to " << accessor << " reading " << address << std::endl; + // if (r == OK) + // std::cout << "\tGot:" << std::hex << data; + + std::cout.flags(default_flags); + std::cout.fill(default_fill); +} void Cli::store(Accessor accessor, int data, int address) { Response r = this->cache->write(accessor, data, address); - std::cout << r << " to " << accessor << " storing " << data << '\n'; + std::cout << r << " to " << accessor << " storing " << data << " in" + << address << std::endl; } void Cli::clock() @@ -115,7 +129,7 @@ void Cli::clock() void Cli::reset() { this->initialize(); - std::cout << "Done.\n"; + std::cout << "Done." << std::endl; } void Cli::peek(int level) @@ -123,7 +137,8 @@ void Cli::peek(int level) Storage *curr = this->cache; for (int i = 0; i < level; ++i) { if (!curr) { - std::cerr << "Level " << level << " of storage does not exist.\n"; + std::cerr << "Level " << level << " of storage does not exist." + << std::endl; return; } curr = curr->get_lower(); @@ -131,9 +146,9 @@ void Cli::peek(int level) Cache *c = dynamic_cast(curr); if (c) { - std::cout << *c; + std::cout << *c << std::endl; } else { - std::cout << *dynamic_cast(curr); + std::cout << *dynamic_cast(curr) << std::endl; ; } } @@ -141,7 +156,8 @@ void Cli::peek(int level) void Cli::run() { std::cout << "Memory Command Processor Started. Type 'h' for a list of " - "commands.\n"; + "commands." + << std::endl; std::string input; bool run = true; @@ -198,7 +214,7 @@ void Cli::initialize() this->cycle = 1; } -Accessor match_accessor_or_die(std::string s) +Accessor Cli::match_accessor_or_die(std::string s) { if (tolower(s[0]) == 'f') return FETCH; diff --git a/src/main.cc b/src/main.cc index 1259729..08b38e6 100644 --- a/src/main.cc +++ b/src/main.cc @@ -53,9 +53,6 @@ static void parseArguments(int argc, char **argv, bool &python) global_log->log(INFO, "Python will NOT be started!"); python = false; break; - case 'v': - print_version_number(); - exit(EXIT_SUCCESS); default: err(); exit(EXIT_FAILURE); diff --git a/src/storage/cache.cc b/src/storage/cache.cc index d382c3d..1a8a10b 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -104,7 +104,7 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << " | " << std::setfill(' ') << std::setw(MEM_SPEC - LINE_SPEC - L1_CACHE_SPEC + 2) << "TAG" - << " | D\n"; + << " | D" << std::endl; for (int i = 0; i < L1_CACHE_SIZE; ++i) { os << " 0b" << std::setw(L1_CACHE_SPEC) << std::bitset(i) << " | "; @@ -114,7 +114,7 @@ std::ostream &operator<<(std::ostream &os, const Cache &c) } os << "| 0x" << std::setfill(' ') << std::bitset(meta.at(i)[0]) - << " | " << (int)(meta.at(i)[0] >= 0) << '\n'; + << " | " << (int)(meta.at(i)[0] >= 0) << std::endl; } std::cout.flags(default_flags); diff --git a/src/storage/dram.cc b/src/storage/dram.cc index 7353bce..e755c2a 100644 --- a/src/storage/dram.cc +++ b/src/storage/dram.cc @@ -1,8 +1,8 @@ #include "dram.h" #include "definitions.h" #include "response.h" -#include #include +#include #include #include #include @@ -80,18 +80,18 @@ 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> data = - d.view(0, MEM_SIZE); + std::vector> data = d.view(0, MEM_SIZE); os << " " << std::setfill(' ') << std::setw(MEM_SPEC + 2) << "INDEX" - << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA" << '\n'; + << " | " << 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(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'; + os << std::endl; } std::cout.flags(default_flags); -- cgit v1.2.3