summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/cinstruction.h
diff options
context:
space:
mode:
authormanuel <manuel@nc8430.lan>2009-05-14 18:58:48 +0200
committermanuel <manuel@nc8430.lan>2009-05-14 18:58:48 +0200
commit53b68ac658569dea3f5a26745dacf2a9aca0b266 (patch)
tree269af83394e84e2a7142dde87fb15dce413aa5c9 /ue3/mycpu/cinstruction.h
parentddf63e2765a6b225d18c59321595e69e1a126e0c (diff)
parent3563c6dfd0f5f102cb748ecc6ad318601990515e (diff)
downloadooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.tar.gz
ooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.tar.bz2
ooprog-53b68ac658569dea3f5a26745dacf2a9aca0b266.zip
trying merging cpu-mm with default branch
Diffstat (limited to 'ue3/mycpu/cinstruction.h')
-rw-r--r--ue3/mycpu/cinstruction.h306
1 files changed, 146 insertions, 160 deletions
diff --git a/ue3/mycpu/cinstruction.h b/ue3/mycpu/cinstruction.h
index 7d929a5..4cc69de 100644
--- a/ue3/mycpu/cinstruction.h
+++ b/ue3/mycpu/cinstruction.h
@@ -1,39 +1,38 @@
1/** 1/**
2 * @module cinstruction 2 * @module cinstruction
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) 3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief abstract class cpu instructions 4 * @brief Abstract class for displays
5 * @date 17.04.2009 5 * @date 13.05.2009
6 */ 6 */
7 7
8#ifndef CINSTRUCTION_H 8#ifndef CINSTRUCTION_H
9#define CINSTRUCTION_H 9#define CINSTRUCTION_H 1
10#include <map>
11#include <vector>
12#include "cmem.h"
13 10
11#include <iostream>
12#include <list>
13
14/* forward declare CCPU */
15class CCPU;
14 16
15
16/** 17/**
17 * @class CInstruction 18 * @class CInstruction
18 * 19 *
19 * Parses a simple line based scriptfile with some limitations: 20 * Abstract class for displays
20 * first function (starting a block) must be a read-command,
21 * last must be a write-command (ending this block).
22 *
23 * read- and write-commands have hard coded parameters, number#1 being a filetype.
24 * Classes handling certain filetypes must be of type CFile.
25 * Custom functions will be passed to CFile::callFunc().
26 *
27 * On error ParserError will be thrown.
28 */ 21 */
29class CInstruction 22class CInstruction
30{ 23{
31 public: 24 public:
32 25 /**
33 CInstruction() 26 * @method CInstruction
34 {} 27 * @brief Default ctor
35 CInstruction(std::map<std::string, unsigned int>& jumpaddr) 28 * @param name name of instruction
36 : m_jumpaddr(jumpaddr) 29 * @return -
30 * @globalvars none
31 * @exception none
32 * @conditions none
33 */
34 CInstruction(std::string name)
35 : m_name(name)
37 {} 36 {}
38 37
39 /** 38 /**
@@ -47,157 +46,144 @@ class CInstruction
47 */ 46 */
48 virtual ~CInstruction() 47 virtual ~CInstruction()
49 {} 48 {}
50
51
52 virtual void exec(CMem& mem, std::vector<std::string>& instr) = 0;
53
54 protected:
55 std::map<std::string, unsigned int> m_jumpaddr;
56
57
58};
59
60
61
62
63class CFlagInstruction : public CInstruction
64{
65 public:
66 public:
67 CFlagInstruction(bool& zero, bool& sign)
68 : f_zero(zero), f_sign(sign)
69 {}
70 CFlagInstruction(bool& zero, bool& sign, std::map<std::string, unsigned int>& jumpaddr)
71 : CInstruction::CInstruction(jumpaddr), f_zero(zero), f_sign(sign)
72 {}
73 virtual void exec(CMem& mem, std::vector<std::string>& instr) = 0;
74
75 protected:
76 bool &f_zero, &f_sign;
77
78};
79
80
81
82class CInc : public CInstruction
83{
84 public:
85 void exec(CMem& mem, std::vector<std::string>& instr);
86};
87
88
89class CDec : public CInstruction
90{
91 public:
92 void exec(CMem& mem, std::vector<std::string>& instr);
93};
94
95
96
97class CAdd : public CInstruction
98{
99 public:
100 void exec(CMem& mem, std::vector<std::string>& instr);
101};
102
103
104
105class CSub : public CInstruction
106{
107 public:
108 void exec(CMem& mem, std::vector<std::string>& instr);
109};
110
111
112
113class CMul : public CInstruction
114{
115 public:
116 void exec(CMem& mem, std::vector<std::string>& instr);
117};
118
119
120
121class CDiv : public CInstruction
122{
123 public:
124 void exec(CMem& mem, std::vector<std::string>& instr);
125};
126
127
128
129class CLoad : public CInstruction
130{
131 public:
132 void exec(CMem& mem, std::vector<std::string>& instr);
133};
134
135
136
137class CStore : public CInstruction
138{
139 public:
140 void exec(CMem& mem, std::vector<std::string>& instr);
141};
142
143class CTest : public CFlagInstruction
144{
145 public:
146 CTest(bool& zero, bool& sign)
147 : CFlagInstruction::CFlagInstruction(zero, sign)
148 {}
149
150 void exec(CMem& mem, std::vector<std::string>& instr);
151};
152 49
50 /**
51 * @method operator==
52 * @brief implementation of operator ==
53 * @param name reference to std::string
54 * @return true if instructionname is name
55 * @globalvars none
56 * @exception none
57 * @conditions none
58 */
59 virtual bool operator==(std::string& name)
60 {
61 return name == m_name;
62 }
153 63
154class CLabel : public CInstruction 64 /**
155{ 65 * @method operator()
156 public: 66 * @brief implementation of operator (CCPU)
157 void exec(CMem& mem, std::vector<std::string>& instr) 67 * @param cpu pointer to cpu
158 {} 68 * @return -
159 69 * @globalvars none
160}; 70 * @exception std::runtime_error
161 71 * @conditions none
72 */
73 virtual CInstruction& operator()(CCPU *cpu)
74 {
75 execute(cpu);
76 return *this;
77 }
162 78
163class CJumpa : public CInstruction 79 /**
164{ 80 * @method getName
165 public: 81 * @brief returns instruction name
166 CJumpa(std::map<std::string, unsigned int>& jumpaddr) 82 * @param -
167 : CInstruction::CInstruction(jumpaddr) 83 * @return name of instruction
168 {} 84 * @globalvars none
169 void exec(CMem& mem, std::vector<std::string>& instr); 85 * @exception none
86 * @conditions none
87 */
88 virtual const std::string& getName()
89 {
90 return m_name;
91 }
170 92
171}; 93 /**
94 * @method dump
95 * @brief dumps information about instruction to outputstream
96 * @param stream outputstream
97 * @return reference to outputstream
98 * @globalvars none
99 * @exception none
100 * @conditions none
101 */
102 virtual std::ostream& dump(std::ostream& stream)
103 {
104 stream << m_name;
105 return stream;
106 }
172 107
108 /**
109 * @method operator<<
110 * @brief Shift/output operator for outputstream
111 * @param stream reference to outputstream
112 * @param instr object which will be printed to stream
113 * @return reference to outputstream
114 * @globalvars none
115 * @exception none
116 * @conditions none
117 */
118 friend std::ostream& operator<<(std::ostream& stream, CInstruction& instr)
119 {
120 return instr.dump(stream);
121 }
173 122
174class CJumpz : public CFlagInstruction 123 /**
175{ 124 * @method parseRegister
176 125 * @brief parses register syntax Rx (e.g. "R1")
177 public: 126 * @param str register in assembler syntax
178 CJumpz(bool& zero, bool& sign, std::map<std::string, unsigned int>& jumpaddr) 127 * @return registernumber
179 : CFlagInstruction::CFlagInstruction(zero, sign, jumpaddr) 128 * @globalvars none
180 {} 129 * @exception std::runtime_error
181 void exec(CMem& mem, std::vector<std::string>& instr); 130 * @conditions none
182}; 131 */
132 virtual const unsigned parseRegister(const std::string& str);
183 133
134 /**
135 * @method checkRegister
136 * @brief performs a register boundary check
137 * does the register exist in cpu?
138 * @param cpu pointer to cpu
139 * @param regidx registernumber
140 * @return -
141 * @globalvars none
142 * @exception std::runtime_error
143 * @conditions none
144 */
145 virtual void checkRegister(CCPU *cpu, const unsigned regidx);
184 146
185class CJumps : public CFlagInstruction 147 /**
186{ 148 * @method factory
187 public: 149 * @brief creates a new instance of this instruction
188 CJumps(bool& zero ,bool& sign, std::map<std::string, unsigned int>& jumpaddr) 150 * @param -
189 : CFlagInstruction::CFlagInstruction(zero, sign, jumpaddr) 151 * @return new instruction instance
190 {} 152 * @globalvars none
191 void exec(CMem& mem, std::vector<std::string>& instr); 153 * @exception none
192}; 154 * @conditions none
155 */
156 virtual CInstruction *factory() = 0;
193 157
158 /**
159 * @method compile
160 * @brief parses instruction parameters and prepares the
161 * instruction for executing
162 * @param params list of parameters of this instruction
163 * @return -
164 * @globalvars none
165 * @exception std::runtime_error
166 * @conditions none
167 */
168 virtual void compile(std::list<std::string>& params) = 0;
194 169
170 /**
171 * @method execute
172 * @brief executes the instruction
173 * @param cpu pointer to cpu
174 * @return -
175 * @globalvars none
176 * @exception std::runtime_error
177 * @conditions none
178 */
179 virtual void execute(CCPU *cpu) = 0;
195 180
196class CWrite : public CInstruction 181 protected:
197{ 182 /* members */
198 public: 183 /** name of instruction */
199 void exec(CMem& mem, std::vector<std::string>& instr); 184 std::string m_name;
200}; 185};
201 186
202#endif 187#endif
188
203/* vim: set et sw=2 ts=2: */ 189/* vim: set et sw=2 ts=2: */