summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/mycpu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'ue3/mycpu/mycpu.cpp')
-rw-r--r--ue3/mycpu/mycpu.cpp94
1 files changed, 94 insertions, 0 deletions
diff --git a/ue3/mycpu/mycpu.cpp b/ue3/mycpu/mycpu.cpp
new file mode 100644
index 0000000..af6fe08
--- /dev/null
+++ b/ue3/mycpu/mycpu.cpp
@@ -0,0 +1,94 @@
1/**
2 * @module mycpu
3 * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348)
4 * @brief mycpu reads a program file and optional a memory file given as
5 * commandline option.
6 * On error (e.g. unknown function) the program will terminate
7 * @date 11.05.2009
8 * @par Exercise
9 * 3
10 */
11
12#include <iostream>
13#include <boost/program_options.hpp>
14#include "ccpu.h"
15
16using namespace std;
17namespace po = boost::program_options;
18
19/**
20 * @func main
21 * @brief program entry point
22 * @param argc standard parameter of main
23 * @param argv standard parameter of main
24 * @return 0 on success, not 0 otherwise
25 * @globalvars none
26 * @exception none
27 * @conditions none
28 *
29 * setup commandline options, parse them and pass scriptfile to scriptparser
30 * instance. On error print error message to stderr.
31 * Unknown commandline options will print a usage message.
32 */
33int main(int argc, char* argv[])
34{
35 string me(argv[0]);
36
37 /* define commandline options */
38 po::options_description desc("Allowed options");
39 desc.add_options()
40 ("help,h", "this help message")
41 ("progfile,c", po::value<string>(), "program file")
42 ("memfile,m", po::value<string>(), "memory file");
43
44 /* parse commandline options */
45 po::variables_map vm;
46 try
47 {
48 po::store(po::parse_command_line(argc, argv, desc), vm);
49 po::notify(vm);
50 }
51 catch(po::error& ex)
52 {
53 cerr << "Error: " << ex.what() << endl;
54 }
55
56 /* print usage upon request or missing params */
57 if (vm.count("help") || !vm.count("progfile"))
58 {
59 cout << "Usage: " << me << " -c <programfile> [ -m <memoryfile>]" << endl;
60 cout << desc << endl;
61 if ( vm.count("help"))
62 return 0;
63 return 1;
64 }
65
66 string memfile("");
67 if (vm.count("memfile"))
68 memfile = vm["memfile"].as<string>();
69
70 CCPU cpu(vm["progfile"].as<string>(), memfile);
71 cpu.proceed();
72
73/* CScriptparser parser(vm["c"].as<string>());
74 try
75 {
76 parser.parse();
77 }
78 catch(CScriptparser::ParserError& ex)
79 {
80 cerr << me << ": Error while processing scriptfile: " << ex.what() << endl;
81 if (!ex.getLine().empty())
82 cerr << "Scriptline: '" << ex.getLine() << "'" << endl;
83 return 1;
84 }
85 catch(exception& ex)
86 {
87 cerr << me << ": Unexpected exception: " << ex.what() << endl;
88 return 1;
89 }*/
90
91 return 0;
92}
93
94/* vim: set et sw=2 ts=2: */