summaryrefslogtreecommitdiffstats
path: root/ue4/mycpu/cinstruction.h
diff options
context:
space:
mode:
Diffstat (limited to 'ue4/mycpu/cinstruction.h')
-rw-r--r--ue4/mycpu/cinstruction.h189
1 files changed, 189 insertions, 0 deletions
diff --git a/ue4/mycpu/cinstruction.h b/ue4/mycpu/cinstruction.h
new file mode 100644
index 0000000..4cc69de
--- /dev/null
+++ b/ue4/mycpu/cinstruction.h
@@ -0,0 +1,189 @@
1/**
2 * @module cinstruction
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief Abstract class for displays
5 * @date 13.05.2009
6 */
7
8#ifndef CINSTRUCTION_H
9#define CINSTRUCTION_H 1
10
11#include <iostream>
12#include <list>
13
14/* forward declare CCPU */
15class CCPU;
16
17/**
18 * @class CInstruction
19 *
20 * Abstract class for displays
21 */
22class CInstruction
23{
24 public:
25 /**
26 * @method CInstruction
27 * @brief Default ctor
28 * @param name name of instruction
29 * @return -
30 * @globalvars none
31 * @exception none
32 * @conditions none
33 */
34 CInstruction(std::string name)
35 : m_name(name)
36 {}
37
38 /**
39 * @method ~CInstruction
40 * @brief Default dtor
41 * @param -
42 * @return -
43 * @globalvars none
44 * @exception none
45 * @conditions none
46 */
47 virtual ~CInstruction()
48 {}
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 }
63
64 /**
65 * @method operator()
66 * @brief implementation of operator (CCPU)
67 * @param cpu pointer to cpu
68 * @return -
69 * @globalvars none
70 * @exception std::runtime_error
71 * @conditions none
72 */
73 virtual CInstruction& operator()(CCPU *cpu)
74 {
75 execute(cpu);
76 return *this;
77 }
78
79 /**
80 * @method getName
81 * @brief returns instruction name
82 * @param -
83 * @return name of instruction
84 * @globalvars none
85 * @exception none
86 * @conditions none
87 */
88 virtual const std::string& getName()
89 {
90 return m_name;
91 }
92
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 }
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 }
122
123 /**
124 * @method parseRegister
125 * @brief parses register syntax Rx (e.g. "R1")
126 * @param str register in assembler syntax
127 * @return registernumber
128 * @globalvars none
129 * @exception std::runtime_error
130 * @conditions none
131 */
132 virtual const unsigned parseRegister(const std::string& str);
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);
146
147 /**
148 * @method factory
149 * @brief creates a new instance of this instruction
150 * @param -
151 * @return new instruction instance
152 * @globalvars none
153 * @exception none
154 * @conditions none
155 */
156 virtual CInstruction *factory() = 0;
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;
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;
180
181 protected:
182 /* members */
183 /** name of instruction */
184 std::string m_name;
185};
186
187#endif
188
189/* vim: set et sw=2 ts=2: */