[wasm] Rename index to sig_index in CallIndirectOperand
It took me a while to understand that the {index} is actually a signature index. This CL changes the name to {sig_index} to make this more clear. Drive-by: Fix a CHECK to check the canonical signature index instead of the original index. This ensures that there is a canonical signature index in the signature map. Drive-by^2: Un-templatize a method. R=titzer@chromium.org Change-Id: Ifdaec59806c4d5c976170807596503d2874f04e4 Reviewed-on: https://chromium-review.googlesource.com/871190 Reviewed-by: Ben Titzer <titzer@chromium.org> Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Cr-Commit-Position: refs/heads/master@{#50695}
This commit is contained in:
parent
0484e1f9ca
commit
478bfc91cd
@ -2543,7 +2543,7 @@ Node* WasmGraphBuilder::CallIndirect(uint32_t sig_index, Node** args,
|
||||
Int32Constant(fixed_offset)),
|
||||
*effect_, *control_);
|
||||
int32_t canonical_sig_num = env_->module->signature_ids[sig_index];
|
||||
CHECK_GE(sig_index, 0);
|
||||
CHECK_GE(canonical_sig_num, 0);
|
||||
Node* sig_match = graph()->NewNode(machine->WordEqual(), load_sig,
|
||||
jsgraph()->SmiConstant(canonical_sig_num));
|
||||
TrapIfFalse(wasm::kTrapFuncSigMismatch, sig_match, position);
|
||||
|
@ -246,12 +246,12 @@ struct BreakDepthOperand {
|
||||
template <Decoder::ValidateFlag validate>
|
||||
struct CallIndirectOperand {
|
||||
uint32_t table_index;
|
||||
uint32_t index;
|
||||
uint32_t sig_index;
|
||||
FunctionSig* sig = nullptr;
|
||||
unsigned length = 0;
|
||||
inline CallIndirectOperand(Decoder* decoder, const byte* pc) {
|
||||
unsigned len = 0;
|
||||
index = decoder->read_u32v<validate>(pc + 1, &len, "signature index");
|
||||
sig_index = decoder->read_u32v<validate>(pc + 1, &len, "signature index");
|
||||
if (!VALIDATE(decoder->ok())) return;
|
||||
table_index = decoder->read_u8<validate>(pc + 1 + len, "table index");
|
||||
if (!VALIDATE(table_index == 0)) {
|
||||
@ -789,10 +789,10 @@ class WasmDecoder : public Decoder {
|
||||
|
||||
inline bool Complete(const byte* pc, CallIndirectOperand<validate>& operand) {
|
||||
if (!VALIDATE(module_ != nullptr &&
|
||||
operand.index < module_->signatures.size())) {
|
||||
operand.sig_index < module_->signatures.size())) {
|
||||
return false;
|
||||
}
|
||||
operand.sig = module_->signatures[operand.index];
|
||||
operand.sig = module_->signatures[operand.sig_index];
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -802,7 +802,7 @@ class WasmDecoder : public Decoder {
|
||||
return false;
|
||||
}
|
||||
if (!Complete(pc, operand)) {
|
||||
errorf(pc + 1, "invalid signature index: #%u", operand.index);
|
||||
errorf(pc + 1, "invalid signature index: #%u", operand.sig_index);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -369,13 +369,13 @@ class WasmGraphBuildingInterface {
|
||||
void CallDirect(Decoder* decoder,
|
||||
const CallFunctionOperand<validate>& operand,
|
||||
const Value args[], Value returns[]) {
|
||||
DoCall(decoder, nullptr, operand, args, returns, false);
|
||||
DoCall(decoder, nullptr, operand.sig, operand.index, args, returns);
|
||||
}
|
||||
|
||||
void CallIndirect(Decoder* decoder, const Value& index,
|
||||
const CallIndirectOperand<validate>& operand,
|
||||
const Value args[], Value returns[]) {
|
||||
DoCall(decoder, index.node, operand, args, returns, true);
|
||||
DoCall(decoder, index.node, operand.sig, operand.sig_index, args, returns);
|
||||
}
|
||||
|
||||
void SimdOp(Decoder* decoder, WasmOpcode opcode, Vector<Value> args,
|
||||
@ -782,30 +782,29 @@ class WasmGraphBuildingInterface {
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename Operand>
|
||||
void DoCall(WasmFullDecoder<validate, WasmGraphBuildingInterface>* decoder,
|
||||
TFNode* index_node, const Operand& operand, const Value args[],
|
||||
Value returns[], bool is_indirect) {
|
||||
int param_count = static_cast<int>(operand.sig->parameter_count());
|
||||
TFNode* index_node, FunctionSig* sig, uint32_t index,
|
||||
const Value args[], Value returns[]) {
|
||||
int param_count = static_cast<int>(sig->parameter_count());
|
||||
TFNode** arg_nodes = builder_->Buffer(param_count + 1);
|
||||
TFNode** return_nodes = nullptr;
|
||||
arg_nodes[0] = index_node;
|
||||
for (int i = 0; i < param_count; ++i) {
|
||||
arg_nodes[i + 1] = args[i].node;
|
||||
}
|
||||
if (is_indirect) {
|
||||
builder_->CallIndirect(operand.index, arg_nodes, &return_nodes,
|
||||
if (index_node) {
|
||||
builder_->CallIndirect(index, arg_nodes, &return_nodes,
|
||||
decoder->position());
|
||||
} else {
|
||||
builder_->CallDirect(operand.index, arg_nodes, &return_nodes,
|
||||
builder_->CallDirect(index, arg_nodes, &return_nodes,
|
||||
decoder->position());
|
||||
}
|
||||
int return_count = static_cast<int>(operand.sig->return_count());
|
||||
int return_count = static_cast<int>(sig->return_count());
|
||||
for (int i = 0; i < return_count; ++i) {
|
||||
returns[i].node = return_nodes[i];
|
||||
}
|
||||
// The invoked function could have used grow_memory, so we need to
|
||||
// reload mem_size and mem_start
|
||||
// reload mem_size and mem_start.
|
||||
LoadContextIntoSsa(ssa_env_);
|
||||
}
|
||||
};
|
||||
@ -1002,7 +1001,7 @@ bool PrintRawWasmCode(AccountingAllocator* allocator, const FunctionBody& body,
|
||||
}
|
||||
case kExprCallIndirect: {
|
||||
CallIndirectOperand<Decoder::kNoValidate> operand(&i, i.pc());
|
||||
os << " // sig #" << operand.index;
|
||||
os << " // sig #" << operand.sig_index;
|
||||
if (decoder.Complete(i.pc(), operand)) {
|
||||
os << ": " << *operand.sig;
|
||||
}
|
||||
|
@ -1934,7 +1934,7 @@ class ThreadImpl {
|
||||
// Assume only one table for now.
|
||||
DCHECK_LE(module()->function_tables.size(), 1u);
|
||||
ExternalCallResult result =
|
||||
CallIndirectFunction(0, entry_index, operand.index);
|
||||
CallIndirectFunction(0, entry_index, operand.sig_index);
|
||||
switch (result.type) {
|
||||
case ExternalCallResult::INTERNAL:
|
||||
// The import is a function of this instance. Call it directly.
|
||||
|
@ -134,7 +134,7 @@ void PrintWasmText(const WasmModule* module, const ModuleWireBytes& wire_bytes,
|
||||
case kExprCallIndirect: {
|
||||
CallIndirectOperand<Decoder::kNoValidate> operand(&i, i.pc());
|
||||
DCHECK_EQ(0, operand.table_index);
|
||||
os << "call_indirect " << operand.index;
|
||||
os << "call_indirect " << operand.sig_index;
|
||||
break;
|
||||
}
|
||||
case kExprCallFunction: {
|
||||
|
Loading…
Reference in New Issue
Block a user