Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

1
deps/v8/test/common/wasm/OWNERS vendored Normal file
View File

@ -0,0 +1 @@
file:../../../src/wasm/OWNERS

50
deps/v8/test/common/wasm/flag-utils.h vendored Normal file
View File

@ -0,0 +1,50 @@
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_TEST_COMMON_WASM_FLAG_UTILS_H
#define V8_TEST_COMMON_WASM_FLAG_UTILS_H
#include "src/wasm/wasm-features.h"
#include "test/common/flag-utils.h"
namespace v8::internal::wasm {
#define EXPERIMENTAL_FLAG_SCOPE(flag) FLAG_SCOPE(experimental_wasm_##flag)
class V8_NODISCARD WasmFeatureScope {
public:
explicit WasmFeatureScope(WasmEnabledFeatures* features,
WasmEnabledFeature feature, bool val = true)
: prev_(features->contains(feature)),
feature_(feature),
features_(features) {
set(val);
}
~WasmFeatureScope() { set(prev_); }
private:
void set(bool val) {
if (val) {
features_->Add(feature_);
} else {
features_->Remove(feature_);
}
}
bool const prev_;
WasmEnabledFeature const feature_;
WasmEnabledFeatures* const features_;
};
#define WASM_FEATURE_SCOPE(feat) \
WasmFeatureScope feat##_scope(&this->enabled_features_, \
WasmEnabledFeature::feat)
#define WASM_FEATURE_SCOPE_VAL(feat, val) \
WasmFeatureScope feat##_scope(&this->enabled_features_, \
WasmEnabledFeature::feat, val)
} // namespace v8::internal::wasm
#endif // V8_TEST_COMMON_WASM_FLAG_UTILS_H

View File

@ -0,0 +1,115 @@
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TEST_SIGNATURES_H
#define TEST_SIGNATURES_H
#include "src/codegen/signature.h"
#include "src/wasm/value-type.h"
#include "src/wasm/wasm-opcodes.h"
namespace v8::internal::wasm {
// A helper class with many useful signatures in order to simplify tests.
class TestSignatures {
public:
#define SIG(name, Maker, ...) \
static FunctionSig* name() { \
static auto kSig = Maker(__VA_ARGS__); \
return &kSig; \
}
// Empty signature.
static FunctionSig* v_v() {
static FixedSizeSignature<ValueType, 0, 0> kSig;
return &kSig;
}
// Signatures with no return value.
SIG(v_i, MakeSigNoReturn, kWasmI32)
SIG(v_ii, MakeSigNoReturn, kWasmI32, kWasmI32)
SIG(v_iii, MakeSigNoReturn, kWasmI32, kWasmI32, kWasmI32)
SIG(v_a, MakeSigNoReturn, kWasmExternRef)
SIG(v_c, MakeSigNoReturn, kWasmFuncRef)
SIG(v_d, MakeSigNoReturn, kWasmF64)
// Returning one i32 value.
SIG(i_v, MakeSig1Return, kWasmI32)
SIG(i_i, MakeSig1Return, kWasmI32, kWasmI32)
SIG(i_ii, MakeSig1Return, kWasmI32, kWasmI32, kWasmI32)
SIG(i_iii, MakeSig1Return, kWasmI32, kWasmI32, kWasmI32, kWasmI32)
SIG(i_f, MakeSig1Return, kWasmI32, kWasmF32)
SIG(i_ff, MakeSig1Return, kWasmI32, kWasmF32, kWasmF32)
SIG(i_d, MakeSig1Return, kWasmI32, kWasmF64)
SIG(i_dd, MakeSig1Return, kWasmI32, kWasmF64, kWasmF64)
SIG(i_ll, MakeSig1Return, kWasmI32, kWasmI64, kWasmI64)
SIG(i_a, MakeSig1Return, kWasmI32, kWasmExternRef)
SIG(i_aa, MakeSig1Return, kWasmI32, kWasmExternRef, kWasmExternRef)
SIG(i_c, MakeSig1Return, kWasmI32, kWasmFuncRef)
SIG(i_s, MakeSig1Return, kWasmI32, kWasmS128)
// Returning one i64 value.
SIG(l_v, MakeSig1Return, kWasmI64)
SIG(l_a, MakeSig1Return, kWasmI64, kWasmExternRef)
SIG(l_c, MakeSig1Return, kWasmI64, kWasmFuncRef)
SIG(l_l, MakeSig1Return, kWasmI64, kWasmI64)
SIG(l_ll, MakeSig1Return, kWasmI64, kWasmI64, kWasmI64)
// Returning one f32 value.
SIG(f_f, MakeSig1Return, kWasmF32, kWasmF32)
SIG(f_ff, MakeSig1Return, kWasmF32, kWasmF32, kWasmF32)
// Returning one f64 value.
SIG(d_d, MakeSig1Return, kWasmF64, kWasmF64)
SIG(d_dd, MakeSig1Return, kWasmF64, kWasmF64, kWasmF64)
// Returning other values.
SIG(a_v, MakeSig1Return, kWasmExternRef)
SIG(c_v, MakeSig1Return, kWasmFuncRef)
SIG(a_a, MakeSig1Return, kWasmExternRef, kWasmExternRef)
SIG(c_c, MakeSig1Return, kWasmFuncRef, kWasmFuncRef)
SIG(s_i, MakeSig1Return, kWasmS128, kWasmI32)
SIG(s_s, MakeSig1Return, kWasmS128, kWasmS128)
SIG(s_ss, MakeSig1Return, kWasmS128, kWasmS128, kWasmS128)
// Multi-return.
static FunctionSig* ii_v() {
static auto kSig =
FixedSizeSignature<ValueType>::Returns(kWasmI32, kWasmI32);
return &kSig;
}
static FunctionSig* iii_v() {
static auto kSig =
FixedSizeSignature<ValueType>::Returns(kWasmI32, kWasmI32, kWasmI32);
return &kSig;
}
static FunctionSig* many(Zone* zone, ValueType ret, ValueType param,
int count) {
FunctionSig::Builder builder(zone, ret == kWasmVoid ? 0 : 1, count);
if (ret != kWasmVoid) builder.AddReturn(ret);
for (int i = 0; i < count; i++) {
builder.AddParam(param);
}
return builder.Get();
}
private:
template <typename... ParamTypes>
static FixedSizeSignature<ValueType, 0, sizeof...(ParamTypes)>
MakeSigNoReturn(ParamTypes... param_types) {
return FixedSizeSignature<ValueType>::Params(param_types...);
}
template <typename... ParamTypes>
static FixedSizeSignature<ValueType, 1, sizeof...(ParamTypes)> MakeSig1Return(
ValueType return_type, ParamTypes... param_types) {
return FixedSizeSignature<ValueType>::Returns(return_type)
.Params(param_types...);
}
};
} // namespace v8::internal::wasm
#endif // TEST_SIGNATURES_H

1099
deps/v8/test/common/wasm/wasm-macro-gen.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,166 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "test/common/wasm/wasm-module-runner.h"
#include "src/execution/isolate.h"
#include "src/handles/handles.h"
#include "src/objects/heap-number-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/property-descriptor.h"
#include "src/wasm/module-decoder.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-js.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-opcodes.h"
#include "src/wasm/wasm-result.h"
namespace v8::internal::wasm::testing {
MaybeDirectHandle<WasmModuleObject> CompileForTesting(
Isolate* isolate, ErrorThrower* thrower,
base::Vector<const uint8_t> bytes) {
auto enabled_features = WasmEnabledFeatures::FromIsolate(isolate);
MaybeDirectHandle<WasmModuleObject> module = GetWasmEngine()->SyncCompile(
isolate, enabled_features, CompileTimeImports{}, thrower,
base::OwnedCopyOf(bytes));
DCHECK_EQ(thrower->error(), module.is_null());
return module;
}
MaybeDirectHandle<WasmInstanceObject> CompileAndInstantiateForTesting(
Isolate* isolate, ErrorThrower* thrower,
base::Vector<const uint8_t> bytes) {
MaybeDirectHandle<WasmModuleObject> module =
CompileForTesting(isolate, thrower, bytes);
if (module.is_null()) return {};
return GetWasmEngine()->SyncInstantiate(isolate, thrower,
module.ToHandleChecked(), {}, {});
}
DirectHandleVector<Object> MakeDefaultArguments(Isolate* isolate,
const FunctionSig* sig) {
size_t param_count = sig->parameter_count();
DirectHandleVector<Object> arguments(isolate, param_count);
for (size_t i = 0; i < param_count; ++i) {
switch (sig->GetParam(i).kind()) {
case kI32:
case kF32:
case kF64:
case kS128:
// Argument here for kS128 does not matter as we should error out before
// hitting this case.
arguments[i] =
direct_handle(Smi::FromInt(static_cast<int>(i)), isolate);
break;
case kI64:
arguments[i] = BigInt::FromInt64(isolate, static_cast<int64_t>(i));
break;
case kRefNull:
arguments[i] = isolate->factory()->null_value();
break;
case kRef:
arguments[i] = isolate->factory()->undefined_value();
break;
case kI8:
case kI16:
case kF16:
case kVoid:
case kTop:
case kBottom:
UNREACHABLE();
}
}
return arguments;
}
int32_t CompileAndRunWasmModule(Isolate* isolate, const uint8_t* module_start,
const uint8_t* module_end) {
HandleScope scope(isolate);
ErrorThrower thrower(isolate, "CompileAndRunWasmModule");
MaybeDirectHandle<WasmInstanceObject> instance =
CompileAndInstantiateForTesting(
isolate, &thrower,
base::VectorOf(module_start, module_end - module_start));
if (instance.is_null()) {
return -1;
}
return CallWasmFunctionForTesting(isolate, instance.ToHandleChecked(), "main",
{});
}
MaybeDirectHandle<WasmExportedFunction> GetExportedFunction(
Isolate* isolate, DirectHandle<WasmInstanceObject> instance,
const char* name) {
DirectHandle<JSObject> exports_object;
DirectHandle<Name> exports =
isolate->factory()->InternalizeUtf8String("exports");
exports_object = Cast<JSObject>(
JSObject::GetProperty(isolate, instance, exports).ToHandleChecked());
DirectHandle<Name> main_name =
isolate->factory()->NewStringFromAsciiChecked(name);
PropertyDescriptor desc;
Maybe<bool> property_found = JSReceiver::GetOwnPropertyDescriptor(
isolate, exports_object, main_name, &desc);
if (!property_found.FromMaybe(false)) return {};
if (!IsJSFunction(*desc.value())) return {};
return Cast<WasmExportedFunction>(desc.value());
}
int32_t CallWasmFunctionForTesting(
Isolate* isolate, DirectHandle<WasmInstanceObject> instance,
const char* name, base::Vector<const DirectHandle<Object>> args,
std::unique_ptr<const char[]>* exception) {
DCHECK_IMPLIES(exception != nullptr, *exception == nullptr);
MaybeDirectHandle<WasmExportedFunction> maybe_export =
GetExportedFunction(isolate, instance, name);
DirectHandle<WasmExportedFunction> exported_function;
if (!maybe_export.ToHandle(&exported_function)) {
return -1;
}
// Call the JS function.
DirectHandle<Object> undefined = isolate->factory()->undefined_value();
MaybeDirectHandle<Object> retval =
Execution::Call(isolate, exported_function, undefined, args);
// The result should be a number.
if (retval.is_null()) {
DCHECK(isolate->has_exception());
if (exception && !isolate->is_execution_terminating()) {
DirectHandle<String> exception_string = Object::NoSideEffectsToString(
isolate, direct_handle(isolate->exception(), isolate));
*exception = exception_string->ToCString();
}
isolate->clear_internal_exception();
return -1;
}
DirectHandle<Object> result = retval.ToHandleChecked();
// Multi-value returns, get the first return value (see InterpretWasmModule).
if (IsJSArray(*result)) {
auto receiver = Cast<JSReceiver>(result);
result = JSObject::GetElement(isolate, receiver, 0).ToHandleChecked();
}
if (IsSmi(*result)) {
return Smi::ToInt(*result);
}
if (IsHeapNumber(*result)) {
return static_cast<int32_t>(Cast<HeapNumber>(*result)->value());
}
if (IsBigInt(*result)) {
return static_cast<int32_t>(Cast<BigInt>(*result)->AsInt64());
}
return -1;
}
void SetupIsolateForWasmModule(Isolate* isolate) { WasmJs::Install(isolate); }
} // namespace v8::internal::wasm::testing

View File

@ -0,0 +1,60 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_MODULE_RUNNER_H_
#define V8_WASM_MODULE_RUNNER_H_
#include "src/execution/isolate.h"
#include "src/objects/objects.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-objects.h"
#include "src/wasm/wasm-result.h"
namespace v8 {
namespace internal {
namespace wasm {
namespace testing {
// Returns a MaybeHandle to the JsToWasm wrapper of the wasm function exported
// with the given name by the provided instance.
MaybeDirectHandle<WasmExportedFunction> GetExportedFunction(
Isolate* isolate, DirectHandle<WasmInstanceObject> instance,
const char* name);
// Call an exported wasm function by name. Returns -1 if the export does not
// exist or throws an error. Errors are cleared from the isolate before
// returning. {exception} is set to a string representation of the exception (if
// set and an exception occurs).
int32_t CallWasmFunctionForTesting(
Isolate* isolate, DirectHandle<WasmInstanceObject> instance,
const char* name, base::Vector<const DirectHandle<Object>> args,
std::unique_ptr<const char[]>* exception = nullptr);
// Decode, verify, and run the function labeled "main" in the
// given encoded module. The module should have no imports.
int32_t CompileAndRunWasmModule(Isolate* isolate, const uint8_t* module_start,
const uint8_t* module_end);
// Decode and compile the given module with no imports.
MaybeDirectHandle<WasmModuleObject> CompileForTesting(
Isolate* isolate, ErrorThrower* thrower, base::Vector<const uint8_t> bytes);
// Decode, compile, and instantiate the given module with no imports.
MaybeDirectHandle<WasmInstanceObject> CompileAndInstantiateForTesting(
Isolate* isolate, ErrorThrower* thrower, base::Vector<const uint8_t> bytes);
// Generate an array of default arguments for the given signature, to be used
// when calling compiled code.
DirectHandleVector<Object> MakeDefaultArguments(Isolate* isolate,
const FunctionSig* sig);
// Install function map, module symbol for testing
void SetupIsolateForWasmModule(Isolate* isolate);
} // namespace testing
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_MODULE_RUNNER_H_