Commit cd646f88 authored by aseemgarg's avatar aseemgarg Committed by Commit bot

refactor BlockVisitor in asm to wasm and fix tests

TEST=asm-wasm.js
R=titzer@chromium.org,bradnelson@google.com
BUG=

Review URL: https://codereview.chromium.org/1584573002

Cr-Commit-Position: refs/heads/master@{#33253}
parent 8cf79873
...@@ -92,8 +92,8 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -92,8 +92,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
} }
} }
DCHECK(in_function_); DCHECK(in_function_);
BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false); BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false,
block_size_ = static_cast<byte>(stmt->statements()->length()); static_cast<byte>(stmt->statements()->length()));
RECURSE(VisitStatements(stmt->statements())); RECURSE(VisitStatements(stmt->statements()));
DCHECK(block_size_ >= 0); DCHECK(block_size_ >= 0);
} }
...@@ -106,12 +106,13 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -106,12 +106,13 @@ class AsmWasmBuilderImpl : public AstVisitor {
public: public:
BlockVisitor(AsmWasmBuilderImpl* builder, BreakableStatement* stmt, BlockVisitor(AsmWasmBuilderImpl* builder, BreakableStatement* stmt,
WasmOpcode opcode, bool is_loop) WasmOpcode opcode, bool is_loop, int initial_block_size)
: builder_(builder) { : builder_(builder) {
builder_->breakable_blocks_.push_back(std::make_pair(stmt, is_loop)); builder_->breakable_blocks_.push_back(std::make_pair(stmt, is_loop));
builder_->current_function_builder_->Emit(opcode); builder_->current_function_builder_->Emit(opcode);
index_ = builder_->current_function_builder_->EmitEditableImmediate(0); index_ = builder_->current_function_builder_->EmitEditableImmediate(0);
prev_block_size_ = builder_->block_size_; prev_block_size_ = builder_->block_size_;
builder_->block_size_ = initial_block_size;
} }
~BlockVisitor() { ~BlockVisitor() {
builder_->current_function_builder_->EditImmediate(index_, builder_->current_function_builder_->EditImmediate(index_,
...@@ -225,8 +226,7 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -225,8 +226,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
VisitLiteral(label); VisitLiteral(label);
current_function_builder_->Emit(kExprGetLocal); current_function_builder_->Emit(kExprGetLocal);
AddLeb128(fall_through, true); AddLeb128(fall_through, true);
BlockVisitor visitor(this, nullptr, kExprBlock, false); BlockVisitor visitor(this, nullptr, kExprBlock, false, 0);
block_size_ = 0;
SetLocalTo(fall_through, 1); SetLocalTo(fall_through, 1);
ZoneList<Statement*>* stmts = clause->statements(); ZoneList<Statement*>* stmts = clause->statements();
block_size_ += stmts->length(); block_size_ += stmts->length();
...@@ -236,8 +236,8 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -236,8 +236,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitSwitchStatement(SwitchStatement* stmt) { void VisitSwitchStatement(SwitchStatement* stmt) {
VariableProxy* tag = stmt->tag()->AsVariableProxy(); VariableProxy* tag = stmt->tag()->AsVariableProxy();
DCHECK(tag != NULL); DCHECK(tag != NULL);
BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false); BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprBlock, false,
block_size_ = 0; 0);
uint16_t fall_through = current_function_builder_->AddLocal(kAstI32); uint16_t fall_through = current_function_builder_->AddLocal(kAstI32);
SetLocalTo(fall_through, 0); SetLocalTo(fall_through, 0);
...@@ -258,8 +258,8 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -258,8 +258,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitDoWhileStatement(DoWhileStatement* stmt) { void VisitDoWhileStatement(DoWhileStatement* stmt) {
DCHECK(in_function_); DCHECK(in_function_);
BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true); BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true,
block_size_ = 2; 2);
RECURSE(Visit(stmt->body())); RECURSE(Visit(stmt->body()));
current_function_builder_->Emit(kExprIf); current_function_builder_->Emit(kExprIf);
RECURSE(Visit(stmt->cond())); RECURSE(Visit(stmt->cond()));
...@@ -269,8 +269,8 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -269,8 +269,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
void VisitWhileStatement(WhileStatement* stmt) { void VisitWhileStatement(WhileStatement* stmt) {
DCHECK(in_function_); DCHECK(in_function_);
BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true); BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true,
block_size_ = 1; 1);
current_function_builder_->Emit(kExprIf); current_function_builder_->Emit(kExprIf);
RECURSE(Visit(stmt->cond())); RECURSE(Visit(stmt->cond()));
current_function_builder_->EmitWithU8(kExprBr, 0); current_function_builder_->EmitWithU8(kExprBr, 0);
...@@ -283,8 +283,8 @@ class AsmWasmBuilderImpl : public AstVisitor { ...@@ -283,8 +283,8 @@ class AsmWasmBuilderImpl : public AstVisitor {
block_size_++; block_size_++;
RECURSE(Visit(stmt->init())); RECURSE(Visit(stmt->init()));
} }
BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true); BlockVisitor visitor(this, stmt->AsBreakableStatement(), kExprLoop, true,
block_size_ = 0; 0);
if (stmt->cond() != nullptr) { if (stmt->cond() != nullptr) {
block_size_++; block_size_++;
current_function_builder_->Emit(kExprIf); current_function_builder_->Emit(kExprIf);
......
...@@ -15,7 +15,7 @@ function EmptyTest() { ...@@ -15,7 +15,7 @@ function EmptyTest() {
return {caller: caller}; return {caller: caller};
} }
assertEquals(11, WASM.asmCompileRun(EmptyTest.toString())); assertEquals(11, _WASMEXP_.asmCompileRun(EmptyTest.toString()));
function IntTest() { function IntTest() {
"use asm"; "use asm";
...@@ -683,7 +683,7 @@ function TestConditional() { ...@@ -683,7 +683,7 @@ function TestConditional() {
return {caller:caller}; return {caller:caller};
} }
assertEquals(41, WASM.asmCompileRun(TestConditional.toString())); assertEquals(41, _WASMEXP_.asmCompileRun(TestConditional.toString()));
function TestSwitch() { function TestSwitch() {
"use asm" "use asm"
...@@ -710,7 +710,7 @@ function TestSwitch() { ...@@ -710,7 +710,7 @@ function TestSwitch() {
return {caller:caller}; return {caller:caller};
} }
assertEquals(23, WASM.asmCompileRun(TestSwitch.toString())); assertEquals(23, _WASMEXP_.asmCompileRun(TestSwitch.toString()));
function TestSwitchFallthrough() { function TestSwitchFallthrough() {
"use asm" "use asm"
...@@ -731,7 +731,7 @@ function TestSwitchFallthrough() { ...@@ -731,7 +731,7 @@ function TestSwitchFallthrough() {
return {caller:caller}; return {caller:caller};
} }
assertEquals(42, WASM.asmCompileRun(TestSwitchFallthrough.toString())); assertEquals(42, _WASMEXP_.asmCompileRun(TestSwitchFallthrough.toString()));
function TestNestedSwitch() { function TestNestedSwitch() {
"use asm" "use asm"
...@@ -756,4 +756,4 @@ function TestNestedSwitch() { ...@@ -756,4 +756,4 @@ function TestNestedSwitch() {
return {caller:caller}; return {caller:caller};
} }
assertEquals(43, WASM.asmCompileRun(TestNestedSwitch.toString())); assertEquals(43, _WASMEXP_.asmCompileRun(TestNestedSwitch.toString()));
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