Index: src/compiler/ffi-compiler.h |
diff --git a/src/compiler/ffi-compiler.h b/src/compiler/ffi-compiler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..dd12748aff71e8f00db59b20f6c99b0286562207 |
--- /dev/null |
+++ b/src/compiler/ffi-compiler.h |
@@ -0,0 +1,153 @@ |
+// Copyright 2016 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. |
+ |
+#ifndef V8_COMPILER_FFI_COMPILER_H_ |
+#define V8_COMPILER_FFI_COMPILER_H_ |
+ |
+#include "include/v8-ffi.h" |
+ |
+// Clients of this interface shouldn't depend on lots of compiler internals. |
+// Do not include anything from src/compiler here! |
+#include "src/compiler.h" |
+#include "src/machine-type.h" |
+#include "src/zone/zone.h" |
+ |
+namespace v8 { |
+namespace internal { |
+ |
+namespace compiler { |
+// Forward declarations for some compiler data structures. |
+class Node; |
+class JSGraph; |
+class Graph; |
+class Operator; |
+class SourcePositionTable; |
+} |
+ |
+namespace ffi { |
+ |
+using v8::ffi::FFIType; |
+using v8::ffi::FFITypeElement; |
+using v8::ffi::FFIStructSignature; |
+ |
+typedef Signature<FFITypeElement> FFISignature; |
+ |
+struct NativeFunction { |
+ FFISignature* sig; |
+ uint8_t* start; |
+}; |
+} // namespace ffi |
+ |
+namespace compiler { |
+Handle<JSFunction> CompileJSToNativeWrapper(Isolate* isolate, |
+ Handle<String> name, |
+ ffi::NativeFunction func); |
+void* FFIFunctionBind(Isolate* isolate, ffi::NativeFunction func, |
+ Handle<JSReceiver> args); |
+void* BuildFFISerializer(Isolate* isolate, ffi::NativeFunction func); |
+void* BuildFFIDeserializedExecutor(Isolate* isolate, ffi::NativeFunction func); |
+// Used by runtime-ffi.cc |
+int TypeSize(ffi::FFIType type); |
+void WriteObject(Handle<Object> value, ffi::FFIType type, char* dest); |
+MachineType FFITypeToMachineType(ffi::FFITypeElement elem); |
+MachineType* TranslateSignature(ffi::FFISignature* sig); |
+ |
+class FFIGraphBuilder { |
+ public: |
+ FFIGraphBuilder(Zone* z, JSGraph* g); |
+ |
+ Node** Buffer(size_t count) { |
+ if (count > cur_bufsize_) { |
+ size_t new_size = count + cur_bufsize_ + 5; |
+ cur_buffer_ = |
+ reinterpret_cast<Node**>(zone_->New(new_size * sizeof(Node*))); |
+ cur_bufsize_ = new_size; |
+ } |
+ return cur_buffer_; |
+ } |
+ |
+ Node* Start(unsigned params); |
+ |
+ MachineType* GetMachineTypes(ffi::FFISignature* sig); |
+ |
+ void BuildJSToNativeWrapper(ffi::NativeFunction func); |
+ |
+ Node* ToJS(Node* node, Node* context, ffi::FFITypeElement elem); |
+ Node* FromJS(Node* node, Node* context, ffi::FFITypeElement elem); |
+ |
+ Node* BuildCCall(ffi::FFISignature* sig, Node** args); |
+ |
+ static void PrintDebugName(Node* node); |
+ |
+ Node* Control() { return *control_; } |
+ Node* Effect() { return *effect_; } |
+ |
+ // void set_module(wasm::ModuleEnv* module) { this->module_ = module; } |
+ |
+ void set_control_ptr(Node** control) { this->control_ = control; } |
+ |
+ void set_effect_ptr(Node** effect) { this->effect_ = effect; } |
+ |
+ private: |
+ static const int kDefaultBufferSize = 16; |
+ |
+ Zone* zone_; |
+ JSGraph* jsgraph_; |
+ Node** control_; |
+ Node** effect_; |
+ Node** cur_buffer_; |
+ size_t cur_bufsize_; |
+ Node* def_buffer_[kDefaultBufferSize]; |
+ |
+ SetOncePointer<const Operator> allocate_heap_number_operator_; |
+ |
+ // Internal helper methods. |
+ JSGraph* jsgraph() { return jsgraph_; } |
+ Graph* graph(); |
+ |
+ Node* BuildJavaScriptToNumber(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* JSStringToCharPtr(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* CharPtrToJSString(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* ForeignToPointer(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* PointerToForeign(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* TypedArrayToUint8Ptr(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* BufferToPtrNoCopy(Node* node, Node* context, Node* effect, |
+ Node* control); |
+ Node* JSFunctionToFnPtr(Node* node, Node* context, ffi::FFISignature* sig, |
+ Node* effect_, Node* control_); |
+ Node* JSObjectToStructPtr(Node* node, Node* context, |
+ ffi::FFIStructSignature* sig, Node* effect, |
+ Node* control); |
+ Node* BuildChangeInt32ToTagged(Node* value); |
+ Node* BuildChangeFloat64ToTagged(Node* value); |
+ Node* BuildChangeTaggedToFloat64(Node* value); |
+ Node* BuildChangeTaggedToInt32(Node* value); |
+ |
+ Node* BuildChangeInt32ToSmi(Node* value); |
+ Node* BuildChangeSmiToInt32(Node* value); |
+ Node* BuildChangeSmiToFloat64(Node* value); |
+ Node* BuildTestNotSmi(Node* value); |
+ Node* BuildSmiShiftBitsConstant(); |
+ |
+ Node* BuildAllocateHeapNumberWithValue(Node* value, Node* control); |
+ Node* BuildLoadHeapNumberValue(Node* value, Node* control); |
+ Node* BuildHeapNumberValueIndexConstant(); |
+ |
+ Node** Realloc(Node** buffer, size_t old_count, size_t new_count) { |
+ Node** buf = Buffer(new_count); |
+ if (buf != buffer) memcpy(buf, buffer, old_count * sizeof(Node*)); |
+ return buf; |
+ } |
+}; |
+} // namespace compiler |
+} // namespace internal |
+} // namespace v8 |
+ |
+#endif // V8_COMPILER_FFI_COMPILER_H_ |