Add ToBoolean-conversion of constants in Crankshaft and use it when generating a branch based on a constant.
Review URL: http://codereview.chromium.org/6801050 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7552 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
15b2573bd9
commit
3dbbb3d771
@ -1114,9 +1114,9 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) {
|
||||
return new LIsConstructCallAndBranch(TempRegister());
|
||||
} else {
|
||||
if (v->IsConstant()) {
|
||||
if (HConstant::cast(v)->handle()->IsTrue()) {
|
||||
if (HConstant::cast(v)->ToBoolean()) {
|
||||
return new LGoto(instr->FirstSuccessor()->block_id());
|
||||
} else if (HConstant::cast(v)->handle()->IsFalse()) {
|
||||
} else {
|
||||
return new LGoto(instr->SecondSuccessor()->block_id());
|
||||
}
|
||||
}
|
||||
|
@ -1050,6 +1050,23 @@ HConstant* HConstant::CopyToTruncatedInt32() const {
|
||||
}
|
||||
|
||||
|
||||
bool HConstant::ToBoolean() const {
|
||||
// Converts the constant's boolean value according to
|
||||
// ECMAScript section 9.2 ToBoolean conversion.
|
||||
if (HasInteger32Value()) return Integer32Value() != 0;
|
||||
if (HasDoubleValue()) {
|
||||
double v = DoubleValue();
|
||||
return v != 0 && !isnan(v);
|
||||
}
|
||||
if (handle()->IsTrue()) return true;
|
||||
if (handle()->IsFalse()) return false;
|
||||
if (handle()->IsUndefined()) return false;
|
||||
if (handle()->IsNull()) return false;
|
||||
if (handle()->IsString() &&
|
||||
String::cast(*handle())->length() == 0) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void HConstant::PrintDataTo(StringStream* stream) {
|
||||
handle()->ShortPrint(stream);
|
||||
}
|
||||
|
@ -1961,6 +1961,8 @@ class HConstant: public HTemplateInstruction<0> {
|
||||
}
|
||||
bool HasStringValue() const { return handle_->IsString(); }
|
||||
|
||||
bool ToBoolean() const;
|
||||
|
||||
virtual intptr_t Hashcode() {
|
||||
ASSERT(!HEAP->allow_allocation(false));
|
||||
return reinterpret_cast<intptr_t>(*handle());
|
||||
|
@ -1120,9 +1120,9 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) {
|
||||
return new LIsConstructCallAndBranch(TempRegister());
|
||||
} else {
|
||||
if (v->IsConstant()) {
|
||||
if (HConstant::cast(v)->handle()->IsTrue()) {
|
||||
if (HConstant::cast(v)->ToBoolean()) {
|
||||
return new LGoto(instr->FirstSuccessor()->block_id());
|
||||
} else if (HConstant::cast(v)->handle()->IsFalse()) {
|
||||
} else {
|
||||
return new LGoto(instr->SecondSuccessor()->block_id());
|
||||
}
|
||||
}
|
||||
|
@ -1114,9 +1114,9 @@ LInstruction* LChunkBuilder::DoTest(HTest* instr) {
|
||||
return new LIsConstructCallAndBranch(TempRegister());
|
||||
} else {
|
||||
if (v->IsConstant()) {
|
||||
if (HConstant::cast(v)->handle()->IsTrue()) {
|
||||
if (HConstant::cast(v)->ToBoolean()) {
|
||||
return new LGoto(instr->FirstSuccessor()->block_id());
|
||||
} else if (HConstant::cast(v)->handle()->IsFalse()) {
|
||||
} else {
|
||||
return new LGoto(instr->SecondSuccessor()->block_id());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user