1// Copyright 2021 the V8 project authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "src/wasm/wasm-init-expr.h" 6 7#include "src/wasm/wasm-features.h" 8#include "src/wasm/wasm-module.h" 9 10namespace v8 { 11namespace internal { 12namespace wasm { 13 14ValueType WasmInitExpr::type(const WasmModule* module, 15 const WasmFeatures& enabled_features) const { 16 switch (kind()) { 17 case kNone: 18 return kWasmBottom; 19 case kGlobalGet: 20 return immediate().index < module->globals.size() 21 ? module->globals[immediate().index].type 22 : kWasmBottom; 23 case kI32Const: 24 return kWasmI32; 25 case kI64Const: 26 return kWasmI64; 27 case kF32Const: 28 return kWasmF32; 29 case kF64Const: 30 return kWasmF64; 31 case kS128Const: 32 return kWasmS128; 33 case kRefFuncConst: { 34 uint32_t heap_type = enabled_features.has_typed_funcref() 35 ? module->functions[immediate().index].sig_index 36 : HeapType::kFunc; 37 return ValueType::Ref(heap_type, kNonNullable); 38 } 39 case kRefNullConst: 40 return ValueType::Ref(immediate().heap_type, kNullable); 41 case kStructNewWithRtt: 42 case kStructNew: 43 case kStructNewDefaultWithRtt: 44 case kStructNewDefault: 45 case kArrayInit: 46 case kArrayInitStatic: 47 return ValueType::Ref(immediate().index, kNonNullable); 48 case kRttCanon: 49 return ValueType::Rtt(immediate().heap_type); 50 } 51} 52 53} // namespace wasm 54} // namespace internal 55} // namespace v8 56