当前位置: 首页>>代码示例>>C++>>正文


C++ CompiledFile类代码示例

本文整理汇总了C++中CompiledFile的典型用法代码示例。如果您正苦于以下问题:C++ CompiledFile类的具体用法?C++ CompiledFile怎么用?C++ CompiledFile使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CompiledFile类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: test_body

  void test_body() {
    std::istringstream stream;
    stream.str("!RBIX\n1\n42\nt");

    CompiledFile* cf = CompiledFile::load(stream);
    TS_ASSERT_EQUALS(cf->body(state), cTrue);
  }
开发者ID:DanielVartanov,项目名称:rubinius,代码行数:7,代码来源:test_compiled_file.hpp

示例2: stream

  void Environment::run_file(std::string file) {
    if(!state->probe->nil_p()) state->probe->load_runtime(state, file);

    std::ifstream stream(file.c_str());
    if(!stream) throw std::runtime_error("Unable to open file to run");

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") throw std::runtime_error("Invalid file");

    // TODO check version number
    cf->execute(state);

    if(!G(current_task)->exception()->nil_p()) {
      // Reset the context so we can show the backtrace
      // HACK need to use write barrier aware stuff?
      Exception* exc = G(current_task)->exception();
      G(current_task)->active(state, exc->context());

      std::ostringstream msg;

      msg << "exception detected at toplevel: ";
      if(!exc->message()->nil_p()) {
        msg << exc->message()->c_str();
      }
      msg << " (" << exc->klass()->name()->c_str(state) << ")";
      Assertion::raise(msg.str().c_str());
    }
  }
开发者ID:gustin,项目名称:rubinius,代码行数:28,代码来源:environment.cpp

示例3: main

int main(int argc, char **argv) {
  JITCompiler compiler;
  VMManager * manager = new VMManager;
  SharedState * shared = manager->create_shared_state();
  ConfigParser * config = new ConfigParser;
  shared->user_config = config;
  VM* state = shared->thread_nexus()->new_vm();

  state->initialize(VM::default_bytes);
  state->boot();

  state->global_lock().lock();

  std::ifstream stream(argv[1]);
  if(!stream) {
    cout << "Can't open ' " << argv[1] << "'\n";
    return 1;
  }

  CompiledFile* cf = CompiledFile::load(state, stream);
  if(cf->magic != "!RBIX") {
    cout << "Invalid file.\n";
  }

  MachineCode* mcode = as<CompiledCode>(cf->body(state))->formalize(state, false);

  delete cf;

  compiler.compile(state, mcode);
  MachineMethod* mm = MachineMethod::create(state, mcode, compiler);
  mm->show();
  return 0;
}
开发者ID:Justme0,项目名称:rubinius,代码行数:33,代码来源:jit-test.cpp

示例4: test_load_file

  void test_load_file() {
    std::fstream stream("vm/test/fixture.rbc_");
    TS_ASSERT(!!stream);

    CompiledFile* cf = CompiledFile::load(stream);
    TS_ASSERT_EQUALS(cf->magic, "!RBIX");

    CompiledCode* code = try_as<CompiledCode>(cf->body(state));
    TS_ASSERT(code);
  }
开发者ID:DanielVartanov,项目名称:rubinius,代码行数:10,代码来源:test_compiled_file.hpp

示例5: stream

  void Environment::run_file(std::string file) {
    std::ifstream stream(file.c_str());
    if(!stream) {
      std::string msg = std::string("Unable to open file to run: ");
      msg.append(file);
      throw std::runtime_error(msg);
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      std::ostringstream msg;
      msg << "attempted to open a bytecode file with invalid magic identifier"
          << ": path: " << file << ", magic: " << cf->magic;
      throw std::runtime_error(msg.str().c_str());
    }
    if((signature_ > 0 && cf->signature != signature_)
        || cf->version != version_) {
      throw BadKernelFile(file);
    }

    cf->execute(state);

    if(state->vm()->thread_state()->raise_reason() == cException) {
      Exception* exc = as<Exception>(state->vm()->thread_state()->current_exception());
      std::ostringstream msg;

      msg << "exception detected at toplevel: ";
      if(!exc->reason_message()->nil_p()) {
        if(String* str = try_as<String>(exc->reason_message())) {
          msg << str->c_str(state);
        } else {
          msg << "<non-string Exception message>";
        }
      } else if(Exception::argument_error_p(state, exc)) {
        msg << "given "
            << as<Fixnum>(exc->get_ivar(state, state->symbol("@given")))->to_native()
            << ", expected "
            << as<Fixnum>(exc->get_ivar(state, state->symbol("@expected")))->to_native();
      }
      msg << " (" << exc->klass()->debug_str(state) << ")";
      std::cout << msg.str() << "\n";
      exc->print_locations(state);
      Assertion::raise(msg.str().c_str());
    }

    delete cf;
  }
开发者ID:dead2eer,项目名称:rubinius,代码行数:47,代码来源:environment.cpp

示例6: stream

  //
  // HACK: remove this when performance is better and compiled_file.rb
  // unmarshal_data method works.
  Object* System::compiledfile_load(STATE, String* path, Object* version) {
    if(!state->probe->nil_p()) {
      state->probe->load_runtime(state, std::string(path->c_str()));
    }

    std::ifstream stream(path->c_str());
    if(!stream) {
      std::ostringstream msg;
      msg << "unable to open file to run: " << path->c_str();
      Exception::io_error(state, msg.str().c_str());
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      std::ostringstream msg;
      msg << "Invalid file: " << path->c_str();
      Exception::io_error(state, msg.str().c_str());
    }

    return cf->body(state);
  }
开发者ID:gustin,项目名称:rubinius,代码行数:24,代码来源:system.cpp

示例7: stream

  //
  // HACK: remove this when performance is better and compiled_file.rb
  // unmarshal_data method works.
  Object* System::compiledfile_load(STATE, String* path, Integer* version) {
    std::ifstream stream(path->c_str(state));
    if(!stream) {
      return Primitives::failure();
    }

    CompiledFile* cf = CompiledFile::load(stream);
    if(cf->magic != "!RBIX") {
      delete cf;
      return Primitives::failure();
    }

    uint64_t ver = version->to_ulong_long();
    if((ver > 0 && cf->version != ver) || cf->sum != "x") {
      delete cf;
      return Primitives::failure();
    }

    Object *body = cf->body(state);

    delete cf;
    return body;
  }
开发者ID:angelim,项目名称:rubinius,代码行数:26,代码来源:system.cpp

示例8: prettyprint_in_file

    void AST_t::prettyprint_in_file(const CompiledFile& compiled_file, bool internal) const
    {
        if (!internal)
        {
            prettyprint_set_not_internal_output();
        }
        else
        {
            prettyprint_set_internal_output();
        }

        FILE *file = fopen(compiled_file.get_filename().c_str(), "a");
        if (file == NULL)
        {
            running_error("Could not open output file '%s' (%s)\n", 
                    compiled_file.get_filename().c_str(), 
                    strerror(errno));
        }

        ::prettyprint(file, this->_ast);

        fclose(file);
    }
开发者ID:sdruix,项目名称:AutomaticParallelization,代码行数:23,代码来源:tl-ast.cpp


注:本文中的CompiledFile类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。