diff options
| author | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 15:27:58 +0200 |
|---|---|---|
| committer | Günther Neuwirth <e0626638@student.tuwien.ac.at> | 2009-05-12 15:27:58 +0200 |
| commit | 34483e07a0548d32651cda4ca4282f3cf8cae870 (patch) | |
| tree | ef499b9850e60cc45ca4de1605c962a5cc040a8f /ue3/mycpu/cmem.cpp | |
| parent | fe1ef6b47f59899e8687bb1dcc92eba1d103a08f (diff) | |
| download | ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.tar.gz ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.tar.bz2 ooprog-34483e07a0548d32651cda4ca4282f3cf8cae870.zip | |
adding rest of files
Diffstat (limited to 'ue3/mycpu/cmem.cpp')
| -rw-r--r-- | ue3/mycpu/cmem.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/ue3/mycpu/cmem.cpp b/ue3/mycpu/cmem.cpp new file mode 100644 index 0000000..d27f74e --- /dev/null +++ b/ue3/mycpu/cmem.cpp | |||
| @@ -0,0 +1,65 @@ | |||
| 1 | /** | ||
| 2 | * @module cprogram | ||
| 3 | * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) | ||
| 4 | * @brief class for parsing and saving a program | ||
| 5 | * @date 11.05.2009 | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <fstream> | ||
| 9 | #include <sstream> | ||
| 10 | #include <string> | ||
| 11 | #include <boost/tokenizer.hpp> | ||
| 12 | #include <boost/algorithm/string.hpp> | ||
| 13 | #include "cdat.h" | ||
| 14 | #include "cmem.h" | ||
| 15 | |||
| 16 | |||
| 17 | |||
| 18 | using namespace std; | ||
| 19 | using namespace boost; | ||
| 20 | |||
| 21 | CMem::CMem(const std::string& memfile) : | ||
| 22 | m_memfile(memfile) | ||
| 23 | { | ||
| 24 | |||
| 25 | dump(std::cout); | ||
| 26 | |||
| 27 | } | ||
| 28 | |||
| 29 | /*----------------------------------------------------------------------------*/ | ||
| 30 | |||
| 31 | CMem::~CMem() | ||
| 32 | { | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | /*----------------------------------------------------------------------------*/ | ||
| 37 | |||
| 38 | CDat& CMem::getRegister(const string reg) | ||
| 39 | { | ||
| 40 | istringstream stmp ( | ||
| 41 | reg.substr(reg.find_first_of("R") + 1, reg.size()) | ||
| 42 | ); | ||
| 43 | |||
| 44 | unsigned int regnr; | ||
| 45 | stmp >> regnr; | ||
| 46 | |||
| 47 | // if (regnr >= MAX_REGISTER ) | ||
| 48 | |||
| 49 | if (regnr == m_registers.size()) | ||
| 50 | { | ||
| 51 | m_registers.push_back(CDat((int)0)); | ||
| 52 | return m_registers[m_registers.size() - 1]; | ||
| 53 | } | ||
| 54 | |||
| 55 | return m_registers[regnr]; | ||
| 56 | } | ||
| 57 | /*----------------------------------------------------------------------------*/ | ||
| 58 | |||
| 59 | #ifdef DEBUG | ||
| 60 | void CMem::dump(std::ostream& out) | ||
| 61 | { | ||
| 62 | out << endl << "Memory file:" << endl << m_memfile << endl; | ||
| 63 | out << endl << "Memory file content:" << endl; | ||
| 64 | } | ||
| 65 | #endif | ||
