Changeset 206110 in webkit


Ignore:
Timestamp:
Sep 19, 2016 1:39:55 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

Update WASM towards 0xc
https://bugs.webkit.org/show_bug.cgi?id=162067

Reviewed by Geoffrey Garen.

This patch updates some of the core parts of the WASM frontend to the 0xc standard.
First, it changes the section names from strings to bytecodes. It also adds support
for inline block signatures. This is a change from the old version that used to have
each branch indicate the arity. Finally, this patch updates all the tests and deletes
a duplicate test.

  • CMakeLists.txt:
  • JavaScriptCore.xcodeproj/project.pbxproj:
  • testWASM.cpp:

(runWASMTests):

  • wasm/WASMB3IRGenerator.cpp:
  • wasm/WASMFormat.h:
  • wasm/WASMFunctionParser.h:

(JSC::WASM::FunctionParser<Context>::FunctionParser):
(JSC::WASM::FunctionParser<Context>::parseBlock):
(JSC::WASM::FunctionParser<Context>::parseExpression):

  • wasm/WASMModuleParser.cpp:

(JSC::WASM::ModuleParser::parse):

  • wasm/WASMSections.cpp: Removed.

(JSC::WASM::Sections::lookup): Deleted.

  • wasm/WASMSections.h:

(JSC::WASM::Sections::validateOrder):

Location:
trunk/Source/JavaScriptCore
Files:
1 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/CMakeLists.txt

    r205666 r206110  
    855855    wasm/WASMModuleParser.cpp
    856856    wasm/WASMPlan.cpp
    857     wasm/WASMSections.cpp
    858857
    859858    yarr/RegularExpression.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r206104 r206110  
     12016-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
    1312016-09-19  Yusuke Suzuki  <utatane.tea@gmail.com>
    232
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r206011 r206110  
    12061206                539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; };
    12071207                53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; };
    1208                 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; };
    12091208                53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; };
    12101209                53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; };
     
    34153414                53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; };
    34163415                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>"; };
    34183416                53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; };
    34193417                53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = "<group>"; };
     
    56065604                                531374BC1D5CE67600AF7A0B /* WASMPlan.h */,
    56075605                                53F40E8C1D5901F20099A1B6 /* WASMParser.h */,
    5608                                 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */,
    56095606                                53F40E841D58F9770099A1B6 /* WASMSections.h */,
    56105607                        );
     
    90509047                                A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */,
    90519048                                0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */,
    9052                                 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */,
    90539049                                0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */,
    90549050                                0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */,
  • trunk/Source/JavaScriptCore/testWASM.cpp

    r205769 r206110  
    244244        // Generated from:
    245245        //    (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)
    247247        //      (if (i32.eq (get_local $x) (get_local $y))
    248248        //       (then (br 0))
     
    252252        //     )
    253253        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
    261259        };
    262260
     
    281279        // Generated from:
    282280        //    (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)
    284282        //      (loop
    285283        //       (if (i32.eq (get_local $x) (get_local $y))
     
    293291        //     )
    294292        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
    303300        };
    304301
     
    320317    }
    321318
    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
    384327        };
    385328
     
    396339
    397340    {
    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
    406348        };
    407349
     
    415357        CHECK_EQ(invoke<int>(*plan.result[0], { }), 11);
    416358    }
    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
    427368        };
    428369
     
    438379
    439380    {
    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
    448388        };
    449389
     
    459399
    460400    {
    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, 0x04, 0x74, 0x79, 0x70, 0x65, 0x87, 0x80, 0x80,
    464             0x00, 0x01, 0x40, 0x02, 0x01, 0x01, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f,
    465             0x6e, 0x82, 0x80, 0x80, 0x00, 0x01, 0x00, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x8e, 0x80, 0x80, 0x00,
    466             0x01, 0x89, 0x80, 0x80, 0x00, 0x00, 0x14, 0x00, 0x14, 0x01, 0x40, 0x09, 0x01, 0x0f
     401        // 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
    467407        };
    468408
     
    483423        // Generated from:
    484424        //    (module
    485         //     (func "locals" (param $x i32) (result i32) (local $num i32)
     425        //     (func (export "locals") (param $x i32) (result i32) (local $num i32)
    486426        //      (set_local $num (get_local $x))
    487427        //      (return (get_local $num))
     
    489429        //     )
    490430        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
    497436        };
    498437
     
    511450        // Generated from:
    512451        //    (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)
    527460        //        )
    528461        //       )
    529         //      (return (get_local $total))
     462        //      (return (get_local $y))
    530463        //      )
    531464        //     )
    532465        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
    540472        };
    541473
     
    556488        // Generated from:
    557489        //    (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)
    559491        //      (set_local $total (i32.const 0))
    560492        //      (set_local $i (i32.const 0))
     
    574506        //     )
    575507        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
    585516        };
    586517
     
    609540        //       (block
    610541        //        (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
    611549        //         (br_if 0 (i32.eq (get_local $x) (i32.const 0)))
    612550        //         (br 1)
     
    614552        //        (return (i32.const 1))
    615553        //        )
    616         //       (block
    617         //        (block
    618         //         (br_if 0 (i32.eq (get_local $x) (get_local $y)))
    619         //         (br 1)
    620         //         )
    621         //        (return (i32.const 0))
    622         //        )
    623554        //       (set_local $x (i32.sub (get_local $x) (i32.const 1)))
    624555        //       (br 0)
    625556        //       )
     557        //       (unreachable)
    626558        //      )
    627559        //     )
    628560        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
    638569        };
    639570
  • trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp

    r205769 r206110  
    106106public:
    107107    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)
    109109            : continuation(continuation)
    110110            , special(special)
    111             , stack(stack)
    112         {
     111        {
     112            if (signature != Void)
     113                result.append(proc.addVariable(toB3Type(signature)));
    113114        }
    114115
     
    144145        BasicBlock* targetBlockForBranch(Procedure& proc)
    145146        {
    146             if (special)
     147            if (type() == BlockType::Loop)
    147148                return special;
    148149            return continuation.get(proc);
     
    156157        LazyBlock continuation;
    157158        BasicBlock* special;
    158         Optional<Vector<Variable*>> stack;
     159        Vector<Variable*, 1> result;
    159160    };
    160161
    161162    typedef Value* ExpressionType;
    162163    typedef ControlData ControlType;
     164    typedef Vector<ExpressionType, 1> ExpressionList;
     165    typedef Vector<Variable*, 1> ResultList;
    163166    static constexpr ExpressionType emptyExpression = nullptr;
    164167
     
    175178    bool WARN_UNUSED_RETURN unaryOp(UnaryOpType, ExpressionType arg, ExpressionType& result);
    176179
    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);
    180183    bool WARN_UNUSED_RETURN addElse(ControlData&);
    181184
    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);
    185188
    186189    bool isContinuationReachable(ControlData&);
    187190
    188     void dump(const Vector<ControlType>& controlStack, const Vector<ExpressionType, 1>& expressionStack);
     191    void dump(const Vector<ControlType>& controlStack, const ExpressionList& expressionStack);
    189192
    190193private:
    191194    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);
    194196
    195197    Procedure& m_proc;
     
    266268}
    267269
    268 B3IRGenerator::ControlData B3IRGenerator::addBlock()
    269 {
    270     return ControlData(Nullopt);
    271 }
    272 
    273 B3IRGenerator::ControlData B3IRGenerator::addLoop()
     270B3IRGenerator::ControlData B3IRGenerator::addBlock(Type signature)
     271{
     272    return ControlData(m_proc, signature);
     273}
     274
     275B3IRGenerator::ControlData B3IRGenerator::addLoop(Type signature)
    274276{
    275277    BasicBlock* body = m_proc.addBlock();
     
    277279    body->addPredecessor(m_currentBlock);
    278280    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
     284B3IRGenerator::ControlData B3IRGenerator::addIf(ExpressionType condition, Type signature)
    283285{
    284286    // FIXME: This needs to do some kind of stack passing.
     
    294296
    295297    m_currentBlock = taken;
    296     return ControlData(Nullopt, notTaken, continuation);
     298    return ControlData(m_proc, signature, notTaken, continuation);
    297299}
    298300
     
    307309}
    308310
    309 bool B3IRGenerator::addReturn(const Vector<ExpressionType, 1>& returnValues)
     311bool B3IRGenerator::addReturn(const ExpressionList& returnValues)
    310312{
    311313    ASSERT(returnValues.size() <= 1);
     
    317319}
    318320
    319 bool B3IRGenerator::addBranch(ControlData& data, ExpressionType condition, const Vector<ExpressionType, 1>& returnValues)
     321bool B3IRGenerator::addBranch(ControlData& data, ExpressionType condition, const ExpressionList& returnValues)
    320322{
    321323    BasicBlock* target = data.targetBlockForBranch(m_proc);
    322     unifyValuesWithBlock(returnValues, data.stack, target);
     324    unifyValuesWithBlock(returnValues, data.result);
    323325    if (condition) {
    324326        BasicBlock* continuation = m_proc.addBlock();
     
    336338}
    337339
    338 bool B3IRGenerator::endBlock(ControlData& data, Vector<ExpressionType, 1>& expressionStack)
     340bool B3IRGenerator::endBlock(ControlData& data, ExpressionList& expressionStack)
    339341{
    340342    if (!data.continuation)
     
    350352    }
    351353
    352     unifyValuesWithBlock(expressionStack, data.stack, continuation);
     354    unifyValuesWithBlock(expressionStack, data.result);
    353355    m_currentBlock->appendNewControlValue(m_proc, Jump, Origin(), continuation);
    354356    continuation->addPredecessor(m_currentBlock);
     
    378380}
    379381
    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());
     382void B3IRGenerator::unifyValuesWithBlock(const ExpressionList& resultStack, ResultList& result)
     383{
     384    ASSERT(result.size() >= resultStack.size());
    402385
    403386    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
     390void B3IRGenerator::dump(const Vector<ControlType>& controlStack, const ExpressionList& expressionStack)
    408391{
    409392    dataLogLn("Processing Graph:");
  • trunk/Source/JavaScriptCore/wasm/WASMFormat.h

    r205552 r206110  
    5656
    5757enum Type : uint8_t {
    58     I32 = 1,
     58    Void,
     59    I32,
    5960    I64,
    6061    F32,
    6162    F64,
    6263    LastValueType = F64,
    63     Void
    6464};
    6565
  • trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h

    r205769 r206110  
    6060    Vector<ExpressionType, 1> m_expressionStack;
    6161    Vector<ControlType> m_controlStack;
     62    const Signature& m_signature;
    6263    unsigned m_unreachableBlocks { 0 };
    6364};
     
    6768    : Parser(sourceBuffer, info.start, info.end)
    6869    , 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);
    7175}
    7276
     
    102106
    103107        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)));
    105109            m_context.dump(m_controlStack, m_expressionStack);
    106110        }
     
    180184
    181185    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));
    183191        return true;
    184192    }
    185193
    186194    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));
    188200        return true;
    189201    }
    190202
    191203    case OpType::If: {
     204        Type inlineSignature;
     205        if (!parseValueType(inlineSignature))
     206            return false;
     207
    192208        ExpressionType condition = m_expressionStack.takeLast();
    193         m_controlStack.append(m_context.addIf(condition));
     209        m_controlStack.append(m_context.addIf(condition, inlineSignature));
    194210        return true;
    195211    }
     
    201217    case OpType::Branch:
    202218    case OpType::BranchIf: {
    203         uint32_t arity;
    204         if (!parseVarUInt32(arity) || arity > m_expressionStack.size())
    205             return false;
    206 
    207219        uint32_t target;
    208         if (!parseVarUInt32(target))
     220        if (!parseVarUInt32(target) || target >= m_controlStack.size())
    209221            return false;
    210222
     
    215227            m_unreachableBlocks = 1;
    216228
    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;
    223229        ControlType& data = m_controlStack[m_controlStack.size() - 1 - target];
    224230
    225         return m_context.addBranch(data, condition, values);
     231        return m_context.addBranch(data, condition, m_expressionStack);
    226232    }
    227233
    228234    case OpType::Return: {
    229         uint8_t returnCount;
    230         if (!parseVarUInt1(returnCount))
    231             return false;
    232235        Vector<ExpressionType, 1> returnValues;
    233         if (returnCount)
     236        if (m_signature.returnType != Void)
    234237            returnValues.append(m_expressionStack.takeLast());
    235238
  • trunk/Source/JavaScriptCore/wasm/WASMModuleParser.cpp

    r205552 r206110  
    6262        if (verbose)
    6363            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
    7389        if (!Sections::validateOrder(previousSection, section))
    7490            return false;
    75         m_offset += sectionNameLength;
    7691
    7792        uint32_t sectionLength;
     
    8297
    8398        switch (section) {
    84         case Sections::End:
    85             return true;
    86 
    8799        case Sections::FunctionTypes: {
    88100            if (verbose)
     
    109121        }
    110122
    111         case Sections::Unknown: {
     123        case Sections::Unknown:
     124        // FIXME: Delete this when we support all the sections.
     125        default: {
    112126            if (verbose)
    113127                dataLogLn("Unknown section, skipping.");
  • trunk/Source/JavaScriptCore/wasm/WASMSections.h

    r205552 r206110  
    3030namespace JSC { namespace WASM {
    3131
    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 
    3932struct 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,
    4437        Unknown
    4538    };
    46     static Section lookup(const uint8_t*, unsigned);
    4739    static bool validateOrder(Section previous, Section next)
    4840    {
    49         // This allows unknown sections after End, which I doubt will ever be supported but
    50         // there is no reason to potentially break backwards compatability.
    5141        if (previous == Unknown)
    5242            return true;
Note: See TracChangeset for help on using the changeset viewer.