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 | e8fbf581f70a899a26f71e4b2220dccd1b986ed8 (patch) | |
| tree | 1e3097ec91c7fcd7fc9d00f912b46814900201f0 | |
| parent | af103123a90eaf34437b7979eee2579bab8b4b36 (diff) | |
overload << operator for dram
| -rw-r--r-- | inc/cache.h | 2 | ||||
| -rw-r--r-- | inc/definitions.h | 2 | ||||
| -rw-r--r-- | inc/dram.h | 14 | ||||
| -rw-r--r-- | src/cli/cli.cc | 10 | ||||
| -rw-r--r-- | src/main.cc | 4 | ||||
| -rw-r--r-- | src/storage/cache.cc | 1 | ||||
| -rw-r--r-- | src/storage/dram.cc | 29 | 
7 files changed, 50 insertions, 12 deletions
| diff --git a/inc/cache.h b/inc/cache.h index 0c9b3d7..04f6181 100644 --- a/inc/cache.h +++ b/inc/cache.h @@ -50,6 +50,6 @@ class Cache : public Storage  	std::array<std::array<int, 2>, L1_CACHE_SIZE> meta;  }; -std::ostream &operator<<(std::ostream &os, const Cache &a); +std::ostream &operator<<(std::ostream &os, const Cache &c);  #endif /* CACHE_H_INCLUDED */ diff --git a/inc/definitions.h b/inc/definitions.h index 98c4575..62ed0f6 100644 --- a/inc/definitions.h +++ b/inc/definitions.h @@ -16,7 +16,7 @@   * The number of bits to specify a memory line   * calculated as: (/ (expt 2 15) 4)   */ -#define MEM_SPEC 13 +#define MEM_SPEC 8  /**   * The total number of words in memory   */ @@ -1,5 +1,7 @@  #ifndef DRAM_H  #define DRAM_H +#include "definitions.h" +#include <ostream>  #include <storage.h>  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<signed int, LINE_SIZE>& data) override; +	Response read( +		Accessor accessor, +		int address, +		std::array<signed int, LINE_SIZE> &data) override; -	private: +  private:  	/**  	 * Helper for `write`.  	 */ @@ -26,8 +31,9 @@ class Dram : public Storage  	/**  	 * Helper for `read`.  	 */ -	void do_read(std::array<signed int, LINE_SIZE>& data_line, int address); +	void do_read(std::array<signed int, LINE_SIZE> &data_line, int address);  }; -#endif /* DRAM_H_INCLUDED */ +std::ostream &operator<<(std::ostream &os, const Dram &d); +#endif /* DRAM_H_INCLUDED */ diff --git a/src/cli/cli.cc b/src/cli/cli.cc index 2126798..e968a42 100644 --- a/src/cli/cli.cc +++ b/src/cli/cli.cc @@ -5,6 +5,8 @@  #include "response.h"  #include <stdio.h> +static Logger *global_log = Logger::getInstance(); +  Cli::Cli()  {  	this->initialize(); @@ -83,10 +85,9 @@ void Cli::help()  		   "specified address. Accessor must be one of: \"MEM\", \"FETCH\", "  		   "\"L1CACHE\".\n"  		<< "  c - manually advances the clock\n" +		<< "  f - advances the clock until one operation reports completion\n"  		<< "  r - side door function that resets the memory configuration and "  		   "cycles\n" -		<< "  u <address> <data> - side door function that updates " -		   "the memory at the specified address with data provided\n"  		<< "  p <storage-level> <base> <lines> - side door function that peeks "  		   "the current status of the entire memory subsystem\n"  		<< "  h - Prints this help text\n" @@ -129,7 +130,8 @@ void Cli::peek(int level)  	if (c) {  		std::cout << *c;  	} else { -		std::cout << "dram"; +		std::cout << *dynamic_cast<Dram *>(curr); +		;  	}  } @@ -173,7 +175,7 @@ void Cli::run()  void Cli::initialize()  {  	Logger *global_log = Logger::getInstance(); -	global_log->log(INFO, "Resetting memory configuration.\n"); +	global_log->log(INFO, "Resetting memory configuration.");  	if (this->cache == nullptr)  		delete this->cache;  	Dram *d = new Dram(MEM_SIZE, MEM_DELAY); diff --git a/src/main.cc b/src/main.cc index 8a24fdb..f2f416d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -4,6 +4,8 @@  #include <getopt.h>  #include <iostream> +static Logger *global_log = Logger::getInstance(); +  static std::string version_number = "v0.1";  static std::string banner =    "    _/_/_/    _/_/_/    _/_/_/    _/_/_/   \n" @@ -32,7 +34,6 @@ static void err()  static void parseArguments(int argc, char **argv, bool &python)  { -	Logger *global_log = Logger::getInstance();  	struct option long_options[] = {  		{"debug", no_argument, 0, 'd'},  		{"no-python", no_argument, 0, 'p'}, @@ -64,7 +65,6 @@ static void parseArguments(int argc, char **argv, bool &python)  int main(int argc, char **argv)  { -	Logger *global_log = Logger::getInstance();  	print_version_number();  	Cli cli;  	global_log->log(INFO, "Initializing..."); diff --git a/src/storage/cache.cc b/src/storage/cache.cc index d382c3d..6dd0b8a 100644 --- a/src/storage/cache.cc +++ b/src/storage/cache.cc @@ -100,6 +100,7 @@ std::ostream &operator<<(std::ostream &os, const Cache &c)  		c.view(0, L1_CACHE_SIZE);  	std::array<std::array<int, 2>, L1_CACHE_SIZE> meta = c.get_meta(); +	cout << data.capacity();  	os << " " << std::setfill(' ') << std::setw(L1_CACHE_SPEC + 2) << "INDEX"  	   << " | " << std::setfill(' ') << std::setw((8 + 3) * 4 - 1) << "DATA"  	   << " | " << std::setfill(' ') 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; +} | 
