Skip to content

Commit 20fd6c1

Browse files
committed
Support bignum library in wabt
1 parent be36244 commit 20fd6c1

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/wabt.cpp

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,39 @@ ExecutionResult WabtEngine::execute(
584584
}
585585
);
586586

587+
// Create the bignum host module
588+
// The lifecycle of this pointer is handled by `env`.
589+
hostModule = env.AppendHostModule("bignum");
590+
heraAssert(hostModule, "Failed to create host module.");
591+
592+
hostModule->AppendFuncExport(
593+
"mul256",
594+
{{Type::I32, Type::I32, Type::I32}, {}},
595+
[&interface](
596+
const interp::HostFunc*,
597+
const interp::FuncSignature*,
598+
const interp::TypedValues& args,
599+
interp::TypedValues&
600+
) {
601+
interface.mul256(args[0].value.i32, args[1].value.i32, args[2].value.i32);
602+
return interp::Result::Ok;
603+
}
604+
);
605+
606+
hostModule->AppendFuncExport(
607+
"umulmod256",
608+
{{Type::I32, Type::I32, Type::I32, Type::I32}, {}},
609+
[&interface](
610+
const interp::HostFunc*,
611+
const interp::FuncSignature*,
612+
const interp::TypedValues& args,
613+
interp::TypedValues&
614+
) {
615+
interface.umulmod256(args[0].value.i32, args[1].value.i32, args[2].value.i32, args[3].value.i32);
616+
return interp::Result::Ok;
617+
}
618+
);
619+
587620
#if HERA_DEBUGGING
588621
// Create debug host module
589622
// The lifecycle of this pointer is handled by `env`.
@@ -1112,6 +1145,37 @@ void WabtEngine::verifyContract(bytes_view code) {
11121145
}
11131146
);
11141147

1148+
// Create the bignum host module
1149+
// The lifecycle of this pointer is handled by `env`.
1150+
hostModule = env.AppendHostModule("bignum");
1151+
heraAssert(hostModule, "Failed to create host module.");
1152+
1153+
hostModule->AppendFuncExport(
1154+
"mul256",
1155+
{{Type::I32, Type::I32, Type::I32}, {}},
1156+
[&](
1157+
const interp::HostFunc*,
1158+
const interp::FuncSignature*,
1159+
const interp::TypedValues&,
1160+
interp::TypedValues&
1161+
) {
1162+
return interp::Result::Ok;
1163+
}
1164+
);
1165+
1166+
hostModule->AppendFuncExport(
1167+
"umulmod256",
1168+
{{Type::I32, Type::I32, Type::I32, Type::I32}, {}},
1169+
[&](
1170+
const interp::HostFunc*,
1171+
const interp::FuncSignature*,
1172+
const interp::TypedValues&,
1173+
interp::TypedValues&
1174+
) {
1175+
return interp::Result::Ok;
1176+
}
1177+
);
1178+
11151179
#if HERA_DEBUGGING
11161180
// Create debug host module
11171181
// The lifecycle of this pointer is handled by `env`.

0 commit comments

Comments
 (0)