Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2035)

Unified Diff: test/cctest/wasm/wasm-run-utils.h

Issue 1916403002: [wasm] Add tests for function name encoding (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@wasm-offset-table-3
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: test/cctest/wasm/wasm-run-utils.h
diff --git a/test/cctest/wasm/wasm-run-utils.h b/test/cctest/wasm/wasm-run-utils.h
index 1d0fd7110d6eff801a6e3549d3850f8ad998ef4f..120292c1d295702901049c6d52e9ed0468f82686 100644
--- a/test/cctest/wasm/wasm-run-utils.h
+++ b/test/cctest/wasm/wasm-run-utils.h
@@ -21,6 +21,7 @@
#include "src/wasm/ast-decoder.h"
#include "src/wasm/wasm-js.h"
+#include "src/wasm/wasm-macro-gen.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-opcodes.h"
@@ -202,6 +203,21 @@ class TestingModule : public ModuleEnv {
instance->function_code[index] = code;
}
+ void SetFunctionBytes(uint32_t index, const byte* start, const byte* end) {
+ int length = static_cast<int>(end - start);
+ DCHECK_EQ(end - start, length);
+ uint32_t bytes_offset = AddModuleBytes(Vector<const byte>(start, length));
+ module_.functions[index].code_start_offset = bytes_offset;
+ module_.functions[index].code_end_offset = bytes_offset + length;
+ }
+
+ void SetFunctionName(uint32_t index, Vector<const char> name) {
+ uint32_t name_offset = AddModuleBytes(Vector<const byte>(
+ reinterpret_cast<const byte*>(name.start()), name.length()));
+ module_.functions[index].name_offset = name_offset;
+ module_.functions[index].name_length = name.length();
+ }
+
void AddIndirectFunctionTable(int* functions, int table_size) {
Isolate* isolate = module->shared_isolate;
Handle<FixedArray> fixed =
@@ -225,12 +241,23 @@ class TestingModule : public ModuleEnv {
}
}
+ Handle<JSObject> Instantiate() {
+ Isolate* isolate = module->shared_isolate;
+ Handle<JSObject> ffi; // We don't need ffi in tests.
+ Handle<JSArrayBuffer> memory; // We don't need memory in tests.
+ return module->Instantiate(isolate, ffi, memory).ToHandleChecked();
+ }
+
private:
WasmModule module_;
WasmModuleInstance instance_;
uint32_t global_offset;
V8_ALIGNED(8) byte global_data[kMaxGlobalsSize]; // preallocated global data.
+ // This vector contains function names and wasm code, but not in any valid
+ // format. It is references by WasmFunctions (name_offset, code_start_offset).
+ std::vector<byte> module_bytes_;
+
WasmGlobal* AddGlobal(MachineType mem_type) {
byte size = WasmOpcodes::MemSize(mem_type);
global_offset = (global_offset + size - 1) & ~(size - 1); // align
@@ -240,6 +267,17 @@ class TestingModule : public ModuleEnv {
CHECK_LT(global_offset, kMaxGlobalsSize);
return &module->globals.back();
}
+
+ uint32_t AddModuleBytes(Vector<const byte> bytes) {
+ DCHECK(module->module_start == nullptr ||
+ module->module_start == module_bytes_.data());
+ DCHECK_EQ(module->module_start == nullptr, module_bytes_.empty());
+ module_bytes_.insert(module_bytes_.end(), bytes.start(),
+ bytes.start() + bytes.length());
+ module->module_start = module_bytes_.data();
+ module->module_end = module_bytes_.data() + module_bytes_.size();
+ return static_cast<uint32_t>(module_bytes_.size() - bytes.length());
+ }
};
inline void TestBuildingGraph(Zone* zone, JSGraph* jsgraph, ModuleEnv* module,
@@ -467,6 +505,8 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
local_decls.Prepend(&start, &end);
TestBuildingGraph(main_zone(), &jsgraph, testing_module_, sig,
&source_position_table_, start, end);
+ if (testing_module_ != nullptr)
+ testing_module_->SetFunctionBytes(function_index_, start, end);
delete[] start;
}
@@ -523,6 +563,8 @@ class WasmFunctionCompiler : public HandleAndZoneScope,
function()->sig_index = sig_index;
Handle<Code> code = Compile();
testing_module_->SetFunctionCode(function_index_, code);
+ if (debug_name_.start() != nullptr)
+ testing_module_->SetFunctionName(function_index_, debug_name_);
return static_cast<uint32_t>(function_index_);
}

Powered by Google App Engine
This is Rietveld 408576698