Commit 45b1f8ca authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[base] Simplify and extend VectorOf method

And use it in several places in wasm.

R=tebbi@chromium.org

Bug: v8:8562
Change-Id: I1e857baf33e99849eb32ac2c94e39d7f27b180c8
Reviewed-on: https://chromium-review.googlesource.com/c/1391757
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58495}
parent 94ba6c6f
......@@ -10,6 +10,7 @@
#include <iterator>
#include "src/allocation.h"
#include "src/base/macros.h"
#include "src/checks.h"
#include "src/globals.h"
......@@ -257,10 +258,10 @@ inline int StrLength(const char* string) {
return static_cast<int>(length);
}
#define STATIC_CHAR_VECTOR(x) \
v8::internal::Vector<const uint8_t>(reinterpret_cast<const uint8_t*>(x), \
arraysize(x) - 1)
#define STATIC_CHAR_VECTOR(x) \
v8::internal::VectorOf( \
reinterpret_cast<const uint8_t*>(implicit_cast<const char*>(x)), \
arraysize(x) - 1)
inline Vector<const char> CStrVector(const char* data) {
return Vector<const char>(data, StrLength(data));
......@@ -288,13 +289,17 @@ inline constexpr Vector<T> ArrayVector(T (&arr)[N]) {
return Vector<T>(arr);
}
// Construct a Vector from a start pointer and a size.
template <typename T>
inline constexpr Vector<T> VectorOf(T* start, size_t size) {
return Vector<T>(start, size);
}
// Construct a Vector from anything providing a {data()} and {size()} accessor.
template <typename Container,
typename T = typename std::remove_reference<
decltype(*(std::declval<Container>()).data())>::type,
typename = decltype((std::declval<Container>()).size())>
inline constexpr Vector<T> VectorOf(Container&& c) {
return Vector<T>(c.data(), c.size());
template <typename Container>
inline constexpr auto VectorOf(Container&& c)
-> decltype(VectorOf(c.data(), c.size())) {
return VectorOf(c.data(), c.size());
}
} // namespace internal
......
......@@ -328,11 +328,10 @@ void LiftoffAssembler::CacheState::InitMerge(const CacheState& source,
// multiple times need to be copied to another free register. Compute the list
// of used registers.
LiftoffRegList used_regs;
for (auto& src : Vector<const VarState>{source_begin, num_locals}) {
for (auto& src : VectorOf(source_begin, num_locals)) {
if (src.is_reg()) used_regs.set(src.reg());
}
for (auto& src :
Vector<const VarState>{source_begin + stack_base + discarded, arity}) {
for (auto& src : VectorOf(source_begin + stack_base + discarded, arity)) {
if (src.is_reg()) used_regs.set(src.reg());
}
......
......@@ -3395,8 +3395,7 @@ Handle<Script> CreateWasmScript(Isolate* isolate,
int name_chars = SNPrintF(ArrayVector(buffer), "wasm-%08x", hash);
DCHECK(name_chars >= 0 && name_chars < kBufferSize);
MaybeHandle<String> name_str = isolate->factory()->NewStringFromOneByte(
Vector<const uint8_t>(reinterpret_cast<uint8_t*>(buffer), name_chars),
TENURED);
VectorOf(reinterpret_cast<uint8_t*>(buffer), name_chars), TENURED);
script->set_name(*name_str.ToHandleChecked());
if (source_map_url.size() != 0) {
......
......@@ -1025,7 +1025,7 @@ class ModuleDecoderImpl : public Decoder {
StartDecoding(counters, allocator);
uint32_t offset = 0;
Vector<const byte> orig_bytes(start(), end() - start());
DecodeModuleHeader(Vector<const uint8_t>(start(), end() - start()), offset);
DecodeModuleHeader(VectorOf(start(), end() - start()), offset);
if (failed()) {
return FinishDecoding(verify_functions);
}
......
......@@ -42,7 +42,7 @@ class WasmStreaming::WasmStreamingImpl {
}
void OnBytesReceived(const uint8_t* bytes, size_t size) {
streaming_decoder_->OnBytesReceived(i::Vector<const uint8_t>(bytes, size));
streaming_decoder_->OnBytesReceived(i::VectorOf(bytes, size));
}
void Finish() { streaming_decoder_->Finish(); }
......@@ -338,20 +338,14 @@ class InstantiateBytesResultResolver
i::Handle<i::JSObject> result =
isolate_->factory()->NewJSObject(isolate_->object_function());
const uint8_t* instance_str = reinterpret_cast<const uint8_t*>("instance");
i::Handle<i::String> instance_name =
isolate_->factory()
->NewStringFromOneByte(i::Vector<const uint8_t>(
instance_str,
i::StrLength(reinterpret_cast<const char*>(instance_str))))
->NewStringFromOneByte(STATIC_CHAR_VECTOR("instance"))
.ToHandleChecked();
const uint8_t* module_str = reinterpret_cast<const uint8_t*>("module");
i::Handle<i::String> module_name =
isolate_->factory()
->NewStringFromOneByte(i::Vector<const uint8_t>(
module_str,
i::StrLength(reinterpret_cast<const char*>(module_str))))
->NewStringFromOneByte(STATIC_CHAR_VECTOR("module"))
.ToHandleChecked();
i::JSObject::AddProperty(isolate_, result, instance_name, instance,
......
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