Skip to content

Commit 827c193

Browse files
committed
Support bignum library in wabt
1 parent 7cd9571 commit 827c193

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
@@ -580,6 +580,39 @@ ExecutionResult WabtEngine::execute(
580580
}
581581
);
582582

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

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

0 commit comments

Comments
 (0)