OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef VM_RUNTIME_ENTRY_H_ | 5 #ifndef VM_RUNTIME_ENTRY_H_ |
6 #define VM_RUNTIME_ENTRY_H_ | 6 #define VM_RUNTIME_ENTRY_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/flags.h" | 10 #include "vm/flags.h" |
11 #include "vm/native_arguments.h" | 11 #include "vm/native_arguments.h" |
12 | 12 |
13 namespace dart { | 13 namespace dart { |
14 | 14 |
15 DECLARE_FLAG(bool, trace_runtime_calls); | 15 DECLARE_FLAG(bool, trace_runtime_calls); |
16 | 16 |
17 typedef void (*RuntimeFunction)(NativeArguments arguments); | 17 typedef void (*RuntimeFunction)(NativeArguments arguments); |
18 | 18 |
19 | 19 |
20 // Class RuntimeEntry is used to encapsulate runtime functions, it includes | 20 // Class RuntimeEntry is used to encapsulate runtime functions, it includes |
21 // the entry point for the runtime function and the number of arguments expected | 21 // the entry point for the runtime function and the number of arguments expected |
22 // by the function. | 22 // by the function. |
23 class RuntimeEntry : public ValueObject { | 23 class RuntimeEntry : public ValueObject { |
24 public: | 24 public: |
25 RuntimeEntry(const char* name, RuntimeFunction function, | 25 RuntimeEntry(const char* name, RuntimeFunction function, |
26 int argument_count, bool is_leaf) | 26 int argument_count, bool is_leaf, bool is_float) |
27 // TODO(regis): In order to simulate leaf runtime calls taking floating point | |
28 // arguments, we need to add an 'is_float' flag. | |
29 : name_(name), | 27 : name_(name), |
30 function_(function), | 28 function_(function), |
31 argument_count_(argument_count), | 29 argument_count_(argument_count), |
32 is_leaf_(is_leaf) { } | 30 is_leaf_(is_leaf), |
| 31 is_float_(is_float) { } |
33 ~RuntimeEntry() {} | 32 ~RuntimeEntry() {} |
34 | 33 |
35 const char* name() const { return name_; } | 34 const char* name() const { return name_; } |
36 RuntimeFunction function() const { return function_; } | 35 RuntimeFunction function() const { return function_; } |
37 int argument_count() const { return argument_count_; } | 36 int argument_count() const { return argument_count_; } |
38 bool is_leaf() const { return is_leaf_; } | 37 bool is_leaf() const { return is_leaf_; } |
| 38 bool is_float() const { return is_float_; } |
39 uword GetEntryPoint() const { return reinterpret_cast<uword>(function()); } | 39 uword GetEntryPoint() const { return reinterpret_cast<uword>(function()); } |
40 | 40 |
41 // Generate code to call the runtime entry. | 41 // Generate code to call the runtime entry. |
42 void Call(Assembler* assembler) const; | 42 void Call(Assembler* assembler) const; |
43 | 43 |
44 private: | 44 private: |
45 const char* name_; | 45 const char* name_; |
46 const RuntimeFunction function_; | 46 const RuntimeFunction function_; |
47 const int argument_count_; | 47 const int argument_count_; |
48 const bool is_leaf_; | 48 const bool is_leaf_; |
| 49 const bool is_float_; |
49 | 50 |
50 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); | 51 DISALLOW_COPY_AND_ASSIGN(RuntimeEntry); |
51 }; | 52 }; |
52 | 53 |
53 | 54 |
54 // Helper macros for declaring and defining runtime entries. | 55 // Helper macros for declaring and defining runtime entries. |
55 | 56 |
56 #define DEFINE_RUNTIME_ENTRY(name, argument_count) \ | 57 #define DEFINE_RUNTIME_ENTRY(name, argument_count) \ |
57 extern void DRT_##name(NativeArguments arguments); \ | 58 extern void DRT_##name(NativeArguments arguments); \ |
58 extern const RuntimeEntry k##name##RuntimeEntry( \ | 59 extern const RuntimeEntry k##name##RuntimeEntry( \ |
59 "DRT_"#name, &DRT_##name, argument_count, false); \ | 60 "DRT_"#name, &DRT_##name, argument_count, false, false); \ |
60 static void DRT_Helper##name(Isolate* isolate, NativeArguments arguments); \ | 61 static void DRT_Helper##name(Isolate* isolate, NativeArguments arguments); \ |
61 void DRT_##name(NativeArguments arguments) { \ | 62 void DRT_##name(NativeArguments arguments) { \ |
62 CHECK_STACK_ALIGNMENT; \ | 63 CHECK_STACK_ALIGNMENT; \ |
63 VERIFY_ON_TRANSITION; \ | 64 VERIFY_ON_TRANSITION; \ |
64 if (FLAG_trace_runtime_calls) OS::Print("Runtime call: %s\n", ""#name); \ | 65 if (FLAG_trace_runtime_calls) OS::Print("Runtime call: %s\n", ""#name); \ |
65 { \ | 66 { \ |
66 StackZone zone(arguments.isolate()); \ | 67 StackZone zone(arguments.isolate()); \ |
67 HANDLESCOPE(arguments.isolate()); \ | 68 HANDLESCOPE(arguments.isolate()); \ |
68 DRT_Helper##name(arguments.isolate(), arguments); \ | 69 DRT_Helper##name(arguments.isolate(), arguments); \ |
69 } \ | 70 } \ |
70 VERIFY_ON_TRANSITION; \ | 71 VERIFY_ON_TRANSITION; \ |
71 } \ | 72 } \ |
72 static void DRT_Helper##name(Isolate* isolate, NativeArguments arguments) | 73 static void DRT_Helper##name(Isolate* isolate, NativeArguments arguments) |
73 | 74 |
74 #define DECLARE_RUNTIME_ENTRY(name) \ | 75 #define DECLARE_RUNTIME_ENTRY(name) \ |
75 extern const RuntimeEntry k##name##RuntimeEntry | 76 extern const RuntimeEntry k##name##RuntimeEntry |
76 | 77 |
77 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, ...) \ | 78 #define DEFINE_LEAF_RUNTIME_ENTRY(type, name, argument_count, ...) \ |
78 extern "C" type DLRT_##name(__VA_ARGS__); \ | 79 extern "C" type DLRT_##name(__VA_ARGS__); \ |
79 extern const RuntimeEntry k##name##RuntimeEntry( \ | 80 extern const RuntimeEntry k##name##RuntimeEntry( \ |
80 "DLRT_"#name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), 0, true); \ | 81 "DLRT_"#name, reinterpret_cast<RuntimeFunction>(&DLRT_##name), \ |
| 82 argument_count, true, false); \ |
81 type DLRT_##name(__VA_ARGS__) { \ | 83 type DLRT_##name(__VA_ARGS__) { \ |
82 CHECK_STACK_ALIGNMENT; \ | 84 CHECK_STACK_ALIGNMENT; \ |
83 NoGCScope no_gc_scope; \ | 85 NoGCScope no_gc_scope; \ |
84 | 86 |
85 #define END_LEAF_RUNTIME_ENTRY } | 87 #define END_LEAF_RUNTIME_ENTRY } |
86 | 88 |
87 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ | 89 #define DECLARE_LEAF_RUNTIME_ENTRY(type, name, ...) \ |
88 extern const RuntimeEntry k##name##RuntimeEntry; \ | 90 extern const RuntimeEntry k##name##RuntimeEntry; \ |
89 extern "C" type DLRT_##name(__VA_ARGS__) | 91 extern "C" type DLRT_##name(__VA_ARGS__) |
90 | 92 |
91 } // namespace dart | 93 } // namespace dart |
92 | 94 |
93 #endif // VM_RUNTIME_ENTRY_H_ | 95 #endif // VM_RUNTIME_ENTRY_H_ |
OLD | NEW |