diff options
Diffstat (limited to 'ue4/mycpu/mycpu.cpp')
| -rw-r--r-- | ue4/mycpu/mycpu.cpp | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/ue4/mycpu/mycpu.cpp b/ue4/mycpu/mycpu.cpp index b25e721..6c9f71a 100644 --- a/ue4/mycpu/mycpu.cpp +++ b/ue4/mycpu/mycpu.cpp | |||
| @@ -6,7 +6,7 @@ | |||
| 6 | * be executed in linear order (except jumps) afterwards. In order to | 6 | * be executed in linear order (except jumps) afterwards. In order to |
| 7 | * initialize the memory of the cpu before execution an optional | 7 | * initialize the memory of the cpu before execution an optional |
| 8 | * memoryfile can be passed as commandline option. | 8 | * memoryfile can be passed as commandline option. |
| 9 | * @date 13.05.2009 | 9 | * @date 26.05.2009 |
| 10 | * @par Exercise | 10 | * @par Exercise |
| 11 | * 4 | 11 | * 4 |
| 12 | */ | 12 | */ |
| @@ -16,9 +16,10 @@ | |||
| 16 | #include <fstream> | 16 | #include <fstream> |
| 17 | #include <stdexcept> | 17 | #include <stdexcept> |
| 18 | #include <stdlib.h> | 18 | #include <stdlib.h> |
| 19 | #include "ccpu.h" | 19 | #include "cdat.h" |
| 20 | #include "cmem.h" | 20 | #include "cmem.h" |
| 21 | #include "cprogram.h" | 21 | #include "cprogram.h" |
| 22 | #include "ccpu.h" | ||
| 22 | 23 | ||
| 23 | using namespace std; | 24 | using namespace std; |
| 24 | namespace po = boost::program_options; | 25 | namespace po = boost::program_options; |
| @@ -47,6 +48,7 @@ int main(int argc, char* argv[]) | |||
| 47 | po::options_description desc("Allowed options"); | 48 | po::options_description desc("Allowed options"); |
| 48 | desc.add_options() | 49 | desc.add_options() |
| 49 | ("help,h", "this help message") | 50 | ("help,h", "this help message") |
| 51 | ("format,f", po::value<string>(), "format") | ||
| 50 | ("compile,c", po::value<string>(), "input programfile") | 52 | ("compile,c", po::value<string>(), "input programfile") |
| 51 | ("memory,m", po::value<string>(), "input memoryfile"); | 53 | ("memory,m", po::value<string>(), "input memoryfile"); |
| 52 | 54 | ||
| @@ -65,13 +67,13 @@ int main(int argc, char* argv[]) | |||
| 65 | /* print usage upon request or missing params */ | 67 | /* print usage upon request or missing params */ |
| 66 | if (vm.count("help") || !vm.count("compile")) | 68 | if (vm.count("help") || !vm.count("compile")) |
| 67 | { | 69 | { |
| 68 | cout << "Usage: " << me << " -c <programfile> [-m <memoryfile>]" << endl; | 70 | cout << "Usage: " << me << " [-f <format>] -c <programfile> [-m <memoryfile>]" << endl; |
| 69 | cout << desc << endl; | 71 | cout << desc << endl; |
| 70 | return 0; | 72 | return 0; |
| 71 | } | 73 | } |
| 72 | 74 | ||
| 73 | /* create memory and optionally initialize memory from file */ | 75 | /* create memory and optionally initialize memory from file */ |
| 74 | CMem memory; | 76 | CMem<CDat<int> > memory; |
| 75 | if (vm.count("memory")) | 77 | if (vm.count("memory")) |
| 76 | { | 78 | { |
| 77 | string memoryfile(vm["memory"].as<string>()); | 79 | string memoryfile(vm["memory"].as<string>()); |
| @@ -101,7 +103,7 @@ int main(int argc, char* argv[]) | |||
| 101 | } | 103 | } |
| 102 | 104 | ||
| 103 | /* create program instance */ | 105 | /* create program instance */ |
| 104 | CProgram program; | 106 | CProgram<CDat<int> > program; |
| 105 | string programfile(vm["compile"].as<string>()); | 107 | string programfile(vm["compile"].as<string>()); |
| 106 | ifstream file(programfile.c_str(), ios::in); | 108 | ifstream file(programfile.c_str(), ios::in); |
| 107 | if (!file.is_open()) | 109 | if (!file.is_open()) |
| @@ -131,7 +133,7 @@ int main(int argc, char* argv[]) | |||
| 131 | /* create cpu and execute the program */ | 133 | /* create cpu and execute the program */ |
| 132 | try | 134 | try |
| 133 | { | 135 | { |
| 134 | CCPU cpu(256); | 136 | CCPU<CDat<int> > cpu(256); |
| 135 | cpu.setMemory(&memory); | 137 | cpu.setMemory(&memory); |
| 136 | cpu.setProgram(&program); | 138 | cpu.setProgram(&program); |
| 137 | cpu.run(); | 139 | cpu.run(); |
