Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: src/wasm/encoder.h

Issue 2345593003: [wasm] Master CL for Binary 0xC changes. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix test failures and TSAN races. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_ENCODER_H_ 5 #ifndef V8_WASM_ENCODER_H_
6 #define V8_WASM_ENCODER_H_ 6 #define V8_WASM_ENCODER_H_
7 7
8 #include "src/signature.h" 8 #include "src/signature.h"
9 #include "src/zone/zone-containers.h" 9 #include "src/zone/zone-containers.h"
10 10
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject { 114 class V8_EXPORT_PRIVATE WasmFunctionBuilder : public ZoneObject {
115 public: 115 public:
116 // Building methods. 116 // Building methods.
117 void SetSignature(FunctionSig* sig); 117 void SetSignature(FunctionSig* sig);
118 uint32_t AddLocal(LocalType type); 118 uint32_t AddLocal(LocalType type);
119 void EmitVarInt(uint32_t val); 119 void EmitVarInt(uint32_t val);
120 void EmitCode(const byte* code, uint32_t code_size); 120 void EmitCode(const byte* code, uint32_t code_size);
121 void Emit(WasmOpcode opcode); 121 void Emit(WasmOpcode opcode);
122 void EmitGetLocal(uint32_t index); 122 void EmitGetLocal(uint32_t index);
123 void EmitSetLocal(uint32_t index); 123 void EmitSetLocal(uint32_t index);
124 void EmitTeeLocal(uint32_t index);
124 void EmitI32Const(int32_t val); 125 void EmitI32Const(int32_t val);
125 void EmitWithU8(WasmOpcode opcode, const byte immediate); 126 void EmitWithU8(WasmOpcode opcode, const byte immediate);
126 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2); 127 void EmitWithU8U8(WasmOpcode opcode, const byte imm1, const byte imm2);
127 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate); 128 void EmitWithVarInt(WasmOpcode opcode, uint32_t immediate);
128 void SetExported(); 129 void SetExported();
129 void SetName(const char* name, int name_length); 130 void SetName(const char* name, int name_length);
131
132 void WriteSignature(ZoneBuffer& buffer) const;
133 void WriteExport(ZoneBuffer& buffer) const;
134 void WriteBody(ZoneBuffer& buffer) const;
135
130 bool exported() { return exported_; } 136 bool exported() { return exported_; }
131 137 uint32_t func_index() { return func_index_; }
132 // Writing methods. 138 FunctionSig* signature();
133 void WriteSignature(ZoneBuffer& buffer) const;
134 void WriteExport(ZoneBuffer& buffer, uint32_t func_index) const;
135 void WriteBody(ZoneBuffer& buffer) const;
136 139
137 private: 140 private:
138 explicit WasmFunctionBuilder(WasmModuleBuilder* builder); 141 explicit WasmFunctionBuilder(WasmModuleBuilder* builder);
139 friend class WasmModuleBuilder; 142 friend class WasmModuleBuilder;
140 friend class WasmTemporary; 143 friend class WasmTemporary;
141 WasmModuleBuilder* builder_; 144 WasmModuleBuilder* builder_;
142 LocalDeclEncoder locals_; 145 LocalDeclEncoder locals_;
143 uint32_t signature_index_; 146 uint32_t signature_index_;
144 bool exported_; 147 bool exported_;
148 uint32_t func_index_;
145 ZoneVector<uint8_t> body_; 149 ZoneVector<uint8_t> body_;
146 ZoneVector<char> name_; 150 ZoneVector<char> name_;
147 ZoneVector<uint32_t> i32_temps_; 151 ZoneVector<uint32_t> i32_temps_;
148 ZoneVector<uint32_t> i64_temps_; 152 ZoneVector<uint32_t> i64_temps_;
149 ZoneVector<uint32_t> f32_temps_; 153 ZoneVector<uint32_t> f32_temps_;
150 ZoneVector<uint32_t> f64_temps_; 154 ZoneVector<uint32_t> f64_temps_;
151 }; 155 };
152 156
153 class WasmTemporary { 157 class WasmTemporary {
154 public: 158 public:
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 uint32_t sig_index; 209 uint32_t sig_index;
206 const char* name; 210 const char* name;
207 int name_length; 211 int name_length;
208 }; 212 };
209 213
210 class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject { 214 class V8_EXPORT_PRIVATE WasmModuleBuilder : public ZoneObject {
211 public: 215 public:
212 explicit WasmModuleBuilder(Zone* zone); 216 explicit WasmModuleBuilder(Zone* zone);
213 217
214 // Building methods. 218 // Building methods.
215 uint32_t AddFunction(); 219 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig);
216 uint32_t AddGlobal(LocalType type, bool exported); 220 void SetImportName(uint32_t index, const char* name, int name_length) {
217 WasmFunctionBuilder* FunctionAt(size_t index); 221 imports_[index].name = name;
222 imports_[index].name_length = name_length;
223 }
224 WasmFunctionBuilder* AddFunction(FunctionSig* sig = nullptr);
225 uint32_t AddGlobal(LocalType type, bool exported, bool mutability = true);
218 void AddDataSegment(WasmDataSegmentEncoder* data); 226 void AddDataSegment(WasmDataSegmentEncoder* data);
219 uint32_t AddSignature(FunctionSig* sig); 227 uint32_t AddSignature(FunctionSig* sig);
220 void AddIndirectFunction(uint32_t index); 228 void AddIndirectFunction(uint32_t index);
221 void MarkStartFunction(uint32_t index); 229 void MarkStartFunction(WasmFunctionBuilder* builder);
222 uint32_t AddImport(const char* name, int name_length, FunctionSig* sig);
223 230
224 // Writing methods. 231 // Writing methods.
225 void WriteTo(ZoneBuffer& buffer) const; 232 void WriteTo(ZoneBuffer& buffer) const;
226 233
227 struct CompareFunctionSigs { 234 struct CompareFunctionSigs {
228 bool operator()(FunctionSig* a, FunctionSig* b) const; 235 bool operator()(FunctionSig* a, FunctionSig* b) const;
229 }; 236 };
230 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap; 237 typedef ZoneMap<FunctionSig*, uint32_t, CompareFunctionSigs> SignatureMap;
231 238
232 Zone* zone() { return zone_; } 239 Zone* zone() { return zone_; }
233 240
241 FunctionSig* GetSignature(uint32_t index) { return signatures_[index]; }
242
234 private: 243 private:
244 friend class WasmFunctionBuilder;
235 Zone* zone_; 245 Zone* zone_;
236 ZoneVector<FunctionSig*> signatures_; 246 ZoneVector<FunctionSig*> signatures_;
237 ZoneVector<WasmFunctionImport> imports_; 247 ZoneVector<WasmFunctionImport> imports_;
238 ZoneVector<WasmFunctionBuilder*> functions_; 248 ZoneVector<WasmFunctionBuilder*> functions_;
239 ZoneVector<WasmDataSegmentEncoder*> data_segments_; 249 ZoneVector<WasmDataSegmentEncoder*> data_segments_;
240 ZoneVector<uint32_t> indirect_functions_; 250 ZoneVector<uint32_t> indirect_functions_;
241 ZoneVector<std::pair<LocalType, bool>> globals_; 251 ZoneVector<std::tuple<LocalType, bool, bool>> globals_;
242 SignatureMap signature_map_; 252 SignatureMap signature_map_;
243 int start_function_index_; 253 int start_function_index_;
244 }; 254 };
245 255
256 inline FunctionSig* WasmFunctionBuilder::signature() {
257 return builder_->signatures_[signature_index_];
258 }
259
246 } // namespace wasm 260 } // namespace wasm
247 } // namespace internal 261 } // namespace internal
248 } // namespace v8 262 } // namespace v8
249 263
250 #endif // V8_WASM_ENCODER_H_ 264 #endif // V8_WASM_ENCODER_H_
OLDNEW
« no previous file with comments | « src/wasm/decoder.h ('k') | src/wasm/encoder.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698