blob: ec60b566baf6c80f40f0aed2a1f041b606eb67d1 (
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
|
/**
* @module cprogram
* @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
* @brief class for parsing and saving a program
* @date 11.05.2009
*/
#include <fstream>
#include <sstream>
#include <string>
#include <boost/tokenizer.hpp>
#include <boost/algorithm/string.hpp>
#include "cdat.h"
#include "cmem.h"
using namespace std;
using namespace boost;
CMem::CMem(const std::string& memfile) :
m_memfile(memfile)
{
dump(std::cout);
}
/*----------------------------------------------------------------------------*/
CMem::~CMem()
{
}
/*----------------------------------------------------------------------------*/
CDat& CMem::getRegister(const string reg)
{
istringstream stmp (
reg.substr(reg.find_first_of("R") + 1, reg.size())
);
unsigned int regnr;
stmp >> regnr;
// if (regnr >= MAX_REGISTER )
if (regnr >= m_registers.size())
{
for ( int i = m_registers.size(); i <= (int)regnr; i++)
m_registers.push_back(CDat((int)0));
return m_registers[m_registers.size() - 1];
}
return m_registers[regnr];
}
/*----------------------------------------------------------------------------*/
#ifdef DEBUG
void CMem::dump(std::ostream& out)
{
out << endl << "Memory file:" << endl << m_memfile << endl;
out << endl << "Memory file content:" << endl;
}
#endif
|