@@ -140,20 +140,20 @@ class V8 : public WasmVm {
140140
141141static std::string printValue (const wasm::Val &value) {
142142 switch (value.kind ()) {
143- case wasm::I32:
143+ case wasm::ValKind:: I32:
144144 return std::to_string (value.get <uint32_t >());
145- case wasm::I64:
145+ case wasm::ValKind:: I64:
146146 return std::to_string (value.get <uint64_t >());
147- case wasm::F32:
147+ case wasm::ValKind:: F32:
148148 return std::to_string (value.get <float >());
149- case wasm::F64:
149+ case wasm::ValKind:: F64:
150150 return std::to_string (value.get <double >());
151151 default :
152152 return " unknown" ;
153153 }
154154}
155155
156- static std::string printValues (const wasm::Val values[] , size_t size) {
156+ static std::string printValues (const wasm::vec<wasm:: Val> & values, size_t size) {
157157 if (size == 0 ) {
158158 return " " ;
159159 }
@@ -170,17 +170,17 @@ static std::string printValues(const wasm::Val values[], size_t size) {
170170
171171static const char *printValKind (wasm::ValKind kind) {
172172 switch (kind) {
173- case wasm::I32:
173+ case wasm::ValKind:: I32:
174174 return " i32" ;
175- case wasm::I64:
175+ case wasm::ValKind:: I64:
176176 return " i64" ;
177- case wasm::F32:
177+ case wasm::ValKind:: F32:
178178 return " f32" ;
179- case wasm::F64:
179+ case wasm::ValKind:: F64:
180180 return " f64" ;
181- case wasm::ANYREF :
182- return " anyref " ;
183- case wasm::FUNCREF:
181+ case wasm::ValKind::EXTERNREF :
182+ return " externref " ;
183+ case wasm::ValKind:: FUNCREF:
184184 return " funcref" ;
185185 default :
186186 return " unknown" ;
@@ -229,11 +229,11 @@ template <typename T> wasm::Val makeVal(T t) { return wasm::Val::make(t); }
229229template <> wasm::Val makeVal (Word t) { return wasm::Val::make (static_cast <uint32_t >(t.u64_ )); }
230230
231231template <typename T> constexpr auto convertArgToValKind ();
232- template <> constexpr auto convertArgToValKind<Word>() { return wasm::I32; };
233- template <> constexpr auto convertArgToValKind<uint32_t >() { return wasm::I32; };
234- template <> constexpr auto convertArgToValKind<int64_t >() { return wasm::I64; };
235- template <> constexpr auto convertArgToValKind<uint64_t >() { return wasm::I64; };
236- template <> constexpr auto convertArgToValKind<double >() { return wasm::F64; };
232+ template <> constexpr auto convertArgToValKind<Word>() { return wasm::ValKind:: I32; };
233+ template <> constexpr auto convertArgToValKind<uint32_t >() { return wasm::ValKind:: I32; };
234+ template <> constexpr auto convertArgToValKind<int64_t >() { return wasm::ValKind:: I64; };
235+ template <> constexpr auto convertArgToValKind<uint64_t >() { return wasm::ValKind:: I64; };
236+ template <> constexpr auto convertArgToValKind<double >() { return wasm::ValKind:: F64; };
237237
238238template <typename T, std::size_t ... I>
239239constexpr auto convertArgsTupleToValTypesImpl (std::index_sequence<I...> /* comptime*/ ) {
@@ -343,7 +343,7 @@ bool V8::link(std::string_view /*debug_name*/) {
343343 assert (module_ != nullptr );
344344
345345 const auto import_types = module_.get ()->imports ();
346- std::vector< const wasm::Extern *> imports;
346+ wasm::vec< wasm::Extern *> imports = wasm::vec<wasm::Extern*>:: make_uninitialized (import_types. size ()) ;
347347
348348 for (size_t i = 0 ; i < import_types.size (); i++) {
349349 std::string_view module (import_types[i]->module ().get (), import_types[i]->module ().size ());
@@ -352,7 +352,7 @@ bool V8::link(std::string_view /*debug_name*/) {
352352
353353 switch (import_type->kind ()) {
354354
355- case wasm::EXTERN_FUNC : {
355+ case wasm::ExternKind::FUNC : {
356356 auto it = host_functions_.find (std::string (module ) + " ." + std::string (name));
357357 if (it == host_functions_.end ()) {
358358 fail (FailState::UnableToInitializeCode,
@@ -372,18 +372,18 @@ bool V8::link(std::string_view /*debug_name*/) {
372372 printValTypes (func->type ()->results ()));
373373 return false ;
374374 }
375- imports. push_back ( func) ;
375+ imports[i] = func;
376376 } break ;
377377
378- case wasm::EXTERN_GLOBAL : {
378+ case wasm::ExternKind::GLOBAL : {
379379 // TODO(PiotrSikora): add support when/if needed.
380380 fail (FailState::UnableToInitializeCode,
381381 " Failed to load Wasm module due to a missing import: " + std::string (module ) + " ." +
382382 std::string (name));
383383 return false ;
384384 } break ;
385385
386- case wasm::EXTERN_MEMORY : {
386+ case wasm::ExternKind::MEMORY : {
387387 assert (memory_ == nullptr );
388388 auto type = wasm::MemoryType::make (import_type->memory ()->limits ());
389389 if (type == nullptr ) {
@@ -393,10 +393,10 @@ bool V8::link(std::string_view /*debug_name*/) {
393393 if (memory_ == nullptr ) {
394394 return false ;
395395 }
396- imports. push_back ( memory_.get () );
396+ imports[i] = memory_.get ();
397397 } break ;
398398
399- case wasm::EXTERN_TABLE : {
399+ case wasm::ExternKind::TABLE : {
400400 assert (table_ == nullptr );
401401 auto type =
402402 wasm::TableType::make (wasm::ValType::make (import_type->table ()->element ()->kind ()),
@@ -408,16 +408,12 @@ bool V8::link(std::string_view /*debug_name*/) {
408408 if (table_ == nullptr ) {
409409 return false ;
410410 }
411- imports. push_back ( table_.get () );
411+ imports[i] = table_.get ();
412412 } break ;
413413 }
414414 }
415415
416- if (import_types.size () != imports.size ()) {
417- return false ;
418- }
419-
420- instance_ = wasm::Instance::make (store_.get (), module_.get (), imports.data ());
416+ instance_ = wasm::Instance::make (store_.get (), module_.get (), imports);
421417 if (instance_ == nullptr ) {
422418 fail (FailState::UnableToInitializeCode, " Failed to create new Wasm instance" );
423419 return false ;
@@ -435,16 +431,16 @@ bool V8::link(std::string_view /*debug_name*/) {
435431
436432 switch (export_type->kind ()) {
437433
438- case wasm::EXTERN_FUNC : {
434+ case wasm::ExternKind::FUNC : {
439435 assert (export_item->func () != nullptr );
440436 module_functions_.insert_or_assign (std::string (name), export_item->func ()->copy ());
441437 } break ;
442438
443- case wasm::EXTERN_GLOBAL : {
439+ case wasm::ExternKind::GLOBAL : {
444440 // TODO(PiotrSikora): add support when/if needed.
445441 } break ;
446442
447- case wasm::EXTERN_MEMORY : {
443+ case wasm::ExternKind::MEMORY : {
448444 assert (export_item->memory () != nullptr );
449445 assert (memory_ == nullptr );
450446 memory_ = exports[i]->memory ()->copy ();
@@ -453,7 +449,7 @@ bool V8::link(std::string_view /*debug_name*/) {
453449 }
454450 } break ;
455451
456- case wasm::EXTERN_TABLE : {
452+ case wasm::ExternKind::TABLE : {
457453 // TODO(PiotrSikora): add support when/if needed.
458454 } break ;
459455 }
@@ -531,7 +527,7 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
531527 convertArgsTupleToValTypes<std::tuple<>>());
532528 auto func = wasm::Func::make (
533529 store_.get (), type.get (),
534- [](void *data, const wasm::Val params[] , wasm::Val /* results*/ [] ) -> wasm::own<wasm::Trap> {
530+ [](void *data, const wasm::vec<wasm:: Val>& params, wasm::vec<wasm:: Val>& /* results*/ ) -> wasm::own<wasm::Trap> {
535531 auto *func_data = reinterpret_cast <FuncData *>(data);
536532 const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
537533 if (log) {
@@ -567,7 +563,7 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
567563 convertArgsTupleToValTypes<std::tuple<R>>());
568564 auto func = wasm::Func::make (
569565 store_.get (), type.get (),
570- [](void *data, const wasm::Val params[] , wasm::Val results[] ) -> wasm::own<wasm::Trap> {
566+ [](void *data, const wasm::vec<wasm:: Val>& params, wasm::vec<wasm:: Val>& results) -> wasm::own<wasm::Trap> {
571567 auto *func_data = reinterpret_cast <FuncData *>(data);
572568 const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
573569 if (log) {
@@ -621,20 +617,21 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
621617 const bool log = cmpLogLevel (LogLevel::trace);
622618 SaveRestoreContext saved_context (context);
623619 wasm::own<wasm::Trap> trap = nullptr ;
620+ wasm::vec<wasm::Val> results = wasm::vec<wasm::Val>::make_uninitialized ();
624621
625622 // Workaround for MSVC++ not supporting zero-sized arrays.
626623 if constexpr (sizeof ...(args) > 0 ) {
627- wasm::Val params[] = { makeVal (args)...} ;
624+ wasm::vec<wasm:: Val> params = wasm::vec<wasm::Val>:: make ( makeVal (args)...) ;
628625 if (log) {
629626 integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
630627 printValues (params, sizeof ...(Args)) + " )" );
631628 }
632- trap = func->call (params, nullptr );
629+ trap = func->call (params, results );
633630 } else {
634631 if (log) {
635632 integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
636633 }
637- trap = func->call (nullptr , nullptr );
634+ trap = func->call (wasm::vec<wasm::Val>:: make_uninitialized (), results );
638635 }
639636
640637 if (trap) {
@@ -671,12 +668,12 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
671668 *function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
672669 const bool log = cmpLogLevel (LogLevel::trace);
673670 SaveRestoreContext saved_context (context);
674- wasm::Val results[ 1 ] ;
671+ wasm::vec<wasm:: Val> results = wasm::vec<wasm::Val>:: make_uninitialized ( 1 ) ;
675672 wasm::own<wasm::Trap> trap = nullptr ;
676673
677674 // Workaround for MSVC++ not supporting zero-sized arrays.
678675 if constexpr (sizeof ...(args) > 0 ) {
679- wasm::Val params[] = { makeVal (args)...} ;
676+ wasm::vec<wasm:: Val> params = wasm::vec<wasm::Val>:: make ( makeVal (args)...) ;
680677 if (log) {
681678 integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
682679 printValues (params, sizeof ...(Args)) + " )" );
@@ -686,7 +683,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
686683 if (log) {
687684 integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
688685 }
689- trap = func->call (nullptr , results);
686+ trap = func->call (wasm::vec<wasm::Val>:: make_uninitialized () , results);
690687 }
691688
692689 if (trap) {
0 commit comments