summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-14 18:15:28 +0200
committermanuel <manuel@nc8430.lan>2009-05-14 18:15:28 +0200
commitad6ca84f6e93f983de926ae71f31f42325986f61 (patch)
treea28df3e6aa600fc7eec4194bc81dbda930de6c8f /ue3/mycpu
parent9e7c204525a50f36ba7aa7563f1a9702d0bb6f44 (diff)
downloadooprog-ad6ca84f6e93f983de926ae71f31f42325986f61.tar.gz
ooprog-ad6ca84f6e93f983de926ae71f31f42325986f61.tar.bz2
ooprog-ad6ca84f6e93f983de926ae71f31f42325986f61.zip
* making cdisplay a template
* adding some asserts * adding classdiagramm and protokoll * fixing protokoll.pdf in ue1
Diffstat (limited to 'ue3/mycpu')
-rw-r--r--ue3/mycpu/cdisplay.h26
-rw-r--r--ue3/mycpu/cinstruction.cpp2
-rw-r--r--ue3/mycpu/instructions.cpp34
-rw-r--r--ue3/mycpu/test/memory11
-rw-r--r--ue3/mycpu/test/program113
-rwxr-xr-xue3/mycpu/test/test.sh4
6 files changed, 56 insertions, 24 deletions
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 @@
1/** 1/**
2 * @module cdisplay 2 * @module cdisplay
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Abstract class for displays 4 * @brief Abstract template class for displays
5 * @date 10.05.2009 5 * @date 10.05.2009
6 */ 6 */
7 7
@@ -9,15 +9,16 @@
9#define CDISPLAY_H 1 9#define CDISPLAY_H 1
10 10
11/** 11/**
12 * @class CDisplay 12 * @class CDisplayT
13 * 13 *
14 * Abstract class for displays 14 * Abstract template class for displays
15 */ 15 */
16class CDisplay 16template <class T>
17class CDisplayT
17{ 18{
18 public: 19 public:
19 /** 20 /**
20 * @method CDisplay 21 * @method CDisplayT
21 * @brief Default ctor 22 * @brief Default ctor
22 * @param name name of display 23 * @param name name of display
23 * @return - 24 * @return -
@@ -25,12 +26,12 @@ class CDisplay
25 * @exception none 26 * @exception none
26 * @conditions none 27 * @conditions none
27 */ 28 */
28 CDisplay(std::string name) 29 CDisplayT(std::string name)
29 : m_name(name) 30 : m_name(name)
30 {} 31 {}
31 32
32 /** 33 /**
33 * @method ~CDisplay 34 * @method ~CDisplayT
34 * @brief Default dtor 35 * @brief Default dtor
35 * @param - 36 * @param -
36 * @return - 37 * @return -
@@ -38,7 +39,7 @@ class CDisplay
38 * @exception none 39 * @exception none
39 * @conditions none 40 * @conditions none
40 */ 41 */
41 virtual ~CDisplay() 42 virtual ~CDisplayT()
42 {} 43 {}
43 44
44 /** 45 /**
@@ -64,7 +65,7 @@ class CDisplay
64 * @exception none 65 * @exception none
65 * @conditions none 66 * @conditions none
66 */ 67 */
67 virtual void display(const CDat &value) = 0; 68 virtual void display(const T &value) = 0;
68 69
69 protected: 70 protected:
70 /* members */ 71 /* members */
@@ -72,6 +73,13 @@ class CDisplay
72 std::string m_name; 73 std::string m_name;
73}; 74};
74 75
76/**
77 * @class CDisplay
78 *
79 * Memory definition for CCPU
80 */
81typedef CDisplayT<CDat> CDisplay;
82
75#endif 83#endif
76 84
77/* vim: set et sw=2 ts=2: */ 85/* 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 @@
8#include <sstream> 8#include <sstream>
9#include <stdexcept> 9#include <stdexcept>
10#include <boost/lexical_cast.hpp> 10#include <boost/lexical_cast.hpp>
11#include <assert.h>
11#include "cinstruction.h" 12#include "cinstruction.h"
12#include "ccpu.h" 13#include "ccpu.h"
13 14
@@ -35,6 +36,7 @@ const unsigned CInstruction::parseRegister(const std::string& str)
35 36
36inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx) 37inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx)
37{ 38{
39 assert(cpu != NULL);
38 if (regidx >= cpu->getRegisterCount()) 40 if (regidx >= cpu->getRegisterCount())
39 { 41 {
40 stringstream sstr; 42 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 @@
6 */ 6 */
7 7
8#include <map> 8#include <map>
9#include <assert.h>
9#include "instructions.h" 10#include "instructions.h"
10 11
11using namespace std; 12using namespace std;
@@ -22,6 +23,8 @@ void CInstructionInc::compile(std::list<std::string>& params)
22 23
23void CInstructionInc::execute(CCPU *cpu) 24void CInstructionInc::execute(CCPU *cpu)
24{ 25{
26 assert(cpu != NULL);
27 assert(cpu->getRegisters() != NULL);
25 checkRegister(cpu, m_regidx1); 28 checkRegister(cpu, m_regidx1);
26 cpu->getRegisters()[ m_regidx1 ]++; 29 cpu->getRegisters()[ m_regidx1 ]++;
27} 30}
@@ -40,6 +43,8 @@ void CInstructionDec::compile(std::list<std::string>& params)
40 43
41void CInstructionDec::execute(CCPU *cpu) 44void CInstructionDec::execute(CCPU *cpu)
42{ 45{
46 assert(cpu != NULL);
47 assert(cpu->getRegisters() != NULL);
43 checkRegister(cpu, m_regidx1); 48 checkRegister(cpu, m_regidx1);
44 cpu->getRegisters()[ m_regidx1 ]--; 49 cpu->getRegisters()[ m_regidx1 ]--;
45} 50}
@@ -62,6 +67,8 @@ void CInstructionAdd::compile(std::list<std::string>& params)
62 67
63void CInstructionAdd::execute(CCPU *cpu) 68void CInstructionAdd::execute(CCPU *cpu)
64{ 69{
70 assert(cpu != NULL);
71 assert(cpu->getRegisters() != NULL);
65 checkRegister(cpu, m_regidx1); 72 checkRegister(cpu, m_regidx1);
66 checkRegister(cpu, m_regidx2); 73 checkRegister(cpu, m_regidx2);
67 checkRegister(cpu, m_regidx3); 74 checkRegister(cpu, m_regidx3);
@@ -87,6 +94,8 @@ void CInstructionSub::compile(std::list<std::string>& params)
87 94
88void CInstructionSub::execute(CCPU *cpu) 95void CInstructionSub::execute(CCPU *cpu)
89{ 96{
97 assert(cpu != NULL);
98 assert(cpu->getRegisters() != NULL);
90 checkRegister(cpu, m_regidx1); 99 checkRegister(cpu, m_regidx1);
91 checkRegister(cpu, m_regidx2); 100 checkRegister(cpu, m_regidx2);
92 checkRegister(cpu, m_regidx3); 101 checkRegister(cpu, m_regidx3);
@@ -137,6 +146,8 @@ void CInstructionDiv::compile(std::list<std::string>& params)
137 146
138void CInstructionDiv::execute(CCPU *cpu) 147void CInstructionDiv::execute(CCPU *cpu)
139{ 148{
149 assert(cpu != NULL);
150 assert(cpu->getRegisters() != NULL);
140 checkRegister(cpu, m_regidx1); 151 checkRegister(cpu, m_regidx1);
141 checkRegister(cpu, m_regidx2); 152 checkRegister(cpu, m_regidx2);
142 checkRegister(cpu, m_regidx3); 153 checkRegister(cpu, m_regidx3);
@@ -160,6 +171,9 @@ void CInstructionLoad::compile(std::list<std::string>& params)
160 171
161void CInstructionLoad::execute(CCPU *cpu) 172void CInstructionLoad::execute(CCPU *cpu)
162{ 173{
174 assert(cpu != NULL);
175 assert(cpu->getRegisters() != NULL);
176 assert(cpu->getMemory() != NULL);
163 checkRegister(cpu, m_regidx1); 177 checkRegister(cpu, m_regidx1);
164 checkRegister(cpu, m_regidx2); 178 checkRegister(cpu, m_regidx2);
165 CDat val(cpu->getRegisters()[ m_regidx2 ]); 179 CDat val(cpu->getRegisters()[ m_regidx2 ]);
@@ -182,6 +196,9 @@ void CInstructionStore::compile(std::list<std::string>& params)
182 196
183void CInstructionStore::execute(CCPU *cpu) 197void CInstructionStore::execute(CCPU *cpu)
184{ 198{
199 assert(cpu != NULL);
200 assert(cpu->getRegisters() != NULL);
201 assert(cpu->getMemory() != NULL);
185 checkRegister(cpu, m_regidx1); 202 checkRegister(cpu, m_regidx1);
186 checkRegister(cpu, m_regidx2); 203 checkRegister(cpu, m_regidx2);
187 CDat val(cpu->getRegisters()[ m_regidx2 ]); 204 CDat val(cpu->getRegisters()[ m_regidx2 ]);
@@ -202,6 +219,8 @@ void CInstructionTest::compile(std::list<std::string>& params)
202 219
203void CInstructionTest::execute(CCPU *cpu) 220void CInstructionTest::execute(CCPU *cpu)
204{ 221{
222 assert(cpu != NULL);
223 assert(cpu->getRegisters() != NULL);
205 checkRegister(cpu, m_regidx1); 224 checkRegister(cpu, m_regidx1);
206 if (cpu->getRegisters()[ m_regidx1 ] == CDat(0)) 225 if (cpu->getRegisters()[ m_regidx1 ] == CDat(0))
207 cpu->setFlagZero(true); 226 cpu->setFlagZero(true);
@@ -223,6 +242,9 @@ void CInstructionJumpA::compile(std::list<std::string>& params)
223 242
224void CInstructionJumpA::execute(CCPU *cpu) 243void CInstructionJumpA::execute(CCPU *cpu)
225{ 244{
245 assert(cpu != NULL);
246 assert(cpu->getRegisters() != NULL);
247 assert(cpu->getProgram() != NULL);
226 if (m_addr.empty()) 248 if (m_addr.empty())
227 throw runtime_error("Empty address"); 249 throw runtime_error("Empty address");
228 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 250 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
@@ -242,8 +264,13 @@ void CInstructionJumpZ::compile(std::list<std::string>& params)
242 264
243void CInstructionJumpZ::execute(CCPU *cpu) 265void CInstructionJumpZ::execute(CCPU *cpu)
244{ 266{
267 assert(cpu != NULL);
268 assert(cpu->getRegisters() != NULL);
269 assert(cpu->getProgram() != NULL);
245 if (!cpu->getFlagZero()) 270 if (!cpu->getFlagZero())
246 return; 271 return;
272 if (m_addr.empty())
273 throw runtime_error("Empty address");
247 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 274 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
248} 275}
249 276
@@ -261,8 +288,13 @@ void CInstructionJumpS::compile(std::list<std::string>& params)
261 288
262void CInstructionJumpS::execute(CCPU *cpu) 289void CInstructionJumpS::execute(CCPU *cpu)
263{ 290{
291 assert(cpu != NULL);
292 assert(cpu->getRegisters() != NULL);
293 assert(cpu->getProgram() != NULL);
264 if (!cpu->getFlagSign()) 294 if (!cpu->getFlagSign())
265 return; 295 return;
296 if (m_addr.empty())
297 throw runtime_error("Empty address");
266 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr); 298 cpu->getRegisters()[ 0 ] = cpu->getProgram()->findLabel(m_addr);
267} 299}
268 300
@@ -282,6 +314,8 @@ void CInstructionWrite::compile(std::list<std::string>& params)
282 314
283void CInstructionWrite::execute(CCPU *cpu) 315void CInstructionWrite::execute(CCPU *cpu)
284{ 316{
317 assert(cpu != NULL);
318 assert(cpu->getRegisters() != NULL);
285 checkRegister(cpu, m_regidx1); 319 checkRegister(cpu, m_regidx1);
286 if (m_dev.empty()) 320 if (m_dev.empty())
287 throw runtime_error("Empty device"); 321 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 @@
120
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 @@
1# set R2 = 10
2LOAD R2, R1
3
4# start of loop
5label Loop:
6inc R3
7sub R4, R3, R2
8test R4
9jumpz EndLoop
10write WDEZ, R3
11jumpa Loop
12
13label 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
32 if [ "$md5_1" != "$md5_2" ] 32 if [ "$md5_1" != "$md5_2" ]
33 then 33 then
34 echo " ERROR: output and $reffile differ" 34 echo " ERROR: output and $reffile differ"
35 diff -Nau $reffile $tmpfile 35 diff -Naur "$reffile" "$tmpfile"
36 rm -rf "$tmpfile"
36 exit 1 37 exit 1
37 else 38 else
38 echo " SUCCESS" 39 echo " SUCCESS"
39 fi 40 fi
41 rm -rf "$tmpfile"
40done 42done