1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
7 #include "src/runtime/runtime.h"
8 #include "src/runtime/runtime-utils.h"
13 // Header of runtime functions.
14 #define F(name, number_of_args, result_size) \
15 Object* Runtime_##name(int args_length, Object** args_object, \
18 #define P(name, number_of_args, result_size) \
19 ObjectPair Runtime_##name(int args_length, Object** args_object, \
22 // Reference implementation for inlined runtime functions. Only used when the
23 // compiler does not support a certain intrinsic. Don't optimize these, but
24 // implement the intrinsic in the respective compiler instead.
25 #define I(name, number_of_args, result_size) \
26 Object* RuntimeReference_##name(int args_length, Object** args_object, \
29 RUNTIME_FUNCTION_LIST_RETURN_OBJECT(F)
30 RUNTIME_FUNCTION_LIST_RETURN_PAIR(P)
31 INLINE_OPTIMIZED_FUNCTION_LIST(F)
32 INLINE_FUNCTION_LIST(I)
39 #define F(name, number_of_args, result_size) \
41 Runtime::k##name, Runtime::RUNTIME, #name, FUNCTION_ADDR(Runtime_##name), \
42 number_of_args, result_size \
47 #define I(name, number_of_args, result_size) \
49 Runtime::kInline##name, Runtime::INLINE, "_" #name, \
50 FUNCTION_ADDR(RuntimeReference_##name), number_of_args, result_size \
55 #define IO(name, number_of_args, result_size) \
57 Runtime::kInlineOptimized##name, Runtime::INLINE_OPTIMIZED, "_" #name, \
58 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size \
63 static const Runtime::Function kIntrinsicFunctions[] = {
64 RUNTIME_FUNCTION_LIST(F) INLINE_OPTIMIZED_FUNCTION_LIST(F)
65 INLINE_FUNCTION_LIST(I) INLINE_OPTIMIZED_FUNCTION_LIST(IO)};
72 void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate,
73 Handle<NameDictionary> dict) {
74 DCHECK(dict->NumberOfElements() == 0);
75 HandleScope scope(isolate);
76 for (int i = 0; i < kNumFunctions; ++i) {
77 const char* name = kIntrinsicFunctions[i].name;
78 if (name == NULL) continue;
79 Handle<NameDictionary> new_dict = NameDictionary::Add(
80 dict, isolate->factory()->InternalizeUtf8String(name),
81 Handle<Smi>(Smi::FromInt(i), isolate), PropertyDetails(NONE, DATA, 0));
82 // The dictionary does not need to grow.
83 CHECK(new_dict.is_identical_to(dict));
88 const Runtime::Function* Runtime::FunctionForName(Handle<String> name) {
89 Heap* heap = name->GetHeap();
90 int entry = heap->intrinsic_function_names()->FindEntry(name);
91 if (entry != kNotFound) {
92 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry);
93 int function_index = Smi::cast(smi_index)->value();
94 return &(kIntrinsicFunctions[function_index]);
100 const Runtime::Function* Runtime::FunctionForEntry(Address entry) {
101 for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) {
102 if (entry == kIntrinsicFunctions[i].entry) {
103 return &(kIntrinsicFunctions[i]);
110 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
111 return &(kIntrinsicFunctions[static_cast<int>(id)]);
115 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
116 return os << Runtime::FunctionForId(id)->name;
119 } // namespace internal