diff options
Diffstat (limited to 'ue3/mycpu/cmem.cpp')
| -rw-r--r-- | ue3/mycpu/cmem.cpp | 124 |
1 files changed, 0 insertions, 124 deletions
diff --git a/ue3/mycpu/cmem.cpp b/ue3/mycpu/cmem.cpp deleted file mode 100644 index 165747b..0000000 --- a/ue3/mycpu/cmem.cpp +++ /dev/null | |||
| @@ -1,124 +0,0 @@ | |||
| 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 | |||
| 41 | unsigned int regnr = getRegNr(reg); | ||
| 42 | |||
| 43 | // if (regnr >= MAX_REGISTER ) | ||
| 44 | |||
| 45 | if (regnr >= m_registers.size()) | ||
| 46 | { | ||
| 47 | for ( int i = m_registers.size(); i <= (int)regnr; i++) | ||
| 48 | m_registers.push_back(CDat((int)0)); | ||
| 49 | return m_registers[m_registers.size() - 1]; | ||
| 50 | } | ||
| 51 | |||
| 52 | return m_registers[regnr]; | ||
| 53 | } | ||
| 54 | |||
| 55 | /*----------------------------------------------------------------------------*/ | ||
| 56 | |||
| 57 | string CMem::getMemAt(const std::string addr) | ||
| 58 | { | ||
| 59 | int pos = getRegister(addr).getTypeValue(); | ||
| 60 | /* open and read mem */ | ||
| 61 | ifstream file(m_memfile.c_str(), ios::in); | ||
| 62 | string cur_line; | ||
| 63 | for (int i = 0; i <= pos; i++) | ||
| 64 | getline(file, cur_line); | ||
| 65 | |||
| 66 | file.close(); | ||
| 67 | if (cur_line.empty()) | ||
| 68 | return ""; | ||
| 69 | trim(cur_line); | ||
| 70 | return cur_line; | ||
| 71 | } | ||
| 72 | void CMem::setMemAt(const std::string addr, const CDat& value) | ||
| 73 | { | ||
| 74 | unsigned int pos = getRegister(addr).getTypeValue(); | ||
| 75 | /* open and read mem */ | ||
| 76 | ifstream ifile(m_memfile.c_str() ); | ||
| 77 | vector<string> tmp; | ||
| 78 | unsigned int i = 0; | ||
| 79 | while (ifile.good()) | ||
| 80 | { | ||
| 81 | string cur_line; | ||
| 82 | getline(ifile, cur_line); | ||
| 83 | if(!cur_line.empty()) | ||
| 84 | tmp.push_back(cur_line); | ||
| 85 | i++; | ||
| 86 | } | ||
| 87 | ifile.close(); | ||
| 88 | cout << tmp.size()<<"sasa"<<pos<<" "<<endl; | ||
| 89 | |||
| 90 | ofstream ofile(m_memfile.c_str(), fstream::trunc); | ||
| 91 | i = 0; | ||
| 92 | while (ofile.good() && i < tmp.size()) | ||
| 93 | { | ||
| 94 | if (i != pos) | ||
| 95 | ofile << tmp[i] << endl; | ||
| 96 | else | ||
| 97 | ofile << value << endl; | ||
| 98 | cout << tmp[i]<< endl; | ||
| 99 | i++; | ||
| 100 | } | ||
| 101 | ofile.close(); | ||
| 102 | } | ||
| 103 | /*----------------------------------------------------------------------------*/ | ||
| 104 | |||
| 105 | unsigned int CMem::getRegNr(const std::string reg) | ||
| 106 | { | ||
| 107 | istringstream stmp ( | ||
| 108 | reg.substr(reg.find_first_of("R") + 1, reg.size()) | ||
| 109 | ); | ||
| 110 | |||
| 111 | unsigned int regnr; | ||
| 112 | stmp >> regnr; | ||
| 113 | return regnr; | ||
| 114 | } | ||
| 115 | |||
| 116 | /*----------------------------------------------------------------------------*/ | ||
| 117 | |||
| 118 | #ifdef DEBUG | ||
| 119 | void CMem::dump(std::ostream& out) | ||
| 120 | { | ||
| 121 | out << endl << "Memory file:" << endl << m_memfile << endl; | ||
| 122 | out << endl << "Memory file content:" << endl; | ||
| 123 | } | ||
| 124 | #endif | ||
