| OLD | NEW |
| 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 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 emit_u8(bytes, this.memory.exp ? 1 : 0); | 157 emit_u8(bytes, this.memory.exp ? 1 : 0); |
| 158 } | 158 } |
| 159 | 159 |
| 160 // Add signatures section | 160 // Add signatures section |
| 161 if (this.signatures.length > 0) { | 161 if (this.signatures.length > 0) { |
| 162 if (debug) print("emitting signatures @ " + bytes.length); | 162 if (debug) print("emitting signatures @ " + bytes.length); |
| 163 emit_u8(bytes, kDeclSignatures); | 163 emit_u8(bytes, kDeclSignatures); |
| 164 emit_varint(bytes, this.signatures.length); | 164 emit_varint(bytes, this.signatures.length); |
| 165 for (sig of this.signatures) { | 165 for (sig of this.signatures) { |
| 166 var params = sig.length - 1; | 166 var params = sig.length - 1; |
| 167 emit_u8(bytes, params); | 167 emit_varint(bytes, params); |
| 168 for (var j = 0; j < sig.length; j++) { | 168 for (var j = 0; j < sig.length; j++) { |
| 169 emit_u8(bytes, sig[j]); | 169 emit_u8(bytes, sig[j]); |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 // Add imports section | 174 // Add imports section |
| 175 if (this.imports.length > 0) { | 175 if (this.imports.length > 0) { |
| 176 if (debug) print("emitting imports @ " + bytes.length); | 176 if (debug) print("emitting imports @ " + bytes.length); |
| 177 emit_u8(bytes, kDeclImportTable); | 177 emit_u8(bytes, kDeclImportTable); |
| 178 emit_varint(bytes, this.imports.length); | 178 emit_varint(bytes, this.imports.length); |
| 179 for (imp of this.imports) { | 179 for (imp of this.imports) { |
| 180 emit_u16(bytes, imp.sig_index); | 180 emit_varint(bytes, imp.sig_index); |
| 181 emit_string(bytes, imp.module); | 181 emit_string(bytes, imp.module); |
| 182 if (imp.name == undefined) { | 182 if (imp.name == undefined) { |
| 183 emit_u32(bytes, 0); | 183 emit_u32(bytes, 0); |
| 184 } else { | 184 } else { |
| 185 emit_string(bytes, imp.name); | 185 emit_string(bytes, imp.name); |
| 186 } | 186 } |
| 187 } | 187 } |
| 188 } | 188 } |
| 189 | 189 |
| 190 // Add functions section | 190 // Add functions section |
| (...skipping 30 matching lines...) Expand all Loading... |
| 221 if (l.i64_count > 0) { | 221 if (l.i64_count > 0) { |
| 222 local_decls.push({count: l.i64_count, type: kAstI64}); | 222 local_decls.push({count: l.i64_count, type: kAstI64}); |
| 223 } | 223 } |
| 224 if (l.f32_count > 0) { | 224 if (l.f32_count > 0) { |
| 225 local_decls.push({count: l.f32_count, type: kAstF32}); | 225 local_decls.push({count: l.f32_count, type: kAstF32}); |
| 226 } | 226 } |
| 227 if (l.f64_count > 0) { | 227 if (l.f64_count > 0) { |
| 228 local_decls.push({count: l.f64_count, type: kAstF64}); | 228 local_decls.push({count: l.f64_count, type: kAstF64}); |
| 229 } | 229 } |
| 230 } | 230 } |
| 231 emit_u8(bytes, local_decls.length); | 231 emit_varint(bytes, local_decls.length); |
| 232 for (decl of local_decls) { | 232 for (decl of local_decls) { |
| 233 emit_varint(bytes, decl.count); | 233 emit_varint(bytes, decl.count); |
| 234 emit_u8(bytes, decl.type); | 234 emit_u8(bytes, decl.type); |
| 235 } | 235 } |
| 236 | 236 |
| 237 for (var i = 0; i < func.body.length; i++) { | 237 for (var i = 0; i < func.body.length; i++) { |
| 238 emit_u8(bytes, func.body[i]); | 238 emit_u8(bytes, func.body[i]); |
| 239 } | 239 } |
| 240 var length = bytes.length - length_pos - 2; | 240 var length = bytes.length - length_pos - 2; |
| 241 bytes[length_pos] = length & 0xff; | 241 bytes[length_pos] = length & 0xff; |
| 242 bytes[length_pos + 1] = (length >> 8) & 0xff; | 242 bytes[length_pos + 1] = (length >> 8) & 0xff; |
| 243 | 243 |
| 244 index++; | 244 index++; |
| 245 } | 245 } |
| 246 } | 246 } |
| 247 | 247 |
| 248 // Add start function section. | 248 // Add start function section. |
| 249 if (this.start_index != undefined) { | 249 if (this.start_index != undefined) { |
| 250 if (debug) print("emitting start function @ " + bytes.length); | 250 if (debug) print("emitting start function @ " + bytes.length); |
| 251 emit_u8(bytes, kDeclStartFunction); | 251 emit_u8(bytes, kDeclStartFunction); |
| 252 emit_varint(bytes, this.start_index); | 252 emit_varint(bytes, this.start_index); |
| 253 } | 253 } |
| 254 | 254 |
| 255 if (this.function_table.length > 0) { | 255 if (this.function_table.length > 0) { |
| 256 if (debug) print("emitting function table @ " + bytes.length); | 256 if (debug) print("emitting function table @ " + bytes.length); |
| 257 emit_u8(bytes, kDeclFunctionTable); | 257 emit_u8(bytes, kDeclFunctionTable); |
| 258 emit_varint(bytes, this.function_table.length); | 258 emit_varint(bytes, this.function_table.length); |
| 259 for (index of this.function_table) { | 259 for (index of this.function_table) { |
| 260 emit_u16(bytes, index); | 260 emit_varint(bytes, index); |
| 261 } | 261 } |
| 262 } | 262 } |
| 263 | 263 |
| 264 if (exports > 0) { | 264 if (exports > 0) { |
| 265 if (debug) print("emitting exports @ " + bytes.length); | 265 if (debug) print("emitting exports @ " + bytes.length); |
| 266 emit_u8(bytes, kDeclExportTable); | 266 emit_u8(bytes, kDeclExportTable); |
| 267 emit_varint(bytes, exports); | 267 emit_varint(bytes, exports); |
| 268 for (func of this.functions) { | 268 for (func of this.functions) { |
| 269 for (exp of func.exports) { | 269 for (exp of func.exports) { |
| 270 emit_u16(bytes, func.index); | 270 emit_varint(bytes, func.index); |
| 271 emit_string(bytes, exp); | 271 emit_string(bytes, exp); |
| 272 } | 272 } |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 | 275 |
| 276 if (this.data_segments.length > 0) { | 276 if (this.data_segments.length > 0) { |
| 277 if (debug) print("emitting data segments @ " + bytes.length); | 277 if (debug) print("emitting data segments @ " + bytes.length); |
| 278 emit_u8(bytes, kDeclDataSegments); | 278 emit_u8(bytes, kDeclDataSegments); |
| 279 emit_varint(bytes, this.data_segments.length); | 279 emit_varint(bytes, this.data_segments.length); |
| 280 for (seg of this.data_segments) { | 280 for (seg of this.data_segments) { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 } | 367 } |
| 368 | 368 |
| 369 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { | 369 WasmModuleBuilder.prototype.instantiate = function(ffi, memory) { |
| 370 var buffer = this.toBuffer(); | 370 var buffer = this.toBuffer(); |
| 371 if (memory != undefined) { | 371 if (memory != undefined) { |
| 372 return Wasm.instantiateModule(buffer, ffi, memory); | 372 return Wasm.instantiateModule(buffer, ffi, memory); |
| 373 } else { | 373 } else { |
| 374 return Wasm.instantiateModule(buffer, ffi); | 374 return Wasm.instantiateModule(buffer, ffi); |
| 375 } | 375 } |
| 376 } | 376 } |
| OLD | NEW |