Commit 3b45da47 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[wasm-c-api] Roll 70a2889: Remove template meta-programming

This change is very mechanical:
own<Foo*> → own<Foo>
vec<Foo*> → ownvec<Foo>
As usual, everything in third_party/ is straight-up copied from upstream.

Change-Id: If5fabda99e2b281da6f2e71ce23a2f5b68aaac86
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1760815
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63263}
parent 8e478b8d
This diff is collapsed.
......@@ -28,7 +28,7 @@ class StoreImpl {
}
private:
friend own<Store*> Store::make(Engine*);
friend own<Store> Store::make(Engine*);
StoreImpl() {}
......
......@@ -14,11 +14,11 @@ namespace wasm {
namespace {
own<Trap*> Stage2(void* env, const Val args[], Val results[]) {
own<Trap> Stage2(void* env, const Val args[], Val results[]) {
printf("Stage2...\n");
WasmCapiTest* self = reinterpret_cast<WasmCapiTest*>(env);
Func* stage3 = self->GetExportedFunction(1);
own<Trap*> trap = stage3->call(args, results);
own<Trap> trap = stage3->call(args, results);
if (trap) {
printf("Stage2: got exception: %s\n", trap->message().get());
} else {
......@@ -27,7 +27,7 @@ own<Trap*> Stage2(void* env, const Val args[], Val results[]) {
return trap;
}
own<Trap*> Stage4_GC(void* env, const Val args[], Val results[]) {
own<Trap> Stage4_GC(void* env, const Val args[], Val results[]) {
printf("Stage4...\n");
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(env);
isolate->heap()->PreciseCollectAllGarbage(
......@@ -57,7 +57,7 @@ class WasmCapiCallbacksTest : public WasmCapiTest {
}
private:
own<Func*> stage2_;
own<Func> stage2_;
};
} // namespace
......@@ -72,7 +72,7 @@ TEST_F(WasmCapiCallbacksTest, Trap) {
Instantiate(imports);
Val args[] = {Val::i32(42)};
Val results[1];
own<Trap*> trap = GetExportedFunction(0)->call(args, results);
own<Trap> trap = GetExportedFunction(0)->call(args, results);
EXPECT_NE(trap, nullptr);
printf("Stage0: Got trap as expected: %s\n", trap->message().get());
}
......@@ -87,21 +87,21 @@ TEST_F(WasmCapiCallbacksTest, GC) {
i::Isolate* isolate =
reinterpret_cast<::wasm::StoreImpl*>(store())->i_isolate();
own<Func*> stage4 = Func::make(store(), cpp_i_i_sig(), Stage4_GC, isolate);
own<Func> stage4 = Func::make(store(), cpp_i_i_sig(), Stage4_GC, isolate);
EXPECT_EQ(cpp_i_i_sig()->params().size(), stage4->type()->params().size());
EXPECT_EQ(cpp_i_i_sig()->results().size(), stage4->type()->results().size());
Extern* imports[] = {stage2(), stage4.get()};
Instantiate(imports);
Val args[] = {Val::i32(42)};
Val results[1];
own<Trap*> trap = GetExportedFunction(0)->call(args, results);
own<Trap> trap = GetExportedFunction(0)->call(args, results);
EXPECT_EQ(trap, nullptr);
EXPECT_EQ(43, results[0].i32());
}
namespace {
own<Trap*> FibonacciC(void* env, const Val args[], Val results[]) {
own<Trap> FibonacciC(void* env, const Val args[], Val results[]) {
int32_t x = args[0].i32();
if (x == 0 || x == 1) {
results[0] = Val::i32(x);
......@@ -113,7 +113,7 @@ own<Trap*> FibonacciC(void* env, const Val args[], Val results[]) {
// style, but this test intentionally ensures that it works if someone
// insists on doing it.
Val recursive_args[] = {Val::i32(x - 1)};
own<Trap*> trap = fibo_wasm->call(recursive_args, results);
own<Trap> trap = fibo_wasm->call(recursive_args, results);
DCHECK_NULL(trap);
int32_t x1 = results[0].i32();
recursive_args[0] = Val::i32(x - 2);
......@@ -148,20 +148,20 @@ TEST_F(WasmCapiTest, Recursion) {
AddExportedFunction(CStrVector("fibonacci_wasm"), code_fibo,
sizeof(code_fibo), wasm_i_i_sig());
own<Func*> fibonacci = Func::make(store(), cpp_i_i_sig(), FibonacciC, this);
own<Func> fibonacci = Func::make(store(), cpp_i_i_sig(), FibonacciC, this);
Extern* imports[] = {fibonacci.get()};
Instantiate(imports);
// Enough iterations to make it interesting, few enough to keep it fast.
Val args[] = {Val::i32(15)};
Val results[1];
own<Trap*> result = GetExportedFunction(0)->call(args, results);
own<Trap> result = GetExportedFunction(0)->call(args, results);
EXPECT_EQ(result, nullptr);
EXPECT_EQ(610, results[0].i32());
}
namespace {
own<Trap*> PlusOne(const Val args[], Val results[]) {
own<Trap> PlusOne(const Val args[], Val results[]) {
int32_t a0 = args[0].i32();
results[0] = Val::i32(a0 + 1);
int64_t a1 = args[1].i64();
......@@ -177,16 +177,16 @@ own<Trap*> PlusOne(const Val args[], Val results[]) {
} // namespace
TEST_F(WasmCapiTest, DirectCallCapiFunction) {
own<FuncType*> cpp_sig =
FuncType::make(vec<ValType*>::make(
own<FuncType> cpp_sig =
FuncType::make(ownvec<ValType>::make(
ValType::make(::wasm::I32), ValType::make(::wasm::I64),
ValType::make(::wasm::F32), ValType::make(::wasm::F64),
ValType::make(::wasm::ANYREF)),
vec<ValType*>::make(
ownvec<ValType>::make(
ValType::make(::wasm::I32), ValType::make(::wasm::I64),
ValType::make(::wasm::F32), ValType::make(::wasm::F64),
ValType::make(::wasm::ANYREF)));
own<Func*> func = Func::make(store(), cpp_sig.get(), PlusOne);
own<Func> func = Func::make(store(), cpp_sig.get(), PlusOne);
Extern* imports[] = {func.get()};
ValueType wasm_types[] = {kWasmI32, kWasmI64, kWasmF32, kWasmF64,
kWasmAnyRef, kWasmI32, kWasmI64, kWasmF32,
......@@ -203,7 +203,7 @@ TEST_F(WasmCapiTest, DirectCallCapiFunction) {
Val::ref(func->copy())};
Val results[5];
// Test that {func} can be called directly.
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(a0 + 1, results[0].i32());
EXPECT_EQ(a1 + 1, results[1].i64());
......
......@@ -49,15 +49,15 @@ TEST_F(WasmCapiTest, InstanceFinalization) {
static const int kIterations = 10;
for (int iteration = 0; iteration < kIterations; iteration++) {
void* finalizer_data = reinterpret_cast<void*>(iteration);
own<Instance*> instance = Instance::make(store(), module(), nullptr);
own<Instance> instance = Instance::make(store(), module(), nullptr);
EXPECT_NE(nullptr, instance.get());
instance->set_host_info(finalizer_data, &FinalizeInstance);
own<Func*> func = instance->exports()[0]->func()->copy();
own<Func> func = instance->exports()[0]->func()->copy();
ASSERT_NE(func, nullptr);
func->set_host_info(finalizer_data, &FinalizeFunction);
own<Foreign*> foreign = Foreign::make(store());
own<Foreign> foreign = Foreign::make(store());
foreign->set_host_info(finalizer_data, &FinalizeForeign);
}
Shutdown();
......
......@@ -90,21 +90,21 @@ TEST_F(WasmCapiTest, Globals) {
&param_i64);
// Create imported globals.
own<GlobalType*> const_f32_type =
own<GlobalType> const_f32_type =
GlobalType::make(ValType::make(::wasm::F32), ::wasm::CONST);
own<GlobalType*> const_i64_type =
own<GlobalType> const_i64_type =
GlobalType::make(ValType::make(::wasm::I64), ::wasm::CONST);
own<GlobalType*> var_f32_type =
own<GlobalType> var_f32_type =
GlobalType::make(ValType::make(::wasm::F32), ::wasm::VAR);
own<GlobalType*> var_i64_type =
own<GlobalType> var_i64_type =
GlobalType::make(ValType::make(::wasm::I64), ::wasm::VAR);
own<Global*> const_f32_import =
own<Global> const_f32_import =
Global::make(store(), const_f32_type.get(), Val::f32(1));
own<Global*> const_i64_import =
own<Global> const_i64_import =
Global::make(store(), const_i64_type.get(), Val::i64(2));
own<Global*> var_f32_import =
own<Global> var_f32_import =
Global::make(store(), var_f32_type.get(), Val::f32(3));
own<Global*> var_i64_import =
own<Global> var_i64_import =
Global::make(store(), var_i64_type.get(), Val::i64(4));
Extern* imports[] = {const_f32_import.get(), const_i64_import.get(),
var_f32_import.get(), var_i64_import.get()};
......
......@@ -15,7 +15,7 @@ using ::wasm::Message;
namespace {
own<Trap*> IdentityCallback(const Val args[], Val results[]) {
own<Trap> IdentityCallback(const Val args[], Val results[]) {
results[0] = args[0].copy();
return nullptr;
}
......@@ -55,10 +55,10 @@ TEST_F(WasmCapiTest, HostRef) {
AddExportedFunction(CStrVector("func.call"), func_call_code,
sizeof(func_call_code), &r_r_sig);
own<FuncType*> func_type =
FuncType::make(vec<ValType*>::make(ValType::make(::wasm::ANYREF)),
vec<ValType*>::make(ValType::make(::wasm::ANYREF)));
own<Func*> callback = Func::make(store(), func_type.get(), IdentityCallback);
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::ANYREF)),
ownvec<ValType>::make(ValType::make(::wasm::ANYREF)));
own<Func> callback = Func::make(store(), func_type.get(), IdentityCallback);
Extern* imports[] = {callback.get()};
Instantiate(imports);
......@@ -68,8 +68,8 @@ TEST_F(WasmCapiTest, HostRef) {
const Func* table_get = GetExportedFunction(3);
const Func* func_call = GetExportedFunction(4);
own<Foreign*> host1 = Foreign::make(store());
own<Foreign*> host2 = Foreign::make(store());
own<Foreign> host1 = Foreign::make(store());
own<Foreign> host2 = Foreign::make(store());
host1->set_host_info(reinterpret_cast<void*>(1));
host2->set_host_info(reinterpret_cast<void*>(2));
......@@ -78,14 +78,14 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_TRUE(host2->copy()->same(host2.get()));
Val val = Val::ref(host1->copy());
EXPECT_TRUE(val.ref()->copy()->same(host1.get()));
own<Ref*> ref = val.release_ref();
own<Ref> ref = val.release_ref();
EXPECT_EQ(nullptr, val.ref());
EXPECT_TRUE(ref->copy()->same(host1.get()));
// Interact with the Global.
Val args[2];
Val results[1];
own<Trap*> trap = global_get->call(nullptr, results);
own<Trap> trap = global_get->call(nullptr, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(nullptr, results[0].release_ref());
args[0] = Val::ref(host1.get()->copy());
......@@ -100,7 +100,7 @@ TEST_F(WasmCapiTest, HostRef) {
trap = global_get->call(nullptr, results);
EXPECT_EQ(nullptr, trap);
EXPECT_TRUE(results[0].release_ref()->same(host2.get()));
args[0] = Val::ref(own<Ref*>());
args[0] = Val::ref(own<Ref>());
trap = global_set->call(args, nullptr);
EXPECT_EQ(nullptr, trap);
trap = global_get->call(nullptr, results);
......@@ -133,7 +133,7 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_EQ(nullptr, trap);
EXPECT_TRUE(results[0].release_ref()->same(host2.get()));
args[0] = Val::i32(0);
args[1] = Val::ref(own<Ref*>());
args[1] = Val::ref(own<Ref>());
trap = table_set->call(args, nullptr);
EXPECT_EQ(nullptr, trap);
trap = table_get->call(args, results);
......@@ -141,7 +141,7 @@ TEST_F(WasmCapiTest, HostRef) {
EXPECT_EQ(nullptr, results[0].release_ref());
// Interact with the Function.
args[0] = Val::ref(own<Ref*>());
args[0] = Val::ref(own<Ref>());
trap = func_call->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(nullptr, results[0].release_ref());
......
......@@ -73,7 +73,7 @@ TEST_F(WasmCapiTest, Memory) {
EXPECT_EQ(0, result[0].i32());
// load(0x20000) -> trap
args[0] = Val::i32(0x20000);
own<Trap*> trap = load_func->call(args, result);
own<Trap> trap = load_func->call(args, result);
EXPECT_NE(nullptr, trap.get());
// Mutate memory.
......@@ -114,8 +114,8 @@ TEST_F(WasmCapiTest, Memory) {
// Create standalone memory.
// TODO(wasm): Once Wasm allows multiple memories, turn this into an import.
own<MemoryType*> mem_type = MemoryType::make(Limits(5, 5));
own<Memory*> memory2 = Memory::make(store(), mem_type.get());
own<MemoryType> mem_type = MemoryType::make(Limits(5, 5));
own<Memory> memory2 = Memory::make(store(), mem_type.get());
EXPECT_EQ(5u, memory2->size());
EXPECT_EQ(false, memory2->grow(1));
EXPECT_EQ(true, memory2->grow(0));
......
......@@ -51,8 +51,8 @@ TEST_F(WasmCapiTest, Reflect) {
Instantiate(nullptr);
vec<ExportType*> export_types = module()->exports();
const vec<Extern*>& exports = this->exports();
ownvec<ExportType> export_types = module()->exports();
const ownvec<Extern>& exports = this->exports();
EXPECT_EQ(exports.size(), export_types.size());
EXPECT_EQ(4u, exports.size());
for (size_t i = 0; i < exports.size(); i++) {
......@@ -62,13 +62,13 @@ TEST_F(WasmCapiTest, Reflect) {
if (kind == ::wasm::EXTERN_FUNC) {
ExpectName(kFuncName, export_types[i]->name());
const FuncType* type = extern_type->func();
const vec<ValType*>& params = type->params();
const ownvec<ValType>& params = type->params();
EXPECT_EQ(4u, params.size());
EXPECT_EQ(::wasm::I32, params[0]->kind());
EXPECT_EQ(::wasm::I64, params[1]->kind());
EXPECT_EQ(::wasm::F32, params[2]->kind());
EXPECT_EQ(::wasm::F64, params[3]->kind());
const vec<ValType*>& results = type->results();
const ownvec<ValType>& results = type->results();
EXPECT_EQ(2u, results.size());
EXPECT_EQ(::wasm::I32, results[0]->kind());
EXPECT_EQ(::wasm::ANYREF, results[1]->kind());
......
......@@ -12,7 +12,7 @@ namespace {
bool g_callback_called;
own<Trap*> Callback(const Val args[], Val results[]) {
own<Trap> Callback(const Val args[], Val results[]) {
g_callback_called = true;
return nullptr;
}
......@@ -27,16 +27,15 @@ TEST_F(WasmCapiTest, Serialize) {
Compile();
vec<byte_t> serialized = module()->serialize();
own<Module*> deserialized = Module::deserialize(store(), serialized);
own<Module> deserialized = Module::deserialize(store(), serialized);
own<FuncType*> callback_type =
FuncType::make(vec<ValType*>::make(), vec<ValType*>::make());
own<Func*> callback = Func::make(store(), callback_type.get(), Callback);
own<FuncType> callback_type =
FuncType::make(ownvec<ValType>::make(), ownvec<ValType>::make());
own<Func> callback = Func::make(store(), callback_type.get(), Callback);
Extern* imports[] = {callback.get()};
own<Instance*> instance =
Instance::make(store(), deserialized.get(), imports);
vec<Extern*> exports = instance->exports();
own<Instance> instance = Instance::make(store(), deserialized.get(), imports);
ownvec<Extern> exports = instance->exports();
Func* run = exports[0]->func();
g_callback_called = false;
run->call();
......
......@@ -14,7 +14,7 @@ using ::wasm::TableType;
namespace {
own<Trap*> Negate(const Val args[], Val results[]) {
own<Trap> Negate(const Val args[], Val results[]) {
results[0] = Val(-args[0].i32());
return nullptr;
}
......@@ -22,14 +22,14 @@ own<Trap*> Negate(const Val args[], Val results[]) {
void ExpectTrap(const Func* func, int arg1, int arg2) {
Val args[2] = {Val::i32(arg1), Val::i32(arg2)};
Val results[1];
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_NE(nullptr, trap);
}
void ExpectResult(int expected, const Func* func, int arg1, int arg2) {
Val args[2] = {Val::i32(arg1), Val::i32(arg2)};
Val results[1];
own<Trap*> trap = func->call(args, results);
own<Trap> trap = func->call(args, results);
EXPECT_EQ(nullptr, trap);
EXPECT_EQ(expected, results[0].i32());
}
......@@ -60,7 +60,7 @@ TEST_F(WasmCapiTest, Table) {
Func* call_indirect = GetExportedFunction(1);
Func* f = GetExportedFunction(2);
Func* g = GetExportedFunction(3);
own<Func*> h = Func::make(store(), cpp_i_i_sig(), Negate);
own<Func> h = Func::make(store(), cpp_i_i_sig(), Negate);
// Try cloning.
EXPECT_TRUE(table->copy()->same(table));
......@@ -106,9 +106,9 @@ TEST_F(WasmCapiTest, Table) {
// Create standalone table.
// TODO(wasm+): Once Wasm allows multiple tables, turn this into import.
own<TableType*> tabletype =
own<TableType> tabletype =
TableType::make(ValType::make(FUNCREF), Limits(5, 5));
own<Table*> table2 = Table::make(store(), tabletype.get());
own<Table> table2 = Table::make(store(), tabletype.get());
EXPECT_EQ(5u, table2->size());
EXPECT_FALSE(table2->grow(1));
EXPECT_TRUE(table2->grow(0));
......
......@@ -19,26 +19,27 @@ const int kNumThreads = 10;
const int kIterationsPerThread = 3;
int g_traces;
own<Trap*> Callback(void* env, const Val args[], Val results[]) {
own<Trap> Callback(void* env, const Val args[], Val results[]) {
std::lock_guard<std::mutex> lock(*reinterpret_cast<std::mutex*>(env));
g_traces += args[0].i32();
return nullptr;
}
void Main(Engine* engine, Shared<Module>* shared, std::mutex* mutex, int id) {
own<Store*> store = Store::make(engine);
own<Module*> module = Module::obtain(store.get(), shared);
own<Store> store = Store::make(engine);
own<Module> module = Module::obtain(store.get(), shared);
EXPECT_NE(nullptr, module.get());
for (int i = 0; i < kIterationsPerThread; i++) {
std::this_thread::sleep_for(std::chrono::microseconds(100));
// Create imports.
own<FuncType*> func_type = FuncType::make(
vec<ValType*>::make(ValType::make(::wasm::I32)), vec<ValType*>::make());
own<Func*> func = Func::make(store.get(), func_type.get(), Callback, mutex);
own<::wasm::GlobalType*> global_type =
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::I32)),
ownvec<ValType>::make());
own<Func> func = Func::make(store.get(), func_type.get(), Callback, mutex);
own<::wasm::GlobalType> global_type =
::wasm::GlobalType::make(ValType::make(::wasm::I32), ::wasm::CONST);
own<Global*> global =
own<Global> global =
Global::make(store.get(), global_type.get(), Val::i32(id));
// Instantiate and run.
......@@ -46,9 +47,8 @@ void Main(Engine* engine, Shared<Module>* shared, std::mutex* mutex, int id) {
// imports always come before function imports, regardless of the
// order of builder()->Add*Import() calls below.
Extern* imports[] = {global.get(), func.get()};
own<Instance*> instance =
Instance::make(store.get(), module.get(), imports);
vec<Extern*> exports = instance->exports();
own<Instance> instance = Instance::make(store.get(), module.get(), imports);
ownvec<Extern> exports = instance->exports();
Func* run_func = exports[0]->func();
run_func->call();
}
......@@ -70,7 +70,7 @@ TEST_F(WasmCapiTest, Threads) {
FunctionSig empty_sig(0, 0, nullptr);
AddExportedFunction(CStrVector("run"), code, sizeof(code), &empty_sig);
Compile();
own<Shared<Module>*> shared = module()->share();
own<Shared<Module>> shared = module()->share();
// Spawn threads.
g_traces = 0;
......@@ -92,9 +92,9 @@ TEST_F(WasmCapiTest, Threads) {
TEST_F(WasmCapiTest, MultiStoresOneThread) {
// These Stores intentionally have overlapping, but non-nested lifetimes.
own<Store*> store1 = Store::make(engine());
own<Store*> store2 = Store::make(engine());
own<Store*> store3 = Store::make(engine());
own<Store> store1 = Store::make(engine());
own<Store> store2 = Store::make(engine());
own<Store> store3 = Store::make(engine());
store1.reset();
store2.reset();
store3.reset();
......
......@@ -20,7 +20,7 @@ using ::wasm::Message;
namespace {
own<Trap*> FailCallback(void* env, const Val args[], Val results[]) {
own<Trap> FailCallback(void* env, const Val args[], Val results[]) {
Store* store = reinterpret_cast<Store*>(env);
Message message = Message::make(std::string("callback abort"));
return Trap::make(store, message);
......@@ -45,10 +45,11 @@ TEST_F(WasmCapiTest, Traps) {
byte code2[] = {WASM_I32V_3(0), WASM_UNREACHABLE, WASM_I32V_1(1)};
AddExportedFunction(CStrVector("unreachable"), code2, sizeof(code2), &sig);
own<FuncType*> func_type = FuncType::make(
vec<ValType*>::make(), vec<ValType*>::make(ValType::make(::wasm::I32)));
own<Func*> cpp_callback = Func::make(store(), func_type.get(), FailCallback,
reinterpret_cast<void*>(store()));
own<FuncType> func_type =
FuncType::make(ownvec<ValType>::make(),
ownvec<ValType>::make(ValType::make(::wasm::I32)));
own<Func> cpp_callback = Func::make(store(), func_type.get(), FailCallback,
reinterpret_cast<void*>(store()));
Extern* imports[] = {cpp_callback.get()};
Instantiate(imports);
......@@ -67,24 +68,24 @@ TEST_F(WasmCapiTest, Traps) {
const uint32_t func2_offset = func2->code.offset();
Func* cpp_trapping_func = GetExportedFunction(0);
own<Trap*> cpp_trap = cpp_trapping_func->call();
own<Trap> cpp_trap = cpp_trapping_func->call();
EXPECT_NE(nullptr, cpp_trap.get());
ExpectMessage("Uncaught Error: callback abort", cpp_trap->message());
own<Frame*> frame = cpp_trap->origin();
own<Frame> frame = cpp_trap->origin();
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(1u, frame->func_index());
EXPECT_EQ(1u, frame->func_offset());
EXPECT_EQ(func1_offset + frame->func_offset(), frame->module_offset());
vec<Frame*> trace = cpp_trap->trace();
ownvec<Frame> trace = cpp_trap->trace();
EXPECT_EQ(1u, trace.size());
frame = trace[0].move();
frame.reset(trace[0].release());
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(1u, frame->func_index());
EXPECT_EQ(1u, frame->func_offset());
EXPECT_EQ(func1_offset + frame->func_offset(), frame->module_offset());
Func* wasm_trapping_func = GetExportedFunction(1);
own<Trap*> wasm_trap = wasm_trapping_func->call();
own<Trap> wasm_trap = wasm_trapping_func->call();
EXPECT_NE(nullptr, wasm_trap.get());
ExpectMessage("Uncaught RuntimeError: unreachable", wasm_trap->message());
frame = wasm_trap->origin();
......@@ -94,7 +95,7 @@ TEST_F(WasmCapiTest, Traps) {
EXPECT_EQ(func2_offset + frame->func_offset(), frame->module_offset());
trace = wasm_trap->trace();
EXPECT_EQ(1u, trace.size());
frame = trace[0].move();
frame.reset(trace[0].release());
EXPECT_TRUE(frame->instance()->same(instance()));
EXPECT_EQ(2u, frame->func_index());
EXPECT_EQ(5u, frame->func_offset());
......
......@@ -27,6 +27,7 @@ using ::wasm::Instance;
using ::wasm::Memory;
using ::wasm::Module;
using ::wasm::own;
using ::wasm::ownvec;
using ::wasm::Ref;
using ::wasm::Store;
using ::wasm::Table;
......@@ -42,13 +43,13 @@ class WasmCapiTest : public ::testing::Test {
zone_(&allocator_, ZONE_NAME),
wire_bytes_(&zone_),
builder_(&zone_),
exports_(vec<Extern*>::make()),
exports_(ownvec<Extern>::make()),
wasm_i_i_sig_(1, 1, wasm_i_i_sig_types_) {
engine_ = Engine::make();
store_ = Store::make(engine_.get());
cpp_i_i_sig_ =
FuncType::make(vec<ValType*>::make(ValType::make(::wasm::I32)),
vec<ValType*>::make(ValType::make(::wasm::I32)));
FuncType::make(ownvec<ValType>::make(ValType::make(::wasm::I32)),
ownvec<ValType>::make(ValType::make(::wasm::I32)));
}
void Compile() {
......@@ -79,7 +80,7 @@ class WasmCapiTest : public ::testing::Test {
Func* GetExportedFunction(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_FUNC);
Func* func = exported->func();
DCHECK_NE(func, nullptr);
......@@ -88,7 +89,7 @@ class WasmCapiTest : public ::testing::Test {
Global* GetExportedGlobal(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_GLOBAL);
Global* global = exported->global();
DCHECK_NE(global, nullptr);
......@@ -97,7 +98,7 @@ class WasmCapiTest : public ::testing::Test {
Memory* GetExportedMemory(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_MEMORY);
Memory* memory = exported->memory();
DCHECK_NE(memory, nullptr);
......@@ -106,7 +107,7 @@ class WasmCapiTest : public ::testing::Test {
Table* GetExportedTable(size_t index) {
DCHECK_GT(exports_.size(), index);
Extern* exported = exports_[index];
Extern* exported = exports_[index].get();
DCHECK_EQ(exported->kind(), ::wasm::EXTERN_TABLE);
Table* table = exported->table();
DCHECK_NE(table, nullptr);
......@@ -125,7 +126,7 @@ class WasmCapiTest : public ::testing::Test {
Store* store() { return store_.get(); }
Module* module() { return module_.get(); }
Instance* instance() { return instance_.get(); }
const vec<Extern*>& exports() { return exports_; }
const ownvec<Extern>& exports() { return exports_; }
ZoneBuffer* wire_bytes() { return &wire_bytes_; }
FunctionSig* wasm_i_i_sig() { return &wasm_i_i_sig_; }
......@@ -136,12 +137,12 @@ class WasmCapiTest : public ::testing::Test {
Zone zone_;
ZoneBuffer wire_bytes_;
WasmModuleBuilder builder_;
own<Engine*> engine_;
own<Store*> store_;
own<Module*> module_;
own<Instance*> instance_;
vec<Extern*> exports_;
own<FuncType*> cpp_i_i_sig_;
own<Engine> engine_;
own<Store> store_;
own<Module> module_;
own<Instance> instance_;
ownvec<Extern> exports_;
own<FuncType> cpp_i_i_sig_;
ValueType wasm_i_i_sig_types_[2] = {kWasmI32, kWasmI32};
FunctionSig wasm_i_i_sig_;
};
......
......@@ -36,7 +36,7 @@ auto operator<<(std::ostream& out, const wasm::Val& val) -> std::ostream& {
// A function to be called from Wasm code.
auto print_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl << "> " << args[0] << std::endl;
results[0] = args[0].copy();
return nullptr;
......@@ -46,7 +46,7 @@ auto print_callback(
// A function closure.
auto closure_callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
auto i = *reinterpret_cast<int*>(env);
std::cout << "Calling back closure..." << std::endl;
std::cout << "> " << i << std::endl;
......@@ -87,8 +87,8 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto print_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto print_func = wasm::Func::make(store, print_type.get(), print_callback);
......@@ -96,8 +96,8 @@ void run() {
std::cout << "Creating closure..." << std::endl;
int i = 42;
auto closure_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto closure_func = wasm::Func::make(store, closure_type.get(), closure_callback, &i);
......
......@@ -7,7 +7,7 @@
#include "wasm.hh"
auto get_export_global(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Global* {
auto get_export_global(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Global* {
if (exports.size() <= i || !exports[i]->global()) {
std::cout << "> Error accessing global export " << i << "!" << std::endl;
exit(1);
......@@ -15,7 +15,7 @@ auto get_export_global(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Glo
return exports[i]->global();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto hello_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> Hello world!" << std::endl;
return nullptr;
......@@ -49,7 +49,7 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto hello_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(), wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(), wasm::ownvec<wasm::ValType>::make()
);
auto hello_func = wasm::Func::make(store, hello_type.get(), hello_callback);
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> " << (args[0].ref() ? args[0].ref()->get_host_info() : nullptr) << std::endl;
results[0] = args[0].copy();
......@@ -18,7 +18,7 @@ auto callback(
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "/" << exports.size() << "!" << std::endl;
exit(1);
......@@ -28,7 +28,7 @@ auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const
void call_r_v(const wasm::Func* func, const wasm::Ref* ref) {
std::cout << "call_r_v... " << std::flush;
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
if (func->call(args, nullptr)) {
std::cout << "> Error calling function!" << std::endl;
exit(1);
......@@ -36,7 +36,7 @@ void call_r_v(const wasm::Func* func, const wasm::Ref* ref) {
std::cout << "okay" << std::endl;
}
auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref*> {
auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref> {
std::cout << "call_v_r... " << std::flush;
wasm::Val results[1];
if (func->call(nullptr, results)) {
......@@ -47,9 +47,9 @@ auto call_v_r(const wasm::Func* func) -> wasm::own<wasm::Ref*> {
return results[0].release_ref();
}
auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::Ref*> {
auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::Ref> {
std::cout << "call_r_r... " << std::flush;
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[1] = {wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
wasm::Val results[1];
if (func->call(args, results)) {
std::cout << "> Error calling function!" << std::endl;
......@@ -61,7 +61,7 @@ auto call_r_r(const wasm::Func* func, const wasm::Ref* ref) -> wasm::own<wasm::R
void call_ir_v(const wasm::Func* func, int32_t i, const wasm::Ref* ref) {
std::cout << "call_ir_v... " << std::flush;
wasm::Val args[2] = {wasm::Val::i32(i), wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref*>())};
wasm::Val args[2] = {wasm::Val::i32(i), wasm::Val::ref(ref ? ref->copy() : wasm::own<wasm::Ref>())};
if (func->call(args, nullptr)) {
std::cout << "> Error calling function!" << std::endl;
exit(1);
......@@ -69,7 +69,7 @@ void call_ir_v(const wasm::Func* func, int32_t i, const wasm::Ref* ref) {
std::cout << "okay" << std::endl;
}
auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref*> {
auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref> {
std::cout << "call_i_r... " << std::flush;
wasm::Val args[1] = {wasm::Val::i32(i)};
wasm::Val results[1];
......@@ -81,7 +81,7 @@ auto call_i_r(const wasm::Func* func, int32_t i) -> wasm::own<wasm::Ref*> {
return results[0].release_ref();
}
void check(wasm::own<wasm::Ref*> actual, const wasm::Ref* expected) {
void check(wasm::own<wasm::Ref> actual, const wasm::Ref* expected) {
if (actual.get() != expected &&
!(actual && expected && actual->same(expected))) {
std::cout << "> Error reading reference, expected "
......@@ -123,8 +123,8 @@ void run() {
// Create external callback function.
std::cout << "Creating callback..." << std::endl;
auto callback_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::ANYREF)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::ANYREF))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ANYREF)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::ANYREF))
);
auto callback_func = wasm::Func::make(store, callback_type.get(), callback);
......
......@@ -7,7 +7,7 @@
#include "wasm.hh"
auto get_export_memory(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Memory* {
auto get_export_memory(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Memory* {
if (exports.size() <= i || !exports[i]->memory()) {
std::cout << "> Error accessing memory export " << i << "!" << std::endl;
exit(1);
......@@ -15,7 +15,7 @@ auto get_export_memory(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Mem
return exports[i]->memory();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......
......@@ -33,7 +33,7 @@ auto operator<<(std::ostream& out, const wasm::ValType& type) -> std::ostream& {
return out;
}
auto operator<<(std::ostream& out, const wasm::vec<wasm::ValType*>& types) -> std::ostream& {
auto operator<<(std::ostream& out, const wasm::ownvec<wasm::ValType>& types) -> std::ostream& {
bool first = true;
for (size_t i = 0; i < types.size(); ++i) {
if (first) {
......
......@@ -10,7 +10,7 @@
// A function to be called from Wasm code.
auto hello_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
std::cout << "> Hello world!" << std::endl;
return nullptr;
......@@ -61,7 +61,7 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto hello_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(), wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(), wasm::ownvec<wasm::ValType>::make()
);
auto hello_func = wasm::Func::make(store, hello_type.get(), hello_callback);
......
......@@ -10,14 +10,14 @@
// A function to be called from Wasm code.
auto neg_callback(
const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
results[0] = wasm::Val(-args[0].i32());
return nullptr;
}
auto get_export_table(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Table* {
auto get_export_table(wasm::ownvec<wasm::Extern>& exports, size_t i) -> wasm::Table* {
if (exports.size() <= i || !exports[i]->table()) {
std::cout << "> Error accessing table export " << i << "!" << std::endl;
exit(1);
......@@ -25,7 +25,7 @@ auto get_export_table(wasm::vec<wasm::Extern*>& exports, size_t i) -> wasm::Tabl
return exports[i]->table();
}
auto get_export_func(const wasm::vec<wasm::Extern*>& exports, size_t i) -> const wasm::Func* {
auto get_export_func(const wasm::ownvec<wasm::Extern>& exports, size_t i) -> const wasm::Func* {
if (exports.size() <= i || !exports[i]->func()) {
std::cout << "> Error accessing function export " << i << "!" << std::endl;
exit(1);
......@@ -118,8 +118,8 @@ void run() {
// Create external function.
std::cout << "Creating callback..." << std::endl;
auto neg_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto h = wasm::Func::make(store, neg_type.get(), neg_callback);
......
......@@ -11,7 +11,7 @@ const int N_REPS = 3;
// A function to be called from Wasm code.
auto callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
assert(args[0].kind() == wasm::I32);
std::lock_guard<std::mutex>(*reinterpret_cast<std::mutex*>(env));
std::cout << "Thread " << args[0].i32() << " running..." << std::endl;
......@@ -42,8 +42,8 @@ void run(
// Create imports.
auto func_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32)),
wasm::vec<wasm::ValType*>::make()
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32)),
wasm::ownvec<wasm::ValType>::make()
);
auto func = wasm::Func::make(store, func_type.get(), callback, mutex);
......
......@@ -9,7 +9,7 @@
// A function to be called from Wasm code.
auto fail_callback(
void* env, const wasm::Val args[], wasm::Val results[]
) -> wasm::own<wasm::Trap*> {
) -> wasm::own<wasm::Trap> {
std::cout << "Calling back..." << std::endl;
auto store = reinterpret_cast<wasm::Store*>(env);
auto message = wasm::Name::make(std::string("callback abort"));
......@@ -57,8 +57,8 @@ void run() {
// Create external print functions.
std::cout << "Creating callback..." << std::endl;
auto fail_type = wasm::FuncType::make(
wasm::vec<wasm::ValType*>::make(),
wasm::vec<wasm::ValType*>::make(wasm::ValType::make(wasm::I32))
wasm::ownvec<wasm::ValType>::make(),
wasm::ownvec<wasm::ValType>::make(wasm::ValType::make(wasm::I32))
);
auto fail_func =
wasm::Func::make(store, fail_type.get(), fail_callback, store);
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment