@@ -70,15 +70,15 @@ template <> constexpr ValueType inferValueType<proxy_wasm::Word>() { return Valu
70
70
namespace proxy_wasm {
71
71
72
72
// Forward declarations.
73
+ template <typename ... Args>
74
+ void getFunctionWavm (WasmVm *vm, std::string_view function_name,
75
+ std::function<void (ContextBase *, Args...)> *function);
73
76
template <typename R, typename ... Args>
74
77
void getFunctionWavm (WasmVm *vm, std::string_view function_name,
75
78
std::function<R(ContextBase *, Args...)> *function);
76
79
template <typename R, typename ... Args>
77
80
void registerCallbackWavm (WasmVm *vm, std::string_view module_name, std::string_view function_name,
78
- R (*)(Args...));
79
- template <typename F, typename R, typename ... Args>
80
- void registerCallbackWavm (WasmVm *vm, std::string_view module_name, std::string_view function_name,
81
- F, R (*)(Args...));
81
+ R (*function)(Args...));
82
82
83
83
namespace Wavm {
84
84
@@ -431,86 +431,6 @@ void registerCallbackWavm(WasmVm *vm, std::string_view module_name, std::string_
431
431
reinterpret_cast <void *>(f), inferHostFunctionType (f)));
432
432
}
433
433
434
- template void registerCallbackWavm<void , void *>(WasmVm *vm, std::string_view module_name,
435
- std::string_view function_name, void (*f)(void *));
436
- template void registerCallbackWavm<void , void *, U32>(WasmVm *vm, std::string_view module_name,
437
- std::string_view function_name,
438
- void (*f)(void *, U32));
439
- template void registerCallbackWavm<void , void *, U32, U32>(WasmVm *vm, std::string_view module_name,
440
- std::string_view function_name,
441
- void (*f)(void *, U32, U32));
442
- template void registerCallbackWavm<void , void *, U32, U32, U32>(WasmVm *vm,
443
- std::string_view module_name,
444
- std::string_view function_name,
445
- void (*f)(void *, U32, U32, U32));
446
- template void
447
- registerCallbackWavm<void , void *, U32, U32, U32, U32>(WasmVm *vm, std::string_view module_name,
448
- std::string_view function_name,
449
- void (*f)(void *, U32, U32, U32, U32));
450
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32>(
451
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
452
- void (*f)(void *, U32, U32, U32, U32, U32));
453
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32, U32>(
454
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
455
- void (*f)(void *, U32, U32, U32, U32, U32, U32));
456
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32, U32, U32>(
457
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
458
- void (*f)(void *, U32, U32, U32, U32, U32, U32, U32));
459
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32, U32, U32, U32>(
460
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
461
- void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32));
462
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32, U32, U32, U32, U32>(
463
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
464
- void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32));
465
- template void registerCallbackWavm<void , void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32>(
466
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
467
- void (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32));
468
-
469
- template void registerCallbackWavm<U32, void *>(WasmVm *vm, std::string_view module_name,
470
- std::string_view function_name, U32 (*f)(void *));
471
- template void registerCallbackWavm<U32, void *, U32>(WasmVm *vm, std::string_view module_name,
472
- std::string_view function_name,
473
- U32 (*f)(void *, U32));
474
- template void registerCallbackWavm<U32, void *, U32, U32>(WasmVm *vm, std::string_view module_name,
475
- std::string_view function_name,
476
- U32 (*f)(void *, U32, U32));
477
- template void registerCallbackWavm<U32, void *, U32, U32, U32>(WasmVm *vm,
478
- std::string_view module_name,
479
- std::string_view function_name,
480
- U32 (*f)(void *, U32, U32, U32));
481
- template void
482
- registerCallbackWavm<U32, void *, U32, U32, U32, U32>(WasmVm *vm, std::string_view module_name,
483
- std::string_view function_name,
484
- U32 (*f)(void *, U32, U32, U32, U32));
485
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32>(
486
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
487
- U32 (*f)(void *, U32, U32, U32, U32, U32));
488
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32, U32>(
489
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
490
- U32 (*f)(void *, U32, U32, U32, U32, U32, U32));
491
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32, U32, U32>(
492
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
493
- U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32));
494
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32, U32, U32, U32>(
495
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
496
- U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32));
497
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32, U32, U32, U32, U32>(
498
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
499
- U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32));
500
- template void registerCallbackWavm<U32, void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32>(
501
- WasmVm *vm, std::string_view module_name, std::string_view function_name,
502
- U32 (*f)(void *, U32, U32, U32, U32, U32, U32, U32, U32, U32, U32));
503
-
504
- template void registerCallbackWavm<U64, void *, U32>(WasmVm *vm, std::string_view module_name,
505
- std::string_view function_name,
506
- U64 (*f)(void *, U32));
507
- template void registerCallbackWavm<void , void *, U32, I64>(WasmVm *vm, std::string_view module_name,
508
- std::string_view function_name,
509
- void (*f)(void *, U32, I64));
510
- template void registerCallbackWavm<void , void *, U32, U64>(WasmVm *vm, std::string_view module_name,
511
- std::string_view function_name,
512
- void (*f)(void *, U32, U64));
513
-
514
434
template <typename R, typename ... Args>
515
435
IR::FunctionType inferStdFunctionType (std::function<R(ContextBase *, Args...)> *) {
516
436
return IR::FunctionType (IR::inferResultType<R>(), IR::TypeTuple ({IR::inferValueType<Args>()...}));
@@ -521,8 +441,8 @@ static bool checkFunctionType(WAVM::Runtime::Function *f, IR::FunctionType t) {
521
441
}
522
442
523
443
template <typename R, typename ... Args>
524
- void getFunctionWavmReturn (WasmVm *vm, std::string_view function_name,
525
- std::function<R(ContextBase *, Args...)> *function, uint32_t ) {
444
+ void getFunctionWavm (WasmVm *vm, std::string_view function_name,
445
+ std::function<R(ContextBase *, Args...)> *function) {
526
446
auto wavm = static_cast <proxy_wasm::Wavm::Wavm *>(vm);
527
447
auto f =
528
448
asFunctionNullable (getInstanceExport (wavm->module_instance_ , std::string (function_name)));
@@ -550,11 +470,9 @@ void getFunctionWavmReturn(WasmVm *vm, std::string_view function_name,
550
470
};
551
471
}
552
472
553
- struct Void {};
554
-
555
- template <typename R, typename ... Args>
556
- void getFunctionWavmReturn (WasmVm *vm, std::string_view function_name,
557
- std::function<R(ContextBase *, Args...)> *function, Void) {
473
+ template <typename ... Args>
474
+ void getFunctionWavm (WasmVm *vm, std::string_view function_name,
475
+ std::function<void (ContextBase *, Args...)> *function) {
558
476
auto wavm = static_cast <proxy_wasm::Wavm::Wavm *>(vm);
559
477
auto f =
560
478
asFunctionNullable (getInstanceExport (wavm->module_instance_ , std::string (function_name)));
@@ -568,104 +486,11 @@ void getFunctionWavmReturn(WasmVm *vm, std::string_view function_name,
568
486
wavm->fail (FailState::UnableToInitializeCode,
569
487
" Bad function signature for: " + std::string (function_name));
570
488
}
571
- *function = [wavm, f, function_name](ContextBase *context, Args... args) -> R {
489
+ *function = [wavm, f, function_name](ContextBase *context, Args... args) {
572
490
WasmUntaggedValue values[] = {args...};
573
491
CALL_WITH_CONTEXT (invokeFunction (wavm->context_ , f, getFunctionType (f), &values[0 ]), context,
574
492
wavm);
575
493
};
576
494
}
577
495
578
- // NB: Unfortunately 'void' is not treated like every other function type in C++. In
579
- // particular it is not possible to specialize a template based on 'void'. Instead
580
- // we use 'Void' for template matching. Note that the template implementation above
581
- // which matchers on 'bool' does not use 'Void' in the implemenation.
582
- template <typename R, typename ... Args>
583
- void getFunctionWavm (WasmVm *vm, std::string_view function_name,
584
- std::function<R(ContextBase *, Args...)> *function) {
585
- typename std::conditional<std::is_void<R>::value, Void, uint32_t >::type x{};
586
- getFunctionWavmReturn (vm, function_name, function, x);
587
- }
588
-
589
- template void getFunctionWavm<void >(WasmVm *, std::string_view,
590
- std::function<void (ContextBase *)> *);
591
- template void getFunctionWavm<void , uint32_t >(WasmVm *, std::string_view,
592
- std::function<void (ContextBase *, uint32_t )> *);
593
- template void
594
- getFunctionWavm<void , uint32_t , uint32_t >(WasmVm *, std::string_view,
595
- std::function<void (ContextBase *, uint32_t , uint32_t )> *);
596
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t >(
597
- WasmVm *, std::string_view, std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t )> *);
598
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t >(
599
- WasmVm *, std::string_view,
600
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t )> *);
601
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
602
- WasmVm *, std::string_view,
603
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t )> *);
604
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
605
- WasmVm *, std::string_view,
606
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t )>
607
- *);
608
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
609
- WasmVm *, std::string_view,
610
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
611
- uint32_t )> *);
612
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
613
- WasmVm *, std::string_view,
614
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
615
- uint32_t , uint32_t )> *);
616
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
617
- WasmVm *, std::string_view,
618
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
619
- uint32_t , uint32_t , uint32_t )> *);
620
- template void getFunctionWavm<void , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
621
- WasmVm *, std::string_view,
622
- std::function<void (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
623
- uint32_t , uint32_t , uint32_t , uint32_t )> *);
624
-
625
- template void getFunctionWavm<uint32_t >(WasmVm *, std::string_view,
626
- std::function<uint32_t (ContextBase *)> *);
627
- template void
628
- getFunctionWavm<uint32_t , uint32_t >(WasmVm *, std::string_view,
629
- std::function<uint32_t (ContextBase *, uint32_t )> *);
630
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t >(
631
- WasmVm *, std::string_view, std::function<uint32_t (ContextBase *, uint32_t , uint32_t )> *);
632
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t >(
633
- WasmVm *, std::string_view,
634
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t )> *);
635
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
636
- WasmVm *, std::string_view,
637
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t )> *);
638
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
639
- WasmVm *, std::string_view,
640
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t )> *);
641
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
642
- WasmVm *, std::string_view,
643
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
644
- uint32_t )> *);
645
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
646
- WasmVm *, std::string_view,
647
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
648
- uint32_t , uint32_t )> *);
649
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
650
- WasmVm *, std::string_view,
651
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
652
- uint32_t , uint32_t , uint32_t )> *);
653
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
654
- WasmVm *, std::string_view,
655
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
656
- uint32_t , uint32_t , uint32_t , uint32_t )> *);
657
- template void getFunctionWavm<uint32_t , uint32_t , uint32_t , uint32_t , uint32_t , uint32_t >(
658
- WasmVm *, std::string_view,
659
- std::function<uint32_t (ContextBase *, uint32_t , uint32_t , uint32_t , uint32_t , uint32_t ,
660
- uint32_t , uint32_t , uint32_t , uint32_t , uint32_t )> *);
661
-
662
- template <typename T> T getValue (IR::Value) {}
663
- template <> Word getValue (IR::Value v) { return v.u32 ; }
664
- template <> int32_t getValue (IR::Value v) { return v.i32 ; }
665
- template <> uint32_t getValue (IR::Value v) { return v.u32 ; }
666
- template <> int64_t getValue (IR::Value v) { return v.i64 ; }
667
- template <> uint64_t getValue (IR::Value v) { return v.u64 ; }
668
- template <> float getValue (IR::Value v) { return v.f32 ; }
669
- template <> double getValue (IR::Value v) { return v.f64 ; }
670
-
671
496
} // namespace proxy_wasm
0 commit comments