summaryrefslogtreecommitdiffstats
path: root/ue4/doxygen/cinstruction_8h-source.html
blob: 2026b0e46a4108d7d3335de84ad2b07d06d513c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>mycpu: mycpu/cinstruction.h Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.3 -->
<div class="tabs">
  <ul>
    <li><a href="index.html"><span>Main&nbsp;Page</span></a></li>
    <li><a href="annotated.html"><span>Classes</span></a></li>
    <li class="current"><a href="files.html"><span>Files</span></a></li>
  </ul>
</div>
<h1>mycpu/cinstruction.h</h1><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00008"></a>00008 <span class="preprocessor">#ifndef CINSTRUCTION_H</span>
<a name="l00009"></a>00009 <span class="preprocessor"></span><span class="preprocessor">#define CINSTRUCTION_H 1</span>
<a name="l00010"></a>00010 <span class="preprocessor"></span>
<a name="l00011"></a>00011 <span class="preprocessor">#include &lt;iostream&gt;</span>
<a name="l00012"></a>00012 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00013"></a>00013 <span class="preprocessor">#include &lt;sstream&gt;</span>
<a name="l00014"></a>00014 <span class="preprocessor">#include &lt;boost/lexical_cast.hpp&gt;</span>
<a name="l00015"></a>00015 <span class="preprocessor">#include &lt;assert.h&gt;</span>
<a name="l00016"></a>00016 <span class="preprocessor">#include &lt;stdexcept&gt;</span>
<a name="l00017"></a>00017 
<a name="l00023"></a><a class="code" href="classCInstructionError.html">00023</a> <span class="keyword">class </span><a class="code" href="classCInstructionError.html">CInstructionError</a>
<a name="l00024"></a>00024  : <span class="keyword">public</span> std::invalid_argument
<a name="l00025"></a>00025 {
<a name="l00026"></a>00026   <span class="keyword">public</span>:
<a name="l00037"></a><a class="code" href="classCInstructionError.html#c37becef1c3689b6917759d849ad23e2">00037</a>     <a class="code" href="classCInstructionError.html#c37becef1c3689b6917759d849ad23e2" title="Default exception ctor.">CInstructionError</a>(<span class="keyword">const</span> std::string&amp; what)
<a name="l00038"></a>00038       : std::invalid_argument(what)
<a name="l00039"></a>00039     {}
<a name="l00040"></a>00040 };
<a name="l00041"></a>00041 
<a name="l00042"></a>00042 <span class="preprocessor">#include "ccpu.h"</span>
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 <span class="comment">/* forward declare CCPU */</span>
<a name="l00045"></a>00045 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00046"></a>00046 <span class="keyword">class </span><a class="code" href="classCCPU.html">CCPU</a>;
<a name="l00047"></a>00047 
<a name="l00053"></a>00053 <span class="keyword">template</span> &lt;<span class="keyword">class</span> T&gt;
<a name="l00054"></a><a class="code" href="classCInstruction.html">00054</a> <span class="keyword">class </span><a class="code" href="classCInstruction.html">CInstruction</a>
<a name="l00055"></a>00055 {
<a name="l00056"></a>00056   <span class="keyword">public</span>:
<a name="l00067"></a><a class="code" href="classCInstruction.html#0bdc94fd4728d4035e1f13923376e450">00067</a>     <a class="code" href="classCInstruction.html#0bdc94fd4728d4035e1f13923376e450" title="Default ctor.">CInstruction</a>(std::string name)
<a name="l00068"></a>00068       : <a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">m_name</a>(name)
<a name="l00069"></a>00069     {}
<a name="l00070"></a>00070 
<a name="l00081"></a><a class="code" href="classCInstruction.html#ca5a5edd9b94718f1eb37b4269ade54e">00081</a>     <span class="keyword">virtual</span> <a class="code" href="classCInstruction.html#ca5a5edd9b94718f1eb37b4269ade54e" title="Default dtor.">~CInstruction</a>()
<a name="l00082"></a>00082     {}
<a name="l00083"></a>00083 
<a name="l00094"></a><a class="code" href="classCInstruction.html#a62545e40a91e8f7b301ffdeaff7d04f">00094</a>     <span class="keyword">virtual</span> <span class="keywordtype">bool</span> <a class="code" href="classCInstruction.html#a62545e40a91e8f7b301ffdeaff7d04f" title="implementation of operator ==">operator==</a>(std::string&amp; name)
<a name="l00095"></a>00095     {
<a name="l00096"></a>00096       <span class="keywordflow">return</span> name == <a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">m_name</a>;
<a name="l00097"></a>00097     }
<a name="l00098"></a>00098 
<a name="l00109"></a><a class="code" href="classCInstruction.html#334cc56829717b5946b9b42324aa26fe">00109</a>     <span class="keyword">virtual</span> <a class="code" href="classCInstruction.html">CInstruction</a>&amp; <a class="code" href="classCInstruction.html#334cc56829717b5946b9b42324aa26fe" title="implementation of operator (CCPU)">operator()</a>(<a class="code" href="classCCPU.html">CCPU&lt;T&gt;</a> *cpu)
<a name="l00110"></a>00110     {
<a name="l00111"></a>00111       <a class="code" href="classCInstruction.html#7732a6024a2329d5d3f82b3093be42eb" title="executes the instruction">execute</a>(cpu);
<a name="l00112"></a>00112       <span class="keywordflow">return</span> *<span class="keyword">this</span>;
<a name="l00113"></a>00113     }
<a name="l00114"></a>00114 
<a name="l00125"></a><a class="code" href="classCInstruction.html#b240d30bea3acf8d4150f1a5b5f766ef">00125</a>     <span class="keyword">virtual</span> <span class="keyword">const</span> std::string&amp; <a class="code" href="classCInstruction.html#b240d30bea3acf8d4150f1a5b5f766ef" title="returns instruction name">getName</a>()
<a name="l00126"></a>00126     {
<a name="l00127"></a>00127       <span class="keywordflow">return</span> <a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">m_name</a>;
<a name="l00128"></a>00128     }
<a name="l00129"></a>00129 
<a name="l00140"></a><a class="code" href="classCInstruction.html#4338f7ce91bca9c6bbcceb83a3212068">00140</a>     <span class="keyword">virtual</span> std::ostream&amp; <a class="code" href="classCInstruction.html#4338f7ce91bca9c6bbcceb83a3212068" title="dumps information about instruction to outputstream">dump</a>(std::ostream&amp; stream)
<a name="l00141"></a>00141     {
<a name="l00142"></a>00142       stream &lt;&lt; <a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">m_name</a>;
<a name="l00143"></a>00143       <span class="keywordflow">return</span> stream;
<a name="l00144"></a>00144     }
<a name="l00145"></a>00145 
<a name="l00157"></a><a class="code" href="classCInstruction.html#7651b4c147411bca34a0393adf03507d">00157</a>     <span class="keyword">friend</span> std::ostream&amp; <a class="code" href="classCInstruction.html#7651b4c147411bca34a0393adf03507d" title="Shift/output operator for outputstream.">operator&lt;&lt;</a>(std::ostream&amp; stream, <a class="code" href="classCInstruction.html">CInstruction</a>&amp; instr)
<a name="l00158"></a>00158     {
<a name="l00159"></a>00159       <span class="keywordflow">return</span> instr.<a class="code" href="classCInstruction.html#4338f7ce91bca9c6bbcceb83a3212068" title="dumps information about instruction to outputstream">dump</a>(stream);
<a name="l00160"></a>00160     }
<a name="l00161"></a>00161 
<a name="l00172"></a>00172     <span class="keyword">virtual</span> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="classCInstruction.html#70bbbf095733b8e51ea43597d082445e" title="parses register syntax Rx (e.g. &amp;quot;R1&amp;quot;)">parseRegister</a>(<span class="keyword">const</span> std::string&amp; str);
<a name="l00173"></a>00173 
<a name="l00186"></a>00186     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCInstruction.html#a03c72bae5244d808f5c045d2dc26f3b" title="performs a register boundary check does the register exist in cpu?">checkRegister</a>(<a class="code" href="classCCPU.html">CCPU&lt;T&gt;</a> *cpu, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> regidx);
<a name="l00187"></a>00187 
<a name="l00198"></a>00198     <span class="keyword">virtual</span> <a class="code" href="classCInstruction.html">CInstruction</a> *<a class="code" href="classCInstruction.html#3362efb71ca3d9237c66952201564027" title="creates a new instance of this instruction">factory</a>() = 0;
<a name="l00199"></a>00199 
<a name="l00211"></a>00211     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCInstruction.html#caab509da9dd1f300293d6fa5501049a" title="parses instruction parameters and prepares the instruction for executing">compile</a>(std::list&lt;std::string&gt;&amp; params) = 0;
<a name="l00212"></a>00212 
<a name="l00223"></a>00223     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="classCInstruction.html#7732a6024a2329d5d3f82b3093be42eb" title="executes the instruction">execute</a>(<a class="code" href="classCCPU.html">CCPU&lt;T&gt;</a> *cpu) = 0;
<a name="l00224"></a>00224 
<a name="l00225"></a>00225   <span class="keyword">protected</span>:
<a name="l00226"></a>00226     <span class="comment">/* members */</span>
<a name="l00228"></a><a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">00228</a>     std::string <a class="code" href="classCInstruction.html#18a74815caf3645a3368d185d38bf9bc">m_name</a>;
<a name="l00229"></a>00229 };
<a name="l00230"></a>00230 
<a name="l00231"></a>00231 <span class="comment">/*----------------------------------------------------------------------------*/</span>
<a name="l00232"></a>00232 
<a name="l00233"></a>00233 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00234"></a><a class="code" href="classCInstruction.html#70bbbf095733b8e51ea43597d082445e">00234</a> <span class="keyword">const</span> <span class="keywordtype">unsigned</span> <a class="code" href="classCInstruction.html#70bbbf095733b8e51ea43597d082445e" title="parses register syntax Rx (e.g. &amp;quot;R1&amp;quot;)">CInstruction&lt;T&gt;::parseRegister</a>(<span class="keyword">const</span> std::string&amp; str)
<a name="l00235"></a>00235 {
<a name="l00236"></a>00236   <span class="keywordtype">unsigned</span> reg;
<a name="l00237"></a>00237   <span class="keywordflow">if</span> (str.length() &lt; 2 || str[0] != <span class="charliteral">'r'</span>)
<a name="l00238"></a>00238     <span class="keywordflow">throw</span> <a class="code" href="classCInstructionError.html">CInstructionError</a>(<span class="stringliteral">"Invalid syntax of register"</span>);
<a name="l00239"></a>00239 
<a name="l00240"></a>00240   <span class="keywordflow">try</span>
<a name="l00241"></a>00241   {
<a name="l00242"></a>00242     reg = boost::lexical_cast&lt;<span class="keywordtype">unsigned</span>&gt;(str.substr(1));
<a name="l00243"></a>00243   }
<a name="l00244"></a>00244   <span class="keywordflow">catch</span>(boost::bad_lexical_cast&amp; ex)
<a name="l00245"></a>00245   {
<a name="l00246"></a>00246     <span class="keywordflow">throw</span> <a class="code" href="classCInstructionError.html">CInstructionError</a>(<span class="stringliteral">"Invalid syntax of register"</span>);
<a name="l00247"></a>00247   }
<a name="l00248"></a>00248 
<a name="l00249"></a>00249   <span class="keywordflow">return</span> reg;
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251 
<a name="l00252"></a>00252 <span class="comment">/*----------------------------------------------------------------------------*/</span>
<a name="l00253"></a>00253 
<a name="l00254"></a>00254 <span class="keyword">template</span>&lt;<span class="keyword">class</span> T&gt;
<a name="l00255"></a><a class="code" href="classCInstruction.html#a03c72bae5244d808f5c045d2dc26f3b">00255</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> <a class="code" href="classCInstruction.html#a03c72bae5244d808f5c045d2dc26f3b" title="performs a register boundary check does the register exist in cpu?">CInstruction&lt;T&gt;::checkRegister</a>(<a class="code" href="classCCPU.html">CCPU&lt;T&gt;</a> *cpu, <span class="keyword">const</span> <span class="keywordtype">unsigned</span> regidx)
<a name="l00256"></a>00256 {
<a name="l00257"></a>00257   assert(cpu != NULL);
<a name="l00258"></a>00258   <span class="keywordflow">if</span> (regidx &gt;= cpu-&gt;<a class="code" href="classCCPU.html#77eca5c67c741c8ff6c9bd298c5fe1b7" title="get number of registers">getRegisterCount</a>())
<a name="l00259"></a>00259   {
<a name="l00260"></a>00260     std::stringstream sstr;
<a name="l00261"></a>00261     sstr &lt;&lt; <span class="stringliteral">"Register R"</span> &lt;&lt; regidx &lt;&lt; <span class="stringliteral">" doesn't exist (out of bound)"</span>;
<a name="l00262"></a>00262     <span class="keywordflow">throw</span> <a class="code" href="classCInstructionError.html">CInstructionError</a>(sstr.str());
<a name="l00263"></a>00263   }
<a name="l00264"></a>00264 }
<a name="l00265"></a>00265 
<a name="l00266"></a>00266 <span class="preprocessor">#endif</span>
<a name="l00267"></a>00267 <span class="preprocessor"></span>
<a name="l00268"></a>00268 <span class="comment">/* vim: set et sw=2 ts=2: */</span>
</pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Sat May 30 16:32:35 2009 for mycpu by&nbsp;
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.3 </small></address>
</body>
</html>