@@ -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,8 @@ 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 =
347+ wasm::vec<wasm::Extern *>::make_uninitialized (import_types.size ());
347348
348349 for (size_t i = 0 ; i < import_types.size (); i++) {
349350 std::string_view module (import_types[i]->module ().get (), import_types[i]->module ().size ());
@@ -352,7 +353,7 @@ bool V8::link(std::string_view /*debug_name*/) {
352353
353354 switch (import_type->kind ()) {
354355
355- case wasm::EXTERN_FUNC : {
356+ case wasm::ExternKind::FUNC : {
356357 auto it = host_functions_.find (std::string (module ) + " ." + std::string (name));
357358 if (it == host_functions_.end ()) {
358359 fail (FailState::UnableToInitializeCode,
@@ -372,18 +373,18 @@ bool V8::link(std::string_view /*debug_name*/) {
372373 printValTypes (func->type ()->results ()));
373374 return false ;
374375 }
375- imports. push_back ( func) ;
376+ imports[i] = func;
376377 } break ;
377378
378- case wasm::EXTERN_GLOBAL : {
379+ case wasm::ExternKind::GLOBAL : {
379380 // TODO(PiotrSikora): add support when/if needed.
380381 fail (FailState::UnableToInitializeCode,
381382 " Failed to load Wasm module due to a missing import: " + std::string (module ) + " ." +
382383 std::string (name));
383384 return false ;
384385 } break ;
385386
386- case wasm::EXTERN_MEMORY : {
387+ case wasm::ExternKind::MEMORY : {
387388 assert (memory_ == nullptr );
388389 auto type = wasm::MemoryType::make (import_type->memory ()->limits ());
389390 if (type == nullptr ) {
@@ -393,10 +394,10 @@ bool V8::link(std::string_view /*debug_name*/) {
393394 if (memory_ == nullptr ) {
394395 return false ;
395396 }
396- imports. push_back ( memory_.get () );
397+ imports[i] = memory_.get ();
397398 } break ;
398399
399- case wasm::EXTERN_TABLE : {
400+ case wasm::ExternKind::TABLE : {
400401 assert (table_ == nullptr );
401402 auto type =
402403 wasm::TableType::make (wasm::ValType::make (import_type->table ()->element ()->kind ()),
@@ -408,16 +409,12 @@ bool V8::link(std::string_view /*debug_name*/) {
408409 if (table_ == nullptr ) {
409410 return false ;
410411 }
411- imports. push_back ( table_.get () );
412+ imports[i] = table_.get ();
412413 } break ;
413414 }
414415 }
415416
416- if (import_types.size () != imports.size ()) {
417- return false ;
418- }
419-
420- instance_ = wasm::Instance::make (store_.get (), module_.get (), imports.data ());
417+ instance_ = wasm::Instance::make (store_.get (), module_.get (), imports);
421418 if (instance_ == nullptr ) {
422419 fail (FailState::UnableToInitializeCode, " Failed to create new Wasm instance" );
423420 return false ;
@@ -435,16 +432,16 @@ bool V8::link(std::string_view /*debug_name*/) {
435432
436433 switch (export_type->kind ()) {
437434
438- case wasm::EXTERN_FUNC : {
435+ case wasm::ExternKind::FUNC : {
439436 assert (export_item->func () != nullptr );
440437 module_functions_.insert_or_assign (std::string (name), export_item->func ()->copy ());
441438 } break ;
442439
443- case wasm::EXTERN_GLOBAL : {
440+ case wasm::ExternKind::GLOBAL : {
444441 // TODO(PiotrSikora): add support when/if needed.
445442 } break ;
446443
447- case wasm::EXTERN_MEMORY : {
444+ case wasm::ExternKind::MEMORY : {
448445 assert (export_item->memory () != nullptr );
449446 assert (memory_ == nullptr );
450447 memory_ = exports[i]->memory ()->copy ();
@@ -453,7 +450,7 @@ bool V8::link(std::string_view /*debug_name*/) {
453450 }
454451 } break ;
455452
456- case wasm::EXTERN_TABLE : {
453+ case wasm::ExternKind::TABLE : {
457454 // TODO(PiotrSikora): add support when/if needed.
458455 } break ;
459456 }
@@ -531,7 +528,8 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
531528 convertArgsTupleToValTypes<std::tuple<>>());
532529 auto func = wasm::Func::make (
533530 store_.get (), type.get (),
534- [](void *data, const wasm::Val params[], wasm::Val /* results*/ []) -> wasm::own<wasm::Trap> {
531+ [](void *data, const wasm::vec<wasm::Val> ¶ms,
532+ wasm::vec<wasm::Val> & /* results*/ ) -> wasm::own<wasm::Trap> {
535533 auto *func_data = reinterpret_cast <FuncData *>(data);
536534 const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
537535 if (log) {
@@ -567,7 +565,8 @@ void V8::registerHostFunctionImpl(std::string_view module_name, std::string_view
567565 convertArgsTupleToValTypes<std::tuple<R>>());
568566 auto func = wasm::Func::make (
569567 store_.get (), type.get (),
570- [](void *data, const wasm::Val params[], wasm::Val results[]) -> wasm::own<wasm::Trap> {
568+ [](void *data, const wasm::vec<wasm::Val> ¶ms,
569+ wasm::vec<wasm::Val> &results) -> wasm::own<wasm::Trap> {
571570 auto *func_data = reinterpret_cast <FuncData *>(data);
572571 const bool log = func_data->vm_ ->cmpLogLevel (LogLevel::trace);
573572 if (log) {
@@ -621,20 +620,21 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
621620 const bool log = cmpLogLevel (LogLevel::trace);
622621 SaveRestoreContext saved_context (context);
623622 wasm::own<wasm::Trap> trap = nullptr ;
623+ wasm::vec<wasm::Val> results = wasm::vec<wasm::Val>::make_uninitialized ();
624624
625625 // Workaround for MSVC++ not supporting zero-sized arrays.
626626 if constexpr (sizeof ...(args) > 0 ) {
627- wasm::Val params[] = { makeVal (args)...} ;
627+ wasm::vec<wasm:: Val> params = wasm::vec<wasm::Val>:: make ( makeVal (args)...) ;
628628 if (log) {
629629 integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
630630 printValues (params, sizeof ...(Args)) + " )" );
631631 }
632- trap = func->call (params, nullptr );
632+ trap = func->call (params, results );
633633 } else {
634634 if (log) {
635635 integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
636636 }
637- trap = func->call (nullptr , nullptr );
637+ trap = func->call (wasm::vec<wasm::Val>:: make_uninitialized (), results );
638638 }
639639
640640 if (trap) {
@@ -671,12 +671,12 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
671671 *function = [func, function_name, this ](ContextBase *context, Args... args) -> R {
672672 const bool log = cmpLogLevel (LogLevel::trace);
673673 SaveRestoreContext saved_context (context);
674- wasm::Val results[ 1 ] ;
674+ wasm::vec<wasm:: Val> results = wasm::vec<wasm::Val>:: make_uninitialized ( 1 ) ;
675675 wasm::own<wasm::Trap> trap = nullptr ;
676676
677677 // Workaround for MSVC++ not supporting zero-sized arrays.
678678 if constexpr (sizeof ...(args) > 0 ) {
679- wasm::Val params[] = { makeVal (args)...} ;
679+ wasm::vec<wasm:: Val> params = wasm::vec<wasm::Val>:: make ( makeVal (args)...) ;
680680 if (log) {
681681 integration ()->trace (" [host->vm] " + std::string (function_name) + " (" +
682682 printValues (params, sizeof ...(Args)) + " )" );
@@ -686,7 +686,7 @@ void V8::getModuleFunctionImpl(std::string_view function_name,
686686 if (log) {
687687 integration ()->trace (" [host->vm] " + std::string (function_name) + " ()" );
688688 }
689- trap = func->call (nullptr , results);
689+ trap = func->call (wasm::vec<wasm::Val>:: make_uninitialized () , results);
690690 }
691691
692692 if (trap) {
0 commit comments