Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support wavm as a VM #158

Closed
axic opened this issue Mar 14, 2018 · 1 comment
Closed

Support wavm as a VM #158

axic opened this issue Mar 14, 2018 · 1 comment

Comments

@axic
Copy link
Member

axic commented Mar 14, 2018

Depends on #156.

@axic
Copy link
Member Author

axic commented Jul 29, 2018

Extracted this basic logic from https://github.com/AndrewScheidecker/WAVM/blob/master/Source/Programs/wavm.cpp:

// This is needed because for some reason wavm expects it.
#define DLL_IMPORT

#include <IR/Module.h>
#include <IR/Validate.h>
#include <WASM/WASM.h>
#include <Runtime/Runtime.h>
#include <Runtime/Linker.h>
#include <Runtime/Intrinsics.h>

struct TestResolver : Runtime::Resolver
{
    bool resolve(
      const std::string& moduleName,
      const std::string& exportName,
      IR::ObjectType type,
      Runtime::Object*& outObject) override
    {
      // Implement this here.
      (void)moduleName;
      (void)exportName;
      (void)type;
      (void)outObject;
      return false;
    }
};

bool loadModule(const char* filename,IR::Module& outModule) {
  (void)filename;
  vector<uint8_t> wasmBytes; // iIll this with actual content.
  Serialization::MemoryInputStream stream((const U8*)wasmBytes.data(),wasmBytes.size());
  WASM::serialize(stream,outModule);
  return true;
}

void wavm_test() {
  IR::Module module;
  if (!loadModule("test.wasm", module)) abort();

  Runtime::Compartment* compartment = Runtime::createCompartment();
  //Runtime::Context* context = Runtime::createContext(compartment);

  TestResolver resolver;
  Runtime::LinkResult linkResult = Runtime::linkModule(module, resolver);
  if (!linkResult.success) abort();

  Runtime::ModuleInstance* moduleInstance = Runtime::instantiateModule(
        compartment,
        module,
        std::move(linkResult.resolvedImports),
        "test.wasm");

  if (!moduleInstance) abort();
  
  // Actually retrieve a function and not the start one.
  Runtime::FunctionInstance* startFunction = Runtime::getStartFunction(moduleInstance);
  if (!startFunction) abort();
}

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants