Commit 94ac7850 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Rename EmitVarInt to EmitVarUint

because that's what it actually does. In the next step, I will
introduce EmitVarInt again with the correct semantics, and use it in
EmitI32Const and other places where we don't do proper varint encoding
currently.

R=bradnelson@chromium.org, titzer@chromium.org

Review-Url: https://codereview.chromium.org/2694633003
Cr-Commit-Position: refs/heads/master@{#43198}
parent 0559fd70
......@@ -105,7 +105,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
foreign_init_function_->EmitGetLocal(static_cast<uint32_t>(pos));
ForeignVariable* fv = &foreign_variables_[pos];
uint32_t index = LookupOrInsertGlobal(fv->var, fv->type);
foreign_init_function_->EmitWithVarInt(kExprSetGlobal, index);
foreign_init_function_->EmitWithVarUint(kExprSetGlobal, index);
}
foreign_init_function_->Emit(kExprEnd);
}
......@@ -318,7 +318,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
auto elem = breakable_blocks_.at(i);
if (elem.first == target && elem.second == type) {
int block_distance = static_cast<int>(breakable_blocks_.size() - i - 1);
current_function_builder_->EmitWithVarInt(kExprBr, block_distance);
current_function_builder_->EmitWithVarUint(kExprBr, block_distance);
return;
}
}
......@@ -389,8 +389,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
current_function_builder_->EmitWithU8(kExprIf, kLocalVoid);
DCHECK(case_to_block.find(node->begin) != case_to_block.end());
current_function_builder_->Emit(kExprBr);
current_function_builder_->EmitVarInt(1 + if_depth +
case_to_block[node->begin]);
current_function_builder_->EmitVarUint(1 + if_depth +
case_to_block[node->begin]);
current_function_builder_->Emit(kExprEnd);
} else {
if (node->begin != 0) {
......@@ -401,21 +401,21 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
VisitVariableProxy(tag);
}
current_function_builder_->Emit(kExprBrTable);
current_function_builder_->EmitVarInt(node->end - node->begin + 1);
current_function_builder_->EmitVarUint(node->end - node->begin + 1);
for (int v = node->begin; v <= node->end; ++v) {
if (case_to_block.find(v) != case_to_block.end()) {
uint32_t target = if_depth + case_to_block[v];
current_function_builder_->EmitVarInt(target);
current_function_builder_->EmitVarUint(target);
} else {
uint32_t target = if_depth + default_block;
current_function_builder_->EmitVarInt(target);
current_function_builder_->EmitVarUint(target);
}
if (v == kMaxInt) {
break;
}
}
uint32_t target = if_depth + default_block;
current_function_builder_->EmitVarInt(target);
current_function_builder_->EmitVarUint(target);
}
while (if_depth-- != prev_if_depth) {
......@@ -463,7 +463,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
if (root->left != nullptr || root->right != nullptr ||
root->begin == root->end) {
current_function_builder_->Emit(kExprBr);
current_function_builder_->EmitVarInt(default_block);
current_function_builder_->EmitVarUint(default_block);
}
}
for (int i = 0; i < case_count; ++i) {
......@@ -657,7 +657,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
ValueType var_type = TypeOf(expr);
DCHECK_NE(kWasmStmt, var_type);
if (var->IsContextSlot()) {
current_function_builder_->EmitWithVarInt(
current_function_builder_->EmitWithVarUint(
kExprGetGlobal, LookupOrInsertGlobal(var, var_type));
} else {
current_function_builder_->EmitGetLocal(
......@@ -961,9 +961,9 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
DCHECK_NE(kWasmStmt, var_type);
if (var->IsContextSlot()) {
uint32_t index = LookupOrInsertGlobal(var, var_type);
current_function_builder_->EmitWithVarInt(kExprSetGlobal, index);
current_function_builder_->EmitWithVarUint(kExprSetGlobal, index);
if (fate == kLeaveOnStack) {
current_function_builder_->EmitWithVarInt(kExprGetGlobal, index);
current_function_builder_->EmitWithVarUint(kExprGetGlobal, index);
}
} else {
if (fate == kDrop) {
......@@ -1473,7 +1473,7 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
int parent_pos = returns_value ? parent_binop->position() : pos;
current_function_builder_->AddAsmWasmOffset(pos, parent_pos);
current_function_builder_->Emit(kExprCallFunction);
current_function_builder_->EmitVarInt(index);
current_function_builder_->EmitVarUint(index);
} else {
WasmFunctionBuilder* function = LookupOrInsertFunction(vp->var());
VisitCallArgs(expr);
......@@ -1507,8 +1507,8 @@ class AsmWasmBuilderImpl final : public AstVisitor<AsmWasmBuilderImpl> {
current_function_builder_->AddAsmWasmOffset(expr->position(),
expr->position());
current_function_builder_->Emit(kExprCallIndirect);
current_function_builder_->EmitVarInt(indices->signature_index);
current_function_builder_->EmitVarInt(0); // table index
current_function_builder_->EmitVarUint(indices->signature_index);
current_function_builder_->EmitVarUint(0); // table index
returns_value =
builder_->GetSignature(indices->signature_index)->return_count() >
0;
......
......@@ -62,7 +62,7 @@ WasmFunctionBuilder::WasmFunctionBuilder(WasmModuleBuilder* builder)
direct_calls_(builder->zone()),
asm_offsets_(builder->zone(), 8) {}
void WasmFunctionBuilder::EmitVarInt(uint32_t val) {
void WasmFunctionBuilder::EmitVarUint(uint32_t val) {
byte buffer[8];
byte* ptr = buffer;
LEBHelper::write_u32v(&ptr, val);
......@@ -83,15 +83,15 @@ uint32_t WasmFunctionBuilder::AddLocal(ValueType type) {
}
void WasmFunctionBuilder::EmitGetLocal(uint32_t local_index) {
EmitWithVarInt(kExprGetLocal, local_index);
EmitWithVarUint(kExprGetLocal, local_index);
}
void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) {
EmitWithVarInt(kExprSetLocal, local_index);
EmitWithVarUint(kExprSetLocal, local_index);
}
void WasmFunctionBuilder::EmitTeeLocal(uint32_t local_index) {
EmitWithVarInt(kExprTeeLocal, local_index);
EmitWithVarUint(kExprTeeLocal, local_index);
}
void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) {
......@@ -116,10 +116,10 @@ void WasmFunctionBuilder::EmitWithU8U8(WasmOpcode opcode, const byte imm1,
body_.push_back(imm2);
}
void WasmFunctionBuilder::EmitWithVarInt(WasmOpcode opcode,
uint32_t immediate) {
void WasmFunctionBuilder::EmitWithVarUint(WasmOpcode opcode,
uint32_t immediate) {
body_.push_back(static_cast<byte>(opcode));
EmitVarInt(immediate);
EmitVarUint(immediate);
}
void WasmFunctionBuilder::EmitI32Const(int32_t value) {
......
......@@ -121,7 +121,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
// Building methods.
void SetSignature(FunctionSig* sig);
uint32_t AddLocal(ValueType type);
void EmitVarInt(uint32_t val);
void EmitVarUint(uint32_t val);
void EmitCode(const byte* code, uint32_t code_size);
void Emit(WasmOpcode opcode);
void EmitGetLocal(uint32_t index);
......@@ -130,7 +130,7 @@ class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
void EmitI32Const(int32_t val);
void EmitWithU8(WasmOpcode opcode, const byte immediate);
void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2);
void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate);
void EmitWithVarUint(WasmOpcode opcode, uint32_t immediate);
void EmitDirectCallIndex(uint32_t index);
void ExportAs(Vector<const char> name);
void SetName(Vector<const char> name);
......
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