Skip to content

Commit

Permalink
Update WAVM binding to match new API
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Feb 8, 2019
1 parent f81d443 commit d4e36cd
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/wavm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#pragma GCC diagnostic ignored "-Wunused-variable"

using namespace std;
using namespace WAVM;

namespace hera {

Expand All @@ -60,7 +61,7 @@ class WavmEthereumInterface : public EthereumInterface {
EthereumInterface(_context, _code, _msg, _result, _meterGas)
{}

void setWasmMemory(Runtime::MemoryInstance* _wasmMemory) {
void setWasmMemory(Runtime::Memory* _wasmMemory) {
m_wasmMemory = _wasmMemory;
}

Expand All @@ -70,7 +71,7 @@ class WavmEthereumInterface : public EthereumInterface {
void memorySet(size_t offset, uint8_t value) override { (Runtime::memoryArrayPtr<U8>(m_wasmMemory, offset, 1))[0] = value; }
uint8_t memoryGet(size_t offset) override { return (Runtime::memoryArrayPtr<U8>(m_wasmMemory, offset, 1))[0]; }

Runtime::MemoryInstance* m_wasmMemory;
Runtime::Memory* m_wasmMemory;
};

unique_ptr<WasmEngine> WavmEngine::create()
Expand Down Expand Up @@ -181,7 +182,7 @@ namespace wavm_host_module {

bool resolve(const string& moduleName,
const string& exportName,
IR::ObjectType type,
IR::ExternType type,
Runtime::Object*& outObject) override
{
outObject = nullptr;
Expand All @@ -202,7 +203,8 @@ ExecutionResult WavmEngine::execute(
) {
ExecutionResult result = internalExecute(context, code, state_code, msg, meterInterfaceGas);
// And clean up mess left by this run.
Runtime::collectGarbage();
// TODO: enable this.
// Runtime::collectCompartmentGarbage(compartment);
return result;
}

Expand Down Expand Up @@ -255,7 +257,7 @@ ExecutionResult WavmEngine::internalExecute(
heraAssert(linkResult.success, "Couldn't link contract against host module.");

// compile the module from IR to LLVM bitcode
Runtime::GCPointer<Runtime::Module> module = Runtime::compileModule(moduleIR);
Runtime::ModuleRef module = Runtime::compileModule(moduleIR);

// instantiate contract module
Runtime::GCPointer<Runtime::ModuleInstance> moduleInstance = Runtime::instantiateModule(compartment, module, move(linkResult.resolvedImports), "<ewasmcontract>");
Expand All @@ -265,7 +267,7 @@ ExecutionResult WavmEngine::internalExecute(
wavm_host_module::interface.top()->setWasmMemory(asMemory(Runtime::getInstanceExport(moduleInstance, "memory")));

// invoke the main function
Runtime::GCPointer<Runtime::FunctionInstance> mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main"));
Runtime::GCPointer<Runtime::Function> mainFunction = asFunctionNullable(Runtime::getInstanceExport(moduleInstance, "main"));
ensureCondition(mainFunction, ContractValidationFailure, "\"main\" not found");

// this is how WAVM's try/catch for exceptions
Expand Down

0 comments on commit d4e36cd

Please sign in to comment.