wasm

apply_context.cpp

action_trace apply_context::exec_one()
{
     control.get_wasm_interface().apply(a.code_version, a.code, *this);
}

wasm_interface.cpp

   void wasm_interface::apply( const digest_type& code_id, const shared_string& code, apply_context& context ) {
      my->get_instantiated_module(code_id, code, context.trx_context)->apply(context);
   }

wasm_interface_private.hpp

 struct wasm_interface_impl {
     std::unique_ptr& get_instantiated_module( const digest_type& code_id,
                                                                                    const shared_string& code,
                                                                                    transaction_context& trx_context )
      {
            it = instantiation_cache.emplace(code_id, runtime_interface->instantiate_module((const char*)bytes.data(), bytes.size(), parse_initial_memory(module))).first;
      }

binaryen.cpp

class binaryen_instantiated_module : public wasm_instantiated_module_interface {
      void apply(apply_context& context) override {
         LiteralList args = {Literal(uint64_t(context.receiver)),
                         Literal(uint64_t(context.act.account)),
                             Literal(uint64_t(context.act.name))};
         call("apply", args, context);
      }

      void call(const string& entry_point, LiteralList& args, apply_context& context){
         const unsigned initial_memory_size = _module->memory.initial*Memory::kPageSize;
         interpreter_interface local_interface(_shared_linear_memory, _table, _import_lut, initial_memory_size, context);

         //zero out the initial pages
         memset(_shared_linear_memory.data, 0, initial_memory_size);
         //copy back in the initial data
         memcpy(_shared_linear_memory.data, _initial_memory.data(), _initial_memory.size());
         
         //be aware that construction of the ModuleInstance implictly fires the start function
         ModuleInstance instance(*_module.get(), &local_interface);
         instance.callExport(Name(entry_point), args);
      }
    }

std::unique_ptr binaryen_runtime::instantiate_module(const char* code_bytes, size_t code_size, std::vector initial_memory) {
     try {
         return std::make_unique(_memory, initial_memory, move(table), move(import_lut), move(module))
     }

binaryen.hpp

struct interpreter_interface : ModuleInstance::ExternalInterface {
}

class binaryen_runtime : public eosio::chain::wasm_runtime_interface {
}

wasm-interpreter.h

template
class ModuleInstanceBase {

  Module& wasm;
  ExternalInterface* externalInterface;
};

class ModuleInstance : public ModuleInstanceBase {
public:
  ModuleInstance(Module& wasm, ExternalInterface* externalInterface) : ModuleInstanceBase(wasm, externalInterface) {}
};

你可能感兴趣的:(wasm)