OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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. |
| 4 |
| 5 #ifndef V8_COMPILER_FFI_COMPILER_H_ |
| 6 #define V8_COMPILER_FFI_COMPILER_H_ |
| 7 |
| 8 #include "include/v8-ffi.h" |
| 9 |
| 10 // Clients of this interface shouldn't depend on lots of compiler internals. |
| 11 // Do not include anything from src/compiler here! |
| 12 #include "src/compiler.h" |
| 13 #include "src/machine-type.h" |
| 14 #include "src/zone/zone.h" |
| 15 |
| 16 namespace v8 { |
| 17 namespace internal { |
| 18 |
| 19 namespace compiler { |
| 20 // Forward declarations for some compiler data structures. |
| 21 class Node; |
| 22 class JSGraph; |
| 23 class Graph; |
| 24 class Operator; |
| 25 class SourcePositionTable; |
| 26 } |
| 27 |
| 28 namespace ffi { |
| 29 |
| 30 using v8::ffi::FFIType; |
| 31 using v8::ffi::FFITypeElement; |
| 32 using v8::ffi::FFIStructSignature; |
| 33 |
| 34 typedef Signature<FFITypeElement> FFISignature; |
| 35 |
| 36 struct NativeFunction { |
| 37 FFISignature* sig; |
| 38 uint8_t* start; |
| 39 }; |
| 40 } // namespace ffi |
| 41 |
| 42 namespace compiler { |
| 43 Handle<JSFunction> CompileJSToNativeWrapper(Isolate* isolate, |
| 44 Handle<String> name, |
| 45 ffi::NativeFunction func); |
| 46 void* FFIFunctionBind(Isolate* isolate, ffi::NativeFunction func, |
| 47 Handle<JSReceiver> args); |
| 48 void* BuildFFISerializer(Isolate* isolate, ffi::NativeFunction func); |
| 49 void* BuildFFIDeserializedExecutor(Isolate* isolate, ffi::NativeFunction func); |
| 50 // Used by runtime-ffi.cc |
| 51 int TypeSize(ffi::FFIType type); |
| 52 void WriteObject(Handle<Object> value, ffi::FFIType type, char* dest); |
| 53 MachineType FFITypeToMachineType(ffi::FFITypeElement elem); |
| 54 MachineType* TranslateSignature(ffi::FFISignature* sig); |
| 55 |
| 56 class FFIGraphBuilder { |
| 57 public: |
| 58 FFIGraphBuilder(Zone* z, JSGraph* g); |
| 59 |
| 60 Node** Buffer(size_t count) { |
| 61 if (count > cur_bufsize_) { |
| 62 size_t new_size = count + cur_bufsize_ + 5; |
| 63 cur_buffer_ = |
| 64 reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*))); |
| 65 cur_bufsize_ = new_size; |
| 66 } |
| 67 return cur_buffer_; |
| 68 } |
| 69 |
| 70 Node* Start(unsigned params); |
| 71 |
| 72 MachineType* GetMachineTypes(ffi::FFISignature* sig); |
| 73 |
| 74 void BuildJSToNativeWrapper(ffi::NativeFunction func); |
| 75 |
| 76 Node* ToJS(Node* node, Node* context, ffi::FFITypeElement elem); |
| 77 Node* FromJS(Node* node, Node* context, ffi::FFITypeElement elem); |
| 78 |
| 79 Node* BuildCCall(ffi::FFISignature* sig, Node** args); |
| 80 |
| 81 static void PrintDebugName(Node* node); |
| 82 |
| 83 Node* Control() { return *control_; } |
| 84 Node* Effect() { return *effect_; } |
| 85 |
| 86 // void set_module(wasm::ModuleEnv* module) { this->module_ = module; } |
| 87 |
| 88 void set_control_ptr(Node** control) { this->control_ = control; } |
| 89 |
| 90 void set_effect_ptr(Node** effect) { this->effect_ = effect; } |
| 91 |
| 92 private: |
| 93 static const int kDefaultBufferSize = 16; |
| 94 |
| 95 Zone* zone_; |
| 96 JSGraph* jsgraph_; |
| 97 Node** control_; |
| 98 Node** effect_; |
| 99 Node** cur_buffer_; |
| 100 size_t cur_bufsize_; |
| 101 Node* def_buffer_[kDefaultBufferSize]; |
| 102 |
| 103 SetOncePointer<const Operator> allocate_heap_number_operator_; |
| 104 |
| 105 // Internal helper methods. |
| 106 JSGraph* jsgraph() { return jsgraph_; } |
| 107 Graph* graph(); |
| 108 |
| 109 Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, |
| 110 Node* control); |
| 111 Node* JSStringToCharPtr(Node* node, Node* context, Node* effect, |
| 112 Node* control); |
| 113 Node* CharPtrToJSString(Node* node, Node* context, Node* effect, |
| 114 Node* control); |
| 115 Node* ForeignToPointer(Node* node, Node* context, Node* effect, |
| 116 Node* control); |
| 117 Node* PointerToForeign(Node* node, Node* context, Node* effect, |
| 118 Node* control); |
| 119 Node* TypedArrayToUint8Ptr(Node* node, Node* context, Node* effect, |
| 120 Node* control); |
| 121 Node* BufferToPtrNoCopy(Node* node, Node* context, Node* effect, |
| 122 Node* control); |
| 123 Node* JSFunctionToFnPtr(Node* node, Node* context, ffi::FFISignature* sig, |
| 124 Node* effect_, Node* control_); |
| 125 Node* JSObjectToStructPtr(Node* node, Node* context, |
| 126 ffi::FFIStructSignature* sig, Node* effect, |
| 127 Node* control); |
| 128 Node* BuildChangeInt32ToTagged(Node* value); |
| 129 Node* BuildChangeFloat64ToTagged(Node* value); |
| 130 Node* BuildChangeTaggedToFloat64(Node* value); |
| 131 Node* BuildChangeTaggedToInt32(Node* value); |
| 132 |
| 133 Node* BuildChangeInt32ToSmi(Node* value); |
| 134 Node* BuildChangeSmiToInt32(Node* value); |
| 135 Node* BuildChangeSmiToFloat64(Node* value); |
| 136 Node* BuildTestNotSmi(Node* value); |
| 137 Node* BuildSmiShiftBitsConstant(); |
| 138 |
| 139 Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control); |
| 140 Node* BuildLoadHeapNumberValue(Node* value, Node* control); |
| 141 Node* BuildHeapNumberValueIndexConstant(); |
| 142 |
| 143 Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { |
| 144 Node** buf = Buffer(new_count); |
| 145 if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); |
| 146 return buf; |
| 147 } |
| 148 }; |
| 149 } // namespace compiler |
| 150 } // namespace internal |
| 151 } // namespace v8 |
| 152 |
| 153 #endif // V8_COMPILER_FFI_COMPILER_H_ |
OLD | NEW |