Skip to content

Commit

Permalink
Support bignum library in wabt
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Apr 26, 2019
1 parent 035de45 commit 77c0866
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions src/wabt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,39 @@ ExecutionResult WabtEngine::execute(
}
);

// Create the bignum host module
// The lifecycle of this pointer is handled by `env`.
hostModule = env.AppendHostModule("bignum");
heraAssert(hostModule, "Failed to create host module.");

hostModule->AppendFuncExport(
"mul256",
{{Type::I32, Type::I32, Type::I32}, {}},
[&interface](
const interp::HostFunc*,
const interp::FuncSignature*,
const interp::TypedValues& args,
interp::TypedValues&
) {
interface.mul256(args[0].value.i32, args[1].value.i32, args[2].value.i32);
return interp::Result::Ok;
}
);

hostModule->AppendFuncExport(
"umulmod256",
{{Type::I32, Type::I32, Type::I32, Type::I32}, {}},
[&interface](
const interp::HostFunc*,
const interp::FuncSignature*,
const interp::TypedValues& args,
interp::TypedValues&
) {
interface.umulmod256(args[0].value.i32, args[1].value.i32, args[2].value.i32, args[3].value.i32);
return interp::Result::Ok;
}
);

#if HERA_DEBUGGING
// Create debug host module
// The lifecycle of this pointer is handled by `env`.
Expand Down Expand Up @@ -1109,6 +1142,37 @@ void WabtEngine::verifyContract(std::vector<uint8_t> const& code) {
}
);

// Create the bignum host module
// The lifecycle of this pointer is handled by `env`.
hostModule = env.AppendHostModule("bignum");
heraAssert(hostModule, "Failed to create host module.");

hostModule->AppendFuncExport(
"mul256",
{{Type::I32, Type::I32, Type::I32}, {}},
[&](
const interp::HostFunc*,
const interp::FuncSignature*,
const interp::TypedValues&,
interp::TypedValues&
) {
return interp::Result::Ok;
}
);

hostModule->AppendFuncExport(
"umulmod256",
{{Type::I32, Type::I32, Type::I32, Type::I32}, {}},
[&](
const interp::HostFunc*,
const interp::FuncSignature*,
const interp::TypedValues&,
interp::TypedValues&
) {
return interp::Result::Ok;
}
);

#if HERA_DEBUGGING
// Create debug host module
// The lifecycle of this pointer is handled by `env`.
Expand Down

0 comments on commit 77c0866

Please sign in to comment.