diff options
Diffstat (limited to 'inc')
-rw-r--r-- | inc/controller.h | 9 | ||||
-rw-r--r-- | inc/dum.h | 28 | ||||
-rw-r--r-- | inc/ex.h | 4 | ||||
-rw-r--r-- | inc/id.h | 8 | ||||
-rw-r--r-- | inc/if.h | 9 | ||||
-rw-r--r-- | inc/mm.h | 4 | ||||
-rw-r--r-- | inc/stage.h | 12 | ||||
-rw-r--r-- | inc/wb.h | 6 |
8 files changed, 57 insertions, 23 deletions
diff --git a/inc/controller.h b/inc/controller.h index 1c7b2d6..17aba37 100644 --- a/inc/controller.h +++ b/inc/controller.h @@ -1,8 +1,8 @@ #ifndef CONTROLLER_H #define CONTROLLER_H +#include "instrDTO.h" #include "response.h" #include "stage.h" -#include "instrDTO.h" /** * Houses the clock, and acts as the main API to the GUI. @@ -18,7 +18,8 @@ class Controller : public Stage * @return A newly allocated controller object. */ Controller(Stage *stage, Storage *storage, bool is_pipelined); - + InstrDTO *advance(Response p) override; + /** * Direct the simulator to run for `number` clock cycles. * @param the number of clock cycles to run for. @@ -36,7 +37,9 @@ class Controller : public Stage * @return the pc. */ int get_pc(); - InstrDTO *advance(Response p) override; + + private: + void advance_helper() override; }; #endif /* CONTROLLER_H_INCLUDED */ diff --git a/inc/dum.h b/inc/dum.h new file mode 100644 index 0000000..da64b9d --- /dev/null +++ b/inc/dum.h @@ -0,0 +1,28 @@ +#ifndef DUM_H +#define DUM_H +#include "instrDTO.h" +#include "response.h" +#include "stage.h" + +/** + * Don't underestimate mocks (the DUM pipe stage). + */ +class DUM : public Stage +{ + public: + /** + * Constructor. + * @param The next stage in the pipeline. + * @return A newly allocated DUM object. + */ + DUM(Stage *next); + + InstrDTO *advance(Response p) override; + + void set_curr_instr(InstrDTO *); + + private: + void advance_helper() override; +}; + +#endif /* DUM_H_INCLUDED */ @@ -14,10 +14,10 @@ class EX : public Stage * @return A newly allocated EX object. */ EX(Stage *next); - - InstrDTO *advance(Response p) override; + using Stage::advance; private: + void advance_helper(); /** * Maps each mnemonic to a function which carries out the instruction's base * logic. @@ -14,8 +14,7 @@ class ID : public Stage * @return A newly allocated ID object. */ ID(Stage *next); - - InstrDTO *advance(Response p) override; + using Stage::advance; /* The following methods are made public so that they may be tested, and are * not to be called from outside classes during standard execution. @@ -56,10 +55,7 @@ class ID : public Stage void write_guard(signed int &r); private: - /** - * Decodes `curr_instr` and sets status to BLOCKED if a data hazard occurs. - */ - void advance_helper(); + void advance_helper() override; /** * Helper for `get_instr_fields` * Attempts to parse and dereference instruction arguments. Uses read and @@ -18,14 +18,7 @@ class IF : public Stage InstrDTO *advance(Response p) override; private: - /** - * Performs a fetch only if a current fetch is not pending. Pending means - * that a fetch has completed successfully, but the caller stage in the - * pipeline is not ready to receive it. In this case, `curr_instr` is not - * the nullptr. - * @return STALLED if we are waiting on the storage devices, OK otherwise. - */ - void advance_helper(); + void advance_helper() override; }; #endif /* IF_H_INCLUDED */ @@ -13,8 +13,10 @@ class MM : public Stage * @return A newly allocated MM object. */ MM(Stage *next); + using Stage::advance; - InstrDTO *advance(Response p) override; + private: + void advance_helper() override; }; #endif /* MM_H_INCLUDED */ diff --git a/inc/stage.h b/inc/stage.h index c0dc6a8..56a3589 100644 --- a/inc/stage.h +++ b/inc/stage.h @@ -28,16 +28,26 @@ class Stage virtual ~Stage(); /** * Advances this stage by a single clock cycle. + * A boilerplate version is provided in stage.cc. + * * @param a DTO object containing the next instruction to be processed. * @param a response, indicating whether or not the parent pipe stage is * ready to accept a new instruction object next cycle. * @return a response, indicating whether this pipeline stage is stalling, * busy, or done. + * + * Must set the status to STALLED when an operation completes. */ - virtual InstrDTO *advance(Response p) = 0; + virtual InstrDTO *advance(Response p); protected: /** + * The function expected to do the majority of the work. + * + * Must set the status to OK when an operation is ready. + */ + virtual void advance_helper() = 0; + /** * Sets the bit in the condition code register corresponding to `c`. * @param the condition code to set. * @param the truthy value to set it to. @@ -13,8 +13,10 @@ class WB : public Stage * @return A newly allocated WB object. */ WB(Stage *next); - - InstrDTO *advance(Response p) override; + using Stage::advance; + + private: + void advance_helper() override; }; #endif /* WB_H_INCLUDED */ |