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

Side by Side Diff: test/mjsunit/wasm/wasm-module-builder.js

Issue 1775873002: [Wasm] Convert many of the fixed-size values to LEB128. (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 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 function StringRef(string) { 5 function StringRef(string) {
6 this.pos = -1; 6 this.pos = -1;
7 this.string = string; 7 this.string = string;
8 } 8 }
9 9
10 function DataRef(data) { 10 function DataRef(data) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 emit_u8(bytes, this.memory.exp ? 1 : 0); 151 emit_u8(bytes, this.memory.exp ? 1 : 0);
152 } 152 }
153 153
154 // Add signatures section 154 // Add signatures section
155 if (this.signatures.length > 0) { 155 if (this.signatures.length > 0) {
156 if (debug) print("emitting signatures @ " + bytes.length); 156 if (debug) print("emitting signatures @ " + bytes.length);
157 emit_u8(bytes, kDeclSignatures); 157 emit_u8(bytes, kDeclSignatures);
158 emit_varint(bytes, this.signatures.length); 158 emit_varint(bytes, this.signatures.length);
159 for (sig of this.signatures) { 159 for (sig of this.signatures) {
160 var params = sig.length - 1; 160 var params = sig.length - 1;
161 emit_u8(bytes, params); 161 emit_varint(bytes, params);
162 for (var j = 0; j < sig.length; j++) { 162 for (var j = 0; j < sig.length; j++) {
163 emit_u8(bytes, sig[j]); 163 emit_u8(bytes, sig[j]);
164 } 164 }
165 } 165 }
166 } 166 }
167 167
168 // Add imports section 168 // Add imports section
169 if (this.imports.length > 0) { 169 if (this.imports.length > 0) {
170 if (debug) print("emitting imports @ " + bytes.length); 170 if (debug) print("emitting imports @ " + bytes.length);
171 emit_u8(bytes, kDeclImportTable); 171 emit_u8(bytes, kDeclImportTable);
172 emit_varint(bytes, this.imports.length); 172 emit_varint(bytes, this.imports.length);
173 for (imp of this.imports) { 173 for (imp of this.imports) {
174 emit_u16(bytes, imp.sig_index); 174 emit_varint(bytes, imp.sig_index);
175 emit_string(bytes, ""); 175 emit_string(bytes, "");
176 emit_string(bytes, imp.name); 176 emit_string(bytes, imp.name);
177 } 177 }
178 } 178 }
179 179
180 // Add functions section 180 // Add functions section
181 var names = false; 181 var names = false;
182 var exports = 0; 182 var exports = 0;
183 if (this.functions.length > 0) { 183 if (this.functions.length > 0) {
184 if (debug) print("emitting functions @ " + bytes.length); 184 if (debug) print("emitting functions @ " + bytes.length);
(...skipping 26 matching lines...) Expand all
211 if (l.i64_count > 0) { 211 if (l.i64_count > 0) {
212 local_decls.push({count: l.i64_count, type: kAstI64}); 212 local_decls.push({count: l.i64_count, type: kAstI64});
213 } 213 }
214 if (l.f32_count > 0) { 214 if (l.f32_count > 0) {
215 local_decls.push({count: l.f32_count, type: kAstF32}); 215 local_decls.push({count: l.f32_count, type: kAstF32});
216 } 216 }
217 if (l.f64_count > 0) { 217 if (l.f64_count > 0) {
218 local_decls.push({count: l.f64_count, type: kAstF64}); 218 local_decls.push({count: l.f64_count, type: kAstF64});
219 } 219 }
220 } 220 }
221 emit_u8(bytes, local_decls.length); 221 emit_varint(bytes, local_decls.length);
222 for (decl of local_decls) { 222 for (decl of local_decls) {
223 emit_varint(bytes, decl.count); 223 emit_varint(bytes, decl.count);
224 emit_u8(bytes, decl.type); 224 emit_u8(bytes, decl.type);
225 } 225 }
226 226
227 for (var i = 0; i < func.body.length; i++) { 227 for (var i = 0; i < func.body.length; i++) {
228 emit_u8(bytes, func.body[i]); 228 emit_u8(bytes, func.body[i]);
229 } 229 }
230 var length = bytes.length - length_pos - 2; 230 var length = bytes.length - length_pos - 2;
231 bytes[length_pos] = length & 0xff; 231 bytes[length_pos] = length & 0xff;
232 bytes[length_pos + 1] = (length >> 8) & 0xff; 232 bytes[length_pos + 1] = (length >> 8) & 0xff;
233 233
234 index++; 234 index++;
235 } 235 }
236 } 236 }
237 237
238 // Add start function section. 238 // Add start function section.
239 if (this.start_index != undefined) { 239 if (this.start_index != undefined) {
240 if (debug) print("emitting start function @ " + bytes.length); 240 if (debug) print("emitting start function @ " + bytes.length);
241 emit_u8(bytes, kDeclStartFunction); 241 emit_u8(bytes, kDeclStartFunction);
242 emit_varint(bytes, this.start_index); 242 emit_varint(bytes, this.start_index);
243 } 243 }
244 244
245 if (this.function_table.length > 0) { 245 if (this.function_table.length > 0) {
246 if (debug) print("emitting function table @ " + bytes.length); 246 if (debug) print("emitting function table @ " + bytes.length);
247 emit_u8(bytes, kDeclFunctionTable); 247 emit_u8(bytes, kDeclFunctionTable);
248 emit_varint(bytes, this.function_table.length); 248 emit_varint(bytes, this.function_table.length);
249 for (index of this.function_table) { 249 for (index of this.function_table) {
250 emit_u16(bytes, index); 250 emit_varint(bytes, index);
251 } 251 }
252 } 252 }
253 253
254 if (exports > 0) { 254 if (exports > 0) {
255 if (debug) print("emitting exports @ " + bytes.length); 255 if (debug) print("emitting exports @ " + bytes.length);
256 emit_u8(bytes, kDeclExportTable); 256 emit_u8(bytes, kDeclExportTable);
257 emit_varint(bytes, exports); 257 emit_varint(bytes, exports);
258 for (func of this.functions) { 258 for (func of this.functions) {
259 for (exp of func.exports) { 259 for (exp of func.exports) {
260 emit_u16(bytes, func.index); 260 emit_varint(bytes, func.index);
261 emit_string(bytes, exp); 261 emit_string(bytes, exp);
262 } 262 }
263 } 263 }
264 } 264 }
265 265
266 if (this.data_segments.length > 0) { 266 if (this.data_segments.length > 0) {
267 if (debug) print("emitting data segments @ " + bytes.length); 267 if (debug) print("emitting data segments @ " + bytes.length);
268 emit_u8(bytes, kDeclDataSegments); 268 emit_u8(bytes, kDeclDataSegments);
269 emit_varint(bytes, this.data_segments.length); 269 emit_varint(bytes, this.data_segments.length);
270 for (seg of this.data_segments) { 270 for (seg of this.data_segments) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 } 357 }
358 358
359 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { 359 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) {
360 var buffer = this.toBuffer(); 360 var buffer = this.toBuffer();
361 if (memory != undefined) { 361 if (memory != undefined) {
362 return _WASMEXP_.instantiateModule(buffer, ffi, memory); 362 return _WASMEXP_.instantiateModule(buffer, ffi, memory);
363 } else { 363 } else {
364 return _WASMEXP_.instantiateModule(buffer, ffi); 364 return _WASMEXP_.instantiateModule(buffer, ffi);
365 } 365 }
366 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698