Index: src/code-stubs.cc |
diff --git a/src/code-stubs.cc b/src/code-stubs.cc |
index 2ed2ba3c66413e68fc7f4b30f528f502fb5ee3fb..fdc6a15426b623298650af95faf700437b875c16 100644 |
--- a/src/code-stubs.cc |
+++ b/src/code-stubs.cc |
@@ -184,9 +184,79 @@ const char* CodeStub::MajorName(CodeStub::Major major_key, |
} |
} |
+void CodeStub::PrintBaseName(StringStream* stream) { |
+ stream->Add("%s", MajorName(MajorKey(), false)); |
+} |
+ |
void CodeStub::PrintName(StringStream* stream) { |
- stream->Add("%s", MajorName(MajorKey(), false)); |
+ PrintBaseName(stream); |
+ PrintState(stream); |
+} |
+ |
+ |
+Builtins::JavaScript UnaryOpStub::ToJSBuiltin() { |
+ switch (operation_) { |
+ default: |
+ UNREACHABLE(); |
+ case Token::SUB: |
+ return Builtins::UNARY_MINUS; |
+ case Token::BIT_NOT: |
+ return Builtins::BIT_NOT; |
+ } |
+} |
+ |
+ |
+Handle<JSFunction> UnaryOpStub::ToJSFunction(Isolate* isolate) { |
+ Handle<JSBuiltinsObject> builtins(isolate->js_builtins_object()); |
+ Object* builtin = builtins->javascript_builtin(ToJSBuiltin()); |
+ return Handle<JSFunction>(JSFunction::cast(builtin), isolate); |
+} |
+ |
+ |
+MaybeObject* UnaryOpStub::Result(Handle<Object> object, Isolate* isolate) { |
+ Handle<JSFunction> builtin_function = ToJSFunction(isolate); |
+ bool caught_exception; |
+ Handle<Object> result = Execution::Call(builtin_function, object, |
+ 0, NULL, &caught_exception); |
+ if (caught_exception) { |
+ return Failure::Exception(); |
+ } |
+ return *result; |
+} |
+ |
+ |
+void UnaryOpStub::UpdateStatus(Handle<Object> object) { |
+ State old_state(state_); |
+ if (object->IsSmi()) { |
+ state_.Add(SMI); |
+ if (operation_ == Token::SUB && *object == 0) { |
+ // The result (-0) has to be represented as double. |
+ state_.Add(HEAP_NUMBER); |
+ } |
+ } else if (object->IsHeapNumber()) { |
+ state_.Add(HEAP_NUMBER); |
+ } else { |
+ state_.Add(GENERIC); |
+ } |
+ TraceTransition(old_state, state_); |
+} |
+ |
+ |
+Handle<Type> UnaryOpStub::GetType(Isolate* isolate) { |
+ if (state_.Contains(GENERIC)) { |
+ return handle(Type::Any(), isolate); |
+ } |
+ Handle<Type> type = handle(Type::None(), isolate); |
+ if (state_.Contains(SMI)) { |
+ type = handle( |
+ Type::Union(type, handle(Type::Smi(), isolate)), isolate); |
+ } |
+ if (state_.Contains(HEAP_NUMBER)) { |
+ type = handle( |
+ Type::Union(type, handle(Type::Double(), isolate)), isolate); |
+ } |
+ return type; |
} |
@@ -275,6 +345,29 @@ void BinaryOpStub::GenerateCallRuntime(MacroAssembler* masm) { |
#undef __ |
+void UnaryOpStub::PrintBaseName(StringStream* stream) { |
+ CodeStub::PrintBaseName(stream); |
+ if (operation_ == Token::SUB) stream->Add("Minus"); |
+ if (operation_ == Token::BIT_NOT) stream->Add("Not"); |
+} |
+ |
+ |
+void UnaryOpStub::PrintState(StringStream* stream) { |
+ state_.Print(stream); |
+} |
+ |
+ |
+void UnaryOpStub::State::Print(StringStream* stream) const { |
+ stream->Add("("); |
+ SimpleListPrinter printer(stream); |
+ if (IsEmpty()) printer.Add("None"); |
+ if (Contains(GENERIC)) printer.Add("Generic"); |
+ if (Contains(HEAP_NUMBER)) printer.Add("HeapNumber"); |
+ if (Contains(SMI)) printer.Add("Smi"); |
+ stream->Add(")"); |
+} |
+ |
+ |
void BinaryOpStub::PrintName(StringStream* stream) { |
const char* op_name = Token::Name(op_); |
const char* overwrite_name; |
@@ -431,8 +524,9 @@ void ICCompareStub::Generate(MacroAssembler* masm) { |
} |
-void CompareNilICStub::Record(Handle<Object> object) { |
+void CompareNilICStub::UpdateStatus(Handle<Object> object) { |
ASSERT(state_ != State::Generic()); |
+ State old_state(state_); |
if (object->IsNull()) { |
state_.Add(NULL_TYPE); |
} else if (object->IsUndefined()) { |
@@ -446,18 +540,22 @@ void CompareNilICStub::Record(Handle<Object> object) { |
} else { |
state_.Add(MONOMORPHIC_MAP); |
} |
+ TraceTransition(old_state, state_); |
} |
-void CompareNilICStub::State::TraceTransition(State to) const { |
+template<class StateType> |
+void HydrogenCodeStub::TraceTransition(StateType from, StateType to) { |
#ifdef DEBUG |
if (!FLAG_trace_ic) return; |
char buffer[100]; |
NoAllocationStringAllocator allocator(buffer, |
static_cast<unsigned>(sizeof(buffer))); |
StringStream stream(&allocator); |
- stream.Add("[CompareNilIC : "); |
- Print(&stream); |
+ stream.Add("["); |
+ PrintBaseName(&stream); |
+ stream.Add(": "); |
+ from.Print(&stream); |
stream.Add("=>"); |
to.Print(&stream); |
stream.Add("]\n"); |
@@ -465,12 +563,14 @@ void CompareNilICStub::State::TraceTransition(State to) const { |
#endif |
} |
+void CompareNilICStub::PrintBaseName(StringStream* stream) { |
+ CodeStub::PrintBaseName(stream); |
+ stream->Add((nil_value_ == kNullValue) ? "(NullValue)": |
+ "(UndefinedValue)"); |
+} |
-void CompareNilICStub::PrintName(StringStream* stream) { |
- stream->Add("CompareNilICStub_"); |
+void CompareNilICStub::PrintState(StringStream* stream) { |
state_.Print(stream); |
- stream->Add((nil_value_ == kNullValue) ? "(NullValue|": |
- "(UndefinedValue|"); |
} |
@@ -615,16 +715,15 @@ void CallConstructStub::PrintName(StringStream* stream) { |
} |
-bool ToBooleanStub::Record(Handle<Object> object) { |
+bool ToBooleanStub::UpdateStatus(Handle<Object> object) { |
Types old_types(types_); |
- bool to_boolean_value = types_.Record(object); |
- old_types.TraceTransition(types_); |
+ bool to_boolean_value = types_.UpdateStatus(object); |
+ TraceTransition(old_types, types_); |
return to_boolean_value; |
} |
-void ToBooleanStub::PrintName(StringStream* stream) { |
- stream->Add("ToBooleanStub_"); |
+void ToBooleanStub::PrintState(StringStream* stream) { |
types_.Print(stream); |
} |
@@ -645,24 +744,7 @@ void ToBooleanStub::Types::Print(StringStream* stream) const { |
} |
-void ToBooleanStub::Types::TraceTransition(Types to) const { |
- #ifdef DEBUG |
- if (!FLAG_trace_ic) return; |
- char buffer[100]; |
- NoAllocationStringAllocator allocator(buffer, |
- static_cast<unsigned>(sizeof(buffer))); |
- StringStream stream(&allocator); |
- stream.Add("[ToBooleanIC : "); |
- Print(&stream); |
- stream.Add("=>"); |
- to.Print(&stream); |
- stream.Add("]\n"); |
- stream.OutputToStdOut(); |
- #endif |
-} |
- |
- |
-bool ToBooleanStub::Types::Record(Handle<Object> object) { |
+bool ToBooleanStub::Types::UpdateStatus(Handle<Object> object) { |
if (object->IsUndefined()) { |
Add(UNDEFINED); |
return false; |