Exemple #1
0
  machine::machine(const string& file, const size_t th,
                   const scheduler_type _sched_type, const machine_arguments& margs, const string& data_file):
    filename(file),
    sched_type(_sched_type),
    alarm_thread(NULL),
    slices(th) /* th = number of threads, slices is for statistics */
  {
    bool added_data_file(false);

    vm::All = new vm::all();
    vm::All->PROGRAM = new vm::program(file);
    vm::theProgram = vm::All->PROGRAM;
    if(vm::All->PROGRAM->is_data())
      throw machine_error(string("cannot run data files"));
    if(data_file != string("")) {
      if(file_exists(data_file)) {
        vm::program data(data_file);
        if(!vm::All->PROGRAM->add_data_file(data)) {
          throw machine_error(string("could not import data file"));
        }
        added_data_file = true;
      } else {
        throw machine_error(string("data file ") + data_file + string(" not found"));
      }
    }

    if(margs.size() < vm::All->PROGRAM->num_args_needed())
      throw machine_error(string("this program requires ") + utils::to_string(vm::All->PROGRAM->num_args_needed()) + " arguments");

    vm::All->MACHINE = this;
    vm::All->ARGUMENTS = margs;
    vm::All->DATABASE = new database(added_data_file ? data_file : filename, get_creation_function(_sched_type));
    vm::All->NUM_THREADS = th;

    // Instantiate the scheduler object
    switch(sched_type) {
    case SCHED_SERIAL:
      vm::All->ALL_THREADS.push_back(dynamic_cast<sched::base*>(new sched::serial_local()));
      break;
    case SCHED_UNKNOWN: assert(false); break;
    default: break;
    }

    assert(vm::All->ALL_THREADS.size() == vm::All->NUM_THREADS);

  }
Exemple #2
0
	inline runtime::rstring::ptr get_argument(const argument_id id)
	{
		assert(id <= ARGUMENTS.size());
		return runtime::rstring::make_string(ARGUMENTS[id-1]);
	}