2014-09-11 13:18:58 +00:00
|
|
|
// Copyright 2014 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2015-08-14 09:41:32 +00:00
|
|
|
#include "src/code-factory.h"
|
2014-09-11 13:18:58 +00:00
|
|
|
|
|
|
|
#include "src/bootstrapper.h"
|
|
|
|
#include "src/ic/ic.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2015-03-02 13:36:38 +00:00
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
2015-07-13 13:39:26 +00:00
|
|
|
Callable CodeFactory::LoadIC(Isolate* isolate, TypeofMode typeof_mode,
|
2015-06-30 15:24:27 +00:00
|
|
|
LanguageMode language_mode) {
|
2014-09-11 13:18:58 +00:00
|
|
|
return Callable(
|
2015-06-30 15:24:27 +00:00
|
|
|
LoadIC::initialize_stub(
|
2015-07-13 13:39:26 +00:00
|
|
|
isolate, LoadICState(typeof_mode, language_mode).GetExtraICState()),
|
2014-09-11 13:18:58 +00:00
|
|
|
LoadDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 09:49:43 +00:00
|
|
|
// static
|
2015-02-23 12:34:07 +00:00
|
|
|
Callable CodeFactory::LoadICInOptimizedCode(
|
2015-07-13 13:39:26 +00:00
|
|
|
Isolate* isolate, TypeofMode typeof_mode, LanguageMode language_mode,
|
2015-02-23 12:34:07 +00:00
|
|
|
InlineCacheState initialization_state) {
|
|
|
|
auto code = LoadIC::initialize_stub_in_optimized_code(
|
2015-07-13 13:39:26 +00:00
|
|
|
isolate, LoadICState(typeof_mode, language_mode).GetExtraICState(),
|
2015-06-30 15:24:27 +00:00
|
|
|
initialization_state);
|
2015-05-20 13:19:11 +00:00
|
|
|
return Callable(code, LoadWithVectorDescriptor(isolate));
|
2014-10-10 09:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
2015-06-30 15:24:27 +00:00
|
|
|
Callable CodeFactory::KeyedLoadIC(Isolate* isolate,
|
|
|
|
LanguageMode language_mode) {
|
|
|
|
ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
|
|
|
|
: kNoExtraICState;
|
|
|
|
return Callable(KeyedLoadIC::initialize_stub(isolate, state),
|
2014-09-11 13:18:58 +00:00
|
|
|
LoadDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-10 09:49:43 +00:00
|
|
|
// static
|
2015-02-25 19:32:36 +00:00
|
|
|
Callable CodeFactory::KeyedLoadICInOptimizedCode(
|
2015-06-30 15:24:27 +00:00
|
|
|
Isolate* isolate, LanguageMode language_mode,
|
|
|
|
InlineCacheState initialization_state) {
|
|
|
|
ExtraICState state = is_strong(language_mode) ? LoadICState::kStrongModeState
|
|
|
|
: kNoExtraICState;
|
2015-02-25 19:32:36 +00:00
|
|
|
auto code = KeyedLoadIC::initialize_stub_in_optimized_code(
|
2015-06-30 15:24:27 +00:00
|
|
|
isolate, initialization_state, state);
|
2015-05-15 13:25:25 +00:00
|
|
|
if (initialization_state != MEGAMORPHIC) {
|
2015-05-20 13:19:11 +00:00
|
|
|
return Callable(code, LoadWithVectorDescriptor(isolate));
|
2014-10-10 09:49:43 +00:00
|
|
|
}
|
2015-02-25 19:32:36 +00:00
|
|
|
return Callable(code, LoadDescriptor(isolate));
|
2014-10-10 09:49:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-01-27 11:23:51 +00:00
|
|
|
// static
|
2015-11-09 08:47:59 +00:00
|
|
|
Callable CodeFactory::CallIC(Isolate* isolate, int argc,
|
|
|
|
ConvertReceiverMode mode) {
|
|
|
|
return Callable(CallIC::initialize_stub(isolate, argc, mode),
|
2015-01-27 11:23:51 +00:00
|
|
|
CallFunctionWithFeedbackDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
2015-11-09 08:47:59 +00:00
|
|
|
Callable CodeFactory::CallICInOptimizedCode(Isolate* isolate, int argc,
|
|
|
|
ConvertReceiverMode mode) {
|
|
|
|
return Callable(
|
|
|
|
CallIC::initialize_stub_in_optimized_code(isolate, argc, mode),
|
|
|
|
CallFunctionWithFeedbackAndVectorDescriptor(isolate));
|
2015-01-27 11:23:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
2015-02-04 09:34:05 +00:00
|
|
|
Callable CodeFactory::StoreIC(Isolate* isolate, LanguageMode language_mode) {
|
2015-02-23 12:34:07 +00:00
|
|
|
return Callable(
|
|
|
|
StoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
|
2015-06-26 07:53:21 +00:00
|
|
|
FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
|
|
|
|
: StoreDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
Callable CodeFactory::StoreICInOptimizedCode(
|
|
|
|
Isolate* isolate, LanguageMode language_mode,
|
|
|
|
InlineCacheState initialization_state) {
|
|
|
|
CallInterfaceDescriptor descriptor =
|
|
|
|
FLAG_vector_stores && initialization_state != MEGAMORPHIC
|
|
|
|
? VectorStoreICDescriptor(isolate)
|
|
|
|
: StoreDescriptor(isolate);
|
|
|
|
return Callable(StoreIC::initialize_stub_in_optimized_code(
|
|
|
|
isolate, language_mode, initialization_state),
|
|
|
|
descriptor);
|
2014-09-11 13:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
2015-02-04 09:34:05 +00:00
|
|
|
Callable CodeFactory::KeyedStoreIC(Isolate* isolate,
|
|
|
|
LanguageMode language_mode) {
|
2015-02-25 19:32:36 +00:00
|
|
|
return Callable(
|
|
|
|
KeyedStoreIC::initialize_stub(isolate, language_mode, UNINITIALIZED),
|
2015-06-26 07:53:21 +00:00
|
|
|
FLAG_vector_stores ? VectorStoreICTrampolineDescriptor(isolate)
|
|
|
|
: StoreDescriptor(isolate));
|
2015-02-25 19:32:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
Callable CodeFactory::KeyedStoreICInOptimizedCode(
|
|
|
|
Isolate* isolate, LanguageMode language_mode,
|
|
|
|
InlineCacheState initialization_state) {
|
2015-06-26 07:53:21 +00:00
|
|
|
CallInterfaceDescriptor descriptor =
|
|
|
|
FLAG_vector_stores && initialization_state != MEGAMORPHIC
|
|
|
|
? VectorStoreICDescriptor(isolate)
|
|
|
|
: StoreDescriptor(isolate);
|
|
|
|
return Callable(KeyedStoreIC::initialize_stub_in_optimized_code(
|
|
|
|
isolate, language_mode, initialization_state),
|
|
|
|
descriptor);
|
2014-09-11 13:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
2015-05-12 15:23:53 +00:00
|
|
|
Callable CodeFactory::CompareIC(Isolate* isolate, Token::Value op,
|
2015-06-08 12:17:58 +00:00
|
|
|
Strength strength) {
|
|
|
|
Handle<Code> code = CompareIC::GetUninitialized(isolate, op, strength);
|
2015-03-19 13:09:26 +00:00
|
|
|
return Callable(code, CompareDescriptor(isolate));
|
2014-09-11 13:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-27 11:21:23 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::CompareNilIC(Isolate* isolate, NilValue nil_value) {
|
|
|
|
Handle<Code> code = CompareNilICStub::GetUninitialized(isolate, nil_value);
|
|
|
|
return Callable(code, CompareNilDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
2015-04-24 12:32:56 +00:00
|
|
|
Callable CodeFactory::BinaryOpIC(Isolate* isolate, Token::Value op,
|
2015-06-08 12:17:58 +00:00
|
|
|
Strength strength) {
|
|
|
|
BinaryOpICStub stub(isolate, op, strength);
|
2014-09-11 13:18:58 +00:00
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
2015-07-13 09:18:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-22 12:15:55 +00:00
|
|
|
// static
|
2015-08-25 04:48:36 +00:00
|
|
|
Callable CodeFactory::InstanceOf(Isolate* isolate) {
|
|
|
|
InstanceOfStub stub(isolate);
|
2015-06-22 12:15:55 +00:00
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ToBoolean(Isolate* isolate,
|
|
|
|
ToBooleanStub::ResultMode mode,
|
|
|
|
ToBooleanStub::Types types) {
|
|
|
|
ToBooleanStub stub(isolate, mode, types);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
Callable CodeFactory::ToNumber(Isolate* isolate) {
|
|
|
|
ToNumberStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-28 12:59:51 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ToString(Isolate* isolate) {
|
|
|
|
ToStringStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-19 08:35:00 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ToLength(Isolate* isolate) {
|
|
|
|
ToLengthStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-31 12:25:28 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ToObject(Isolate* isolate) {
|
|
|
|
ToObjectStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-19 11:59:24 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::NumberToString(Isolate* isolate) {
|
|
|
|
NumberToStringStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
Callable CodeFactory::RegExpConstructResult(Isolate* isolate) {
|
|
|
|
RegExpConstructResultStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::StringAdd(Isolate* isolate, StringAddFlags flags,
|
|
|
|
PretenureFlag pretenure_flag) {
|
|
|
|
StringAddStub stub(isolate, flags, pretenure_flag);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-18 08:30:22 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::StringCompare(Isolate* isolate) {
|
|
|
|
StringCompareStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-06 13:31:00 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::Typeof(Isolate* isolate) {
|
|
|
|
TypeofStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-21 15:43:31 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::FastCloneShallowArray(Isolate* isolate) {
|
|
|
|
// TODO(mstarzinger): Thread through AllocationSiteMode at some point.
|
|
|
|
FastCloneShallowArrayStub stub(isolate, DONT_TRACK_ALLOCATION_SITE);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// static
|
|
|
|
Callable CodeFactory::FastCloneShallowObject(Isolate* isolate, int length) {
|
|
|
|
FastCloneShallowObjectStub stub(isolate, length);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-02 09:30:15 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::FastNewContext(Isolate* isolate, int slot_count) {
|
|
|
|
FastNewContextStub stub(isolate, slot_count);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-27 09:08:20 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::FastNewClosure(Isolate* isolate,
|
|
|
|
LanguageMode language_mode,
|
|
|
|
FunctionKind kind) {
|
|
|
|
FastNewClosureStub stub(isolate, language_mode, kind);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-24 15:30:30 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ArgumentsAccess(Isolate* isolate,
|
|
|
|
bool is_unmapped_arguments,
|
|
|
|
bool has_duplicate_parameters) {
|
|
|
|
ArgumentsAccessStub::Type type = ArgumentsAccessStub::ComputeType(
|
|
|
|
is_unmapped_arguments, has_duplicate_parameters);
|
|
|
|
ArgumentsAccessStub stub(isolate, type);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-11-04 12:58:17 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::AllocateHeapNumber(Isolate* isolate) {
|
|
|
|
AllocateHeapNumberStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-30 16:11:54 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::AllocateMutableHeapNumber(Isolate* isolate) {
|
|
|
|
AllocateMutableHeapNumberStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-16 08:40:02 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::AllocateInNewSpace(Isolate* isolate) {
|
|
|
|
AllocateInNewSpaceStub stub(isolate);
|
|
|
|
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-04 11:53:08 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::ArgumentAdaptor(Isolate* isolate) {
|
|
|
|
return Callable(isolate->builtins()->ArgumentsAdaptorTrampoline(),
|
|
|
|
ArgumentAdaptorDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-04 15:04:19 +00:00
|
|
|
// static
|
2015-11-09 08:47:59 +00:00
|
|
|
Callable CodeFactory::Call(Isolate* isolate, ConvertReceiverMode mode) {
|
|
|
|
return Callable(isolate->builtins()->Call(mode),
|
2015-11-04 15:04:19 +00:00
|
|
|
CallTrampolineDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-11-05 13:30:41 +00:00
|
|
|
// static
|
2015-11-09 08:47:59 +00:00
|
|
|
Callable CodeFactory::CallFunction(Isolate* isolate, ConvertReceiverMode mode) {
|
|
|
|
return Callable(isolate->builtins()->CallFunction(mode),
|
2015-11-05 13:30:41 +00:00
|
|
|
CallTrampolineDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-14 10:05:18 +00:00
|
|
|
// static
|
2015-10-02 18:13:41 +00:00
|
|
|
Callable CodeFactory::InterpreterPushArgsAndCall(Isolate* isolate) {
|
|
|
|
return Callable(isolate->builtins()->InterpreterPushArgsAndCall(),
|
|
|
|
InterpreterPushArgsAndCallDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-15 16:46:16 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::InterpreterPushArgsAndConstruct(Isolate* isolate) {
|
|
|
|
return Callable(isolate->builtins()->InterpreterPushArgsAndConstruct(),
|
|
|
|
InterpreterPushArgsAndConstructDescriptor(isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
// static
|
|
|
|
Callable CodeFactory::InterpreterCEntry(Isolate* isolate) {
|
|
|
|
// TODO(rmcilroy): Deal with runtime functions that return two values.
|
|
|
|
// Note: If we ever use fpregs in the interpreter then we will need to
|
|
|
|
// save fpregs too.
|
|
|
|
CEntryStub stub(isolate, 1, kDontSaveFPRegs, kArgvInRegister);
|
|
|
|
return Callable(stub.GetCode(), InterpreterCEntryDescriptor(isolate));
|
2015-09-14 10:05:18 +00:00
|
|
|
}
|
|
|
|
|
2014-09-11 13:18:58 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|