diff options
author | bd <bdunahu@operationnull.com> | 2025-04-11 21:14:25 -0400 |
---|---|---|
committer | bd <bdunahu@operationnull.com> | 2025-04-11 21:14:25 -0400 |
commit | 101f0facf8002907ca6e19faabfdcf472c0c3152 (patch) | |
tree | f5cdc59276f18428a02db3898be6ccf23753c349 /src | |
parent | 1b5a73c67f9eaaf73e5046f52c48105579a7dae4 (diff) |
Move source files to top-level src directory
Diffstat (limited to 'src')
-rw-r--r-- | src/accessor.cc (renamed from src/utils/accessor.cc) | 0 | ||||
-rw-r--r-- | src/cache.cc (renamed from src/storage/cache.cc) | 0 | ||||
-rw-r--r-- | src/cli/cli.cc | 214 | ||||
-rw-r--r-- | src/dram.cc (renamed from src/storage/dram.cc) | 0 | ||||
-rw-r--r-- | src/logger.cc (renamed from src/logger/logger.cc) | 0 | ||||
-rw-r--r-- | src/response.cc (renamed from src/utils/response.cc) | 0 | ||||
-rw-r--r-- | src/storage.cc (renamed from src/storage/storage.cc) | 0 | ||||
-rw-r--r-- | src/utils.cc (renamed from src/utils/utils.cc) | 0 |
8 files changed, 0 insertions, 214 deletions
diff --git a/src/utils/accessor.cc b/src/accessor.cc index 99347ed..99347ed 100644 --- a/src/utils/accessor.cc +++ b/src/accessor.cc diff --git a/src/storage/cache.cc b/src/cache.cc index 80f59ef..80f59ef 100644 --- a/src/storage/cache.cc +++ b/src/cache.cc diff --git a/src/cli/cli.cc b/src/cli/cli.cc deleted file mode 100644 index 58575cb..0000000 --- a/src/cli/cli.cc +++ /dev/null @@ -1,214 +0,0 @@ -#include "cli.h" -#include "cache.h" -#include "definitions.h" -#include "dram.h" -#include "response.h" -#include "accessor.h" -#include "utils.h" -#include <iostream> - -Cli::Cli() -{ - this->cache = nullptr; - this->cycle = 0; - this->initialize(); - - commands['l'] = [this](std::vector<std::string> args) { - Accessor a; - if (args.size() >= 2) { - try { - a = match_accessor_or_die(args[0]); - load(a, std::stoi(args[1])); - } catch (const std::invalid_argument &e) { - std::cerr << "Invalid input: " << e.what() << std::endl; - } - } else { - std::cout << "Usage: l <memory-address>\n"; - } - return; - }; - - commands['s'] = [this](std::vector<std::string> args) { - Accessor a; - if (args.size() >= 3) { - try { - a = match_accessor_or_die(args[0]); - store(a, std::stoi(args[1]), std::stoi(args[2])); - } catch (const std::invalid_argument &e) { - std::cerr << "Invalid input: " << e.what() << std::endl; - } - } else { - std::cout << "Usage: s <memory-address> <data>\n"; - } - return; - }; - - commands['r'] = [this](std::vector<std::string> args) { - (void)args; - reset(); - return; - }; - - commands['p'] = [this](std::vector<std::string> args) { - if (args.size() >= 1) { - try { - peek(std::stoi(args[0])); - } catch (const std::invalid_argument &e) { - std::cerr << "Invalid input: " << e.what() << std::endl; - } - } else { - std::cout << "Usage: v <storage-level> <base> <lines>\n"; - } - return; - }; - - commands['h'] = [this](std::vector<std::string> args) { - (void)args; - help(); - return; - }; -} - -Cli::~Cli() { delete this->cache; } - -void Cli::help() -{ - std::cout - << "Available commands:" << std::endl - << " [l]oad <address> - Load data from memory at the specified " - "address" - << std::endl - << " [s]tore <accessor> <data> <address> - Stores data into memory at " - "specified address. Acessor must be one of: [f]etch, [m]em" - << " [p]eek <storage-level> <base> <lines> - side door function that " - "peeks the current status of the entire memory subsystem" - << std::endl - << " [r]eset - side door function that resets the memory " - "configuration and " - "cycles" - << std::endl - << " [h]elp - prints this help text" << std::endl - << " [q]uit - quits the program" << std::endl; -} - -void Cli::load(Accessor accessor, int address) -{ - address = wrap_address(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 << " Got: " << std::hex << data << std::endl; - - std::cout.flags(default_flags); - std::cout.fill(default_fill); -} - -void Cli::store(Accessor accessor, int data, int address) -{ - address = wrap_address(address); - Response r = this->cache->write_word(accessor, data, address); - std::cout << r << " to " << accessor << " storing " << data << " in " - << address << std::endl; -} - -void Cli::reset() -{ - this->initialize(); - std::cout << "Done." << std::endl; -} - -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." - << std::endl; - return; - } - curr = curr->get_lower(); - } - - Cache *c = dynamic_cast<Cache *>(curr); - if (c) { - std::cout << *c << std::endl; - } else { - std::cout << *dynamic_cast<Dram *>(curr) << std::endl; - ; - } -} - -void Cli::run() -{ - std::cout << "Memory Command Processor Started. Type 'h' for a list of " - "commands." - << std::endl; - std::string input; - - bool run = true; - while (run) { - std::cout << this->cycle << "> "; - std::getline(std::cin, input); - - std::istringstream iss1(input); - std::vector<std::string> words; - std::string sentence; - std::string word; - - while (std::getline(iss1, sentence, ';')) { - words.clear(); - std::istringstream iss2(sentence); - - while (iss2 >> word) { - words.push_back(word); - } - if (words.empty()) - continue; - - std::string command = words[0]; - words.erase(words.begin()); - - if (command == "q") { - run = false; - break; - } - - auto it = commands.find(tolower(command[0])); - if (it != commands.end()) { - it->second(words); - } else { - std::cout << "Unknown command: '" << command - << "'. Type 'help' for available commands." - << std::endl; - } - } - } -} - -void Cli::initialize() -{ - Logger *global_log = Logger::getInstance(); - - global_log->log(INFO, "Resetting memory configuration and cycle."); - - if (this->cache != nullptr) - delete this->cache; - - Dram *d = new Dram(MEM_DELAY); - this->cache = new Cache(d, L1_CACHE_DELAY); - this->cycle = 1; -} - -Accessor Cli::match_accessor_or_die(std::string s) -{ - if (tolower(s[0]) == 'f') - return FETCH; - else if (tolower(s[0]) == 'm') - return MEM; - else - throw std::invalid_argument(s); -} diff --git a/src/storage/dram.cc b/src/dram.cc index f90f8db..f90f8db 100644 --- a/src/storage/dram.cc +++ b/src/dram.cc diff --git a/src/logger/logger.cc b/src/logger.cc index b07e66f..b07e66f 100644 --- a/src/logger/logger.cc +++ b/src/logger.cc diff --git a/src/utils/response.cc b/src/response.cc index 3d6e439..3d6e439 100644 --- a/src/utils/response.cc +++ b/src/response.cc diff --git a/src/storage/storage.cc b/src/storage.cc index fed607b..fed607b 100644 --- a/src/storage/storage.cc +++ b/src/storage.cc diff --git a/src/utils/utils.cc b/src/utils.cc index e12a0e0..e12a0e0 100644 --- a/src/utils/utils.cc +++ b/src/utils.cc |