Changeset 206110 in webkit
- Timestamp:
- Sep 19, 2016 1:39:55 PM (8 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 1 deleted
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/CMakeLists.txt
r205666 r206110 855 855 wasm/WASMModuleParser.cpp 856 856 wasm/WASMPlan.cpp 857 wasm/WASMSections.cpp858 857 859 858 yarr/RegularExpression.cpp -
trunk/Source/JavaScriptCore/ChangeLog
r206104 r206110 1 2016-09-19 Keith Miller <keith_miller@apple.com> 2 3 Update WASM towards 0xc 4 https://bugs.webkit.org/show_bug.cgi?id=162067 5 6 Reviewed by Geoffrey Garen. 7 8 This patch updates some of the core parts of the WASM frontend to the 0xc standard. 9 First, it changes the section names from strings to bytecodes. It also adds support 10 for inline block signatures. This is a change from the old version that used to have 11 each branch indicate the arity. Finally, this patch updates all the tests and deletes 12 a duplicate test. 13 14 * CMakeLists.txt: 15 * JavaScriptCore.xcodeproj/project.pbxproj: 16 * testWASM.cpp: 17 (runWASMTests): 18 * wasm/WASMB3IRGenerator.cpp: 19 * wasm/WASMFormat.h: 20 * wasm/WASMFunctionParser.h: 21 (JSC::WASM::FunctionParser<Context>::FunctionParser): 22 (JSC::WASM::FunctionParser<Context>::parseBlock): 23 (JSC::WASM::FunctionParser<Context>::parseExpression): 24 * wasm/WASMModuleParser.cpp: 25 (JSC::WASM::ModuleParser::parse): 26 * wasm/WASMSections.cpp: Removed. 27 (JSC::WASM::Sections::lookup): Deleted. 28 * wasm/WASMSections.h: 29 (JSC::WASM::Sections::validateOrder): 30 1 31 2016-09-19 Yusuke Suzuki <utatane.tea@gmail.com> 2 32 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r206011 r206110 1206 1206 539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; }; 1207 1207 53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; }; 1208 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; };1209 1208 53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; }; 1210 1209 53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; }; … … 3415 3414 53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; }; 3416 3415 53F40E841D58F9770099A1B6 /* WASMSections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMSections.h; sourceTree = "<group>"; }; 3417 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMSections.cpp; sourceTree = "<group>"; };3418 3416 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; }; 3419 3417 53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = "<group>"; }; … … 5606 5604 531374BC1D5CE67600AF7A0B /* WASMPlan.h */, 5607 5605 53F40E8C1D5901F20099A1B6 /* WASMParser.h */, 5608 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */,5609 5606 53F40E841D58F9770099A1B6 /* WASMSections.h */, 5610 5607 ); … … 9050 9047 A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */, 9051 9048 0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */, 9052 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */,9053 9049 0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */, 9054 9050 0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */, -
trunk/Source/JavaScriptCore/testWASM.cpp
r205769 r206110 244 244 // Generated from: 245 245 // (module 246 // (func "dumb-eq"(param $x i32) (param $y i32) (result i32)246 // (func (export "dumb-eq") (param $x i32) (param $y i32) (result i32) 247 247 // (if (i32.eq (get_local $x) (get_local $y)) 248 248 // (then (br 0)) … … 252 252 // ) 253 253 Vector<uint8_t> vector = { 254 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80, 255 0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 256 0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x91, 0x80, 257 0x80, 0x00, 0x01, 0x00, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 258 0x68, 0x61, 0x6e, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x97, 0x80, 0x80, 0x00, 0x01, 0x92, 0x80, 0x80, 259 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x03, 0x10, 0x00, 0x09, 0x01, 0x04, 0x10, 0x01, 0x09, 260 0x01, 0x0f, 0x0f 254 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 255 0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8b, 0x80, 256 0x80, 0x80, 0x00, 0x01, 0x07, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x65, 0x71, 0x00, 0x00, 0x0a, 0x99, 257 0x80, 0x80, 0x80, 0x00, 0x01, 0x93, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x4d, 258 0x03, 0x00, 0x06, 0x00, 0x04, 0x10, 0x01, 0x09, 0x0f, 0x10, 0x00, 0x09, 0x0f 261 259 }; 262 260 … … 281 279 // Generated from: 282 280 // (module 283 // (func "dumb-less-than"(param $x i32) (param $y i32) (result i32)281 // (func (export "dumb-less-than") (param $x i32) (param $y i32) (result i32) 284 282 // (loop 285 283 // (if (i32.eq (get_local $x) (get_local $y)) … … 293 291 // ) 294 292 Vector<uint8_t> vector = { 295 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80, 296 0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 297 0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x91, 0x80, 298 0x80, 0x00, 0x01, 0x00, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 299 0x68, 0x61, 0x6e, 0x04, 0x63, 0x6f, 0x64, 0x65, 0xaa, 0x80, 0x80, 0x00, 0x01, 0xa5, 0x80, 0x80, 300 0x00, 0x00, 0x02, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x03, 0x10, 0x00, 0x09, 0x01, 0x04, 0x14, 0x00, 301 0x10, 0x00, 0x4d, 0x03, 0x10, 0x01, 0x09, 0x01, 0x0f, 0x0f, 0x14, 0x00, 0x10, 0x01, 0x41, 0x15, 302 0x00, 0x06, 0x00, 0x00, 0x0f, 0x0f 293 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 294 0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x92, 0x80, 295 0x80, 0x80, 0x00, 0x01, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 296 0x68, 0x61, 0x6e, 0x00, 0x00, 0x0a, 0xac, 0x80, 0x80, 0x80, 0x00, 0x01, 0xa6, 0x80, 0x80, 0x80, 297 0x00, 0x00, 0x02, 0x00, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x03, 0x00, 0x10, 0x00, 0x09, 0x04, 0x14, 298 0x00, 0x10, 0x00, 0x4d, 0x03, 0x00, 0x10, 0x01, 0x09, 0x0f, 0x0f, 0x14, 0x00, 0x10, 0x01, 0x41, 299 0x15, 0x00, 0x06, 0x00, 0x0f, 0x00, 0x0f 303 300 }; 304 301 … … 320 317 } 321 318 322 { 323 // Generated from: 324 // (module 325 // (func "dumb-less-than" (param $x i32) (param $y i32) (result i32) 326 // (loop 327 // (block 328 // (block 329 // (br_if 0 (i32.eq (get_local $x) (i32.const 0))) 330 // (br 1) 331 // ) 332 // (return (i32.const 1)) 333 // ) 334 // (block 335 // (block 336 // (br_if 0 (i32.eq (get_local $x) (get_local $y))) 337 // (br 1) 338 // ) 339 // (return (i32.const 0)) 340 // ) 341 // (set_local $x (i32.sub (get_local $x) (i32.const 1))) 342 // (br 0) 343 // ) 344 // ) 345 // ) 346 Vector<uint8_t> vector = { 347 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80, 348 0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 349 0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x91, 0x80, 350 0x80, 0x00, 0x01, 0x00, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 351 0x68, 0x61, 0x6e, 0x04, 0x63, 0x6f, 0x64, 0x65, 0xb9, 0x80, 0x80, 0x00, 0x01, 0xb4, 0x80, 0x80, 352 0x00, 0x00, 0x02, 0x01, 0x01, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x07, 0x00, 0x00, 0x06, 0x00, 0x01, 353 0x0f, 0x10, 0x00, 0x09, 0x01, 0x0f, 0x01, 0x01, 0x14, 0x00, 0x10, 0x00, 0x4d, 0x07, 0x00, 0x00, 354 0x06, 0x00, 0x01, 0x0f, 0x10, 0x01, 0x09, 0x01, 0x0f, 0x14, 0x00, 0x10, 0x01, 0x41, 0x15, 0x00, 355 0x06, 0x00, 0x00, 0x0f, 0x0f 356 }; 357 358 Plan plan(*vm, vector); 359 if (plan.result.size() != 1 || !plan.result[0]) { 360 dataLogLn("Module failed to compile correctly."); 361 CRASH(); 362 } 363 364 // Test this doesn't crash. 365 CHECK_EQ(invoke<int>(*plan.result[0], { box(0), box(1) }), 1); 366 CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(0) }), 0); 367 CHECK_EQ(invoke<int>(*plan.result[0], { box(2), box(1) }), 0); 368 CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(2) }), 1); 369 CHECK_EQ(invoke<int>(*plan.result[0], { box(2), box(2) }), 0); 370 CHECK_EQ(invoke<int>(*plan.result[0], { box(1), box(1) }), 0); 371 CHECK_EQ(invoke<int>(*plan.result[0], { box(2), box(6) }), 1); 372 CHECK_EQ(invoke<int>(*plan.result[0], { box(100), box(6) }), 0); 373 } 374 375 { 376 // Generated from: (module (func "return-i32" (result i32) (return (i32.const 5))) ) 377 Vector<uint8_t> vector = { 378 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80, 379 0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82, 380 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00, 381 0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f, 382 0x64, 0x65, 0x8b, 0x80, 0x80, 0x00, 0x01, 0x86, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x09, 0x01, 383 0x0f 319 320 { 321 // Generated from: (module (func (export "return-i32") (result i32) (return (i32.const 5))) ) 322 Vector<uint8_t> vector = { 323 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 324 0x00, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8e, 0x80, 0x80, 0x80, 325 0x00, 0x01, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x00, 0x00, 0x0a, 326 0x8b, 0x80, 0x80, 0x80, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x09, 0x0f 384 327 }; 385 328 … … 396 339 397 340 { 398 // Generated from: (module (func "return-i32" (result i32) (return (i32.add (i32.const 5) (i32.const 6)))) ) 399 Vector<uint8_t> vector = { 400 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80, 401 0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82, 402 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00, 403 0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f, 404 0x64, 0x65, 0x8e, 0x80, 0x80, 0x00, 0x01, 0x89, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x06, 405 0x40, 0x09, 0x01, 0x0f 341 // Generated from: (module (func (export "return-i32") (result i32) (return (i32.add (i32.const 5) (i32.const 6)))) ) 342 Vector<uint8_t> vector = { 343 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 344 0x00, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8e, 0x80, 0x80, 0x80, 345 0x00, 0x01, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x00, 0x00, 0x0a, 346 0x8e, 0x80, 0x80, 0x80, 0x00, 0x01, 0x88, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x06, 347 0x40, 0x09, 0x0f 406 348 }; 407 349 … … 415 357 CHECK_EQ(invoke<int>(*plan.result[0], { }), 11); 416 358 } 417 418 { 419 // Generated from: (module (func "return-i32" (result i32) (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3)))) ) 420 Vector<uint8_t> vector = { 421 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80, 422 0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82, 423 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00, 424 0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f, 425 0x64, 0x65, 0x91, 0x80, 0x80, 0x00, 0x01, 0x8c, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x03, 426 0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f 359 360 { 361 // Generated from: (module (func (export "return-i32") (result i32) (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3)))) ) 362 Vector<uint8_t> vector = { 363 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 364 0x00, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8e, 0x80, 0x80, 0x80, 365 0x00, 0x01, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x00, 0x00, 0x0a, 366 0x91, 0x80, 0x80, 0x80, 0x00, 0x01, 0x8b, 0x80, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x03, 367 0x40, 0x10, 0x03, 0x40, 0x09, 0x0f 427 368 }; 428 369 … … 438 379 439 380 { 440 // Generated from: (module (func "return-i32" (result i32) (block (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3))))) ) 441 Vector<uint8_t> vector = { 442 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80, 443 0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82, 444 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00, 445 0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f, 446 0x64, 0x65, 0x93, 0x80, 0x80, 0x00, 0x01, 0x8e, 0x80, 0x80, 0x00, 0x00, 0x01, 0x10, 0x05, 0x10, 447 0x03, 0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f, 0x0f 381 // Generated from: (module (func (export "return-i32") (result i32) (block (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3)))) (unreachable)) ) 382 Vector<uint8_t> vector = { 383 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x85, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 384 0x00, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8e, 0x80, 0x80, 0x80, 385 0x00, 0x01, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x00, 0x00, 0x0a, 386 0x95, 0x80, 0x80, 0x80, 0x00, 0x01, 0x8f, 0x80, 0x80, 0x80, 0x00, 0x00, 0x01, 0x00, 0x10, 0x05, 387 0x10, 0x03, 0x40, 0x10, 0x03, 0x40, 0x09, 0x0f, 0x00, 0x0f 448 388 }; 449 389 … … 459 399 460 400 { 461 // Generated from: (module (func $add(param $x i32) (param $y i32) (result i32) (return (i32.add (get_local $x) (get_local $y)))) )462 Vector<uint8_t> vector = { 463 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x0 4, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80,464 0x0 0, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,465 0x 6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x8e, 0x80, 0x80, 0x00,466 0x01, 0x8 9, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x40, 0x09, 0x01, 0x0f401 // Generated from: (module (func (export "add") (param $x i32) (param $y i32) (result i32) (return (i32.add (get_local $x) (get_local $y)))) ) 402 Vector<uint8_t> vector = { 403 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 404 0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x87, 0x80, 405 0x80, 0x80, 0x00, 0x01, 0x03, 0x61, 0x64, 0x64, 0x00, 0x00, 0x0a, 0x8e, 0x80, 0x80, 0x80, 0x00, 406 0x01, 0x88, 0x80, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x40, 0x09, 0x0f 467 407 }; 468 408 … … 483 423 // Generated from: 484 424 // (module 485 // (func "locals"(param $x i32) (result i32) (local $num i32)425 // (func (export "locals") (param $x i32) (result i32) (local $num i32) 486 426 // (set_local $num (get_local $x)) 487 427 // (return (get_local $num)) … … 489 429 // ) 490 430 Vector<uint8_t> vector = { 491 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x86, 0x80, 0x80, 492 0x00, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 493 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x89, 0x80, 0x80, 494 0x00, 0x01, 0x00, 0x06, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x73, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x91, 495 0x80, 0x80, 0x00, 0x01, 0x8c, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x14, 0x00, 0x15, 0x01, 0x14, 496 0x01, 0x09, 0x01, 0x0f 431 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x86, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 432 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8a, 0x80, 0x80, 433 0x80, 0x00, 0x01, 0x06, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x73, 0x00, 0x00, 0x0a, 0x91, 0x80, 0x80, 434 0x80, 0x00, 0x01, 0x8b, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x14, 0x00, 0x15, 0x01, 0x14, 435 0x01, 0x09, 0x0f 497 436 }; 498 437 … … 511 450 // Generated from: 512 451 // (module 513 // (func "dumb-mult" (param $x i32) (param $y i32) (result i32) (local $total i32) (local $i i32) (local $j i32) 514 // (set_local $total (i32.const 0)) 515 // (set_local $i (i32.const 0)) 516 // (block 517 // (loop 518 // (br_if 1 (i32.eq (get_local $i) (get_local $x))) 519 // (set_local $j (i32.const 0)) 520 // (set_local $i (i32.add (get_local $i) (i32.const 1))) 521 // (loop 522 // (br_if 1 (i32.eq (get_local $j) (get_local $y))) 523 // (set_local $total (i32.add (get_local $total) (i32.const 1))) 524 // (set_local $j (i32.add (get_local $j) (i32.const 1))) 525 // (br 0) 526 // ) 452 // (func (export "sum") (param $x i32) (result i32) (local $y i32) 453 // (set_local $y (i32.const 0)) 454 // (loop 455 // (block 456 // (br_if 0 (i32.eq (get_local $x) (i32.const 0))) 457 // (set_local $y (i32.add (get_local $x) (get_local $y))) 458 // (set_local $x (i32.sub (get_local $x) (i32.const 1))) 459 // (br 1) 527 460 // ) 528 461 // ) 529 // (return (get_local $ total))462 // (return (get_local $y)) 530 463 // ) 531 464 // ) 532 465 Vector<uint8_t> vector = { 533 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x86, 0x80, 0x80, 534 0x00, 0x01, 0x40, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 535 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x86, 0x80, 0x80, 536 0x00, 0x01, 0x00, 0x03, 0x73, 0x75, 0x6d, 0x04, 0x63, 0x6f, 0x64, 0x65, 0xae, 0x80, 0x80, 0x00, 537 0x01, 0xa9, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x15, 0x01, 0x02, 0x01, 0x14, 0x00, 538 0x10, 0x00, 0x4d, 0x07, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x40, 0x15, 0x01, 0x14, 0x00, 0x10, 539 0x01, 0x41, 0x15, 0x00, 0x06, 0x00, 0x01, 0x0f, 0x0f, 0x14, 0x01, 0x09, 0x01, 0x0f 466 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x86, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 467 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x87, 0x80, 0x80, 468 0x80, 0x00, 0x01, 0x03, 0x73, 0x75, 0x6d, 0x00, 0x00, 0x0a, 0xae, 0x80, 0x80, 0x80, 0x00, 0x01, 469 0xa8, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x01, 0x10, 0x00, 0x15, 0x01, 0x02, 0x00, 0x01, 0x00, 470 0x14, 0x00, 0x10, 0x00, 0x4d, 0x07, 0x00, 0x14, 0x00, 0x14, 0x01, 0x40, 0x15, 0x01, 0x14, 0x00, 471 0x10, 0x01, 0x41, 0x15, 0x00, 0x06, 0x01, 0x0f, 0x0f, 0x14, 0x01, 0x09, 0x0f 540 472 }; 541 473 … … 556 488 // Generated from: 557 489 // (module 558 // (func "dumb-mult"(param $x i32) (param $y i32) (result i32) (local $total i32) (local $i i32) (local $j i32)490 // (func (export "dumb-mult") (param $x i32) (param $y i32) (result i32) (local $total i32) (local $i i32) (local $j i32) 559 491 // (set_local $total (i32.const 0)) 560 492 // (set_local $i (i32.const 0)) … … 574 506 // ) 575 507 Vector<uint8_t> vector = { 576 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80, 577 0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 578 0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8c, 0x80, 579 0x80, 0x00, 0x01, 0x00, 0x09, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6d, 0x75, 0x6c, 0x74, 0x04, 0x63, 580 0x6f, 0x64, 0x65, 0xc7, 0x80, 0x80, 0x00, 0x01, 0xc2, 0x80, 0x80, 0x00, 0x01, 0x03, 0x01, 0x10, 581 0x00, 0x15, 0x02, 0x10, 0x00, 0x15, 0x03, 0x01, 0x02, 0x14, 0x03, 0x14, 0x00, 0x4d, 0x07, 0x00, 582 0x01, 0x10, 0x00, 0x15, 0x04, 0x14, 0x03, 0x10, 0x01, 0x40, 0x15, 0x03, 0x02, 0x14, 0x04, 0x14, 583 0x01, 0x4d, 0x07, 0x00, 0x01, 0x14, 0x02, 0x10, 0x01, 0x40, 0x15, 0x02, 0x14, 0x04, 0x10, 0x01, 584 0x40, 0x15, 0x04, 0x06, 0x00, 0x00, 0x0f, 0x0f, 0x0f, 0x14, 0x02, 0x09, 0x01, 0x0f 508 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 509 0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x8d, 0x80, 510 0x80, 0x80, 0x00, 0x01, 0x09, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6d, 0x75, 0x6c, 0x74, 0x00, 0x00, 511 0x0a, 0xc7, 0x80, 0x80, 0x80, 0x00, 0x01, 0xc1, 0x80, 0x80, 0x80, 0x00, 0x01, 0x03, 0x01, 0x10, 512 0x00, 0x15, 0x02, 0x10, 0x00, 0x15, 0x03, 0x01, 0x00, 0x02, 0x00, 0x14, 0x03, 0x14, 0x00, 0x4d, 513 0x07, 0x01, 0x10, 0x00, 0x15, 0x04, 0x14, 0x03, 0x10, 0x01, 0x40, 0x15, 0x03, 0x02, 0x00, 0x14, 514 0x04, 0x14, 0x01, 0x4d, 0x07, 0x01, 0x14, 0x02, 0x10, 0x01, 0x40, 0x15, 0x02, 0x14, 0x04, 0x10, 515 0x01, 0x40, 0x15, 0x04, 0x06, 0x00, 0x0f, 0x0f, 0x0f, 0x14, 0x02, 0x09, 0x0f 585 516 }; 586 517 … … 609 540 // (block 610 541 // (block 542 // (br_if 0 (i32.eq (get_local $x) (get_local $y))) 543 // (br 1) 544 // ) 545 // (return (i32.const 0)) 546 // ) 547 // (block 548 // (block 611 549 // (br_if 0 (i32.eq (get_local $x) (i32.const 0))) 612 550 // (br 1) … … 614 552 // (return (i32.const 1)) 615 553 // ) 616 // (block617 // (block618 // (br_if 0 (i32.eq (get_local $x) (get_local $y)))619 // (br 1)620 // )621 // (return (i32.const 0))622 // )623 554 // (set_local $x (i32.sub (get_local $x) (i32.const 1))) 624 555 // (br 0) 625 556 // ) 557 // (unreachable) 626 558 // ) 627 559 // ) 628 560 Vector<uint8_t> vector = { 629 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80, 630 0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 631 0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x91, 0x80, 632 0x80, 0x00, 0x01, 0x00, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 633 0x68, 0x61, 0x6e, 0x04, 0x63, 0x6f, 0x64, 0x65, 0xb9, 0x80, 0x80, 0x00, 0x01, 0xb4, 0x80, 0x80, 634 0x00, 0x00, 0x02, 0x01, 0x01, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x07, 0x00, 0x00, 0x06, 0x00, 0x01, 635 0x0f, 0x10, 0x00, 0x09, 0x01, 0x0f, 0x01, 0x01, 0x14, 0x00, 0x10, 0x00, 0x4d, 0x07, 0x00, 0x00, 636 0x06, 0x00, 0x01, 0x0f, 0x10, 0x01, 0x09, 0x01, 0x0f, 0x14, 0x00, 0x10, 0x01, 0x41, 0x15, 0x00, 637 0x06, 0x00, 0x00, 0x0f, 0x0f 561 0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x40, 562 0x02, 0x01, 0x01, 0x01, 0x01, 0x03, 0x82, 0x80, 0x80, 0x80, 0x00, 0x01, 0x00, 0x07, 0x92, 0x80, 563 0x80, 0x80, 0x00, 0x01, 0x0e, 0x64, 0x75, 0x6d, 0x62, 0x2d, 0x6c, 0x65, 0x73, 0x73, 0x2d, 0x74, 564 0x68, 0x61, 0x6e, 0x00, 0x00, 0x0a, 0xb9, 0x80, 0x80, 0x80, 0x00, 0x01, 0xb3, 0x80, 0x80, 0x80, 565 0x00, 0x00, 0x02, 0x00, 0x01, 0x00, 0x01, 0x00, 0x14, 0x00, 0x14, 0x01, 0x4d, 0x07, 0x00, 0x06, 566 0x01, 0x0f, 0x10, 0x00, 0x09, 0x0f, 0x01, 0x00, 0x01, 0x00, 0x14, 0x00, 0x10, 0x00, 0x4d, 0x07, 567 0x00, 0x06, 0x01, 0x0f, 0x10, 0x01, 0x09, 0x0f, 0x14, 0x00, 0x10, 0x01, 0x41, 0x15, 0x00, 0x06, 568 0x00, 0x0f, 0x00, 0x0f 638 569 }; 639 570 -
trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp
r205769 r206110 106 106 public: 107 107 struct ControlData { 108 ControlData( Optional<Vector<Variable*>>&& stack, BasicBlock* special = nullptr, BasicBlock* continuation = nullptr)108 ControlData(Procedure& proc, Type signature, BasicBlock* special = nullptr, BasicBlock* continuation = nullptr) 109 109 : continuation(continuation) 110 110 , special(special) 111 , stack(stack) 112 { 111 { 112 if (signature != Void) 113 result.append(proc.addVariable(toB3Type(signature))); 113 114 } 114 115 … … 144 145 BasicBlock* targetBlockForBranch(Procedure& proc) 145 146 { 146 if ( special)147 if (type() == BlockType::Loop) 147 148 return special; 148 149 return continuation.get(proc); … … 156 157 LazyBlock continuation; 157 158 BasicBlock* special; 158 Optional<Vector<Variable*>> stack;159 Vector<Variable*, 1> result; 159 160 }; 160 161 161 162 typedef Value* ExpressionType; 162 163 typedef ControlData ControlType; 164 typedef Vector<ExpressionType, 1> ExpressionList; 165 typedef Vector<Variable*, 1> ResultList; 163 166 static constexpr ExpressionType emptyExpression = nullptr; 164 167 … … 175 178 bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType& result); 176 179 177 ControlData WARN_UNUSED_RETURN addBlock( );178 ControlData WARN_UNUSED_RETURN addLoop( );179 ControlData WARN_UNUSED_RETURN addIf(ExpressionType condition );180 ControlData WARN_UNUSED_RETURN addBlock(Type signature); 181 ControlData WARN_UNUSED_RETURN addLoop(Type signature); 182 ControlData WARN_UNUSED_RETURN addIf(ExpressionType condition, Type signature); 180 183 bool WARN_UNUSED_RETURN addElse(ControlData&); 181 184 182 bool WARN_UNUSED_RETURN addReturn(const Vector<ExpressionType, 1>& returnValues);183 bool WARN_UNUSED_RETURN addBranch(ControlData&, ExpressionType condition, const Vector<ExpressionType, 1>& returnValues);184 bool WARN_UNUSED_RETURN endBlock(ControlData&, Vector<ExpressionType, 1>& expressionStack);185 bool WARN_UNUSED_RETURN addReturn(const ExpressionList& returnValues); 186 bool WARN_UNUSED_RETURN addBranch(ControlData&, ExpressionType condition, const ExpressionList& returnValues); 187 bool WARN_UNUSED_RETURN endBlock(ControlData&, ExpressionList& expressionStack); 185 188 186 189 bool isContinuationReachable(ControlData&); 187 190 188 void dump(const Vector<ControlType>& controlStack, const Vector<ExpressionType, 1>& expressionStack);191 void dump(const Vector<ControlType>& controlStack, const ExpressionList& expressionStack); 189 192 190 193 private: 191 194 void unify(Variable* target, const ExpressionType source); 192 Vector<Variable*> initializeIncommingTypes(BasicBlock*, const Vector<ExpressionType, 1>&); 193 void unifyValuesWithBlock(const Vector<ExpressionType, 1>& resultStack, Optional<Vector<Variable*>>& stack, BasicBlock* target); 195 void unifyValuesWithBlock(const ExpressionList& resultStack, ResultList& stack); 194 196 195 197 Procedure& m_proc; … … 266 268 } 267 269 268 B3IRGenerator::ControlData B3IRGenerator::addBlock( )269 { 270 return ControlData( Nullopt);271 } 272 273 B3IRGenerator::ControlData B3IRGenerator::addLoop( )270 B3IRGenerator::ControlData B3IRGenerator::addBlock(Type signature) 271 { 272 return ControlData(m_proc, signature); 273 } 274 275 B3IRGenerator::ControlData B3IRGenerator::addLoop(Type signature) 274 276 { 275 277 BasicBlock* body = m_proc.addBlock(); … … 277 279 body->addPredecessor(m_currentBlock); 278 280 m_currentBlock = body; 279 return ControlData( Vector<Variable*>(), body);280 } 281 282 B3IRGenerator::ControlData B3IRGenerator::addIf(ExpressionType condition )281 return ControlData(m_proc, signature, body); 282 } 283 284 B3IRGenerator::ControlData B3IRGenerator::addIf(ExpressionType condition, Type signature) 283 285 { 284 286 // FIXME: This needs to do some kind of stack passing. … … 294 296 295 297 m_currentBlock = taken; 296 return ControlData( Nullopt, notTaken, continuation);298 return ControlData(m_proc, signature, notTaken, continuation); 297 299 } 298 300 … … 307 309 } 308 310 309 bool B3IRGenerator::addReturn(const Vector<ExpressionType, 1>& returnValues)311 bool B3IRGenerator::addReturn(const ExpressionList& returnValues) 310 312 { 311 313 ASSERT(returnValues.size() <= 1); … … 317 319 } 318 320 319 bool B3IRGenerator::addBranch(ControlData& data, ExpressionType condition, const Vector<ExpressionType, 1>& returnValues)321 bool B3IRGenerator::addBranch(ControlData& data, ExpressionType condition, const ExpressionList& returnValues) 320 322 { 321 323 BasicBlock* target = data.targetBlockForBranch(m_proc); 322 unifyValuesWithBlock(returnValues, data. stack, target);324 unifyValuesWithBlock(returnValues, data.result); 323 325 if (condition) { 324 326 BasicBlock* continuation = m_proc.addBlock(); … … 336 338 } 337 339 338 bool B3IRGenerator::endBlock(ControlData& data, Vector<ExpressionType, 1>& expressionStack)340 bool B3IRGenerator::endBlock(ControlData& data, ExpressionList& expressionStack) 339 341 { 340 342 if (!data.continuation) … … 350 352 } 351 353 352 unifyValuesWithBlock(expressionStack, data. stack, continuation);354 unifyValuesWithBlock(expressionStack, data.result); 353 355 m_currentBlock->appendNewControlValue(m_proc, Jump, Origin(), continuation); 354 356 continuation->addPredecessor(m_currentBlock); … … 378 380 } 379 381 380 Vector<Variable*> B3IRGenerator::initializeIncommingTypes(BasicBlock* block, const Vector<ExpressionType, 1>& source) 381 { 382 Vector<Variable*> result; 383 result.reserveInitialCapacity(source.size()); 384 for (ExpressionType expr : source) { 385 ASSERT(expr->type() != B3::Void); 386 Variable* var = m_proc.addVariable(expr->type()); 387 result.append(var); 388 block->appendNew<VariableValue>(m_proc, B3::Get, Origin(), var); 389 } 390 391 return result; 392 } 393 394 void B3IRGenerator::unifyValuesWithBlock(const Vector<ExpressionType, 1>& resultStack, Optional<Vector<Variable*>>& stack, BasicBlock* target) 395 { 396 if (!stack) { 397 stack = initializeIncommingTypes(target, resultStack); 398 return; 399 } 400 401 ASSERT(stack.value().size() == resultStack.size()); 382 void B3IRGenerator::unifyValuesWithBlock(const ExpressionList& resultStack, ResultList& result) 383 { 384 ASSERT(result.size() >= resultStack.size()); 402 385 403 386 for (size_t i = 0; i < resultStack.size(); ++i) 404 unify( stack.value()[i], resultStack[i]);405 } 406 407 void B3IRGenerator::dump(const Vector<ControlType>& controlStack, const Vector<ExpressionType, 1>& expressionStack)387 unify(result[i], resultStack[i]); 388 } 389 390 void B3IRGenerator::dump(const Vector<ControlType>& controlStack, const ExpressionList& expressionStack) 408 391 { 409 392 dataLogLn("Processing Graph:"); -
trunk/Source/JavaScriptCore/wasm/WASMFormat.h
r205552 r206110 56 56 57 57 enum Type : uint8_t { 58 I32 = 1, 58 Void, 59 I32, 59 60 I64, 60 61 F32, 61 62 F64, 62 63 LastValueType = F64, 63 Void64 64 }; 65 65 -
trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h
r205769 r206110 60 60 Vector<ExpressionType, 1> m_expressionStack; 61 61 Vector<ControlType> m_controlStack; 62 const Signature& m_signature; 62 63 unsigned m_unreachableBlocks { 0 }; 63 64 }; … … 67 68 : Parser(sourceBuffer, info.start, info.end) 68 69 , m_context(context) 69 { 70 m_context.addArguments(info.signature->arguments); 70 , m_signature(*info.signature) 71 { 72 if (verbose) 73 dataLogLn("Parsing function starting at: ", info.start, " ending at: ", info.end); 74 m_context.addArguments(m_signature.arguments); 71 75 } 72 76 … … 102 106 103 107 if (verbose) { 104 dataLogLn("processing op (", m_unreachableBlocks, "): ", RawPointer(reinterpret_cast<void*>(op)) );108 dataLogLn("processing op (", m_unreachableBlocks, "): ", RawPointer(reinterpret_cast<void*>(op)), " at offset: ", RawPointer(reinterpret_cast<void*>(m_offset))); 105 109 m_context.dump(m_controlStack, m_expressionStack); 106 110 } … … 180 184 181 185 case OpType::Block: { 182 m_controlStack.append(m_context.addBlock()); 186 Type inlineSignature; 187 if (!parseValueType(inlineSignature)) 188 return false; 189 190 m_controlStack.append(m_context.addBlock(inlineSignature)); 183 191 return true; 184 192 } 185 193 186 194 case OpType::Loop: { 187 m_controlStack.append(m_context.addLoop()); 195 Type inlineSignature; 196 if (!parseValueType(inlineSignature)) 197 return false; 198 199 m_controlStack.append(m_context.addLoop(inlineSignature)); 188 200 return true; 189 201 } 190 202 191 203 case OpType::If: { 204 Type inlineSignature; 205 if (!parseValueType(inlineSignature)) 206 return false; 207 192 208 ExpressionType condition = m_expressionStack.takeLast(); 193 m_controlStack.append(m_context.addIf(condition ));209 m_controlStack.append(m_context.addIf(condition, inlineSignature)); 194 210 return true; 195 211 } … … 201 217 case OpType::Branch: 202 218 case OpType::BranchIf: { 203 uint32_t arity;204 if (!parseVarUInt32(arity) || arity > m_expressionStack.size())205 return false;206 207 219 uint32_t target; 208 if (!parseVarUInt32(target) )220 if (!parseVarUInt32(target) || target >= m_controlStack.size()) 209 221 return false; 210 222 … … 215 227 m_unreachableBlocks = 1; 216 228 217 Vector<ExpressionType, 1> values(arity);218 for (unsigned i = arity; i; i--)219 values[i-1] = m_expressionStack.takeLast();220 221 if (target >= m_controlStack.size())222 return false;223 229 ControlType& data = m_controlStack[m_controlStack.size() - 1 - target]; 224 230 225 return m_context.addBranch(data, condition, values);231 return m_context.addBranch(data, condition, m_expressionStack); 226 232 } 227 233 228 234 case OpType::Return: { 229 uint8_t returnCount;230 if (!parseVarUInt1(returnCount))231 return false;232 235 Vector<ExpressionType, 1> returnValues; 233 if ( returnCount)236 if (m_signature.returnType != Void) 234 237 returnValues.append(m_expressionStack.takeLast()); 235 238 -
trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp
r205552 r206110 62 62 if (verbose) 63 63 dataLogLn("Starting to parse next section at offset: ", m_offset); 64 uint32_t sectionNameLength; 65 if (!parseVarUInt32(sectionNameLength)) 66 return false; 67 68 // Make sure we can read up to the section's size. 69 if (m_offset + sectionNameLength + maxLEBByteLength >= m_sourceLength) 70 return false; 71 72 Sections::Section section = Sections::lookup(m_source.data() + m_offset, sectionNameLength); 64 65 Sections::Section section = Sections::Unknown; 66 uint8_t sectionByte; 67 if (!parseUInt7(sectionByte)) 68 return false; 69 70 if (sectionByte) { 71 if (sectionByte >= Sections::Unknown) 72 section = Sections::Unknown; 73 else 74 section = static_cast<Sections::Section>(sectionByte); 75 } else { 76 uint32_t sectionNameLength; 77 if (!parseVarUInt32(sectionNameLength)) 78 return false; 79 80 // Make sure we can read up to the section's size. 81 if (m_offset + sectionNameLength + maxLEBByteLength >= m_sourceLength) 82 return false; 83 84 // We don't support any custom sections yet. 85 86 m_offset += sectionNameLength; 87 } 88 73 89 if (!Sections::validateOrder(previousSection, section)) 74 90 return false; 75 m_offset += sectionNameLength;76 91 77 92 uint32_t sectionLength; … … 82 97 83 98 switch (section) { 84 case Sections::End:85 return true;86 87 99 case Sections::FunctionTypes: { 88 100 if (verbose) … … 109 121 } 110 122 111 case Sections::Unknown: { 123 case Sections::Unknown: 124 // FIXME: Delete this when we support all the sections. 125 default: { 112 126 if (verbose) 113 127 dataLogLn("Unknown section, skipping."); -
trunk/Source/JavaScriptCore/wasm/WASMSections.h
r205552 r206110 30 30 namespace JSC { namespace WASM { 31 31 32 // These should be in the order that we expect them to be in the binary.33 #define FOR_EACH_WASM_SECTION_TYPE(macro) \34 macro(FunctionTypes, "type") \35 macro(Signatures, "function") \36 macro(Definitions, "code") \37 macro(End, "end")38 39 32 struct Sections { 40 enum Section {41 #define CREATE_SECTION_ENUM(name, str) name,42 FOR_EACH_WASM_SECTION_TYPE(CREATE_SECTION_ENUM)43 #undef CREATE_SECTION_ENUM 33 enum Section : uint8_t { 34 FunctionTypes = 1, 35 Signatures = 3, 36 Definitions = 10, 44 37 Unknown 45 38 }; 46 static Section lookup(const uint8_t*, unsigned);47 39 static bool validateOrder(Section previous, Section next) 48 40 { 49 // This allows unknown sections after End, which I doubt will ever be supported but50 // there is no reason to potentially break backwards compatability.51 41 if (previous == Unknown) 52 42 return true;
Note: See TracChangeset
for help on using the changeset viewer.