Changeset 187531 in webkit


Ignore:
Timestamp:
Jul 28, 2015 5:55:17 PM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Implement WebAssembly module parser
https://bugs.webkit.org/show_bug.cgi?id=147293

Patch by Sukolsak Sakshuwong <Sukolsak Sakshuwong> on 2015-07-28
Reviewed by Geoffrey Garen.

Implement WebAssembly module parser for WebAssembly files produced by pack-asmjs
<https://github.com/WebAssembly/polyfill-prototype-1>. This patch only checks
the magic number at the beginning of the files. Parsing of the rest will be
implemented in a subsequent patch.

(GlobalObject::finishCreation):
(functionLoadWebAssembly):

  • parser/SourceProvider.h:

(JSC::WebAssemblySourceProvider::create):
(JSC::WebAssemblySourceProvider::data):
(JSC::WebAssemblySourceProvider::WebAssemblySourceProvider):

  • runtime/JSGlobalObject.cpp:

(JSC::JSGlobalObject::init):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSC::JSGlobalObject::wasmModuleStructure):

  • wasm/WASMMagicNumber.h: Added.
  • wasm/WASMModuleParser.cpp: Added.

(JSC::WASMModuleParser::WASMModuleParser):
(JSC::WASMModuleParser::parse):
(JSC::WASMModuleParser::parseModule):
(JSC::parseWebAssembly):

  • wasm/WASMModuleParser.h: Added.
  • wasm/WASMReader.cpp: Added.

(JSC::WASMReader::readUnsignedInt32):
(JSC::WASMReader::readFloat):
(JSC::WASMReader::readDouble):

  • wasm/WASMReader.h: Added.

(JSC::WASMReader::WASMReader):

Location:
trunk/Source/JavaScriptCore
Files:
5 added
9 edited

Legend:

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

    r187515 r187531  
    412412
    413413    wasm/JSWASMModule.cpp
     414    wasm/WASMModuleParser.cpp
     415    wasm/WASMReader.cpp
    414416
    415417    yarr/RegularExpression.cpp
  • trunk/Source/JavaScriptCore/ChangeLog

    r187529 r187531  
     12015-07-28  Sukolsak Sakshuwong  <sukolsak@gmail.com>
     2
     3        Implement WebAssembly module parser
     4        https://bugs.webkit.org/show_bug.cgi?id=147293
     5
     6        Reviewed by Geoffrey Garen.
     7
     8        Implement WebAssembly module parser for WebAssembly files produced by pack-asmjs
     9        <https://github.com/WebAssembly/polyfill-prototype-1>. This patch only checks
     10        the magic number at the beginning of the files. Parsing of the rest will be
     11        implemented in a subsequent patch.
     12
     13        * CMakeLists.txt:
     14        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj:
     15        * JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters:
     16        * JavaScriptCore.xcodeproj/project.pbxproj:
     17        * jsc.cpp:
     18        (GlobalObject::finishCreation):
     19        (functionLoadWebAssembly):
     20        * parser/SourceProvider.h:
     21        (JSC::WebAssemblySourceProvider::create):
     22        (JSC::WebAssemblySourceProvider::data):
     23        (JSC::WebAssemblySourceProvider::WebAssemblySourceProvider):
     24        * runtime/JSGlobalObject.cpp:
     25        (JSC::JSGlobalObject::init):
     26        (JSC::JSGlobalObject::visitChildren):
     27        * runtime/JSGlobalObject.h:
     28        (JSC::JSGlobalObject::wasmModuleStructure):
     29        * wasm/WASMMagicNumber.h: Added.
     30        * wasm/WASMModuleParser.cpp: Added.
     31        (JSC::WASMModuleParser::WASMModuleParser):
     32        (JSC::WASMModuleParser::parse):
     33        (JSC::WASMModuleParser::parseModule):
     34        (JSC::parseWebAssembly):
     35        * wasm/WASMModuleParser.h: Added.
     36        * wasm/WASMReader.cpp: Added.
     37        (JSC::WASMReader::readUnsignedInt32):
     38        (JSC::WASMReader::readFloat):
     39        (JSC::WASMReader::readDouble):
     40        * wasm/WASMReader.h: Added.
     41        (JSC::WASMReader::WASMReader):
     42
    1432015-07-28  Yusuke Suzuki  <utatane.tea@gmail.com>
    244
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj

    r187515 r187531  
    869869    <ClCompile Include="..\tools\JSDollarVMPrototype.cpp" />
    870870    <ClCompile Include="..\wasm\JSWASMModule.cpp" />
     871    <ClCompile Include="..\wasm\WASMModuleParser.cpp" />
     872    <ClCompile Include="..\wasm\WASMReader.cpp" />
    871873    <ClCompile Include="..\yarr\RegularExpression.cpp" />
    872874    <ClCompile Include="..\yarr\YarrCanonicalizeUCS2.cpp" />
     
    17351737    <ClInclude Include="..\tools\TieredMMapArray.h" />
    17361738    <ClInclude Include="..\wasm\JSWASMModule.h" />
     1739    <ClInclude Include="..\wasm\WASMMagicNumber.h" />
     1740    <ClInclude Include="..\wasm\WASMModuleParser.h" />
     1741    <ClInclude Include="..\wasm\WASMReader.h" />
    17371742    <ClInclude Include="..\yarr\RegularExpression.h" />
    17381743    <ClInclude Include="..\yarr\Yarr.h" />
  • trunk/Source/JavaScriptCore/JavaScriptCore.vcxproj/JavaScriptCore.vcxproj.filters

    r187515 r187531  
    17981798      <Filter>wasm</Filter>
    17991799    </ClCompile>
     1800    <ClCompile Include="..\wasm\WASMModuleParser.cpp">
     1801      <Filter>wasm</Filter>
     1802    </ClCompile>
     1803    <ClCompile Include="..\wasm\WASMReader.cpp">
     1804      <Filter>wasm</Filter>
     1805    </ClCompile>
    18001806  </ItemGroup>
    18011807  <ItemGroup>
     
    43024308      <Filter>wasm</Filter>
    43034309    </ClInclude>
     4310    <ClInclude Include="..\wasm\WASMMagicNumber.h">
     4311      <Filter>wasm</Filter>
     4312    </ClInclude>
     4313    <ClInclude Include="..\wasm\WASMModuleParser.h">
     4314      <Filter>wasm</Filter>
     4315    </ClInclude>
     4316    <ClInclude Include="..\wasm\WASMReader.h">
     4317      <Filter>wasm</Filter>
     4318    </ClInclude>
    43044319  </ItemGroup>
    43054320  <ItemGroup>
  • trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj

    r187515 r187531  
    10221022                79EE0BFF1B4AFB85000385C9 /* VariableEnvironment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 79EE0BFD1B4AFB85000385C9 /* VariableEnvironment.cpp */; };
    10231023                79EE0C001B4AFB85000385C9 /* VariableEnvironment.h in Headers */ = {isa = PBXBuildFile; fileRef = 79EE0BFE1B4AFB85000385C9 /* VariableEnvironment.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1024                7B39F76D1B62DE2E00360FB4 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */; };
     1025                7B39F76E1B62DE3200360FB4 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1026                7B39F7701B62DE3200360FB4 /* WASMReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B39F76C1B62DE2200360FB4 /* WASMReader.h */; settings = {ATTRIBUTES = (Private, ); }; };
     1027                7B39F7721B63574D00360FB4 /* WASMReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B39F7711B63574B00360FB4 /* WASMReader.cpp */; };
     1028                7B7A5E271B68288C0027CAD0 /* WASMMagicNumber.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */; settings = {ATTRIBUTES = (Private, ); }; };
    10241029                7B98D1361B60CD5F0023B1A4 /* JSWASMModule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */; };
    10251030                7B98D1371B60CD620023B1A4 /* JSWASMModule.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    27702775                79EE0BFD1B4AFB85000385C9 /* VariableEnvironment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VariableEnvironment.cpp; sourceTree = "<group>"; };
    27712776                79EE0BFE1B4AFB85000385C9 /* VariableEnvironment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VariableEnvironment.h; sourceTree = "<group>"; };
     2777                7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = "<group>"; };
     2778                7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = "<group>"; };
     2779                7B39F76C1B62DE2200360FB4 /* WASMReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMReader.h; sourceTree = "<group>"; };
     2780                7B39F7711B63574B00360FB4 /* WASMReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMReader.cpp; sourceTree = "<group>"; };
     2781                7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMMagicNumber.h; sourceTree = "<group>"; };
    27722782                7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWASMModule.cpp; sourceTree = "<group>"; };
    27732783                7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSWASMModule.h; sourceTree = "<group>"; };
     
    43084318                                7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
    43094319                                7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
     4320                                7B7A5E261B6828840027CAD0 /* WASMMagicNumber.h */,
     4321                                7B39F7691B62DE2200360FB4 /* WASMModuleParser.cpp */,
     4322                                7B39F76A1B62DE2200360FB4 /* WASMModuleParser.h */,
     4323                                7B39F7711B63574B00360FB4 /* WASMReader.cpp */,
     4324                                7B39F76C1B62DE2200360FB4 /* WASMReader.h */,
    43104325                        );
    43114326                        path = wasm;
     
    62156230                                0F2B66F517B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototype.h in Headers */,
    62166231                                0F2B66F617B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototypeInlines.h in Headers */,
     6232                                7B39F76E1B62DE3200360FB4 /* WASMModuleParser.h in Headers */,
    62176233                                BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */,
    62186234                                A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */,
     
    64266442                                0FF7168C15A3B235008F5DAA /* PropertyOffset.h in Headers */,
    64276443                                A785F6BC18C553FE00F10626 /* SpillRegistersMode.h in Headers */,
     6444                                7B7A5E271B68288C0027CAD0 /* WASMMagicNumber.h in Headers */,
    64286445                                BC18C4550E16F5CD00B34460 /* PropertySlot.h in Headers */,
    64296446                                0FB7F39C15ED8E4600F167B2 /* PropertyStorage.h in Headers */,
     
    65596576                                A7B601821639FD2A00372BA3 /* UnlinkedCodeBlock.h in Headers */,
    65606577                                0F2E892C16D028AD009E4FD2 /* UnusedPointer.h in Headers */,
     6578                                7B39F7701B62DE3200360FB4 /* WASMReader.h in Headers */,
    65616579                                0F963B3813FC6FE90002D9B2 /* ValueProfile.h in Headers */,
    65626580                                0F426A481460CBB300131F8F /* ValueRecovery.h in Headers */,
     
    71937211                                0F9D36941AE9CC33000D4DFB /* DFGCleanUpPhase.cpp in Sources */,
    71947212                                A7D89CF717A0B8CC00773AD8 /* DFGFlushFormat.cpp in Sources */,
     7213                                7B39F76D1B62DE2E00360FB4 /* WASMModuleParser.cpp in Sources */,
    71957214                                0F3A1BF91A9ECB7D000DE01A /* DFGPutStackSinkingPhase.cpp in Sources */,
    71967215                                86EC9DC71328DF82002B2AD7 /* DFGGraph.cpp in Sources */,
     
    76077626                                62D2D38F1ADF103F000206C1 /* FunctionRareData.cpp in Sources */,
    76087627                                0F7700921402FF3C0078EB39 /* SamplingCounter.cpp in Sources */,
     7628                                7B39F7721B63574D00360FB4 /* WASMReader.cpp in Sources */,
    76097629                                1429D8850ED21C3D00B89619 /* SamplingTool.cpp in Sources */,
    76107630                                70EC0EC61AA0D7DA00B6AAFA /* StringIteratorPrototype.cpp in Sources */,
  • trunk/Source/JavaScriptCore/jsc.cpp

    r187139 r187531  
    4444#include "JSProxy.h"
    4545#include "JSString.h"
     46#include "JSWASMModule.h"
    4647#include "ProfilerDatabase.h"
    4748#include "SamplingTool.h"
     
    5152#include "TestRunnerUtils.h"
    5253#include "TypeProfilerLog.h"
     54#include "WASMModuleParser.h"
    5355#include <math.h>
    5456#include <stdio.h>
     
    493495static EncodedJSValue JSC_HOST_CALL functionHasBasicBlockExecuted(ExecState*);
    494496static EncodedJSValue JSC_HOST_CALL functionEnableExceptionFuzz(ExecState*);
     497#if ENABLE(WEBASSEMBLY)
     498static EncodedJSValue JSC_HOST_CALL functionLoadWebAssembly(ExecState*);
     499#endif
    495500
    496501#if ENABLE(SAMPLING_FLAGS)
     
    656661        addFunction(vm, "enableExceptionFuzz", functionEnableExceptionFuzz, 0);
    657662       
     663#if ENABLE(WEBASSEMBLY)
     664        addFunction(vm, "loadWebAssembly", functionLoadWebAssembly, 1);
     665#endif
     666
    658667        JSArray* array = constructEmptyArray(globalExec(), 0);
    659668        for (size_t i = 0; i < arguments.size(); ++i)
     
    11831192    return JSValue::encode(jsUndefined());
    11841193}
     1194
     1195#if ENABLE(WEBASSEMBLY)
     1196EncodedJSValue JSC_HOST_CALL functionLoadWebAssembly(ExecState* exec)
     1197{
     1198    String fileName = exec->argument(0).toString(exec)->value(exec);
     1199    Vector<char> buffer;
     1200    if (!fillBufferWithContentsOfFile(fileName, buffer))
     1201        return JSValue::encode(exec->vm().throwException(exec, createError(exec, ASCIILiteral("Could not open file."))));
     1202    RefPtr<WebAssemblySourceProvider> sourceProvider = WebAssemblySourceProvider::create(reinterpret_cast<Vector<uint8_t>&>(buffer), fileName);
     1203    SourceCode source(sourceProvider);
     1204    String errorMessage;
     1205    JSWASMModule* module = parseWebAssembly(exec, source, errorMessage);
     1206    if (!module)
     1207        return JSValue::encode(exec->vm().throwException(exec, createSyntaxError(exec, errorMessage)));
     1208    return JSValue::encode(module);
     1209}
     1210#endif
    11851211
    11861212// Use SEH for Release builds only to get rid of the crash report dialog
  • trunk/Source/JavaScriptCore/parser/SourceProvider.h

    r185346 r187531  
    9595    };
    9696   
     97#if ENABLE(WEBASSEMBLY)
     98    class WebAssemblySourceProvider : public SourceProvider {
     99    public:
     100        static Ref<WebAssemblySourceProvider> create(const Vector<uint8_t>& data, const String& url)
     101        {
     102            return adoptRef(*new WebAssemblySourceProvider(data, url));
     103        }
     104
     105        virtual const String& source() const override
     106        {
     107            return m_source;
     108        }
     109
     110        const Vector<uint8_t>& data() const
     111        {
     112            return m_data;
     113        }
     114
     115    private:
     116        WebAssemblySourceProvider(const Vector<uint8_t>& data, const String& url)
     117            : SourceProvider(url, TextPosition::minimumPosition())
     118            , m_source("[WebAssembly source]")
     119            , m_data(data)
     120        {
     121        }
     122
     123        String m_source;
     124        Vector<uint8_t> m_data;
     125    };
     126#endif
     127
    97128} // namespace JSC
    98129
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r187515 r187531  
    9393#include "JSTypedArrayPrototypes.h"
    9494#include "JSTypedArrays.h"
     95#include "JSWASMModule.h"
    9596#include "JSWeakMap.h"
    9697#include "JSWeakSet.h"
     
    341342    m_promiseStructure.set(vm, this, JSPromise::createStructure(vm, this, m_promisePrototype.get()));
    342343
     344#if ENABLE(WEBASSEMBLY)
     345    m_wasmModuleStructure.set(vm, this, JSWASMModule::createStructure(vm, this));
     346#endif
     347
    343348    m_parseIntFunction.set(vm, this, JSFunction::create(vm, this, 2, vm.propertyNames->parseInt.string(), globalFuncParseInt, NoIntrinsic));
    344349    putDirectWithoutTransition(vm, vm.propertyNames->parseInt, m_parseIntFunction.get(), DontEnum | Function);
     
    802807    visitor.append(&thisObject->m_internalFunctionStructure);
    803808    visitor.append(&thisObject->m_promiseStructure);
     809#if ENABLE(WEBASSEMBLY)
     810    visitor.append(&thisObject->m_wasmModuleStructure);
     811#endif
    804812
    805813#define VISIT_SIMPLE_TYPE(CapitalName, lowerName, properName, instanceType, jsName) \
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h

    r187515 r187531  
    244244    WriteBarrier<Structure> m_regExpMatchesArrayStructure;
    245245    WriteBarrier<Structure> m_promiseStructure;
     246#if ENABLE(WEBASSEMBLY)
     247    WriteBarrier<Structure> m_wasmModuleStructure;
     248#endif
    246249
    247250#define DEFINE_STORAGE_FOR_SIMPLE_TYPE(capitalName, lowerName, properName, instanceType, jsName) \
     
    476479    Structure* regExpMatchesArrayStructure() const { return m_regExpMatchesArrayStructure.get(); }
    477480    Structure* promiseStructure() const { return m_promiseStructure.get(); }
     481#if ENABLE(WEBASSEMBLY)
     482    Structure* wasmModuleStructure() const { return m_wasmModuleStructure.get(); }
     483#endif
    478484
    479485    JS_EXPORT_PRIVATE void setRemoteDebuggingEnabled(bool);
Note: See TracChangeset for help on using the changeset viewer.