From 45581d3d376e8deed84952cb838ae330549e5241 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 12 May 2009 23:18:17 +0200 Subject: my cpu design --- ue3/mycpu/cinstruction.h | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 ue3/mycpu/cinstruction.h (limited to 'ue3/mycpu/cinstruction.h') diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h new file mode 100644 index 0000000..b16c067 --- /dev/null +++ b/ue3/mycpu/cinstruction.h @@ -0,0 +1,98 @@ +/** + * @module cinstruction + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief TODO + * @date 10.05.2009 + */ + +#ifndef CINSTRUCTION_H +#define CINSTRUCTION_H 1 + +#include +#include +//#include "ccpu.h" + +/* declare CCPU */ +class CCPU; + +/** + * @class CInstruction + * + * TODO + */ +class CInstruction +{ + public: + /** + * @method CInstruction + * @brief Default ctor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + CInstruction(std::string name) + : m_name(name) + {}; + + /** + * @method ~CInstruction + * @brief Default dtor + * @param - + * @return - + * @globalvars none + * @exception none + * @conditions none + */ + virtual ~CInstruction() + {}; + + /* TODO */ + virtual bool operator==(std::string& name) + { + return name == m_name; + } + + /* TODO */ + virtual const std::string& getName() + { + return m_name; + } + + /* TODO */ + virtual std::ostream& dump(std::ostream& stream) + { + stream << m_name; + return stream; + } + + /* TODO */ + friend std::ostream& operator<<(std::ostream& stream, CInstruction& instr) + { + return instr.dump(stream); + } + + /* TODO */ + virtual const unsigned parseRegister(const std::string& str); + + /* TODO */ + virtual void checkRegister(CCPU *cpu, unsigned regidx); + + /* TODO */ + virtual CInstruction *factory() = 0; + + /* TODO */ + virtual void compile(std::list& params) = 0; + + /* TODO */ + virtual void execute(CCPU *cpu) = 0; + + protected: + /* members */ + std::string m_name; +}; + +#endif + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3 From 89e202f49b9857dcd3627fbc4e0262125d729bbc Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 04:09:39 +0200 Subject: adding all instructions and displays --- ue3/mycpu/cinstruction.h | 133 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 118 insertions(+), 15 deletions(-) (limited to 'ue3/mycpu/cinstruction.h') diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h index b16c067..57fcff1 100644 --- a/ue3/mycpu/cinstruction.h +++ b/ue3/mycpu/cinstruction.h @@ -10,9 +10,8 @@ #include #include -//#include "ccpu.h" -/* declare CCPU */ +/* forward declare CCPU */ class CCPU; /** @@ -26,7 +25,7 @@ class CInstruction /** * @method CInstruction * @brief Default ctor - * @param - + * @param name name of instruction * @return - * @globalvars none * @exception none @@ -34,7 +33,7 @@ class CInstruction */ CInstruction(std::string name) : m_name(name) - {}; + {} /** * @method ~CInstruction @@ -46,46 +45,150 @@ class CInstruction * @conditions none */ virtual ~CInstruction() - {}; + {} - /* TODO */ + /** + * @method operator== + * @brief implementation of operator == + * @param reference to std::string + * @return true if instructionname is name + * @globalvars none + * @exception none + * @conditions none + */ virtual bool operator==(std::string& name) { return name == m_name; } - /* TODO */ + /** + * @method getName + * @brief returns instruction name + * @param - + * @return name of instruction + * @globalvars none + * @exception none + * @conditions none + */ virtual const std::string& getName() { return m_name; } - /* TODO */ + /** + * @method isLabel + * @brief returns true if the instruction defines a label + * @param - + * @return true if the instruction defines a label + * @globalvars none + * @exception none + * @conditions none + */ + virtual const bool isLabel() + { + return false; + } + + /** + * @method getLabelName + * @brief returns labelname if the instruction defines a label + * @param - + * @return labelname if the instruction defines a label + * @globalvars none + * @exception none + * @conditions none + */ + virtual const std::string getLabelName() + { + return ""; + } + + /** + * @method dump + * @brief dumps information about instruction to outputstream + * @param stream outputstream + * @return reference to outputstream + * @globalvars none + * @exception none + * @conditions none + */ virtual std::ostream& dump(std::ostream& stream) { stream << m_name; return stream; } - /* TODO */ + /** + * @method operator<< + * @brief Shift/output operator for outputstream + * @param stream reference to outputstream + * @param cdat object which will be printed to stream + * @return reference to outputstream + * @globalvars none + * @exception none + * @conditions none + */ friend std::ostream& operator<<(std::ostream& stream, CInstruction& instr) { return instr.dump(stream); } - /* TODO */ + /** + * @method parseRegister + * @brief parses register syntax Rx (e.g. "R1") + * @param str register in assembler syntax + * @return registernumber + * @globalvars none + * @exception runtime_error + * @conditions none + */ virtual const unsigned parseRegister(const std::string& str); - /* TODO */ - virtual void checkRegister(CCPU *cpu, unsigned regidx); + /** + * @method checkRegister + * @brief performs a register boundary check + * does the register exist in cpu? + * @param cpu pointer to cpu + * @param regidx registernumber + * @return - + * @globalvars none + * @exception runtime_error + * @conditions none + */ + virtual void checkRegister(CCPU *cpu, const unsigned regidx); - /* TODO */ + /** + * @method factory + * @brief creates a new instance of this instruction + * @param - + * @return new instruction instance + * @globalvars none + * @exception none + * @conditions none + */ virtual CInstruction *factory() = 0; - /* TODO */ + /** + * @method compile + * @brief parses instruction parameters and prepares the + * instruction for executing + * @param params list of parameters of this instruction + * @return - + * @globalvars none + * @exception runtime_error + * @conditions none + */ virtual void compile(std::list& params) = 0; - /* TODO */ + /** + * @method execute + * @brief executes the instruction + * @param cpu pointer to cpu + * @return - + * @globalvars none + * @exception runtime_error + * @conditions none + */ virtual void execute(CCPU *cpu) = 0; protected: -- cgit v1.2.3 From 431bbac5a99abbccf33500e22aa353ec792eff94 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 15:29:51 +0200 Subject: * adding -Wno-long-long to all Makefiles * adding execute operator to cinstruction * added labels map for better performance --- ue3/mycpu/cinstruction.h | 47 +++++++++++++++++------------------------------ 1 file changed, 17 insertions(+), 30 deletions(-) (limited to 'ue3/mycpu/cinstruction.h') diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h index 57fcff1..40e9ddc 100644 --- a/ue3/mycpu/cinstruction.h +++ b/ue3/mycpu/cinstruction.h @@ -62,45 +62,32 @@ class CInstruction } /** - * @method getName - * @brief returns instruction name - * @param - - * @return name of instruction - * @globalvars none - * @exception none - * @conditions none - */ - virtual const std::string& getName() - { - return m_name; - } - - /** - * @method isLabel - * @brief returns true if the instruction defines a label - * @param - - * @return true if the instruction defines a label + * @method operator() + * @brief implementation of operator (CCPU) + * @param cpu pointer to cpu + * @return - * @globalvars none - * @exception none + * @exception std::runtime_error * @conditions none */ - virtual const bool isLabel() + virtual CInstruction& operator()(CCPU *cpu) { - return false; + execute(cpu); + return *this; } /** - * @method getLabelName - * @brief returns labelname if the instruction defines a label + * @method getName + * @brief returns instruction name * @param - - * @return labelname if the instruction defines a label + * @return name of instruction * @globalvars none * @exception none * @conditions none */ - virtual const std::string getLabelName() + virtual const std::string& getName() { - return ""; + return m_name; } /** @@ -139,7 +126,7 @@ class CInstruction * @param str register in assembler syntax * @return registernumber * @globalvars none - * @exception runtime_error + * @exception std::runtime_error * @conditions none */ virtual const unsigned parseRegister(const std::string& str); @@ -152,7 +139,7 @@ class CInstruction * @param regidx registernumber * @return - * @globalvars none - * @exception runtime_error + * @exception std::runtime_error * @conditions none */ virtual void checkRegister(CCPU *cpu, const unsigned regidx); @@ -175,7 +162,7 @@ class CInstruction * @param params list of parameters of this instruction * @return - * @globalvars none - * @exception runtime_error + * @exception std::runtime_error * @conditions none */ virtual void compile(std::list& params) = 0; @@ -186,7 +173,7 @@ class CInstruction * @param cpu pointer to cpu * @return - * @globalvars none - * @exception runtime_error + * @exception std::runtime_error * @conditions none */ virtual void execute(CCPU *cpu) = 0; -- cgit v1.2.3 From 3c6f886d5a8bfd36c796b963d6e3178ad9577742 Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 16:55:17 +0200 Subject: * added documentation (no more TODOs) * added testsuite + testcase * used copyctor instead of assign operator more often --- ue3/mycpu/cinstruction.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ue3/mycpu/cinstruction.h') diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h index 40e9ddc..942d8cf 100644 --- a/ue3/mycpu/cinstruction.h +++ b/ue3/mycpu/cinstruction.h @@ -1,8 +1,8 @@ /** * @module cinstruction * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) - * @brief TODO - * @date 10.05.2009 + * @brief Abstract class for displays + * @date 13.05.2009 */ #ifndef CINSTRUCTION_H @@ -17,7 +17,7 @@ class CCPU; /** * @class CInstruction * - * TODO + * Abstract class for displays */ class CInstruction { -- cgit v1.2.3 From 67e99a217bd88a289d997b73f3e7cae6019bc22f Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 13 May 2009 17:01:15 +0200 Subject: fixing doxygen documentation --- ue3/mycpu/cinstruction.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'ue3/mycpu/cinstruction.h') diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h index 942d8cf..4cc69de 100644 --- a/ue3/mycpu/cinstruction.h +++ b/ue3/mycpu/cinstruction.h @@ -50,7 +50,7 @@ class CInstruction /** * @method operator== * @brief implementation of operator == - * @param reference to std::string + * @param name reference to std::string * @return true if instructionname is name * @globalvars none * @exception none @@ -109,7 +109,7 @@ class CInstruction * @method operator<< * @brief Shift/output operator for outputstream * @param stream reference to outputstream - * @param cdat object which will be printed to stream + * @param instr object which will be printed to stream * @return reference to outputstream * @globalvars none * @exception none @@ -180,6 +180,7 @@ class CInstruction protected: /* members */ + /** name of instruction */ std::string m_name; }; -- cgit v1.2.3