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..1abe4ac997a8ba2d44e46057dba044352ef55c52 |
--- /dev/null |
+++ b/src/compiler/ffi-compiler.h |
@@ -0,0 +1,117 @@ |
+// 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_ |
+ |
+// 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.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 { |
+ |
+struct NativeFunction { |
+ MachineSignature* sig; |
+ uint8_t* start; |
+}; |
+} |
+ |
+namespace compiler { |
+Handle<JSFunction> CompileJSToNativeWrapper(Isolate* isolate, |
+ Handle<String> name, |
+ ffi::NativeFunction func); |
+ |
+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); |
+ |
+ void BuildJSToNativeWrapper(ffi::NativeFunction func); |
+ |
+ Node* ToJS(Node* node, Node* context, MachineType type); |
+ Node* FromJS(Node* node, Node* context, MachineType type); |
+ |
+ 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* BuildCCall(MachineSignature* sig, Node** args); |
+ |
+ Node* BuildJavaScriptToNumber(Node* node, Node* context, 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_ |