diff options
author | Siddarth Suresh <155843085+SiddarthSuresh98@users.noreply.github.com> | 2025-03-11 11:28:25 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-11 11:28:25 -0400 |
commit | e24e3cd4d296599b9ef1b705846b1c868148b0fd (patch) | |
tree | 25646d98b4bfcf4b9a664eabfc2651c481984c1d /src/utils | |
parent | 357e7fb37caf58cdfcdf85f7553db9378ff16e0c (diff) | |
parent | fde996690d77b81e445450671a0723f837de4eb3 (diff) |
Merge pull request #23 from bdunahu/bdunahu
Memory simulator CLI function implementation
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/accessor.cc | 8 | ||||
-rw-r--r-- | src/utils/response.cc | 8 | ||||
-rw-r--r-- | src/utils/utils.cc | 25 |
3 files changed, 38 insertions, 3 deletions
diff --git a/src/utils/accessor.cc b/src/utils/accessor.cc new file mode 100644 index 0000000..86484c5 --- /dev/null +++ b/src/utils/accessor.cc @@ -0,0 +1,8 @@ +#include "accessor.h" +#include <iostream> + +std::ostream &operator<<(std::ostream &os, Accessor a) +{ + const std::string nameA[] = {"IDLE", "MEM", "FETCH", "L1CACHE", "SIDE"}; + return os << nameA[a]; +} diff --git a/src/utils/response.cc b/src/utils/response.cc new file mode 100644 index 0000000..def6578 --- /dev/null +++ b/src/utils/response.cc @@ -0,0 +1,8 @@ +#include "response.h" +#include <iostream> + +std::ostream &operator<<(std::ostream &os, Response r) +{ + const std::string nameR[] = {"OK", "WAIT", "BLOCKED"}; + return os << nameR[r]; +} diff --git a/src/utils/utils.cc b/src/utils/utils.cc index dfeb2b3..5de8e89 100644 --- a/src/utils/utils.cc +++ b/src/utils/utils.cc @@ -1,11 +1,30 @@ #include "utils.h" #include "definitions.h" +#include <cstdarg> +#include <string> +#include <vector> void get_bit_fields(int address, int *tag, int *index, int *offset) { - *tag = - GET_MID_BITS(address, LINE_SPEC + L1_CACHE_SPEC, - MEM_SPEC + LINE_SPEC + L1_CACHE_SPEC); + *tag = GET_MID_BITS( + address, LINE_SPEC + L1_CACHE_SPEC, + MEM_SPEC + LINE_SPEC + L1_CACHE_SPEC); *index = GET_MID_BITS(address, LINE_SPEC, L1_CACHE_SPEC + LINE_SPEC); *offset = GET_LS_BITS(address, LINE_SPEC); } + +const std::string string_format(const char *const zcFormat, ...) +{ + va_list vaArgs; + va_start(vaArgs, zcFormat); + + va_list vaArgsCopy; + va_copy(vaArgsCopy, vaArgs); + const int iLen = std::vsnprintf(NULL, 0, zcFormat, vaArgsCopy); + va_end(vaArgsCopy); + + std::vector<char> zc(iLen + 1); + std::vsnprintf(zc.data(), zc.size(), zcFormat, vaArgs); + va_end(vaArgs); + return std::string(zc.data(), iLen); +} |