blob: 57acd5f28a02bd9622abc49feb8636a53eb0229b (
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
|
/**
* @module cinstruction
* @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
* @brief TODO
* @date 10.05.2009
*/
#include <sstream>
#include <stdexcept>
#include <boost/lexical_cast.hpp>
#include "cinstruction.h"
#include "ccpu.h"
using namespace std;
const unsigned CInstruction::parseRegister(const std::string& str)
{
unsigned reg;
if (str.length() < 2 || str[0] != 'r')
throw runtime_error("Invalid syntax of register");
try
{
reg = boost::lexical_cast<unsigned>(str.substr(1));
}
catch(boost::bad_lexical_cast& ex)
{
throw runtime_error("Invalid syntax of register");
}
return reg;
}
/*----------------------------------------------------------------------------*/
inline void CInstruction::checkRegister(CCPU *cpu, const unsigned regidx)
{
if (regidx >= cpu->getRegisterCount())
{
stringstream sstr;
sstr << "Register R" << regidx << " doesn't exist (out of bound)";
throw runtime_error(sstr.str());
}
}
/* vim: set et sw=2 ts=2: */
|