Fix a problem when compiling built-ins with the top-level compiler.

Replace runtime call to NumberAdd with call to binary op stub.

Until now the top-level compiler always called a runtime function
for count operations. 

In some places we expected in the JS builtins smis as arguments.
If we perform a count operation before all smis would get converted into
heap numbers by the runtime number add function and result in a runtime 
assert.

Also: Add missing debugger information in the top-level compiler for 
do-while loops.


Review URL: http://codereview.chromium.org/548029

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3610 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 10295069
...@@ -1424,14 +1424,12 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -1424,14 +1424,12 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
} }
} }
// Call runtime for +1/-1. // Call stub for +1/-1.
if (expr->op() == Token::INC) { __ mov(r1, Operand(expr->op() == Token::INC
__ mov(ip, Operand(Smi::FromInt(1))); ? Smi::FromInt(1)
} else { : Smi::FromInt(-1)));
__ mov(ip, Operand(Smi::FromInt(-1))); GenericBinaryOpStub stub(Token::ADD, NO_OVERWRITE);
} __ CallStub(&stub);
__ stm(db_w, sp, ip.bit() | r0.bit());
__ CallRuntime(Runtime::kNumberAdd, 2);
// Store the value returned in r0. // Store the value returned in r0.
switch (assign_type) { switch (assign_type) {
......
...@@ -1184,6 +1184,9 @@ class CountOperation: public Expression { ...@@ -1184,6 +1184,9 @@ class CountOperation: public Expression {
bool is_prefix() const { return is_prefix_; } bool is_prefix() const { return is_prefix_; }
bool is_postfix() const { return !is_prefix_; } bool is_postfix() const { return !is_prefix_; }
Token::Value op() const { return op_; } Token::Value op() const { return op_; }
Token::Value binary_op() {
return op_ == Token::INC ? Token::ADD : Token::SUB;
}
Expression* expression() const { return expression_; } Expression* expression() const { return expression_; }
virtual void MarkAsStatement() { is_prefix_ = true; } virtual void MarkAsStatement() { is_prefix_ = true; }
......
...@@ -183,6 +183,13 @@ void FastCodeGenerator::SetStatementPosition(Statement* stmt) { ...@@ -183,6 +183,13 @@ void FastCodeGenerator::SetStatementPosition(Statement* stmt) {
} }
void FastCodeGenerator::SetStatementPosition(int pos) {
if (FLAG_debug_info) {
CodeGenerator::RecordPositions(masm_, pos);
}
}
void FastCodeGenerator::SetSourcePosition(int pos) { void FastCodeGenerator::SetSourcePosition(int pos) {
if (FLAG_debug_info && pos != RelocInfo::kNoPosition) { if (FLAG_debug_info && pos != RelocInfo::kNoPosition) {
masm_->RecordPosition(pos); masm_->RecordPosition(pos);
...@@ -360,8 +367,6 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) { ...@@ -360,8 +367,6 @@ void FastCodeGenerator::VisitReturnStatement(ReturnStatement* stmt) {
} }
void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) { void FastCodeGenerator::VisitWithEnterStatement(WithEnterStatement* stmt) {
Comment cmnt(masm_, "[ WithEnterStatement"); Comment cmnt(masm_, "[ WithEnterStatement");
SetStatementPosition(stmt); SetStatementPosition(stmt);
...@@ -412,6 +417,7 @@ void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) { ...@@ -412,6 +417,7 @@ void FastCodeGenerator::VisitDoWhileStatement(DoWhileStatement* stmt) {
__ bind(&stack_check_success); __ bind(&stack_check_success);
__ bind(loop_statement.continue_target()); __ bind(loop_statement.continue_target());
SetStatementPosition(stmt->condition_position());
VisitForControl(stmt->cond(), &body, loop_statement.break_target()); VisitForControl(stmt->cond(), &body, loop_statement.break_target());
__ bind(&stack_limit_hit); __ bind(&stack_limit_hit);
......
...@@ -296,6 +296,7 @@ class FastCodeGenerator: public AstVisitor { ...@@ -296,6 +296,7 @@ class FastCodeGenerator: public AstVisitor {
void SetFunctionPosition(FunctionLiteral* fun); void SetFunctionPosition(FunctionLiteral* fun);
void SetReturnPosition(FunctionLiteral* fun); void SetReturnPosition(FunctionLiteral* fun);
void SetStatementPosition(Statement* stmt); void SetStatementPosition(Statement* stmt);
void SetStatementPosition(int pos);
void SetSourcePosition(int pos); void SetSourcePosition(int pos);
// Non-local control flow support. // Non-local control flow support.
......
...@@ -1393,14 +1393,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -1393,14 +1393,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
} }
} }
// Call runtime for +1/-1. // Call stub for +1/-1.
__ push(eax); __ push(eax);
__ push(Immediate(Smi::FromInt(1))); __ push(Immediate(Smi::FromInt(1)));
if (expr->op() == Token::INC) { GenericBinaryOpStub stub(expr->binary_op(),
__ CallRuntime(Runtime::kNumberAdd, 2); NO_OVERWRITE,
} else { NO_GENERIC_BINARY_FLAGS);
__ CallRuntime(Runtime::kNumberSub, 2); __ CallStub(&stub);
}
// Store the value returned in eax. // Store the value returned in eax.
switch (assign_type) { switch (assign_type) {
......
...@@ -1412,14 +1412,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) { ...@@ -1412,14 +1412,13 @@ void FastCodeGenerator::VisitCountOperation(CountOperation* expr) {
} }
} }
// Call runtime for +1/-1. // Call stub for +1/-1.
__ push(rax); __ push(rax);
__ Push(Smi::FromInt(1)); __ Push(Smi::FromInt(1));
if (expr->op() == Token::INC) { GenericBinaryOpStub stub(expr->binary_op(),
__ CallRuntime(Runtime::kNumberAdd, 2); NO_OVERWRITE,
} else { NO_GENERIC_BINARY_FLAGS);
__ CallRuntime(Runtime::kNumberSub, 2); __ CallStub(&stub);
}
// Store the value returned in rax. // Store the value returned in rax.
switch (assign_type) { switch (assign_type) {
......
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