From ad6ca84f6e93f983de926ae71f31f42325986f61 Mon Sep 17 00:00:00 2001 From: manuel Date: Thu, 14 May 2009 18:15:28 +0200 Subject: * making cdisplay a template * adding some asserts * adding classdiagramm and protokoll * fixing protokoll.pdf in ue1 --- ue3/mycpu/cdisplay.h | 26 +++++++++++++++++--------- ue3/mycpu/cinstruction.cpp | 2 ++ ue3/mycpu/instructions.cpp | 34 ++++++++++++++++++++++++++++++++++ ue3/mycpu/test/memory1 | 1 - ue3/mycpu/test/program1 | 13 ------------- ue3/mycpu/test/test.sh | 4 +++- 6 files changed, 56 insertions(+), 24 deletions(-) delete mode 100644 ue3/mycpu/test/memory1 delete mode 100644 ue3/mycpu/test/program1 (limited to 'ue3/mycpu') diff --git a/ue3/mycpu/cdisplay.h b/ue3/mycpu/cdisplay.h index 0a0a723..1523f68 100644 --- a/ue3/mycpu/cdisplay.h +++ b/ue3/mycpu/cdisplay.h @@ -1,7 +1,7 @@ /** * @module cdisplay * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) - * @brief Abstract class for displays + * @brief Abstract template class for displays * @date 10.05.2009 */ @@ -9,15 +9,16 @@ #define CDISPLAY_H 1 /** - * @class CDisplay + * @class CDisplayT * - * Abstract class for displays + * Abstract template class for displays */ -class CDisplay +template +class CDisplayT { public: /** - * @method CDisplay + * @method CDisplayT * @brief Default ctor * @param name name of display * @return - @@ -25,12 +26,12 @@ class CDisplay * @exception none * @conditions none */ - CDisplay(std::string name) + CDisplayT(std::string name) : m_name(name) {} /** - * @method ~CDisplay + * @method ~CDisplayT * @brief Default dtor * @param - * @return - @@ -38,7 +39,7 @@ class CDisplay * @exception none * @conditions none */ - virtual ~CDisplay() + virtual ~CDisplayT() {} /** @@ -64,7 +65,7 @@ class CDisplay * @exception none * @conditions none */ - virtual void display(const CDat &value) = 0; + virtual void display(const T &value) = 0; protected: /* members */ @@ -72,6 +73,13 @@ class CDisplay std::string m_name; }; +/** + * @class CDisplay + * + * Memory definition for CCPU + */ +typedef CDisplayT CDisplay; + #endif /* vim: set et sw=2 ts=2: */ diff --git a/ue3/mycpu/cinstruction.cpp b/ue3/mycpu/cinstruction.cpp index 5c1bd5c..a766015 100644 --- a/ue3/mycpu/cinstruction.cpp +++ b/ue3/mycpu/cinstruction.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "cinstruction.h" #include "ccpu.h" @@ -35,6 +36,7 @@ const unsigned CInstruction::parseRegister(const std::string& str) inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx) { + assert(cpu != NULL); if (regidx >= cpu->getRegisterCount()) { stringstream sstr; diff --git a/ue3/mycpu/instructions.cpp b/ue3/mycpu/instructions.cpp index c2ce096..ef9e944 100644 --- a/ue3/mycpu/instructions.cpp +++ b/ue3/mycpu/instructions.cpp @@ -6,6 +6,7 @@ */ #include +#include #include "instructions.h" using namespace std; @@ -22,6 +23,8 @@ void CInstructionInc::compile(std::list& params) void CInstructionInc::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); cpu->getRegisters()[ m_regidx1 ]++; } @@ -40,6 +43,8 @@ void CInstructionDec::compile(std::list& params) void CInstructionDec::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); cpu->getRegisters()[ m_regidx1 ]--; } @@ -62,6 +67,8 @@ void CInstructionAdd::compile(std::list& params) void CInstructionAdd::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); checkRegister(cpu, m_regidx2); checkRegister(cpu, m_regidx3); @@ -87,6 +94,8 @@ void CInstructionSub::compile(std::list& params) void CInstructionSub::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); checkRegister(cpu, m_regidx2); checkRegister(cpu, m_regidx3); @@ -137,6 +146,8 @@ void CInstructionDiv::compile(std::list& params) void CInstructionDiv::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); checkRegister(cpu, m_regidx2); checkRegister(cpu, m_regidx3); @@ -160,6 +171,9 @@ void CInstructionLoad::compile(std::list& params) void CInstructionLoad::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); + assert(cpu->getMemory() != NULL); checkRegister(cpu, m_regidx1); checkRegister(cpu, m_regidx2); CDat val(cpu->getRegisters()[ m_regidx2 ]); @@ -182,6 +196,9 @@ void CInstructionStore::compile(std::list& params) void CInstructionStore::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); + assert(cpu->getMemory() != NULL); checkRegister(cpu, m_regidx1); checkRegister(cpu, m_regidx2); CDat val(cpu->getRegisters()[ m_regidx2 ]); @@ -202,6 +219,8 @@ void CInstructionTest::compile(std::list& params) void CInstructionTest::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); if (cpu->getRegisters()[ m_regidx1 ] == CDat(0)) cpu->setFlagZero(true); @@ -223,6 +242,9 @@ void CInstructionJumpA::compile(std::list& params) void CInstructionJumpA::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); + assert(cpu->getProgram() != NULL); if (m_addr.empty()) throw runtime_error("Empty address"); cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); @@ -242,8 +264,13 @@ void CInstructionJumpZ::compile(std::list& params) void CInstructionJumpZ::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); + assert(cpu->getProgram() != NULL); if (!cpu->getFlagZero()) return; + if (m_addr.empty()) + throw runtime_error("Empty address"); cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); } @@ -261,8 +288,13 @@ void CInstructionJumpS::compile(std::list& params) void CInstructionJumpS::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); + assert(cpu->getProgram() != NULL); if (!cpu->getFlagSign()) return; + if (m_addr.empty()) + throw runtime_error("Empty address"); cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); } @@ -282,6 +314,8 @@ void CInstructionWrite::compile(std::list& params) void CInstructionWrite::execute(CCPU *cpu) { + assert(cpu != NULL); + assert(cpu->getRegisters() != NULL); checkRegister(cpu, m_regidx1); if (m_dev.empty()) throw runtime_error("Empty device"); diff --git a/ue3/mycpu/test/memory1 b/ue3/mycpu/test/memory1 deleted file mode 100644 index 209e3ef..0000000 --- a/ue3/mycpu/test/memory1 +++ /dev/null @@ -1 +0,0 @@ -20 diff --git a/ue3/mycpu/test/program1 b/ue3/mycpu/test/program1 deleted file mode 100644 index ae5e9d2..0000000 --- a/ue3/mycpu/test/program1 +++ /dev/null @@ -1,13 +0,0 @@ -# set R2 = 10 -LOAD R2, R1 - -# start of loop -label Loop: -inc R3 -sub R4, R3, R2 -test R4 -jumpz EndLoop -write WDEZ, R3 -jumpa Loop - -label EndLoop: diff --git a/ue3/mycpu/test/test.sh b/ue3/mycpu/test/test.sh index ad2ae4d..ff1076c 100755 --- a/ue3/mycpu/test/test.sh +++ b/ue3/mycpu/test/test.sh @@ -32,9 +32,11 @@ do if [ "$md5_1" != "$md5_2" ] then echo " ERROR: output and $reffile differ" - diff -Nau $reffile $tmpfile + diff -Naur "$reffile" "$tmpfile" + rm -rf "$tmpfile" exit 1 else echo " SUCCESS" fi + rm -rf "$tmpfile" done -- cgit v1.2.3