Skip to content

Commit cbcdd4a

Browse files
committed
Support bignum library in wabt
1 parent 035de45 commit cbcdd4a

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

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

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

0 commit comments

Comments
 (0)