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, \
17 FOR_EACH_INTRINSIC_RETURN_OBJECT(F)
20 #define P(name, number_of_args, result_size) \
21 ObjectPair Runtime_##name(int args_length, Object** args_object, \
23 FOR_EACH_INTRINSIC_RETURN_PAIR(P)
27 #define F(name, number_of_args, result_size) \
29 Runtime::k##name, Runtime::RUNTIME, #name, FUNCTION_ADDR(Runtime_##name), \
30 number_of_args, result_size \
35 #define I(name, number_of_args, result_size) \
37 Runtime::kInline##name, Runtime::INLINE, "_" #name, \
38 FUNCTION_ADDR(Runtime_##name), number_of_args, result_size \
43 static const Runtime::Function kIntrinsicFunctions[] = {
44 FOR_EACH_INTRINSIC(F) FOR_EACH_INTRINSIC(I)};
50 void Runtime::InitializeIntrinsicFunctionNames(Isolate* isolate,
51 Handle<NameDictionary> dict) {
52 DCHECK(dict->NumberOfElements() == 0);
53 HandleScope scope(isolate);
54 for (int i = 0; i < kNumFunctions; ++i) {
55 const char* name = kIntrinsicFunctions[i].name;
56 if (name == NULL) continue;
57 Handle<NameDictionary> new_dict = NameDictionary::Add(
58 dict, isolate->factory()->InternalizeUtf8String(name),
59 Handle<Smi>(Smi::FromInt(i), isolate), PropertyDetails::Empty());
60 // The dictionary does not need to grow.
61 CHECK(new_dict.is_identical_to(dict));
66 const Runtime::Function* Runtime::FunctionForName(Handle<String> name) {
67 Heap* heap = name->GetHeap();
68 int entry = heap->intrinsic_function_names()->FindEntry(name);
69 if (entry != kNotFound) {
70 Object* smi_index = heap->intrinsic_function_names()->ValueAt(entry);
71 int function_index = Smi::cast(smi_index)->value();
72 return &(kIntrinsicFunctions[function_index]);
78 const Runtime::Function* Runtime::FunctionForEntry(Address entry) {
79 for (size_t i = 0; i < arraysize(kIntrinsicFunctions); ++i) {
80 if (entry == kIntrinsicFunctions[i].entry) {
81 return &(kIntrinsicFunctions[i]);
88 const Runtime::Function* Runtime::FunctionForId(Runtime::FunctionId id) {
89 return &(kIntrinsicFunctions[static_cast<int>(id)]);
93 std::ostream& operator<<(std::ostream& os, Runtime::FunctionId id) {
94 return os << Runtime::FunctionForId(id)->name;
97 } // namespace internal