OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 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_WASM_COMPILER_H_ | |
Michael Starzinger
2015/12/11 09:15:14
nit: V8_COMPILER_WASM_COMPILER_H_
titzer
2015/12/11 10:16:20
Done.
| |
6 #define V8_WASM_COMPILER_H_ | |
7 | |
8 #include "src/zone.h" | |
9 | |
10 #include "src/wasm/wasm-opcodes.h" | |
Michael Starzinger
2015/12/11 09:15:14
nit: Since this header is allowed to be exported,
titzer
2015/12/11 10:16:21
Done.
| |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 | |
15 namespace compiler { | |
16 // Forward declarations for some compiler data structures. | |
17 class Node; | |
18 class JSGraph; | |
19 } | |
20 | |
21 namespace wasm { | |
22 // Forward declarations for some WASM data structures. | |
23 struct ModuleEnv; | |
24 struct WasmFunction; | |
25 class ErrorThrower; | |
26 | |
27 // Expose {Node} and {Graph} opaquely as {wasm::TFNode} and {wasm::TFGraph}. | |
28 typedef compiler::Node TFNode; | |
29 typedef compiler::JSGraph TFGraph; | |
30 } | |
31 | |
32 namespace compiler { | |
33 // Compiles a single function, producing a code object. | |
34 Handle<Code> CompileWasmFunction(wasm::ErrorThrower& thrower, Isolate* isolate, | |
35 wasm::ModuleEnv* module_env, | |
36 const wasm::WasmFunction& function, int index); | |
37 | |
38 // Wraps a JS function, producing a code object that can be called from WASM. | |
39 Handle<Code> CompileWasmToJSWrapper(Isolate* isolate, wasm::ModuleEnv* module, | |
40 Handle<JSFunction> function, | |
41 uint32_t index); | |
42 | |
43 // Wraps a given wasm code object, producing a JSFunction that can be called | |
44 // from JavaScript. | |
45 Handle<JSFunction> CompileJSToWasmWrapper(Isolate* isolate, | |
46 wasm::ModuleEnv* module, | |
47 Handle<String> name, | |
48 Handle<Code> wasm_code, | |
49 uint32_t index); | |
50 | |
51 // Abstracts details of building TurboFan graph nodes for WASM to separate | |
52 // the WASM decoder from the internal details of TurboFan. | |
53 class WasmTrapHelper; | |
54 class WasmGraphBuilder { | |
55 public: | |
56 WasmGraphBuilder(Zone* z, JSGraph* g); | |
57 | |
58 Node** Buffer(size_t count) { | |
59 if (count > cur_bufsize) { | |
60 size_t new_size = count + cur_bufsize + 5; | |
61 cur_buffer = | |
62 reinterpret_cast<Node**>(zone->New(new_size * sizeof(Node*))); | |
63 cur_bufsize = new_size; | |
64 } | |
65 return cur_buffer; | |
66 } | |
67 | |
68 //----------------------------------------------------------------------- | |
69 // Operations independent of {control} or {effect}. | |
70 //----------------------------------------------------------------------- | |
71 Node* Error(); | |
72 Node* Start(unsigned params); | |
73 Node* Param(unsigned index, wasm::LocalType type); | |
74 Node* Loop(Node* entry); | |
75 Node* Terminate(Node* effect, Node* control); | |
76 Node* Merge(unsigned count, Node** controls); | |
77 Node* Phi(wasm::LocalType type, unsigned count, Node** vals, Node* control); | |
78 Node* EffectPhi(unsigned count, Node** effects, Node* control); | |
79 Node* Int32Constant(int32_t value); | |
80 Node* Int64Constant(int64_t value); | |
81 Node* Float32Constant(float value); | |
82 Node* Float64Constant(double value); | |
83 Node* Constant(Handle<Object> value); | |
84 Node* Binop(wasm::WasmOpcode opcode, Node* left, Node* right); | |
85 Node* Unop(wasm::WasmOpcode opcode, Node* input); | |
86 unsigned InputCount(Node* node); | |
87 bool IsPhiWithMerge(Node* phi, Node* merge); | |
88 void AppendToMerge(Node* merge, Node* from); | |
89 void AppendToPhi(Node* merge, Node* phi, Node* from); | |
90 | |
91 //----------------------------------------------------------------------- | |
92 // Operations that read and/or write {control} and {effect}. | |
93 //----------------------------------------------------------------------- | |
94 Node* Branch(Node* cond, Node** true_node, Node** false_node); | |
95 Node* Switch(unsigned count, Node* key); | |
96 Node* IfValue(int32_t value, Node* sw); | |
97 Node* IfDefault(Node* sw); | |
98 Node* Return(unsigned count, Node** vals); | |
99 Node* ReturnVoid(); | |
100 Node* Unreachable(); | |
101 | |
102 Node* CallDirect(uint32_t index, Node** args); | |
103 Node* CallIndirect(uint32_t index, Node** args); | |
104 void BuildJSToWasmWrapper(Handle<Code> wasm_code, wasm::FunctionSig* sig); | |
105 void BuildWasmToJSWrapper(Handle<JSFunction> function, | |
106 wasm::FunctionSig* sig); | |
107 Node* ToJS(Node* node, Node* context, wasm::LocalType type); | |
108 Node* FromJS(Node* node, Node* context, wasm::LocalType type); | |
109 Node* Invert(Node* node); | |
110 Node* FunctionTable(); | |
111 | |
112 //----------------------------------------------------------------------- | |
113 // Operations that concern the linear memory. | |
114 //----------------------------------------------------------------------- | |
115 Node* MemSize(uint32_t offset); | |
116 Node* LoadGlobal(uint32_t index); | |
117 Node* StoreGlobal(uint32_t index, Node* val); | |
118 Node* LoadMem(wasm::LocalType type, MachineType memtype, Node* index, | |
119 uint32_t offset); | |
120 Node* StoreMem(MachineType type, Node* index, uint32_t offset, Node* val); | |
121 | |
122 static void PrintDebugName(Node* node); | |
123 | |
124 Node* Control() { return *control; } | |
125 Node* Effect() { return *effect; } | |
126 | |
127 void set_module(wasm::ModuleEnv* env) { this->module = env; } | |
128 | |
129 void set_control_ptr(Node** control) { this->control = control; } | |
130 | |
131 void set_effect_ptr(Node** effect) { this->effect = effect; } | |
132 | |
133 private: | |
134 static const int kDefaultBufferSize = 16; | |
135 friend class WasmTrapHelper; | |
136 | |
137 Zone* zone; | |
Michael Starzinger
2015/12/11 09:15:14
nit: Fields don't follow the style guide, missing
titzer
2015/12/11 10:16:20
Done.
| |
138 JSGraph* graph; | |
139 wasm::ModuleEnv* module; | |
140 Node* mem_buffer; | |
141 Node* mem_size; | |
142 Node* function_table; | |
143 Node** control; | |
144 Node** effect; | |
145 Node** cur_buffer; | |
146 size_t cur_bufsize; | |
147 Node* def_buffer[kDefaultBufferSize]; | |
148 | |
149 WasmTrapHelper* trap; | |
150 | |
151 // Internal helper methods. | |
152 Node* String(const char* string); | |
153 Node* MemBuffer(uint32_t offset); | |
154 void BoundsCheckMem(MachineType memtype, Node* index, uint32_t offset); | |
155 | |
156 Node* BuildWasmCall(wasm::FunctionSig* sig, Node** args); | |
157 Node* BuildF32CopySign(Node* left, Node* right); | |
158 Node* BuildF64CopySign(Node* left, Node* right); | |
159 Node* BuildI32Ctz(Node* input); | |
160 Node* BuildI32Popcnt(Node* input); | |
161 Node* BuildI64Ctz(Node* input); | |
162 Node* BuildI64Popcnt(Node* input); | |
163 | |
164 Node** Realloc(Node** buffer, size_t count) { | |
165 Node** buf = Buffer(count); | |
166 if (buf != buffer) memcpy(buf, buffer, count * sizeof(Node*)); | |
167 return buf; | |
168 } | |
169 }; | |
170 } // namespace compiler | |
171 } // namespace internal | |
172 } // namespace v8 | |
173 | |
174 #endif // V8_WASM_COMPILER_H_ | |
Michael Starzinger
2015/12/11 09:15:14
nit: V8_COMPILER_WASM_COMPILER_H_
| |
OLD | NEW |