summaryrefslogtreecommitdiffstats
path: root/ue3/mycpu/mycpu.cpp
blob: af6fe0866ab0c57e53e50ab4102a5b7142eb831a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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 <iostream>
#include <boost/program_options.hpp>
#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<string>(), "program file")
    ("memfile,m", po::value<string>(), "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 <programfile> [ -m <memoryfile>]" << endl;
    cout << desc << endl;
    if ( vm.count("help"))
      return 0;
    return 1;
  }
  
  string memfile("");
  if (vm.count("memfile"))
    memfile = vm["memfile"].as<string>();
  
  CCPU cpu(vm["progfile"].as<string>(), memfile);
  cpu.proceed();
 
/*  CScriptparser parser(vm["c"].as<string>());
  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: */