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