summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/cache.cc8
-rw-r--r--src/dram.cc8
-rw-r--r--src/storage.cc13
3 files changed, 15 insertions, 14 deletions
diff --git a/src/cache.cc b/src/cache.cc
index ee4b00c..68047ed 100644
--- a/src/cache.cc
+++ b/src/cache.cc
@@ -58,13 +58,7 @@ Cache::read_word(void *id, int address, signed int &data)
int
Cache::process(void *id, int address, std::function<void(int index, int offset)> request_handler)
{
- if (id == nullptr)
- throw std::invalid_argument("Accessor cannot be nullptr.");
-
- if (this->current_request == nullptr)
- this->current_request = id;
-
- if (this->current_request != id)
+ if (!preprocess(id))
return 0;
if (is_address_missing(address))
diff --git a/src/dram.cc b/src/dram.cc
index 5e7e57a..bbd18b7 100644
--- a/src/dram.cc
+++ b/src/dram.cc
@@ -54,13 +54,7 @@ Dram::load(std::vector<signed int> program)
int
Dram::process(void *id, int address, std::function<void(int line, int word)> request_handler)
{
- if (id == nullptr)
- throw std::invalid_argument("Accessor cannot be nullptr.");
-
- if (this->current_request == nullptr)
- this->current_request = id;
-
- if (this->current_request != id)
+ if (!preprocess(id))
return 0;
if (!this->is_data_ready())
diff --git a/src/storage.cc b/src/storage.cc
index 17c902d..ee2e7e7 100644
--- a/src/storage.cc
+++ b/src/storage.cc
@@ -1,6 +1,7 @@
#include "storage.h"
#include "definitions.h"
#include <algorithm>
+#include <stdexcept>
Storage::Storage(int delay)
{
@@ -21,6 +22,18 @@ Storage::view(int base, int lines) const
}
int
+Storage::preprocess(void *id)
+{
+ if (id == nullptr)
+ throw std::invalid_argument("Accessor cannot be nullptr.");
+
+ if (this->current_request == nullptr)
+ this->current_request = id;
+
+ return this->current_request == id;
+}
+
+int
Storage::is_data_ready()
{
int r;