From 34483e07a0548d32651cda4ca4282f3cf8cae870 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnther=20Neuwirth?= Date: Tue, 12 May 2009 15:27:58 +0200 Subject: adding rest of files --- ue3/mycpu/mycpu.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 ue3/mycpu/mycpu.cpp (limited to 'ue3/mycpu/mycpu.cpp') 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 @@ +/** + * @module mycpu + * @author Guenther Neuwirth (0626638), Manuel Mausz (0728348) + * @brief mycpu reads a program file and optional a memory file given as + * commandline option. + * On error (e.g. unknown function) the program will terminate + * @date 11.05.2009 + * @par Exercise + * 3 + */ + +#include +#include +#include "ccpu.h" + +using namespace std; +namespace po = boost::program_options; + +/** + * @func main + * @brief program entry point + * @param argc standard parameter of main + * @param argv standard parameter of main + * @return 0 on success, not 0 otherwise + * @globalvars none + * @exception none + * @conditions none + * + * setup commandline options, parse them and pass scriptfile to scriptparser + * instance. On error print error message to stderr. + * Unknown commandline options will print a usage message. + */ +int main(int argc, char* argv[]) +{ + string me(argv[0]); + + /* define commandline options */ + po::options_description desc("Allowed options"); + desc.add_options() + ("help,h", "this help message") + ("progfile,c", po::value(), "program file") + ("memfile,m", po::value(), "memory file"); + + /* parse commandline options */ + po::variables_map vm; + try + { + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + } + catch(po::error& ex) + { + cerr << "Error: " << ex.what() << endl; + } + + /* print usage upon request or missing params */ + if (vm.count("help") || !vm.count("progfile")) + { + cout << "Usage: " << me << " -c [ -m ]" << endl; + cout << desc << endl; + if ( vm.count("help")) + return 0; + return 1; + } + + string memfile(""); + if (vm.count("memfile")) + memfile = vm["memfile"].as(); + + CCPU cpu(vm["progfile"].as(), memfile); + cpu.proceed(); + +/* CScriptparser parser(vm["c"].as()); + try + { + parser.parse(); + } + catch(CScriptparser::ParserError& ex) + { + cerr << me << ": Error while processing scriptfile: " << ex.what() << endl; + if (!ex.getLine().empty()) + cerr << "Scriptline: '" << ex.getLine() << "'" << endl; + return 1; + } + catch(exception& ex) + { + cerr << me << ": Unexpected exception: " << ex.what() << endl; + return 1; + }*/ + + return 0; +} + +/* vim: set et sw=2 ts=2: */ -- cgit v1.2.3