Changeset 204484 in webkit


Ignore:
Timestamp:
Aug 15, 2016 2:35:07 PM (8 years ago)
Author:
keith_miller@apple.com
Message:

Implement WASM Parser and B3 IR generator
https://bugs.webkit.org/show_bug.cgi?id=160681

Reviewed by Benjamin Poulain.

Source/JavaScriptCore:

This patch adds the skeleton for a WebAssembly pipeline. The
pipeline is designed in order to make it easy to have as much of
the compilation process threaded as possible. The flow of the
pipeline roughly goes as follows:

1) Create a WASMPlan with the VM and a Vector of the
assembly. Currently the plan will process all the work
synchronously, however, in the future this can be offloaded to
other threads.

2) The plan will run the WASMModuleParser, which collates all the
information needed to compile each module function
independently. Since, we are still in the early phases, the only
information is the starting and ending byte of the function's
body. The module parser, however, still scans both and
semi-validates the type and the function sections.

3) Each function is decoded and compiled. In the future this
should also include a opcode validation phase. The
WASMFunctionParser is templatized so that a validator should be
able to use most of the same code the B3 IR generator does.

4) When the plan has finished it will fill a Vector of
B3::Compilation objects that correspond to the respective function
in the WASM module.

The current testing plan for the modules is to inline the the
binary generated by the spec's OCaml prototype. The inlined binary
is passed to a WASMPlan then invoked to check the result of the
function. In the future we should add a more robust testing
infrastructure.

(printUsageStatement):
(CommandLine::parseArguments):
(invoke):
(runWASMTests):
(main):

  • wasm/JSWASMModule.h:

(JSC::JSWASMModule::globalVariableTypes):

  • wasm/WASMB3IRGenerator.cpp: Added.

(JSC::WASM::B3IRGenerator::B3IRGenerator):
(JSC::WASM::B3IRGenerator::addLocal):
(JSC::WASM::B3IRGenerator::binaryOp):
(JSC::WASM::B3IRGenerator::addConstant):
(JSC::WASM::B3IRGenerator::addBlock):
(JSC::WASM::B3IRGenerator::endBlock):
(JSC::WASM::B3IRGenerator::addReturn):
(JSC::WASM::B3IRGenerator::unify):
(JSC::WASM::B3IRGenerator::initializeIncommingTypes):
(JSC::WASM::B3IRGenerator::unifyValuesWithLevel):
(JSC::WASM::B3IRGenerator::stackForControlLevel):
(JSC::WASM::B3IRGenerator::blockForControlLevel):
(JSC::WASM::parseAndCompile):

  • wasm/WASMB3IRGenerator.h: Copied from Source/WTF/wtf/DataLog.h.
  • wasm/WASMFormat.h:
  • wasm/WASMFunctionParser.h: Added.

(JSC::WASM::WASMFunctionParser<Context>::WASMFunctionParser):
(JSC::WASM::WASMFunctionParser<Context>::parse):
(JSC::WASM::WASMFunctionParser<Context>::parseBlock):
(JSC::WASM::WASMFunctionParser<Context>::parseExpression):

  • wasm/WASMModuleParser.cpp: Added.

(JSC::WASM::WASMModuleParser::parse):
(JSC::WASM::WASMModuleParser::parseFunctionTypes):
(JSC::WASM::WASMModuleParser::parseFunctionSignatures):
(JSC::WASM::WASMModuleParser::parseFunctionDefinitions):

  • wasm/WASMModuleParser.h: Copied from Source/WTF/wtf/DataLog.h.

(JSC::WASM::WASMModuleParser::WASMModuleParser):
(JSC::WASM::WASMModuleParser::functionInformation):

  • wasm/WASMOps.h: Copied from Source/WTF/wtf/DataLog.h.
  • wasm/WASMParser.h: Added.

(JSC::WASM::WASMParser::parseVarUInt32):
(JSC::WASM::WASMParser::WASMParser):
(JSC::WASM::WASMParser::consumeCharacter):
(JSC::WASM::WASMParser::consumeString):
(JSC::WASM::WASMParser::parseUInt32):
(JSC::WASM::WASMParser::parseUInt7):
(JSC::WASM::WASMParser::parseVarUInt1):
(JSC::WASM::WASMParser::parseValueType):

  • wasm/WASMPlan.cpp: Copied from Source/WTF/wtf/DataLog.h.

(JSC::WASM::Plan::Plan):

  • wasm/WASMPlan.h: Copied from Source/WTF/wtf/DataLog.h.
  • wasm/WASMSections.cpp: Copied from Source/WTF/wtf/DataLog.h.

(JSC::WASM::WASMSections::lookup):

  • wasm/WASMSections.h: Copied from Source/WTF/wtf/DataLog.h.

(JSC::WASM::WASMSections::validateOrder):

Source/WTF:

  • wtf/DataLog.h:

(WTF::dataLogLn): Add a new dataLog function, dataLogLn that
automagically includes a new line at the end of the print.

  • wtf/LEBDecoder.h:

(decodeUInt32):
(decodeInt32): Change the LEBDecoder to take a pointer and length
rather than a Vector.

Location:
trunk/Source
Files:
4 added
8 edited
7 copied

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/ChangeLog

    r204480 r204484  
     12016-08-15  Keith Miller  <keith_miller@apple.com>
     2
     3        Implement WASM Parser and B3 IR generator
     4        https://bugs.webkit.org/show_bug.cgi?id=160681
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        This patch adds the skeleton for a WebAssembly pipeline. The
     9        pipeline is designed in order to make it easy to have as much of
     10        the compilation process threaded as possible. The flow of the
     11        pipeline roughly goes as follows:
     12
     13        1) Create a WASMPlan with the VM and a Vector of the
     14        assembly. Currently the plan will process all the work
     15        synchronously, however, in the future this can be offloaded to
     16        other threads.
     17
     18        2) The plan will run the WASMModuleParser, which collates all the
     19        information needed to compile each module function
     20        independently. Since, we are still in the early phases, the only
     21        information is the starting and ending byte of the function's
     22        body. The module parser, however, still scans both and
     23        semi-validates the type and the function sections.
     24
     25        3) Each function is decoded and compiled. In the future this
     26        should also include a opcode validation phase. The
     27        WASMFunctionParser is templatized so that a validator should be
     28        able to use most of the same code the B3 IR generator does.
     29
     30        4) When the plan has finished it will fill a Vector of
     31        B3::Compilation objects that correspond to the respective function
     32        in the WASM module.
     33
     34
     35        The current testing plan for the modules is to inline the the
     36        binary generated by the spec's OCaml prototype. The inlined binary
     37        is passed to a WASMPlan then invoked to check the result of the
     38        function. In the future we should add a more robust testing
     39        infrastructure.
     40
     41        * JavaScriptCore.xcodeproj/project.pbxproj:
     42        * testWASM.cpp:
     43        (printUsageStatement):
     44        (CommandLine::parseArguments):
     45        (invoke):
     46        (runWASMTests):
     47        (main):
     48        * wasm/JSWASMModule.h:
     49        (JSC::JSWASMModule::globalVariableTypes):
     50        * wasm/WASMB3IRGenerator.cpp: Added.
     51        (JSC::WASM::B3IRGenerator::B3IRGenerator):
     52        (JSC::WASM::B3IRGenerator::addLocal):
     53        (JSC::WASM::B3IRGenerator::binaryOp):
     54        (JSC::WASM::B3IRGenerator::addConstant):
     55        (JSC::WASM::B3IRGenerator::addBlock):
     56        (JSC::WASM::B3IRGenerator::endBlock):
     57        (JSC::WASM::B3IRGenerator::addReturn):
     58        (JSC::WASM::B3IRGenerator::unify):
     59        (JSC::WASM::B3IRGenerator::initializeIncommingTypes):
     60        (JSC::WASM::B3IRGenerator::unifyValuesWithLevel):
     61        (JSC::WASM::B3IRGenerator::stackForControlLevel):
     62        (JSC::WASM::B3IRGenerator::blockForControlLevel):
     63        (JSC::WASM::parseAndCompile):
     64        * wasm/WASMB3IRGenerator.h: Copied from Source/WTF/wtf/DataLog.h.
     65        * wasm/WASMFormat.h:
     66        * wasm/WASMFunctionParser.h: Added.
     67        (JSC::WASM::WASMFunctionParser<Context>::WASMFunctionParser):
     68        (JSC::WASM::WASMFunctionParser<Context>::parse):
     69        (JSC::WASM::WASMFunctionParser<Context>::parseBlock):
     70        (JSC::WASM::WASMFunctionParser<Context>::parseExpression):
     71        * wasm/WASMModuleParser.cpp: Added.
     72        (JSC::WASM::WASMModuleParser::parse):
     73        (JSC::WASM::WASMModuleParser::parseFunctionTypes):
     74        (JSC::WASM::WASMModuleParser::parseFunctionSignatures):
     75        (JSC::WASM::WASMModuleParser::parseFunctionDefinitions):
     76        * wasm/WASMModuleParser.h: Copied from Source/WTF/wtf/DataLog.h.
     77        (JSC::WASM::WASMModuleParser::WASMModuleParser):
     78        (JSC::WASM::WASMModuleParser::functionInformation):
     79        * wasm/WASMOps.h: Copied from Source/WTF/wtf/DataLog.h.
     80        * wasm/WASMParser.h: Added.
     81        (JSC::WASM::WASMParser::parseVarUInt32):
     82        (JSC::WASM::WASMParser::WASMParser):
     83        (JSC::WASM::WASMParser::consumeCharacter):
     84        (JSC::WASM::WASMParser::consumeString):
     85        (JSC::WASM::WASMParser::parseUInt32):
     86        (JSC::WASM::WASMParser::parseUInt7):
     87        (JSC::WASM::WASMParser::parseVarUInt1):
     88        (JSC::WASM::WASMParser::parseValueType):
     89        * wasm/WASMPlan.cpp: Copied from Source/WTF/wtf/DataLog.h.
     90        (JSC::WASM::Plan::Plan):
     91        * wasm/WASMPlan.h: Copied from Source/WTF/wtf/DataLog.h.
     92        * wasm/WASMSections.cpp: Copied from Source/WTF/wtf/DataLog.h.
     93        (JSC::WASM::WASMSections::lookup):
     94        * wasm/WASMSections.h: Copied from Source/WTF/wtf/DataLog.h.
     95        (JSC::WASM::WASMSections::validateOrder):
     96
    1972016-08-15  Benjamin Poulain  <bpoulain@apple.com>
    298
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r204393 r204484  
    11791179                52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11801180                52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
     1181                531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = 531374BC1D5CE67600AF7A0B /* WASMPlan.h */; };
     1182                531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */; };
    11811183                53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
    11821184                53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; };
     
    11921194                539EB0811D55608A00C82EF7 /* testWASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWASM.cpp */; };
    11931195                539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; };
     1196                53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; };
     1197                53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; };
     1198                53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; };
     1199                53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; };
     1200                53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */; };
     1201                53F40E911D5903020099A1B6 /* WASMOps.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E901D5903020099A1B6 /* WASMOps.h */; };
     1202                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */; };
     1203                53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */; };
     1204                53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */; };
    11941205                53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
    11951206                53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    33543365                52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
    33553366                52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
     3367                531374BC1D5CE67600AF7A0B /* WASMPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMPlan.h; sourceTree = "<group>"; };
     3368                531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMPlan.cpp; sourceTree = "<group>"; };
    33563369                53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; };
    33573370                53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; };
     
    33713384                539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; };
    33723385                53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; };
     3386                53F40E841D58F9770099A1B6 /* WASMSections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMSections.h; sourceTree = "<group>"; };
     3387                53F40E861D58F9D60099A1B6 /* WASMSections.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMSections.cpp; sourceTree = "<group>"; };
     3388                53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; };
     3389                53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = "<group>"; };
     3390                53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMB3IRGenerator.cpp; sourceTree = "<group>"; };
     3391                53F40E901D5903020099A1B6 /* WASMOps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMOps.h; sourceTree = "<group>"; };
     3392                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMB3IRGenerator.h; sourceTree = "<group>"; };
     3393                53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = "<group>"; };
     3394                53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = "<group>"; };
    33733395                53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalFunctionAllocationProfile.h; sourceTree = "<group>"; };
    33743396                53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.h; sourceTree = "<group>"; };
     
    55405562                                7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
    55415563                                7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
     5564                                53F40E901D5903020099A1B6 /* WASMOps.h */,
    55425565                                7BC547D21B69599B00959B58 /* WASMFormat.h */,
     5566                                53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */,
     5567                                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */,
     5568                                53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */,
     5569                                53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */,
     5570                                53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */,
     5571                                531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */,
     5572                                531374BC1D5CE67600AF7A0B /* WASMPlan.h */,
     5573                                53F40E8C1D5901F20099A1B6 /* WASMParser.h */,
     5574                                53F40E861D58F9D60099A1B6 /* WASMSections.cpp */,
     5575                                53F40E841D58F9770099A1B6 /* WASMSections.h */,
    55435576                        );
    55445577                        path = wasm;
     
    72127245                                C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */,
    72137246                                0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */,
     7247                                53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */,
    72147248                                6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */,
    72157249                                0F885E111849A3BE00F1E3FA /* BytecodeUseDef.h in Headers */,
     
    72977331                                6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */,
    72987332                                FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */,
     7333                                53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */,
    72997334                                DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */,
    73007335                                0F2D4DDE19832D34007D4B19 /* DebuggerScope.h in Headers */,
     
    74437478                                0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */,
    74447479                                0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */,
     7480                                53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */,
    74457481                                0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */,
    74467482                                0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */,
     
    75977633                                0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */,
    75987634                                0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */,
     7635                                531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */,
    75997636                                2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
    76007637                                0F2BBD981C5FF3F50023EF23 /* B3Variable.h in Headers */,
     
    78087845                                797E07AA1B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h in Headers */,
    78097846                                BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */,
     7847                                53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */,
    78107848                                996B731D1BDA08EF00331B84 /* JSGlobalObject.lut.h in Headers */,
    78117849                                A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */,
     
    78677905                                FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */,
    78687906                                0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
     7907                                53F40E911D5903020099A1B6 /* WASMOps.h in Headers */,
    78697908                                A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */,
    78707909                                A790DD70182F499700588807 /* JSSetIterator.h in Headers */,
     
    79157954                                99DA00B01BD5994E00F4575C /* lazywriter.py in Headers */,
    79167955                                BC18C4310E16F5CD00B34460 /* Lexer.h in Headers */,
     7956                                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */,
    79177957                                BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */,
    79187958                                DCF3D56B1CD29472003D5C65 /* LazyClassStructureInlines.h in Headers */,
     
    89488988                                A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */,
    89498989                                0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */,
     8990                                53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */,
    89508991                                0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */,
    89518992                                0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */,
     
    91619202                                A513E5B7185B8BD3007E95AD /* InjectedScript.cpp in Sources */,
    91629203                                A514B2C2185A684400F3C7CB /* InjectedScriptBase.cpp in Sources */,
     9204                                531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */,
    91639205                                A58E35911860DECF001F24FE /* InjectedScriptHost.cpp in Sources */,
    91649206                                A513E5CA185F9624007E95AD /* InjectedScriptManager.cpp in Sources */,
     
    95379579                                FE5932A7183C5A2600A1ECCC /* VMEntryScope.cpp in Sources */,
    95389580                                FE187A011BFBE55E0038BBCA /* JITMulGenerator.cpp in Sources */,
     9581                                53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */,
    95399582                                26718BA41BE99F780052017B /* AirIteratedRegisterCoalescing.cpp in Sources */,
    95409583                                FED94F2E171E3E2300BE77A4 /* Watchdog.cpp in Sources */,
     
    95469589                                0F338DF91BE96AA80013C88F /* B3CCallValue.cpp in Sources */,
    95479590                                A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
     9591                                53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */,
    95489592                                A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
    95499593                                14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */,
  • trunk/Source/JavaScriptCore/testWASM.cpp

    r204218 r204484  
    2626#include "config.h"
    2727
     28#include "B3Compilation.h"
     29#include "InitializeThreading.h"
    2830#include "JSString.h"
     31#include "VM.h"
     32#include "WASMPlan.h"
    2933#include <wtf/DataLog.h>
    3034#include <wtf/LEBDecoder.h>
     
    3943    Vector<String> m_arguments;
    4044    bool m_runLEBTests { false };
     45    bool m_runWASMTests { false };
    4146
    4247    void parseArguments(int, char**);
     
    4853    fprintf(stderr, "  -h|--help  Prints this help message\n");
    4954    fprintf(stderr, "  -l|--leb   Runs the LEB decoder tests\n");
     55    fprintf(stderr, "  -w|--web   Run the WASM tests\n");
    5056    fprintf(stderr, "\n");
    5157
     
    6470        if (!strcmp(arg, "-l") || !strcmp(arg, "--leb"))
    6571            m_runLEBTests = true;
     72
     73        if (!strcmp(arg, "-w") || !strcmp(arg, "--web"))
     74            m_runWASMTests = true;
    6675    }
    6776
     
    110119        size_t offset = startOffset; \
    111120        uint32_t result; \
    112         bool status = decodeUInt32(vector, offset, result); \
     121        bool status = decodeUInt32(vector.data(), vector.size(), offset, result); \
    113122        RELEASE_ASSERT(status == expectedStatus); \
    114123        if (expectedStatus) { \
     
    158167        size_t offset = startOffset; \
    159168        int32_t result; \
    160         bool status = decodeInt32(vector, offset, result); \
     169        bool status = decodeInt32(vector.data(), vector.size(), offset, result); \
    161170        RELEASE_ASSERT(status == expectedStatus); \
    162171        if (expectedStatus) { \
     
    174183}
    175184
     185#if ENABLE(WEBASSEMBLY)
     186
     187static JSC::VM* vm;
     188
     189using namespace JSC;
     190using namespace WASM;
     191using namespace B3;
     192
     193template<typename T, typename... Arguments>
     194T invoke(MacroAssemblerCodePtr ptr, Arguments... arguments)
     195{
     196    T (*function)(Arguments...) = bitwise_cast<T(*)(Arguments...)>(ptr.executableAddress());
     197    return function(arguments...);
     198}
     199
     200template<typename T, typename... Arguments>
     201T invoke(const Compilation& code, Arguments... arguments)
     202{
     203    return invoke<T>(code.code(), arguments...);
     204}
     205
     206// For now we inline the test files.
     207static void runWASMTests()
     208{
     209    {
     210        // Generated from: (module (func "return-i32" (result i32) (return (i32.const 5))) )
     211        Vector<uint8_t> vector = {
     212            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
     213            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
     214            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
     215            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
     216            0x64, 0x65, 0x8b, 0x80, 0x80, 0x00, 0x01, 0x86, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x09, 0x01,
     217            0x0f
     218        };
     219
     220        Plan plan(*vm, vector);
     221        if (plan.result.size() != 1 || !plan.result[0]) {
     222            dataLogLn("Module failed to compile correctly.");
     223            CRASH();
     224        }
     225
     226        // Test this doesn't crash.
     227        RELEASE_ASSERT(invoke<int>(*plan.result[0]) == 5);
     228    }
     229
     230
     231    {
     232        // Generated from: (module (func "return-i32" (result i32) (return (i32.add (i32.const 5) (i32.const 6)))) )
     233        Vector<uint8_t> vector = {
     234            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
     235            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
     236            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
     237            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
     238            0x64, 0x65, 0x8e, 0x80, 0x80, 0x00, 0x01, 0x89, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x06,
     239            0x40, 0x09, 0x01, 0x0f
     240        };
     241
     242        Plan plan(*vm, vector);
     243        if (plan.result.size() != 1 || !plan.result[0]) {
     244            dataLogLn("Module failed to compile correctly.");
     245            CRASH();
     246        }
     247
     248        // Test this doesn't crash.
     249        RELEASE_ASSERT(invoke<int>(*plan.result[0]) == 11);
     250    }
     251   
     252    {
     253        // Generated from: (module (func "return-i32" (result i32) (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3)))) )
     254        Vector<uint8_t> vector = {
     255            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
     256            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
     257            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
     258            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
     259            0x64, 0x65, 0x91, 0x80, 0x80, 0x00, 0x01, 0x8c, 0x80, 0x80, 0x00, 0x00, 0x10, 0x05, 0x10, 0x03,
     260            0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f
     261        };
     262
     263        Plan plan(*vm, vector);
     264        if (plan.result.size() != 1 || !plan.result[0]) {
     265            dataLogLn("Module failed to compile correctly.");
     266            CRASH();
     267        }
     268
     269        // Test this doesn't crash.
     270        RELEASE_ASSERT(invoke<int>(*plan.result[0]) == 11);
     271    }
     272
     273    {
     274        // Generated from: (module (func "return-i32" (result i32) (block (return (i32.add (i32.add (i32.const 5) (i32.const 3)) (i32.const 3))))) )
     275        Vector<uint8_t> vector = {
     276            0x00, 0x61, 0x73, 0x6d, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x74, 0x79, 0x70, 0x65, 0x85, 0x80, 0x80,
     277            0x00, 0x01, 0x40, 0x00, 0x01, 0x01, 0x08, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x82,
     278            0x80, 0x80, 0x00, 0x01, 0x00, 0x06, 0x65, 0x78, 0x70, 0x6f, 0x72, 0x74, 0x8d, 0x80, 0x80, 0x00,
     279            0x01, 0x00, 0x0a, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x2d, 0x69, 0x33, 0x32, 0x04, 0x63, 0x6f,
     280            0x64, 0x65, 0x93, 0x80, 0x80, 0x00, 0x01, 0x8e, 0x80, 0x80, 0x00, 0x00, 0x01, 0x10, 0x05, 0x10,
     281            0x03, 0x40, 0x10, 0x03, 0x40, 0x09, 0x01, 0x0f, 0x0f
     282        };
     283
     284        Plan plan(*vm, vector);
     285        if (plan.result.size() != 1 || !plan.result[0]) {
     286            dataLogLn("Module failed to compile correctly.");
     287            CRASH();
     288        }
     289
     290        // Test this doesn't crash.
     291        RELEASE_ASSERT(invoke<int>(*plan.result[0]) == 11);
     292    }
     293}
     294
     295#endif // ENABLE(WEBASSEMBLY)
    176296
    177297int main(int argc, char** argv)
     
    182302        runLEBTests();
    183303
     304
     305    if (options.m_runWASMTests) {
     306#if ENABLE(WEBASSEMBLY)
     307        JSC::initializeThreading();
     308        vm = &JSC::VM::create(JSC::LargeHeap).leakRef();
     309        runWASMTests();
     310#else
     311        dataLogLn("WASM is not enabled!");
     312        return EXIT_FAILURE;
     313#endif // ENABLE(WEBASSEMBLY)
     314    }
     315
    184316    return EXIT_SUCCESS;
    185317}
  • trunk/Source/JavaScriptCore/wasm/JSWASMModule.h

    r189993 r204484  
    8080    Vector<WASMFunctionImport>& functionImports() { return m_functionImports; }
    8181    Vector<WASMFunctionImportSignature>& functionImportSignatures() { return m_functionImportSignatures; }
    82     Vector<WASMType>& globalVariableTypes() { return m_globalVariableTypes; }
     82    Vector<WASMValueType>& globalVariableTypes() { return m_globalVariableTypes; }
    8383    Vector<WASMFunctionDeclaration>& functionDeclarations() { return m_functionDeclarations; }
    8484    Vector<WASMFunctionPointerTable>& functionPointerTables() { return m_functionPointerTables; }
     
    100100    Vector<WASMFunctionImport> m_functionImports;
    101101    Vector<WASMFunctionImportSignature> m_functionImportSignatures;
    102     Vector<WASMType> m_globalVariableTypes;
     102    Vector<WASMValueType> m_globalVariableTypes;
    103103    Vector<WASMFunctionDeclaration> m_functionDeclarations;
    104104    Vector<WASMFunctionPointerTable> m_functionPointerTables;
  • trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#pragma once
    2827
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     28#include "B3Compilation.h"
     29#include "VM.h"
     30#include "WASMFormat.h"
    3331
    34 namespace WTF {
     32#if ENABLE(WEBASSEMBLY)
    3533
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     34namespace JSC {
    3735
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     36namespace WASM {
    4137
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
    44 {
    45     dataFile().print(values...);
    46 }
     38std::unique_ptr<B3::Compilation> parseAndCompile(VM&, Vector<uint8_t>&, WASMFunctionInformation, unsigned optLevel = 1);
    4739
    48 } // namespace WTF
     40} // namespace WASM
    4941
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     42} // namespace JSC
    5343
    54 #endif // DataLog_h
    55 
     44#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMFormat.h

    r189892 r204484  
    5353class JSFunction;
    5454
    55 enum class WASMType : uint8_t {
     55enum class WASMValueType : uint8_t {
    5656    I32,
     57    I64,
    5758    F32,
    5859    F64,
     
    6061};
    6162
    62 enum class WASMExpressionType : uint8_t {
     63enum class WASMFunctionReturnType : uint8_t {
    6364    I32,
     65    I64,
    6466    F32,
    6567    F64,
     
    6971
    7072struct WASMSignature {
    71     WASMExpressionType returnType;
    72     Vector<WASMType> arguments;
     73    WASMFunctionReturnType returnType;
     74    Vector<WASMValueType> arguments;
    7375};
    7476
     
    9294};
    9395
     96struct WASMFunctionInformation {
     97    size_t start;
     98    size_t end;
     99};
     100
    94101} // namespace JSC
    95102
  • trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#pragma once
    2827
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     28#include "WASMOps.h"
     29#include "WASMParser.h"
     30#include <wtf/Vector.h>
    3331
    34 namespace WTF {
     32#if ENABLE(WEBASSEMBLY)
    3533
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     34namespace JSC {
    3735
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     36namespace WASM {
    4137
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
    44 {
    45     dataFile().print(values...);
    46 }
     38class WASMModuleParser : public WASMParser {
     39public:
    4740
    48 } // namespace WTF
     41    static const unsigned magicNumber = 0xc;
    4942
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     43    WASMModuleParser(const Vector<uint8_t>& sourceBuffer)
     44        : WASMParser(sourceBuffer, 0, sourceBuffer.size())
     45    {
     46    }
    5347
    54 #endif // DataLog_h
     48    bool WARN_UNUSED_RETURN parse();
    5549
     50    const Vector<WASMFunctionInformation>& functionInformation() { return m_functions; }
     51
     52private:
     53    bool WARN_UNUSED_RETURN parseFunctionTypes();
     54    bool WARN_UNUSED_RETURN parseFunctionSignatures();
     55    bool WARN_UNUSED_RETURN parseFunctionDefinitions();
     56    bool WARN_UNUSED_RETURN parseFunctionDefinition(uint32_t number);
     57    bool WARN_UNUSED_RETURN parseBlock();
     58    bool WARN_UNUSED_RETURN parseExpression(WASMOpType);
     59
     60    Vector<WASMFunctionInformation> m_functions;
     61};
     62
     63} // namespace WASM
     64
     65} // namespace JSC
     66
     67#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMOps.h

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#pragma once
    2827
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     28#if ENABLE(WEBASSEMBLY)
    3329
    34 namespace WTF {
     30namespace JSC {
    3531
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     32namespace WASM {
    3733
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     34#define FOR_EACH_WASM_SPECIAL_OP(macro) \
     35    macro(I32Const, 0x10)
    4136
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
    44 {
    45     dataFile().print(values...);
    46 }
     37#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
     38    macro(Block, 0x01) \
     39    macro(Return, 0x09) \
     40    macro(End, 0x0f)
    4741
    48 } // namespace WTF
     42#define FOR_EACH_WASM_UNARY_OP(macro)
    4943
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     44#define FOR_EACH_WASM_BINARY_OP(macro) \
     45    macro(I32Add, 0x40)
    5346
    54 #endif // DataLog_h
     47#define FOR_EACH_WASM_OP(macro) \
     48    FOR_EACH_WASM_SPECIAL_OP(macro) \
     49    FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
     50    FOR_EACH_WASM_UNARY_OP(macro) \
     51    FOR_EACH_WASM_BINARY_OP(macro)
    5552
     53#define CREATE_ENUM_VALUE(name, id) name = id,
     54
     55enum WASMOpType : uint8_t {
     56    FOR_EACH_WASM_OP(CREATE_ENUM_VALUE)
     57};
     58
     59
     60
     61enum class WASMBinaryOpType : uint8_t {
     62    FOR_EACH_WASM_BINARY_OP(CREATE_ENUM_VALUE)
     63};
     64
     65} // namespace WASM
     66
     67} // namespace JSC
     68
     69#undef CREATE_ENUM_VALUE
     70
     71#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#include "config.h"
     27#include "WASMPlan.h"
    2828
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     29#include "B3Compilation.h"
     30#include "WASMB3IRGenerator.h"
     31#include "WASMModuleParser.h"
     32#include <wtf/DataLog.h>
    3333
    34 namespace WTF {
     34#if ENABLE(WEBASSEMBLY)
    3535
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     36namespace JSC {
    3737
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     38namespace WASM {
    4139
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
     40static const bool verbose = false;
     41
     42Plan::Plan(VM& vm, Vector<uint8_t> source)
    4443{
    45     dataFile().print(values...);
     44    if (verbose)
     45        dataLogLn("Starting plan.");
     46    WASMModuleParser moduleParser(source);
     47    if (!moduleParser.parse()) {
     48        dataLogLn("Parsing module failed.");
     49        return;
     50    }
     51
     52    if (verbose)
     53        dataLogLn("Parsed module.");
     54
     55    for (const WASMFunctionInformation& info : moduleParser.functionInformation()) {
     56        if (verbose)
     57            dataLogLn("Processing funcion starting at: ", info.start, " and ending at: ", info.end);
     58        result.append(parseAndCompile(vm, source, info));
     59    }
    4660}
    4761
    48 } // namespace WTF
     62} // namespace WASM
    4963
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     64} // namespace JSC
    5365
    54 #endif // DataLog_h
    55 
     66#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMPlan.h

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#pragma once
    2827
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     28#include "CompilationResult.h"
     29#include "VM.h"
     30#include <wtf/ThreadSafeRefCounted.h>
     31#include <wtf/Vector.h>
    3332
    34 namespace WTF {
     33#if ENABLE(WEBASSEMBLY)
    3534
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     35namespace JSC {
    3736
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     37namespace B3 {
     38class Compilation;
     39} // namespace B3
    4140
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
    44 {
    45     dataFile().print(values...);
    46 }
     41namespace WASM {
    4742
    48 } // namespace WTF
     43// TODO: This should create a WASM Module not a list of functions.
     44class Plan {
     45public:
     46    JS_EXPORT_PRIVATE Plan(VM&, Vector<uint8_t> source);
    4947
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     48    Vector<std::unique_ptr<B3::Compilation>> result;
     49};
    5350
    54 #endif // DataLog_h
     51} // namespace WASM
    5552
     53} // namespace JSC
     54
     55#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMSections.cpp

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#include "config.h"
     27#include "WASMSections.h"
    2828
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     29#include <wtf/DataLog.h>
     30#include <wtf/text/WTFString.h>
    3331
    34 namespace WTF {
     32#if ENABLE(WEBASSEMBLY)
    3533
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     34namespace JSC {
    3735
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     36namespace WASM {
    4137
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
     38struct SectionData {
     39    unsigned length;
     40    const char* name;
     41};
     42
     43static const bool verbose = false;
     44
     45static const unsigned sectionDataLength = static_cast<unsigned>(WASMSections::Section::Unknown);
     46static const SectionData sectionData[sectionDataLength] {
     47#define CREATE_SECTION_DATA(name, str) { sizeof(str) - 1, str },
     48    FOR_EACH_WASM_SECTION_TYPE(CREATE_SECTION_DATA)
     49#undef CREATE_SECTION_DATA
     50};
     51
     52WASMSections::Section WASMSections::lookup(const uint8_t* name, unsigned length)
    4453{
    45     dataFile().print(values...);
     54    if (verbose)
     55        dataLogLn("Decoding section with name: ", String(name, length));
     56    for (unsigned i = 0; i < sectionDataLength; ++i) {
     57        if (sectionData[i].length != length)
     58            continue;
     59        if (!memcmp(name, sectionData[i].name, length))
     60            return static_cast<WASMSections::Section>(i);
     61    }
     62    return WASMSections::Section::Unknown;
    4663}
    4764
    48 } // namespace WTF
     65} // namespace WASM
    4966
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     67} // namespace JSC
    5368
    54 #endif // DataLog_h
    55 
     69#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/JavaScriptCore/wasm/WASMSections.h

    r204483 r204484  
    11/*
    2  * Copyright (C) 2012 Apple Inc. All rights reserved.
     2 * Copyright (C) 2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2121 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    2222 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    23  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
     23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2424 */
    2525
    26 #ifndef DataLog_h
    27 #define DataLog_h
     26#pragma once
    2827
    29 #include <stdarg.h>
    30 #include <stdio.h>
    31 #include <wtf/FilePrintStream.h>
    32 #include <wtf/StdLibExtras.h>
     28#if ENABLE(WEBASSEMBLY)
    3329
    34 namespace WTF {
     30namespace JSC {
    3531
    36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile();
     32namespace WASM {
    3733
    38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0);
    39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);
    40 WTF_EXPORT_PRIVATE void dataLogFString(const char*);
     34// These should be in the order that we expect them to be in the binary.
     35#define FOR_EACH_WASM_SECTION_TYPE(macro) \
     36    macro(FunctionTypes, "type") \
     37    macro(Signatures, "function") \
     38    macro(Definitions, "code") \
     39    macro(End, "end")
    4140
    42 template<typename... Types>
    43 void dataLog(const Types&... values)
    44 {
    45     dataFile().print(values...);
    46 }
     41struct WASMSections {
     42    enum class Section {
     43#define CREATE_SECTION_ENUM(name, str) name,
     44        FOR_EACH_WASM_SECTION_TYPE(CREATE_SECTION_ENUM)
     45#undef CREATE_SECTION_ENUM
     46        Unknown
     47    };
     48    static Section lookup(const uint8_t*, unsigned);
     49    static bool validateOrder(Section previous, Section next)
     50    {
     51        // This allows unknown sections after End, which I doubt will ever be supported but
     52        // there is no reason to potentially break backwards compatability.
     53        if (previous == Section::Unknown)
     54            return true;
     55        return previous < next;
     56    }
     57};
    4758
    48 } // namespace WTF
     59} // namespace WASM
    4960
    50 using WTF::dataLog;
    51 using WTF::dataLogF;
    52 using WTF::dataLogFString;
     61} // namespace JSC
    5362
    54 #endif // DataLog_h
    55 
     63#endif // ENABLE(WEBASSEMBLY)
  • trunk/Source/WTF/ChangeLog

    r204472 r204484  
     12016-08-15  Keith Miller  <keith_miller@apple.com>
     2
     3        Implement WASM Parser and B3 IR generator
     4        https://bugs.webkit.org/show_bug.cgi?id=160681
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * wtf/DataLog.h:
     9        (WTF::dataLogLn): Add a new dataLog function, dataLogLn that
     10        automagically includes a new line at the end of the print.
     11        * wtf/LEBDecoder.h:
     12        (decodeUInt32):
     13        (decodeInt32): Change the LEBDecoder to take a pointer and length
     14        rather than a Vector.
     15
    1162016-08-15  Keith Rollin  <krollin@apple.com>
    217
  • trunk/Source/WTF/wtf/DataLog.h

    r164424 r204484  
    4646}
    4747
     48template<typename... Types>
     49void dataLogLn(const Types&... values)
     50{
     51    dataFile().print(values..., "\n");
     52}
     53
    4854} // namespace WTF
    4955
    5056using WTF::dataLog;
     57using WTF::dataLogLn;
    5158using WTF::dataLogF;
    5259using WTF::dataLogFString;
  • trunk/Source/WTF/wtf/LEBDecoder.h

    r204218 r204484  
    2727
    2828#include "Compiler.h"
    29 #include "Vector.h"
    3029#include <algorithm>
    31 
    32 #include "DataLog.h"
    3330
    3431// This file contains a bunch of helper functions for decoding LEB numbers.
     
    3835const size_t maxLEBByteLength = 5;
    3936
    40 inline bool WARN_UNUSED_RETURN decodeUInt32(const Vector<uint8_t>& bytes, size_t& offset, uint32_t& result)
     37inline bool WARN_UNUSED_RETURN decodeUInt32(const uint8_t* bytes, size_t length, size_t& offset, uint32_t& result)
    4138{
    42     ASSERT(bytes.size() > offset);
     39    ASSERT(length > offset);
    4340    result = 0;
    4441    unsigned shift = 0;
    45     size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
     42    size_t last = std::min(maxLEBByteLength, length - offset - 1);
    4643    for (unsigned i = 0; true; ++i) {
    4744        uint8_t byte = bytes[offset++];
     
    5754}
    5855
    59 inline bool WARN_UNUSED_RETURN decodeInt32(const Vector<uint8_t>& bytes, size_t& offset, int32_t& result)
     56inline bool WARN_UNUSED_RETURN decodeInt32(const uint8_t* bytes, size_t length, size_t& offset, int32_t& result)
    6057{
    61     ASSERT(bytes.size() > offset);
     58    ASSERT(length > offset);
    6259    result = 0;
    6360    unsigned shift = 0;
    64     size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
     61    size_t last = std::min(maxLEBByteLength, length - offset - 1);
    6562    uint8_t byte;
    6663    for (unsigned i = 0; true; ++i) {
Note: See TracChangeset for help on using the changeset viewer.