Commit d41fd6c5 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm] Rename ValueType::type_name() -> name()

Drive-by: Improve comment, use << operator where possible
Change-Id: I5d2bff57a3f19a0fbb746136a897bf50e1173775
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2308337Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68966}
parent 7cfd1a88
......@@ -1702,7 +1702,7 @@ void WasmArray::WasmArrayPrint(std::ostream& os) { // NOLINT
PrintHeader(os, "WasmArray");
wasm::ArrayType* array_type = type();
uint32_t len = length();
os << "\n - type: " << array_type->element_type().type_name();
os << "\n - type: " << array_type->element_type().name();
os << "\n - length: " << len;
Address data_ptr = ptr() + WasmArray::kHeaderSize - kHeapObjectTag;
switch (array_type->element_type().kind()) {
......
......@@ -1074,7 +1074,7 @@ void LiftoffAssembler::set_num_locals(uint32_t num_locals) {
}
std::ostream& operator<<(std::ostream& os, VarState slot) {
os << slot.type().type_name() << ":";
os << slot.type().name() << ":";
switch (slot.loc()) {
case VarState::kStack:
return os << "s";
......
......@@ -425,7 +425,7 @@ class LiftoffCompiler {
}
LiftoffBailoutReason bailout_reason = BailoutReasonForType(type);
EmbeddedVector<char, 128> buffer;
SNPrintF(buffer, "%s %s", type.type_name().c_str(), context);
SNPrintF(buffer, "%s %s", type.name().c_str(), context);
unsupported(decoder, bailout_reason, buffer.begin());
return false;
}
......
......@@ -212,7 +212,7 @@ ValueType read_value_type(Decoder* decoder, const byte* pc,
if (!VALIDATE(enabled.contains(feature_for_heap_type(heap_type)))) {
decoder->errorf(
pc, "invalid value type '%s', enable with --experimental-wasm-%s",
result.type_name().c_str(),
result.name().c_str(),
WasmFeatures::name_for_feature(feature_for_heap_type(heap_type)));
return kWasmBottom;
}
......@@ -1399,7 +1399,7 @@ class WasmDecoder : public Decoder {
if (!VALIDATE(IsSubtypeOf(elem_type, module_->tables[imm.table.index].type,
module_))) {
errorf(pc, "table %u is not a super-type of %s", imm.table.index,
elem_type.type_name().c_str());
elem_type.name().c_str());
return false;
}
return true;
......@@ -1420,7 +1420,7 @@ class WasmDecoder : public Decoder {
if (!VALIDATE(IsSubtypeOf(
src_type, module_->tables[imm.table_dst.index].type, module_))) {
errorf(pc, "table %u is not a super-type of %s", imm.table_dst.index,
src_type.type_name().c_str());
src_type.name().c_str());
return false;
}
return true;
......@@ -1938,7 +1938,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(
this->pc(),
"Cannot define function-level local of non-defaultable type %s",
this->local_type(index).type_name().c_str());
this->local_type(index).name().c_str());
}
}
this->consume_bytes(locals_length);
......@@ -2612,7 +2612,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(this->pc_,
"invalid argument type to ref.is_null. Expected "
"reference type, got %s",
value.type.type_name().c_str());
value.type.name().c_str());
return 0;
}
UNREACHABLE();
......@@ -2648,7 +2648,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(this->pc_,
"invalid agrument type to ref.as_non_null: Expected "
"reference type, got %s",
value.type.type_name().c_str());
value.type.name().c_str());
}
return 0;
}
......@@ -3177,8 +3177,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(pos,
"inconsistent type in br_table target %u (previous "
"was %s, this one is %s)",
index, type.type_name().c_str(),
(*merge)[i].type.type_name().c_str());
index, type.name().c_str(),
(*merge)[i].type.name().c_str());
return false;
}
} else {
......@@ -3187,8 +3187,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(pos,
"inconsistent type in br_table target %u (previous "
"was %s, this one is %s)",
index, (*result_types)[i].type_name().c_str(),
(*merge)[i].type.type_name().c_str());
index, (*result_types)[i].name().c_str(),
(*merge)[i].type.name().c_str());
return false;
}
}
......@@ -3216,8 +3216,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (!VALIDATE(IsSubtypeOf(val.type, result_types[i], this->module_))) {
this->errorf(this->pc_,
"type error in merge[%u] (expected %s, got %s)", i,
result_types[i].type_name().c_str(),
val.type.type_name().c_str());
result_types[i].name().c_str(), val.type.name().c_str());
return false;
}
}
......@@ -3377,7 +3376,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(
this->pc_ + 2,
"struct.new_with_rtt expected type rtt, found %s of type %s",
SafeOpcodeNameAt(rtt.pc), rtt.type.type_name().c_str());
SafeOpcodeNameAt(rtt.pc), rtt.type.name().c_str());
return 0;
}
// TODO(7748): Drop this check if {imm} is dropped from the proposal
......@@ -3454,7 +3453,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
this->errorf(
this->pc_ + 2,
"array.new_with_rtt expected type rtt, found %s of type %s",
SafeOpcodeNameAt(rtt.pc), rtt.type.type_name().c_str());
SafeOpcodeNameAt(rtt.pc), rtt.type.name().c_str());
return 0;
}
// TODO(7748): Drop this check if {imm} is dropped from the proposal
......@@ -3598,9 +3597,9 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Value rtt = Pop(1);
if (!VALIDATE(rtt.type.kind() == ValueType::kRtt &&
rtt.type.heap_type() == rtt_type.type)) {
this->errorf(
this->pc_, "ref.test: expected rtt for type %s but got %s",
rtt_type.type.name().c_str(), rtt.type.type_name().c_str());
this->errorf(this->pc_,
"ref.test: expected rtt for type %s but got %s",
rtt_type.type.name().c_str(), rtt.type.name().c_str());
return 0;
}
Value obj = Pop(0, ValueType::Ref(obj_type.type, kNullable));
......@@ -3627,9 +3626,9 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Value rtt = Pop(1);
if (!VALIDATE(rtt.type.kind() == ValueType::kRtt &&
rtt.type.heap_type() == rtt_type.type)) {
this->errorf(
this->pc_, "ref.cast: expected rtt for type %s but got %s",
rtt_type.type.name().c_str(), rtt.type.type_name().c_str());
this->errorf(this->pc_,
"ref.cast: expected rtt for type %s but got %s",
rtt_type.type.name().c_str(), rtt.type.name().c_str());
return 0;
}
Value obj = Pop(0, ValueType::Ref(obj_type.type, kNullable));
......@@ -3839,9 +3838,8 @@ class WasmFullDecoder : public WasmDecoder<validate> {
if (!VALIDATE(IsSubtypeOf(val.type, expected, this->module_) ||
val.type == kWasmBottom || expected == kWasmBottom)) {
this->errorf(val.pc, "%s[%d] expected type %s, found %s of type %s",
SafeOpcodeNameAt(this->pc_), index,
expected.type_name().c_str(), SafeOpcodeNameAt(val.pc),
val.type.type_name().c_str());
SafeOpcodeNameAt(this->pc_), index, expected.name().c_str(),
SafeOpcodeNameAt(val.pc), val.type.name().c_str());
}
return val;
}
......@@ -3905,8 +3903,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Value& old = (*merge)[i];
if (!VALIDATE(IsSubtypeOf(val.type, old.type, this->module_))) {
this->errorf(this->pc_, "type error in merge[%u] (expected %s, got %s)",
i, old.type.type_name().c_str(),
val.type.type_name().c_str());
i, old.type.name().c_str(), val.type.name().c_str());
return false;
}
}
......@@ -3923,8 +3920,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Value& end = c->end_merge[i];
if (!VALIDATE(IsSubtypeOf(start.type, end.type, this->module_))) {
this->errorf(this->pc_, "type error in merge[%u] (expected %s, got %s)",
i, end.type.type_name().c_str(),
start.type.type_name().c_str());
i, end.type.name().c_str(), start.type.name().c_str());
return false;
}
}
......@@ -4027,9 +4023,9 @@ class WasmFullDecoder : public WasmDecoder<validate> {
Value& val = stack_values[i];
ValueType expected_type = this->sig_->GetReturn(i);
if (!VALIDATE(IsSubtypeOf(val.type, expected_type, this->module_))) {
this->errorf(
this->pc_, "type error in return[%u] (expected %s, got %s)", i,
expected_type.type_name().c_str(), val.type.type_name().c_str());
this->errorf(this->pc_,
"type error in return[%u] (expected %s, got %s)", i,
expected_type.name().c_str(), val.type.name().c_str());
return false;
}
}
......
......@@ -149,12 +149,12 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
if (decls.type_list[pos] == type) {
++count;
} else {
os << " " << count << " " << type.type_name();
os << " " << count << " " << type.name();
type = decls.type_list[pos];
count = 1;
}
}
os << " " << count << " " << type.type_name();
os << " " << count << " " << type.name();
}
os << std::endl;
if (line_numbers) line_numbers->push_back(kNoByteCode);
......@@ -248,7 +248,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
os << " @" << i.pc_offset();
if (decoder.Complete(imm)) {
for (uint32_t i = 0; i < imm.out_arity(); i++) {
os << " " << imm.out_type(i).type_name();
os << " " << imm.out_type(i).name();
}
}
control_depth++;
......
......@@ -941,7 +941,7 @@ class ModuleDecoderImpl : public Decoder {
this->module_.get())) {
errorf(pos,
"Invalid element segment. Table %u is not a super-type of %s",
table_index, type.type_name().c_str());
table_index, type.name().c_str());
break;
}
}
......@@ -1419,8 +1419,8 @@ class ModuleDecoderImpl : public Decoder {
errorf(pos,
"type mismatch in global initialization "
"(from global #%u), expected %s, got %s",
other_index, global->type.type_name().c_str(),
module->globals[other_index].type.type_name().c_str());
other_index, global->type.name().c_str(),
module->globals[other_index].type.name().c_str());
}
}
}
......@@ -1799,8 +1799,7 @@ class ModuleDecoderImpl : public Decoder {
if (expected != kWasmStmt &&
!IsSubtypeOf(TypeOf(module, expr), expected, module)) {
errorf(pc(), "type error in init expression, expected %s, got %s",
expected.type_name().c_str(),
TypeOf(module, expr).type_name().c_str());
expected.name().c_str(), TypeOf(module, expr).name().c_str());
}
return expr;
}
......
......@@ -820,7 +820,7 @@ void InstanceBuilder::LoadDataSegments(Handle<WasmInstanceObject> instance) {
void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) {
TRACE("init [globals_start=%p + %u] = %lf, type = %s\n",
raw_buffer_ptr(untagged_globals_, 0), global.offset, num,
global.type.type_name().c_str());
global.type.name().c_str());
switch (global.type.kind()) {
case ValueType::kI32:
WriteLittleEndianValue<int32_t>(GetRawGlobalPtr<int32_t>(global),
......@@ -846,7 +846,7 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, double num) {
void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global, int64_t num) {
TRACE("init [globals_start=%p + %u] = %" PRId64 ", type = %s\n",
raw_buffer_ptr(untagged_globals_, 0), global.offset, num,
global.type.type_name().c_str());
global.type.name().c_str());
DCHECK_EQ(kWasmI64, global.type);
WriteLittleEndianValue<int64_t>(GetRawGlobalPtr<int64_t>(global), num);
}
......@@ -893,8 +893,7 @@ void InstanceBuilder::WriteGlobalValue(const WasmGlobal& global,
case ValueType::kI16:
UNREACHABLE();
}
TRACE(", type = %s (from WebAssembly.Global)\n",
global.type.type_name().c_str());
TRACE(", type = %s (from WebAssembly.Global)\n", global.type.name().c_str());
}
void InstanceBuilder::WriteGlobalExternRef(const WasmGlobal& global,
......
......@@ -148,6 +148,7 @@ class HeapType {
return !is_bottom() && representation_ <= kLastSentinel;
}
};
enum Nullability : bool { kNonNullable, kNullable };
class ValueType {
......@@ -360,7 +361,7 @@ class ValueType {
return kShortName[kind()];
}
std::string type_name() const {
std::string name() const {
std::ostringstream buf;
switch (kind()) {
case kRef:
......@@ -373,8 +374,7 @@ class ValueType {
case kOptRef:
if (heap_type().is_generic() &&
heap_representation() != HeapType::kI31) {
// We prefer the shorthand to be backwards-compatible with previous
// proposals.
// We use shorthands to be compatible with the 'reftypes' proposal.
buf << heap_type().name() << "ref";
} else {
buf << "(ref null " << heap_type().name() << ")";
......@@ -382,7 +382,7 @@ class ValueType {
break;
case kRtt:
buf << "(rtt " << static_cast<uint32_t>(depth()) << " "
<< heap_type().name() + ")";
<< heap_type().name() << ")";
break;
default:
buf << kind_name();
......@@ -420,7 +420,7 @@ inline size_t hash_value(ValueType type) {
// Output operator, useful for DCHECKS and others.
inline std::ostream& operator<<(std::ostream& oss, ValueType type) {
return oss << type.type_name();
return oss << type.name();
}
constexpr ValueType kWasmI32 = ValueType::Primitive(ValueType::kI32);
......
......@@ -34,15 +34,15 @@ static bool CheckSignature(ValueType return_type,
const FunctionSig* sig, ErrorThrower* thrower) {
if (sig->return_count() != 1 && return_type != kWasmBottom) {
thrower->CompileError("Invalid return type. Got none, expected %s",
return_type.type_name().c_str());
return_type.name().c_str());
return false;
}
if (sig->return_count() == 1) {
if (sig->GetReturn(0) != return_type) {
thrower->CompileError("Invalid return type. Got %s, expected %s",
sig->GetReturn(0).type_name().c_str(),
return_type.type_name().c_str());
sig->GetReturn(0).name().c_str(),
return_type.name().c_str());
return false;
}
}
......@@ -57,8 +57,7 @@ static bool CheckSignature(ValueType return_type,
if (sig->GetParam(p) != argument_type) {
thrower->CompileError(
"Invalid argument type for argument %zu. Got %s, expected %s", p,
sig->GetParam(p).type_name().c_str(),
argument_type.type_name().c_str());
sig->GetParam(p).name().c_str(), argument_type.name().c_str());
return false;
}
++p;
......
......@@ -221,7 +221,7 @@ void DebugSideTable::Print(std::ostream& os) const {
void DebugSideTable::Entry::Print(std::ostream& os) const {
os << std::setw(6) << std::hex << pc_offset_ << std::dec << " [";
for (auto& value : values_) {
os << " " << value.type.type_name() << ":";
os << " " << value.type.name() << ":";
switch (value.kind) {
case kConstant:
os << "const#" << value.i32_const;
......
......@@ -267,8 +267,7 @@ namespace {
// reflective functions. Should be kept in sync with the {GetValueType} helper.
Handle<String> ToValueTypeString(Isolate* isolate, ValueType type) {
return isolate->factory()->InternalizeUtf8String(
type == kWasmFuncRef ? CStrVector("anyfunc")
: VectorOf(type.type_name()));
type == kWasmFuncRef ? CStrVector("anyfunc") : VectorOf(type.name()));
}
} // namespace
......
......@@ -205,7 +205,7 @@ std::ostream& operator<<(std::ostream& out, const DebugSideTableEntry& entry) {
out << "{";
const char* comma = "";
for (auto& v : entry.values) {
out << comma << v.type.type_name() << " ";
out << comma << v.type.name() << " ";
switch (v.kind) {
case DebugSideTable::Entry::kConstant:
out << "const:" << v.i32_const;
......
......@@ -237,7 +237,7 @@ void GenerateTestCase(Isolate* isolate, ModuleWireBytes wire_bytes,
ValueType type = decls.type_list[pos];
while (pos + count < locals && decls.type_list[pos + count] == type)
++count;
os << ".addLocals({" << type.type_name() << "_count: " << count << "})";
os << ".addLocals({" << type.name() << "_count: " << count << "})";
}
os << "\n";
}
......
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