From 4dbe50416eea0fecc2aa6f5ce3dc7032c95234c5 Mon Sep 17 00:00:00 2001 From: bd Date: Mon, 10 Mar 2025 19:42:01 -0400 Subject: CLI view, clock, store, program banner --- src/cli/cli.cc | 65 +++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 26 deletions(-) (limited to 'src/cli') diff --git a/src/cli/cli.cc b/src/cli/cli.cc index d1631b4..a5706fb 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -2,20 +2,20 @@ #include "cache.h" #include "definitions.h" #include "dram.h" +#include "response.h" #include #include #include Cli::Cli() { - Dram *d = new Dram(MEM_SIZE, MEM_DELAY); - this->cache = new Cache(d, L1_CACHE_DELAY); + this->initialize(); commands["l"] = [this](std::vector args) { if (args.size() >= 1) { try { load(std::stoi(args[0])); - } catch (const std::exception &e) { + } catch (const std::invalid_argument &e) { std::cerr << "Invalid input: " << e.what() << std::endl; } } else { @@ -25,10 +25,17 @@ Cli::Cli() }; commands["s"] = [this](std::vector args) { - if (args.size() >= 2) { + Accessor a; + if (args.size() >= 3) { try { - store(std::stoi(args[0]), std::stoi(args[1])); - } catch (const std::exception &e) { + if (tolower(args[0][0]) == 'f') + a = FETCH; + else if (tolower(args[0][0]) == 'm') + a = MEM; + else + throw std::invalid_argument(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 { @@ -42,12 +49,11 @@ Cli::Cli() return; }; - commands["v"] = [this](std::vector args) { - if (args.size() >= 3) { + commands["p"] = [this](std::vector args) { + if (args.size() >= 1) { try { - view( - std::stoi(args[0]), std::stoi(args[1]), std::stoi(args[2])); - } catch (const std::exception &e) { + peek(std::stoi(args[0])); + } catch (const std::invalid_argument &e) { std::cerr << "Invalid input: " << e.what() << std::endl; } } else { @@ -56,6 +62,11 @@ Cli::Cli() return; }; + commands["c"] = [this](std::vector args) { + clock(); + return; + }; + commands["h"] = [this](std::vector args) { help(); return; @@ -68,16 +79,17 @@ void Cli::help() { std::cout << "Available commands:\n" - << " l - Load data from memory at the specified " + << " l
- Load data from memory at the specified " "address\n" - << " s - Stores data into " - "memory at specified address\n" + << " s
- Stores data into memory at " + "specified address. Accessor must be one of: \"MEM\", \"FETCH\", " + "\"L1CACHE\".\n" << " c - manually advances the clock\n" << " r - side door function that resets the memory configuration and " "cycles\n" - << " u - side door function that updates " + << " u
- side door function that updates " "the memory at the specified address with data provided\n" - << " v - side door function that views " + << " p - side door function that peeks " "the current status of the entire memory subsystem\n" << " h - Prints this help text\n" << " q - Quits the program\n"; @@ -88,10 +100,10 @@ void Cli::load(int memory_address) std::cout << "Loading data from memory address " << memory_address; } -void Cli::store(int memory_address, int data) +void Cli::store(Accessor accessor, int data, int address) { - std::cout << "Storing " << data << " into memory address " - << memory_address; + Response r = this->cache->write(accessor, data, address); + std::cout << r << " to " << accessor << " storing " << data << '\n'; } void Cli::update(int memory_address, int data) @@ -99,17 +111,15 @@ void Cli::update(int memory_address, int data) std::cout << "Resetting memory configuration and cycles.\n"; }; -void Cli::clock() -{ - std::cout << "Resetting memory configuration and cycles.\n"; -} +void Cli::clock() { this->cache->resolve(); } void Cli::reset() { - std::cout << "Resetting memory configuration and cycles.\n"; + this->initialize(); + std::cout << "Done.\n"; } -void Cli::view(int level, int base, int lines) +void Cli::peek(int level) { Storage *curr = this->cache; for (int i = 0; i < level; ++i) { @@ -166,6 +176,9 @@ void Cli::run() void Cli::initialize() { - if (this->cache) + std::cout << "Resetting memory configuration.\n"; + if (this->cache == nullptr) delete this->cache; + Dram *d = new Dram(MEM_SIZE, MEM_DELAY); + this->cache = new Cache(d, L1_CACHE_DELAY); } -- cgit v1.2.3