| Differences between
and this patch
- a/Source/JavaScriptCore/ChangeLog +96 lines
Lines 1-3 a/Source/JavaScriptCore/ChangeLog_sec1
1
2016-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 NOBODY (OOPS!).
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::matchCharacter):
84
        (JSC::WASM::WASMParser::matchString):
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
1
2016-08-08  Brian Burg  <bburg@apple.com>
97
2016-08-08  Brian Burg  <bburg@apple.com>
2
98
3
        Web Inspector: clean up prefixing of Automation protocol generated files
99
        Web Inspector: clean up prefixing of Automation protocol generated files
- a/Source/WTF/ChangeLog +15 lines
Lines 1-3 a/Source/WTF/ChangeLog_sec1
1
2016-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 NOBODY (OOPS!).
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
1
2016-08-06  Sam Weinig  <sam@webkit.org>
16
2016-08-06  Sam Weinig  <sam@webkit.org>
2
17
3
        WTF needs a variant implementation
18
        WTF needs a variant implementation
- a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj +44 lines
Lines 1174-1179 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec1
1174
		52C0611F1AA51E1C00B4ADBA /* RuntimeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */; settings = {ATTRIBUTES = (Private, ); }; };
1174
		52C0611F1AA51E1C00B4ADBA /* RuntimeType.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */; settings = {ATTRIBUTES = (Private, ); }; };
1175
		52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
1175
		52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
1176
		52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
1176
		52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; };
1177
		531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = 531374BC1D5CE67600AF7A0B /* WASMPlan.h */; };
1178
		531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */; };
1177
		53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
1179
		53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; };
1178
		53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; };
1180
		53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; };
1179
		534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */; };
1181
		534902851C7276B70012BCB8 /* TypedArrayCTest.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */; };
Lines 1187-1192 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec2
1187
		539EB07A1D55607000C82EF7 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };
1189
		539EB07A1D55607000C82EF7 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 932F5BD90822A1C700736975 /* JavaScriptCore.framework */; };
1188
		539EB0811D55608A00C82EF7 /* testWASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWASM.cpp */; };
1190
		539EB0811D55608A00C82EF7 /* testWASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWASM.cpp */; };
1189
		539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; };
1191
		539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; };
1192
		53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; };
1193
		53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; };
1194
		53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; };
1195
		53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; };
1196
		53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */; };
1197
		53F40E911D5903020099A1B6 /* WASMOps.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E901D5903020099A1B6 /* WASMOps.h */; };
1198
                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */; };
1199
		53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */; };
1200
		53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */; };
1190
		53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
1201
		53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; };
1191
		53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
1202
		53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; };
1192
		53FA2AE31CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */; };
1203
		53FA2AE31CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */; };
Lines 3342-3347 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec3
3342
		52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeType.h; sourceTree = "<group>"; };
3353
		52C0611D1AA51E1B00B4ADBA /* RuntimeType.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RuntimeType.h; sourceTree = "<group>"; };
3343
		52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
3354
		52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; };
3344
		52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
3355
		52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; };
3356
		531374BC1D5CE67600AF7A0B /* WASMPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMPlan.h; sourceTree = "<group>"; };
3357
		531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMPlan.cpp; sourceTree = "<group>"; };
3345
		53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; };
3358
		53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; };
3346
		53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; };
3359
		53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; };
3347
		534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayCTest.cpp; path = API/tests/TypedArrayCTest.cpp; sourceTree = "<group>"; };
3360
		534902821C7242C80012BCB8 /* TypedArrayCTest.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = TypedArrayCTest.cpp; path = API/tests/TypedArrayCTest.cpp; sourceTree = "<group>"; };
Lines 3359-3364 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec4
3359
		539EB0801D55607000C82EF7 /* testWASM */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testWASM; sourceTree = BUILT_PRODUCTS_DIR; };
3372
		539EB0801D55607000C82EF7 /* testWASM */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = testWASM; sourceTree = BUILT_PRODUCTS_DIR; };
3360
		539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; };
3373
		539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; };
3361
		53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; };
3374
		53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; };
3375
		53F40E841D58F9770099A1B6 /* WASMSections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMSections.h; sourceTree = "<group>"; };
3376
		53F40E861D58F9D60099A1B6 /* WASMSections.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMSections.cpp; sourceTree = "<group>"; };
3377
		53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; };
3378
		53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = "<group>"; };
3379
		53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMB3IRGenerator.cpp; sourceTree = "<group>"; };
3380
		53F40E901D5903020099A1B6 /* WASMOps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMOps.h; sourceTree = "<group>"; };
3381
                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMB3IRGenerator.h; sourceTree = "<group>"; };
3382
		53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = "<group>"; };
3383
		53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = "<group>"; };
3362
		53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalFunctionAllocationProfile.h; sourceTree = "<group>"; };
3384
		53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalFunctionAllocationProfile.h; sourceTree = "<group>"; };
3363
		53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.h; sourceTree = "<group>"; };
3385
		53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.h; sourceTree = "<group>"; };
3364
		53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp; sourceTree = "<group>"; };
3386
		53FA2AE21CF380390022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.cpp; sourceTree = "<group>"; };
Lines 5525-5531 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec5
5525
			children = (
5547
			children = (
5526
				7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
5548
				7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */,
5527
				7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
5549
				7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */,
5550
				53F40E901D5903020099A1B6 /* WASMOps.h */,
5528
				7BC547D21B69599B00959B58 /* WASMFormat.h */,
5551
				7BC547D21B69599B00959B58 /* WASMFormat.h */,
5552
				53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */,
5553
                                53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */,
5554
				53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */,
5555
				53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */,
5556
				53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */,
5557
				531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */,
5558
				531374BC1D5CE67600AF7A0B /* WASMPlan.h */,
5559
				53F40E8C1D5901F20099A1B6 /* WASMParser.h */,
5560
				53F40E861D58F9D60099A1B6 /* WASMSections.cpp */,
5561
				53F40E841D58F9770099A1B6 /* WASMSections.h */,
5529
			);
5562
			);
5530
			path = wasm;
5563
			path = wasm;
5531
			sourceTree = "<group>";
5564
			sourceTree = "<group>";
Lines 7190-7195 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec6
7190
				0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */,
7223
				0F4C91661C29F4F2004341A6 /* B3OriginDump.h in Headers */,
7191
				C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */,
7224
				C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */,
7192
				0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */,
7225
				0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */,
7226
				53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */,
7193
				6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */,
7227
				6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */,
7194
				0F885E111849A3BE00F1E3FA /* BytecodeUseDef.h in Headers */,
7228
				0F885E111849A3BE00F1E3FA /* BytecodeUseDef.h in Headers */,
7195
				0F8023EA1613832B00A0BA45 /* ByValInfo.h in Headers */,
7229
				0F8023EA1613832B00A0BA45 /* ByValInfo.h in Headers */,
Lines 7275-7280 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec7
7275
				BC18C3FB0E16F5CD00B34460 /* DebuggerCallFrame.h in Headers */,
7309
				BC18C3FB0E16F5CD00B34460 /* DebuggerCallFrame.h in Headers */,
7276
				6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */,
7310
				6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */,
7277
				FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */,
7311
				FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */,
7312
				53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */,
7278
				DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */,
7313
				DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */,
7279
				0F2D4DDE19832D34007D4B19 /* DebuggerScope.h in Headers */,
7314
				0F2D4DDE19832D34007D4B19 /* DebuggerScope.h in Headers */,
7280
				0F136D4D174AD69E0075B354 /* DeferGC.h in Headers */,
7315
				0F136D4D174AD69E0075B354 /* DeferGC.h in Headers */,
Lines 7417-7422 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec8
7417
				0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */,
7452
				0F7025AA1714B0FC00382C0E /* DFGOSRExitCompilerCommon.h in Headers */,
7418
				0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */,
7453
				0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */,
7419
				0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */,
7454
				0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */,
7455
				53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */,
7420
				0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */,
7456
				0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */,
7421
				0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */,
7457
				0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */,
7422
				0F6237981AE45CA700D402EA /* DFGPhantomInsertionPhase.h in Headers */,
7458
				0F6237981AE45CA700D402EA /* DFGPhantomInsertionPhase.h in Headers */,
Lines 7571-7576 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec9
7571
				0F2B66AD17B6B54500A7AE3F /* GCIncomingRefCountedInlines.h in Headers */,
7607
				0F2B66AD17B6B54500A7AE3F /* GCIncomingRefCountedInlines.h in Headers */,
7572
				0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */,
7608
				0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */,
7573
				0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */,
7609
				0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */,
7610
				531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */,
7574
				2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
7611
				2AABCDE718EF294200002096 /* GCLogging.h in Headers */,
7575
				0F2BBD981C5FF3F50023EF23 /* B3Variable.h in Headers */,
7612
				0F2BBD981C5FF3F50023EF23 /* B3Variable.h in Headers */,
7576
				A54E8EB018BFFBBB00556D28 /* GCSegmentedArray.h in Headers */,
7613
				A54E8EB018BFFBBB00556D28 /* GCSegmentedArray.h in Headers */,
Lines 7782-7787 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec10
7782
				0F2B66F617B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototypeInlines.h in Headers */,
7819
				0F2B66F617B6B5AB00A7AE3F /* JSGenericTypedArrayViewPrototypeInlines.h in Headers */,
7783
				797E07AA1B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h in Headers */,
7820
				797E07AA1B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h in Headers */,
7784
				BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */,
7821
				BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */,
7822
				53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */,
7785
				996B731D1BDA08EF00331B84 /* JSGlobalObject.lut.h in Headers */,
7823
				996B731D1BDA08EF00331B84 /* JSGlobalObject.lut.h in Headers */,
7786
				A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */,
7824
				A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */,
7787
				A5C3A1A618C0490200C9593A /* JSGlobalObjectConsoleClient.h in Headers */,
7825
				A5C3A1A618C0490200C9593A /* JSGlobalObjectConsoleClient.h in Headers */,
Lines 7841-7846 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec11
7841
				A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */,
7879
				A7C0C4AC168103020017011D /* JSScriptRefPrivate.h in Headers */,
7842
				FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */,
7880
				FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */,
7843
				0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
7881
				0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */,
7882
				53F40E911D5903020099A1B6 /* WASMOps.h in Headers */,
7844
				A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */,
7883
				A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */,
7845
				A790DD70182F499700588807 /* JSSetIterator.h in Headers */,
7884
				A790DD70182F499700588807 /* JSSetIterator.h in Headers */,
7846
				BC18C45E0E16F5CD00B34460 /* CLoopStack.h in Headers */,
7885
				BC18C45E0E16F5CD00B34460 /* CLoopStack.h in Headers */,
Lines 7889-7894 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec12
7889
				0FB5467714F59B5C002C2989 /* LazyOperandValueProfile.h in Headers */,
7928
				0FB5467714F59B5C002C2989 /* LazyOperandValueProfile.h in Headers */,
7890
				99DA00B01BD5994E00F4575C /* lazywriter.py in Headers */,
7929
				99DA00B01BD5994E00F4575C /* lazywriter.py in Headers */,
7891
				BC18C4310E16F5CD00B34460 /* Lexer.h in Headers */,
7930
				BC18C4310E16F5CD00B34460 /* Lexer.h in Headers */,
7931
                                53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */,
7892
				BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */,
7932
				BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */,
7893
				DCF3D56B1CD29472003D5C65 /* LazyClassStructureInlines.h in Headers */,
7933
				DCF3D56B1CD29472003D5C65 /* LazyClassStructureInlines.h in Headers */,
7894
				FE187A021BFBE5610038BBCA /* JITMulGenerator.h in Headers */,
7934
				FE187A021BFBE5610038BBCA /* JITMulGenerator.h in Headers */,
Lines 8921-8926 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec13
8921
				0FBE0F7216C1DB030082C5E8 /* DFGCPSRethreadingPhase.cpp in Sources */,
8961
				0FBE0F7216C1DB030082C5E8 /* DFGCPSRethreadingPhase.cpp in Sources */,
8922
				A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */,
8962
				A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */,
8923
				0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */,
8963
				0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */,
8964
				53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */,
8924
				0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */,
8965
				0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */,
8925
				0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */,
8966
				0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */,
8926
				0F338E121BF0276C0013C88F /* B3OpaqueByproducts.cpp in Sources */,
8967
				0F338E121BF0276C0013C88F /* B3OpaqueByproducts.cpp in Sources */,
Lines 9133-9138 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec14
9133
				9E729407190F01A5001A91B5 /* InitializeThreading.cpp in Sources */,
9174
				9E729407190F01A5001A91B5 /* InitializeThreading.cpp in Sources */,
9134
				A513E5B7185B8BD3007E95AD /* InjectedScript.cpp in Sources */,
9175
				A513E5B7185B8BD3007E95AD /* InjectedScript.cpp in Sources */,
9135
				A514B2C2185A684400F3C7CB /* InjectedScriptBase.cpp in Sources */,
9176
				A514B2C2185A684400F3C7CB /* InjectedScriptBase.cpp in Sources */,
9177
				531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */,
9136
				A58E35911860DECF001F24FE /* InjectedScriptHost.cpp in Sources */,
9178
				A58E35911860DECF001F24FE /* InjectedScriptHost.cpp in Sources */,
9137
				A513E5CA185F9624007E95AD /* InjectedScriptManager.cpp in Sources */,
9179
				A513E5CA185F9624007E95AD /* InjectedScriptManager.cpp in Sources */,
9138
				A5840E20187B7B8600843B10 /* InjectedScriptModule.cpp in Sources */,
9180
				A5840E20187B7B8600843B10 /* InjectedScriptModule.cpp in Sources */,
Lines 9509-9514 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec15
9509
				E18E3A590DF9278C00D90B34 /* VM.cpp in Sources */,
9551
				E18E3A590DF9278C00D90B34 /* VM.cpp in Sources */,
9510
				FE5932A7183C5A2600A1ECCC /* VMEntryScope.cpp in Sources */,
9552
				FE5932A7183C5A2600A1ECCC /* VMEntryScope.cpp in Sources */,
9511
				FE187A011BFBE55E0038BBCA /* JITMulGenerator.cpp in Sources */,
9553
				FE187A011BFBE55E0038BBCA /* JITMulGenerator.cpp in Sources */,
9554
				53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */,
9512
				26718BA41BE99F780052017B /* AirIteratedRegisterCoalescing.cpp in Sources */,
9555
				26718BA41BE99F780052017B /* AirIteratedRegisterCoalescing.cpp in Sources */,
9513
				FED94F2E171E3E2300BE77A4 /* Watchdog.cpp in Sources */,
9556
				FED94F2E171E3E2300BE77A4 /* Watchdog.cpp in Sources */,
9514
				0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */,
9557
				0F919D2515853CE0004A4E7D /* Watchpoint.cpp in Sources */,
Lines 9518-9523 a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj_sec16
9518
				A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */,
9561
				A7CA3AE317DA41AE006538AF /* WeakMapConstructor.cpp in Sources */,
9519
				0F338DF91BE96AA80013C88F /* B3CCallValue.cpp in Sources */,
9562
				0F338DF91BE96AA80013C88F /* B3CCallValue.cpp in Sources */,
9520
				A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
9563
				A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */,
9564
				53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */,
9521
				A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
9565
				A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */,
9522
				14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */,
9566
				14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */,
9523
				709FB8691AE335C60039D069 /* WeakSetConstructor.cpp in Sources */,
9567
				709FB8691AE335C60039D069 /* WeakSetConstructor.cpp in Sources */,
- a/Source/JavaScriptCore/testWASM.cpp -2 / +134 lines
Lines 25-31 a/Source/JavaScriptCore/testWASM.cpp_sec1
25
25
26
#include "config.h"
26
#include "config.h"
27
27
28
#include "B3Compilation.h"
29
#include "InitializeThreading.h"
28
#include "JSString.h"
30
#include "JSString.h"
31
#include "VM.h"
32
#include "WASMPlan.h"
29
#include <wtf/DataLog.h>
33
#include <wtf/DataLog.h>
30
#include <wtf/LEBDecoder.h>
34
#include <wtf/LEBDecoder.h>
31
35
Lines 38-43 public: a/Source/JavaScriptCore/testWASM.cpp_sec2
38
42
39
    Vector<String> m_arguments;
43
    Vector<String> m_arguments;
40
    bool m_runLEBTests { false };
44
    bool m_runLEBTests { false };
45
    bool m_runWASMTests { false };
41
46
42
    void parseArguments(int, char**);
47
    void parseArguments(int, char**);
43
};
48
};
Lines 47-52 static NO_RETURN void printUsageStatement(bool help = false) a/Source/JavaScriptCore/testWASM.cpp_sec3
47
    fprintf(stderr, "Usage: testWASM [options]\n");
52
    fprintf(stderr, "Usage: testWASM [options]\n");
48
    fprintf(stderr, "  -h|--help  Prints this help message\n");
53
    fprintf(stderr, "  -h|--help  Prints this help message\n");
49
    fprintf(stderr, "  -l|--leb   Runs the LEB decoder tests\n");
54
    fprintf(stderr, "  -l|--leb   Runs the LEB decoder tests\n");
55
    fprintf(stderr, "  -w|--web   Run the WASM tests\n");
50
    fprintf(stderr, "\n");
56
    fprintf(stderr, "\n");
51
57
52
    exit(help ? EXIT_SUCCESS : EXIT_FAILURE);
58
    exit(help ? EXIT_SUCCESS : EXIT_FAILURE);
Lines 63-68 void CommandLine::parseArguments(int argc, char** argv) a/Source/JavaScriptCore/testWASM.cpp_sec4
63
69
64
        if (!strcmp(arg, "-l") || !strcmp(arg, "--leb"))
70
        if (!strcmp(arg, "-l") || !strcmp(arg, "--leb"))
65
            m_runLEBTests = true;
71
            m_runLEBTests = true;
72
73
        if (!strcmp(arg, "-w") || !strcmp(arg, "--web"))
74
            m_runWASMTests = true;
66
    }
75
    }
67
76
68
    for (; i < argc; ++i)
77
    for (; i < argc; ++i)
Lines 109-115 void CommandLine::parseArguments(int argc, char** argv) a/Source/JavaScriptCore/testWASM.cpp_sec5
109
        Vector<uint8_t> vector = Vector<uint8_t> init; \
118
        Vector<uint8_t> vector = Vector<uint8_t> init; \
110
        size_t offset = startOffset; \
119
        size_t offset = startOffset; \
111
        uint32_t result; \
120
        uint32_t result; \
112
        bool status = decodeUInt32(vector, offset, result); \
121
        bool status = decodeUInt32(vector.data(), vector.size(), offset, result); \
113
        RELEASE_ASSERT(status == expectedStatus); \
122
        RELEASE_ASSERT(status == expectedStatus); \
114
        if (expectedStatus) { \
123
        if (expectedStatus) { \
115
            RELEASE_ASSERT(result == expectedResult); \
124
            RELEASE_ASSERT(result == expectedResult); \
Lines 157-163 void CommandLine::parseArguments(int argc, char** argv) a/Source/JavaScriptCore/testWASM.cpp_sec6
157
        Vector<uint8_t> vector = Vector<uint8_t> init; \
166
        Vector<uint8_t> vector = Vector<uint8_t> init; \
158
        size_t offset = startOffset; \
167
        size_t offset = startOffset; \
159
        int32_t result; \
168
        int32_t result; \
160
        bool status = decodeInt32(vector, offset, result); \
169
        bool status = decodeInt32(vector.data(), vector.size(), offset, result); \
161
        RELEASE_ASSERT(status == expectedStatus); \
170
        RELEASE_ASSERT(status == expectedStatus); \
162
        if (expectedStatus) { \
171
        if (expectedStatus) { \
163
            int32_t expected = expectedResult; \
172
            int32_t expected = expectedResult; \
Lines 173-178 static void runLEBTests() a/Source/JavaScriptCore/testWASM.cpp_sec7
173
    FOR_EACH_SIGNED_LEB_TEST(TEST_SIGNED_LEB_DECODE)
182
    FOR_EACH_SIGNED_LEB_TEST(TEST_SIGNED_LEB_DECODE)
174
}
183
}
175
184
185
#if ENABLE(WEBASSEMBLY)
186
187
static JSC::VM* vm;
188
189
using namespace JSC;
190
using namespace WASM;
191
using namespace B3;
192
193
template<typename T, typename... Arguments>
194
T invoke(MacroAssemblerCodePtr ptr, Arguments... arguments)
195
{
196
    T (*function)(Arguments...) = bitwise_cast<T(*)(Arguments...)>(ptr.executableAddress());
197
    return function(arguments...);
198
}
199
200
template<typename T, typename... Arguments>
201
T invoke(const Compilation& code, Arguments... arguments)
202
{
203
    return invoke<T>(code.code(), arguments...);
204
}
205
206
// For now we inline the test files.
207
static 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)
176
296
177
int main(int argc, char** argv)
297
int main(int argc, char** argv)
178
{
298
{
Lines 181-186 int main(int argc, char** argv) a/Source/JavaScriptCore/testWASM.cpp_sec8
181
    if (options.m_runLEBTests)
301
    if (options.m_runLEBTests)
182
        runLEBTests();
302
        runLEBTests();
183
303
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
184
    return EXIT_SUCCESS;
316
    return EXIT_SUCCESS;
185
}
317
}
186
318
- a/Source/JavaScriptCore/wasm/JSWASMModule.h -2 / +2 lines
Lines 79-85 public: a/Source/JavaScriptCore/wasm/JSWASMModule.h_sec1
79
    Vector<WASMSignature>& signatures() { return m_signatures; }
79
    Vector<WASMSignature>& signatures() { return m_signatures; }
80
    Vector<WASMFunctionImport>& functionImports() { return m_functionImports; }
80
    Vector<WASMFunctionImport>& functionImports() { return m_functionImports; }
81
    Vector<WASMFunctionImportSignature>& functionImportSignatures() { return m_functionImportSignatures; }
81
    Vector<WASMFunctionImportSignature>& functionImportSignatures() { return m_functionImportSignatures; }
82
    Vector<WASMType>& globalVariableTypes() { return m_globalVariableTypes; }
82
    Vector<WASMValueType>& globalVariableTypes() { return m_globalVariableTypes; }
83
    Vector<WASMFunctionDeclaration>& functionDeclarations() { return m_functionDeclarations; }
83
    Vector<WASMFunctionDeclaration>& functionDeclarations() { return m_functionDeclarations; }
84
    Vector<WASMFunctionPointerTable>& functionPointerTables() { return m_functionPointerTables; }
84
    Vector<WASMFunctionPointerTable>& functionPointerTables() { return m_functionPointerTables; }
85
85
Lines 99-105 private: a/Source/JavaScriptCore/wasm/JSWASMModule.h_sec2
99
    Vector<WASMSignature> m_signatures;
99
    Vector<WASMSignature> m_signatures;
100
    Vector<WASMFunctionImport> m_functionImports;
100
    Vector<WASMFunctionImport> m_functionImports;
101
    Vector<WASMFunctionImportSignature> m_functionImportSignatures;
101
    Vector<WASMFunctionImportSignature> m_functionImportSignatures;
102
    Vector<WASMType> m_globalVariableTypes;
102
    Vector<WASMValueType> m_globalVariableTypes;
103
    Vector<WASMFunctionDeclaration> m_functionDeclarations;
103
    Vector<WASMFunctionDeclaration> m_functionDeclarations;
104
    Vector<WASMFunctionPointerTable> m_functionPointerTables;
104
    Vector<WASMFunctionPointerTable> m_functionPointerTables;
105
105
- a/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp +201 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMB3IRGenerator.cpp_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#include "config.h"
27
#include "WASMB3IRGenerator.h"
28
29
#include "B3BasicBlockInlines.h"
30
#include "B3ValueInlines.h"
31
#include "B3Variable.h"
32
#include "B3VariableValue.h"
33
#include "WASMFunctionParser.h"
34
#include <wtf/Optional.h>
35
36
#if ENABLE(WEBASSEMBLY)
37
38
namespace JSC {
39
40
namespace WASM {
41
42
using namespace B3;
43
44
class B3IRGenerator {
45
public:
46
    typedef Value* ExpressionType;
47
48
    B3IRGenerator(Procedure&);
49
50
    void addLocal(WASMValueType, uint32_t);
51
    ExpressionType addConstant(WASMValueType, uint64_t);
52
53
    bool WARN_UNUSED_RETURN binaryOp(WASMBinaryOpType, ExpressionType left, ExpressionType right, ExpressionType& result);
54
55
    bool WARN_UNUSED_RETURN addBlock();
56
    bool WARN_UNUSED_RETURN endBlock(Vector<ExpressionType>& expressionStack);
57
    bool WARN_UNUSED_RETURN addReturn(const Vector<ExpressionType, 1>& returnValues);
58
59
private:
60
    Optional<Vector<Variable*>>& stackForControlLevel(unsigned);
61
    BasicBlock* blockForControlLevel(unsigned);
62
    void unify(Variable* target, const ExpressionType source);
63
    Vector<Variable*> initializeIncommingTypes(BasicBlock*, const Vector<ExpressionType>&);
64
    void unifyValuesWithLevel(const Vector<ExpressionType>& resultStack, unsigned);
65
66
    Procedure& m_proc;
67
    BasicBlock* m_currentBlock;
68
    // This is a pair of the continuation and the types expected on the stack for that continuation.
69
    Vector<std::pair<BasicBlock*, Optional<Vector<Variable*>>>> m_controlStack;
70
};
71
72
B3IRGenerator::B3IRGenerator(Procedure& procedure)
73
    : m_proc(procedure)
74
{
75
    m_currentBlock = m_proc.addBlock();
76
}
77
78
void B3IRGenerator::addLocal(WASMValueType, uint32_t)
79
{
80
    // TODO: Add locals.
81
}
82
83
bool B3IRGenerator::binaryOp(WASMBinaryOpType op, ExpressionType left, ExpressionType right, ExpressionType& result)
84
{
85
    switch (op) {
86
    case WASMBinaryOpType::I32Add: {
87
        ASSERT(left->type() == B3::Int32 && right->type() == B3::Int32);
88
        result = m_currentBlock->appendNew<Value>(m_proc, Add, Origin(), left, right);
89
        return true;
90
    }
91
    }
92
}
93
94
B3IRGenerator::ExpressionType B3IRGenerator::addConstant(WASMValueType type, uint64_t value)
95
{
96
    switch (type) {
97
    case WASMValueType::I32:
98
        return m_currentBlock->appendNew<Const32Value>(m_proc, Origin(), static_cast<int32_t>(value));
99
    case WASMValueType::I64:
100
        return m_currentBlock->appendNew<Const64Value>(m_proc, Origin(), value);
101
    case WASMValueType::F32:
102
        return m_currentBlock->appendNew<ConstFloatValue>(m_proc, Origin(), bitwise_cast<float>(static_cast<int32_t>(value)));
103
    case WASMValueType::F64:
104
        return m_currentBlock->appendNew<ConstDoubleValue>(m_proc, Origin(), bitwise_cast<double>(value));
105
    default:
106
        RELEASE_ASSERT_NOT_REACHED();
107
        return nullptr;
108
    }
109
}
110
111
bool B3IRGenerator::addBlock()
112
{
113
    m_controlStack.append(std::make_pair(m_proc.addBlock(), Nullopt));
114
    return true;
115
}
116
117
bool B3IRGenerator::endBlock(Vector<ExpressionType>& expressionStack)
118
{
119
    // This means that we are exiting the function.
120
    if (!m_controlStack.size()) {
121
        // FIXME: Should this require the stack is empty? It's not clear from the current spec.
122
        return !expressionStack.size();
123
    }
124
125
    unifyValuesWithLevel(expressionStack, 0);
126
127
    m_currentBlock = m_controlStack.takeLast().first;
128
    return true;
129
}
130
131
bool B3IRGenerator::addReturn(const Vector<ExpressionType, 1>& returnValues)
132
{
133
    ASSERT(returnValues.size() <= 1);
134
    if (returnValues.size())
135
        m_currentBlock->appendNewControlValue(m_proc, B3::Return, Origin(), returnValues[0]);
136
    else
137
        m_currentBlock->appendNewControlValue(m_proc, B3::Return, Origin());
138
    return true;
139
}
140
141
void B3IRGenerator::unify(Variable* variable, ExpressionType source)
142
{
143
    m_currentBlock->appendNew<VariableValue>(m_proc, Set, Origin(), variable, source);
144
}
145
146
Vector<Variable*> B3IRGenerator::initializeIncommingTypes(BasicBlock* block, const Vector<ExpressionType>& source)
147
{
148
    Vector<Variable*> result;
149
    result.reserveInitialCapacity(source.size());
150
    for (ExpressionType expr : source) {
151
        ASSERT(expr->type() != Void);
152
        Variable* var = m_proc.addVariable(expr->type());
153
        result.append(var);
154
        block->appendNew<VariableValue>(m_proc, B3::Get, Origin(), var);
155
    }
156
157
    return result;
158
}
159
160
void B3IRGenerator::unifyValuesWithLevel(const Vector<ExpressionType>& resultStack, unsigned level)
161
{
162
    ASSERT(level < m_controlStack.size());
163
164
    Optional<Vector<Variable*>>& expectedStack = stackForControlLevel(level);
165
    if (!expectedStack) {
166
        expectedStack = initializeIncommingTypes(blockForControlLevel(level), resultStack);
167
        return;
168
    }
169
170
    ASSERT(expectedStack.value().size() != resultStack.size());
171
172
    for (size_t i = 0; i < resultStack.size(); ++i)
173
        unify(expectedStack.value()[i], resultStack[i]);
174
}
175
    
176
Optional<Vector<Variable*>>& B3IRGenerator::stackForControlLevel(unsigned level)
177
{
178
    return m_controlStack[m_controlStack.size() - 1 - level].second;
179
}
180
181
BasicBlock* B3IRGenerator::blockForControlLevel(unsigned level)
182
{
183
    return m_controlStack[m_controlStack.size() - 1 - level].first;
184
}
185
186
std::unique_ptr<Compilation> parseAndCompile(VM& vm, Vector<uint8_t>& source, WASMFunctionInformation info, unsigned optLevel)
187
{
188
    Procedure procedure;
189
    B3IRGenerator context(procedure);
190
    WASMFunctionParser<B3IRGenerator> parser(context, source, info);
191
    if (!parser.parse())
192
        RELEASE_ASSERT_NOT_REACHED();
193
194
    return std::make_unique<Compilation>(vm, procedure, optLevel);
195
}
196
197
} // namespace WASM
198
199
} // namespace JSC
200
201
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h +44 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#include "B3Compilation.h"
29
#include "VM.h"
30
#include "WASMFormat.h"
31
32
#if ENABLE(WEBASSEMBLY)
33
34
namespace JSC {
35
36
namespace WASM {
37
38
std::unique_ptr<B3::Compilation> parseAndCompile(VM&, Vector<uint8_t>&, WASMFunctionInformation, unsigned optLevel = 1);
39
40
} // namespace WASM
41
42
} // namespace JSC
43
44
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMFormat.h -4 / +11 lines
Lines 52-66 namespace JSC { a/Source/JavaScriptCore/wasm/WASMFormat.h_sec1
52
52
53
class JSFunction;
53
class JSFunction;
54
54
55
enum class WASMType : uint8_t {
55
enum class WASMValueType : uint8_t {
56
    I32,
56
    I32,
57
    I64,
57
    F32,
58
    F32,
58
    F64,
59
    F64,
59
    NumberOfTypes
60
    NumberOfTypes
60
};
61
};
61
62
62
enum class WASMExpressionType : uint8_t {
63
enum class WASMFunctionReturnType : uint8_t {
63
    I32,
64
    I32,
65
    I64,
64
    F32,
66
    F32,
65
    F64,
67
    F64,
66
    Void,
68
    Void,
Lines 68-75 enum class WASMExpressionType : uint8_t { a/Source/JavaScriptCore/wasm/WASMFormat.h_sec2
68
};
70
};
69
71
70
struct WASMSignature {
72
struct WASMSignature {
71
    WASMExpressionType returnType;
73
    WASMFunctionReturnType returnType;
72
    Vector<WASMType> arguments;
74
    Vector<WASMValueType> arguments;
73
};
75
};
74
76
75
struct WASMFunctionImport {
77
struct WASMFunctionImport {
Lines 91-96 struct WASMFunctionPointerTable { a/Source/JavaScriptCore/wasm/WASMFormat.h_sec3
91
    Vector<JSFunction*> functions;
93
    Vector<JSFunction*> functions;
92
};
94
};
93
95
96
struct WASMFunctionInformation {
97
    size_t start;
98
    size_t end;
99
};
100
94
} // namespace JSC
101
} // namespace JSC
95
102
96
#endif // ENABLE(WEBASSEMBLY)
103
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMFunctionParser.h +163 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMFunctionParser.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#include "WASMParser.h"
29
#include <wtf/DataLog.h>
30
31
#if ENABLE(WEBASSEMBLY)
32
33
namespace JSC {
34
35
namespace WASM {
36
37
template<typename Context>
38
class WASMFunctionParser : public WASMParser {
39
public:
40
    typedef typename Context::ExpressionType ExpressionType;
41
42
    WASMFunctionParser(Context&, const Vector<uint8_t>& sourceBuffer, const WASMFunctionInformation&);
43
44
    bool WARN_UNUSED_RETURN parse();
45
46
private:
47
    static const bool verbose = false;
48
49
    bool WARN_UNUSED_RETURN parseBlock();
50
    bool WARN_UNUSED_RETURN parseExpression(WASMOpType);
51
    bool WARN_UNUSED_RETURN unifyControl(Vector<ExpressionType>&, unsigned level);
52
53
    Optional<Vector<ExpressionType>>& stackForControlLevel(unsigned level);
54
55
    Context& m_context;
56
    Vector<ExpressionType> m_expressionStack;
57
};
58
59
template<typename Context>
60
WASMFunctionParser<Context>::WASMFunctionParser(Context& context, const Vector<uint8_t>& sourceBuffer, const WASMFunctionInformation& info)
61
    : WASMParser(sourceBuffer, info.start, info.end)
62
    , m_context(context)
63
{
64
}
65
66
template<typename Context>
67
bool WASMFunctionParser<Context>::parse()
68
{
69
    uint32_t localCount;
70
    if (!parseVarUInt32(localCount))
71
        return false;
72
73
    for (uint32_t i = 0; i < localCount; ++i) {
74
        uint32_t numberOfLocalsWithType;
75
        if (!parseUInt32(numberOfLocalsWithType))
76
            return false;
77
78
        WASMValueType typeOfLocal;
79
        if (!parseValueType(typeOfLocal))
80
            return false;
81
82
        m_context.addLocal(typeOfLocal, numberOfLocalsWithType);
83
    }
84
85
    return parseBlock();
86
}
87
88
template<typename Context>
89
bool WASMFunctionParser<Context>::parseBlock()
90
{
91
    while (true) {
92
        uint8_t op;
93
        if (!parseUInt7(op))
94
            return false;
95
96
        if (!parseExpression(static_cast<WASMOpType>(op))) {
97
            if (verbose)
98
                dataLogLn("failed to process op:", op);
99
            return false;
100
        }
101
102
        if (op == WASMOpType::End)
103
            break;
104
    }
105
106
    return true;
107
}
108
109
template<typename Context>
110
bool WASMFunctionParser<Context>::parseExpression(WASMOpType op)
111
{
112
    switch (op) {
113
#define CREATE_CASE(name, value) case name:
114
    FOR_EACH_WASM_BINARY_OP(CREATE_CASE) {
115
#undef CREATE_CASE
116
        ExpressionType left = m_expressionStack.takeLast();
117
        ExpressionType right = m_expressionStack.takeLast();
118
        ExpressionType result;
119
        if (!m_context.binaryOp(static_cast<WASMBinaryOpType>(op), left, right, result))
120
            return false;
121
        m_expressionStack.append(result);
122
        return true;
123
    }
124
125
    case WASMOpType::I32Const: {
126
        uint32_t constant;
127
        if (!parseVarUInt32(constant))
128
            return false;
129
        m_expressionStack.append(m_context.addConstant(WASMValueType::I32, constant));
130
        return true;
131
    }
132
133
    case WASMOpType::Block: {
134
        if (!m_context.addBlock())
135
            return false;
136
        return parseBlock();
137
    }
138
139
    case WASMOpType::Return: {
140
        uint8_t returnCount;
141
        if (!parseVarUInt1(returnCount))
142
            return false;
143
        Vector<ExpressionType, 1> returnValues;
144
        if (returnCount)
145
            returnValues.append(m_expressionStack.takeLast());
146
147
        return m_context.addReturn(returnValues);
148
    }
149
150
    case WASMOpType::End:
151
        return m_context.endBlock(m_expressionStack);
152
153
    }
154
155
    // Unknown opcode.
156
    return false;
157
}
158
159
} // namespace WASM
160
161
} // namespace JSC
162
163
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMModuleParser.cpp +231 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMModuleParser.cpp_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#include "config.h"
27
#include "WASMModuleParser.h"
28
29
#include "WASMFormat.h"
30
#include "WASMOps.h"
31
#include "WASMSections.h"
32
33
#if ENABLE(WEBASSEMBLY)
34
35
namespace JSC {
36
37
namespace WASM {
38
39
static const bool verbose = false;
40
41
bool WASMModuleParser::parse()
42
{
43
    if (m_sourceLength < 8)
44
        return false;
45
    if (!matchCharacter(0))
46
        return false;
47
    if (!matchString("asm"))
48
        return false;
49
50
    // Skip the version number for now since we don't do anything with it.
51
    uint32_t versionNumber;
52
    if (!parseUInt32(versionNumber))
53
        return false;
54
55
    if (versionNumber != magicNumber)
56
        return false;
57
58
59
    if (verbose)
60
        dataLogLn("Passed processing header.");
61
62
    WASMSections::Section previousSection = WASMSections::Section::Unknown;
63
    while (m_offset < m_sourceLength) {
64
        if (verbose)
65
            dataLogLn("Starting to parse next section at offset: ", m_offset);
66
        uint32_t sectionNameLength;
67
        if (!parseVarUInt32(sectionNameLength))
68
            return false;
69
70
        // Make sure we can read up to the section's size.
71
        if (m_offset + sectionNameLength + maxLEBByteLength >= m_sourceLength)
72
            return false;
73
74
        WASMSections::Section section = WASMSections::lookup(m_source.data() + m_offset, sectionNameLength);
75
        if (!WASMSections::validateOrder(previousSection, section))
76
            return false;
77
        m_offset += sectionNameLength;
78
79
        uint32_t sectionLength;
80
        if (!parseVarUInt32(sectionLength))
81
            return false;
82
83
        unsigned end = m_offset + sectionLength;
84
85
        switch (section) {
86
        case WASMSections::Section::End:
87
            return true;
88
89
        case WASMSections::Section::FunctionTypes: {
90
            if (verbose)
91
                dataLogLn("Parsing types.");
92
            if (!parseFunctionTypes())
93
                return false;
94
            break;
95
        }
96
97
        case WASMSections::Section::Signatures: {
98
            if (verbose)
99
                dataLogLn("Parsing function signatures.");
100
            if (!parseFunctionSignatures())
101
                return false;
102
            break;
103
        }
104
105
        case WASMSections::Section::Definitions: {
106
            if (verbose)
107
                dataLogLn("Parsing function definitions.");
108
            if (!parseFunctionDefinitions())
109
                return false;
110
            break;
111
        }
112
113
        case WASMSections::Section::Unknown: {
114
            if (verbose)
115
                dataLogLn("Unknown section, skipping.");
116
            m_offset += sectionLength;
117
            break;
118
        }
119
        }
120
121
        if (verbose)
122
            dataLogLn("Finished parsing section.");
123
124
        if (end != m_offset)
125
            return false;
126
127
        previousSection = section;
128
    }
129
130
    // TODO
131
    return true;
132
}
133
134
bool WASMModuleParser::parseFunctionTypes()
135
{
136
    uint32_t count;
137
    if (!parseVarUInt32(count))
138
        return false;
139
140
    if (verbose)
141
        dataLogLn("count: ", count);
142
143
    for (uint32_t i = 0; i < count; ++i) {
144
        uint8_t type;
145
        if (!parseUInt7(type))
146
            return false;
147
        if (type != 0x40) // Function type constant.
148
            return false;
149
150
        if (verbose)
151
            dataLogLn("Got function type.");
152
153
        uint32_t argumentCount;
154
        if (!parseVarUInt32(argumentCount))
155
            return false;
156
157
        if (verbose)
158
            dataLogLn("argumentCount: ", argumentCount);
159
160
        Vector<WASMValueType> argumentTypes;
161
        for (unsigned i = 0; i < argumentCount; ++i) {
162
            if (!parseUInt7(type) || type >= static_cast<uint8_t>(WASMValueType::NumberOfTypes))
163
                return false;
164
            argumentTypes.append(static_cast<WASMValueType>(type));
165
        }
166
167
        if (!parseVarUInt1(type))
168
            return false;
169
        WASMFunctionReturnType returnType;
170
171
        if (verbose)
172
            dataLogLn(type);
173
174
        if (type) {
175
            WASMValueType value;
176
            if (!parseValueType(value))
177
                return false;
178
            returnType = static_cast<WASMFunctionReturnType>(value);
179
        } else
180
            returnType = WASMFunctionReturnType::Void;
181
182
        // TODO: Actually do something with this data...
183
    }
184
    return true;
185
}
186
187
bool WASMModuleParser::parseFunctionSignatures()
188
{
189
    uint32_t count;
190
    if (!parseVarUInt32(count))
191
        return false;
192
193
    m_functions.resize(count);
194
195
    for (uint32_t i = 0; i < count; ++i) {
196
        uint32_t typeNumber;
197
        if (!parseVarUInt32(typeNumber))
198
            return false;
199
    }
200
201
    return true;
202
}
203
204
bool WASMModuleParser::parseFunctionDefinitions()
205
{
206
    uint32_t count;
207
    if (!parseVarUInt32(count))
208
        return false;
209
210
    if (count != m_functions.size())
211
        return false;
212
213
    for (uint32_t i = 0; i < count; ++i) {
214
        uint32_t functionSize;
215
        if (!parseVarUInt32(functionSize))
216
            return false;
217
218
        WASMFunctionInformation& info = m_functions[i];
219
        info.start = m_offset;
220
        info.end = m_offset + functionSize;
221
        m_offset = info.end;
222
    }
223
224
    return true;
225
}
226
227
} // namespace WASM
228
229
} // namespace JSC
230
231
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMModuleParser.h +67 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMModuleParser.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#include "WASMOps.h"
29
#include "WASMParser.h"
30
#include <wtf/Vector.h>
31
32
#if ENABLE(WEBASSEMBLY)
33
34
namespace JSC {
35
36
namespace WASM {
37
38
class WASMModuleParser : public WASMParser {
39
public:
40
41
    static const unsigned magicNumber = 0xc;
42
43
    WASMModuleParser(const Vector<uint8_t>& sourceBuffer)
44
        : WASMParser(sourceBuffer, 0, sourceBuffer.size())
45
    {
46
    }
47
48
    bool WARN_UNUSED_RETURN parse();
49
50
    const Vector<WASMFunctionInformation>& functionInformation() { return m_functions; }
51
52
private:
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)
- a/Source/JavaScriptCore/wasm/WASMOps.h +71 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMOps.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
namespace JSC {
31
32
namespace WASM {
33
34
#define FOR_EACH_WASM_SPECIAL_OP(macro) \
35
    macro(I32Const, 0x10)
36
37
#define FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \
38
    macro(Block, 0x01) \
39
    macro(Return, 0x09) \
40
    macro(End, 0x0f)
41
42
#define FOR_EACH_WASM_UNARY_OP(macro)
43
44
#define FOR_EACH_WASM_BINARY_OP(macro) \
45
    macro(I32Add, 0x40)
46
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)
52
53
#define CREATE_ENUM_VALUE(name, id) name = id,
54
55
enum WASMOpType : uint8_t {
56
    FOR_EACH_WASM_OP(CREATE_ENUM_VALUE)
57
};
58
59
60
61
enum 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)
- a/Source/JavaScriptCore/wasm/WASMParser.h +134 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMParser.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#include "B3Compilation.h"
29
#include "B3Procedure.h"
30
#include "WASMFormat.h"
31
#include "WASMOps.h"
32
#include "WASMSections.h"
33
#include <wtf/LEBDecoder.h>
34
35
#if ENABLE(WEBASSEMBLY)
36
37
namespace JSC {
38
39
namespace WASM {
40
41
class WASMParser {
42
protected:
43
    WASMParser(const Vector<uint8_t>&, size_t start, size_t end);
44
45
    bool WARN_UNUSED_RETURN matchCharacter(char);
46
    bool WARN_UNUSED_RETURN matchString(const char*);
47
48
    bool WARN_UNUSED_RETURN parseVarUInt1(uint8_t& result);
49
    bool WARN_UNUSED_RETURN parseUInt7(uint8_t& result);
50
    bool WARN_UNUSED_RETURN parseUInt32(uint32_t& result);
51
    bool WARN_UNUSED_RETURN parseVarUInt32(uint32_t& result) { return decodeUInt32(m_source.data(), m_sourceLength, m_offset, result); }
52
53
54
    bool WARN_UNUSED_RETURN parseValueType(WASMValueType& result);
55
56
    const Vector<uint8_t>& m_source;
57
    size_t m_sourceLength;
58
    size_t m_offset;
59
};
60
61
ALWAYS_INLINE WASMParser::WASMParser(const Vector<uint8_t>& sourceBuffer, size_t start, size_t end)
62
    : m_source(sourceBuffer)
63
    , m_sourceLength(end)
64
    , m_offset(start)
65
{
66
    ASSERT(end <= sourceBuffer.size());
67
    ASSERT(start < end);
68
}
69
70
ALWAYS_INLINE bool WASMParser::matchCharacter(char c)
71
{
72
    if (m_offset >= m_sourceLength)
73
        return false;
74
    if (c == m_source[m_offset]) {
75
        m_offset++;
76
        return true;
77
    }
78
    return false;
79
}
80
81
ALWAYS_INLINE bool WASMParser::matchString(const char* str)
82
{
83
    unsigned start = m_offset;
84
    for (unsigned i = 0; str[i]; i++) {
85
        if (!matchCharacter(str[i])) {
86
            m_offset = start;
87
            return false;
88
        }
89
    }
90
    return true;
91
}
92
93
ALWAYS_INLINE bool WASMParser::parseUInt32(uint32_t& result)
94
{
95
    if (m_offset + 4 >= m_sourceLength)
96
        return false;
97
    result = *reinterpret_cast<const uint32_t*>(m_source.data() + m_offset);
98
    m_offset += 4;
99
    return true;
100
}
101
102
ALWAYS_INLINE bool WASMParser::parseUInt7(uint8_t& result)
103
{
104
    if (m_offset >= m_sourceLength)
105
        return false;
106
    result = m_source[m_offset++];
107
    return result < 0x80;
108
}
109
110
ALWAYS_INLINE bool WASMParser::parseVarUInt1(uint8_t& result)
111
{
112
    uint32_t temp;
113
    if (!parseVarUInt32(temp))
114
        return false;
115
    result = static_cast<uint8_t>(temp);
116
    return temp <= 1;
117
}
118
119
ALWAYS_INLINE bool WASMParser::parseValueType(WASMValueType& result)
120
{
121
    uint8_t value;
122
    if (!parseUInt7(value))
123
        return false;
124
    if (value >= static_cast<uint8_t>(WASMValueType::NumberOfTypes))
125
        return false;
126
    result = static_cast<WASMValueType>(value);
127
    return true;
128
}
129
130
} // namespace WASM
131
132
} // namespace JSC
133
134
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMPlan.cpp +66 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMPlan.cpp_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#include "config.h"
27
#include "WASMPlan.h"
28
29
#include "B3Compilation.h"
30
#include "WASMB3IRGenerator.h"
31
#include "WASMModuleParser.h"
32
#include <wtf/DataLog.h>
33
34
#if ENABLE(WEBASSEMBLY)
35
36
namespace JSC {
37
38
namespace WASM {
39
40
static const bool verbose = false;
41
42
Plan::Plan(VM& vm, Vector<uint8_t> source)
43
{
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
    }
60
}
61
62
} // namespace WASM
63
64
} // namespace JSC
65
66
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMPlan.h +55 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMPlan.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#include "CompilationResult.h"
29
#include "VM.h"
30
#include <wtf/ThreadSafeRefCounted.h>
31
#include <wtf/Vector.h>
32
33
#if ENABLE(WEBASSEMBLY)
34
35
namespace JSC {
36
37
namespace B3 {
38
class Compilation;
39
} // namespace B3
40
41
namespace WASM {
42
43
// TODO: This should create a WASM Module not a list of functions.
44
class Plan {
45
public:
46
    JS_EXPORT_PRIVATE Plan(VM&, Vector<uint8_t> source);
47
48
    Vector<std::unique_ptr<B3::Compilation>> result;
49
};
50
51
} // namespace WASM
52
53
} // namespace JSC
54
55
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMSections.cpp +69 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMSections.cpp_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#include "config.h"
27
#include "WASMSections.h"
28
29
#include <wtf/DataLog.h>
30
#include <wtf/text/WTFString.h>
31
32
#if ENABLE(WEBASSEMBLY)
33
34
namespace JSC {
35
36
namespace WASM {
37
38
struct SectionData {
39
    unsigned length;
40
    const char* name;
41
};
42
43
static const bool verbose = false;
44
45
static const unsigned sectionDataLength = static_cast<unsigned>(WASMSections::Section::Unknown);
46
static 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
52
WASMSections::Section WASMSections::lookup(const uint8_t* name, unsigned length)
53
{
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;
63
}
64
65
} // namespace WASM
66
67
} // namespace JSC
68
69
#endif // ENABLE(WEBASSEMBLY)
- a/Source/JavaScriptCore/wasm/WASMSections.h +63 lines
Line 0 a/Source/JavaScriptCore/wasm/WASMSections.h_sec1
1
/*
2
 * Copyright (C) 2016 Apple Inc. All rights reserved.
3
 *
4
 * Redistribution and use in source and binary forms, with or without
5
 * modification, are permitted provided that the following conditions
6
 * are met:
7
 * 1. Redistributions of source code must retain the above copyright
8
 *    notice, this list of conditions and the following disclaimer.
9
 * 2. Redistributions in binary form must reproduce the above copyright
10
 *    notice, this list of conditions and the following disclaimer in the
11
 *    documentation and/or other materials provided with the distribution.
12
 *
13
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
 * (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.
24
 */
25
26
#pragma once
27
28
#if ENABLE(WEBASSEMBLY)
29
30
namespace JSC {
31
32
namespace WASM {
33
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")
40
41
struct 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
};
58
59
} // namespace WASM
60
61
} // namespace JSC
62
63
#endif // ENABLE(WEBASSEMBLY)
- a/Source/WTF/wtf/DataLog.h +7 lines
Lines 45-53 void dataLog(const Types&... values) a/Source/WTF/wtf/DataLog.h_sec1
45
    dataFile().print(values...);
45
    dataFile().print(values...);
46
}
46
}
47
47
48
template<typename... Types>
49
void dataLogLn(const Types&... values)
50
{
51
    dataFile().print(values..., "\n");
52
}
53
48
} // namespace WTF
54
} // namespace WTF
49
55
50
using WTF::dataLog;
56
using WTF::dataLog;
57
using WTF::dataLogLn;
51
using WTF::dataLogF;
58
using WTF::dataLogF;
52
using WTF::dataLogFString;
59
using WTF::dataLogFString;
53
60
- a/Source/WTF/wtf/LEBDecoder.h -9 / +6 lines
Lines 26-48 a/Source/WTF/wtf/LEBDecoder.h_sec1
26
#pragma once
26
#pragma once
27
27
28
#include "Compiler.h"
28
#include "Compiler.h"
29
#include "Vector.h"
30
#include <algorithm>
29
#include <algorithm>
31
30
32
#include "DataLog.h"
33
34
// This file contains a bunch of helper functions for decoding LEB numbers.
31
// This file contains a bunch of helper functions for decoding LEB numbers.
35
// See https://en.wikipedia.org/wiki/LEB128 for more information about the
32
// See https://en.wikipedia.org/wiki/LEB128 for more information about the
36
// LEB format.
33
// LEB format.
37
34
38
const size_t maxLEBByteLength = 5;
35
const size_t maxLEBByteLength = 5;
39
36
40
inline bool WARN_UNUSED_RETURN decodeUInt32(const Vector<uint8_t>& bytes, size_t& offset, uint32_t& result)
37
inline bool WARN_UNUSED_RETURN decodeUInt32(const uint8_t* bytes, size_t length, size_t& offset, uint32_t& result)
41
{
38
{
42
    ASSERT(bytes.size() > offset);
39
    ASSERT(length > offset);
43
    result = 0;
40
    result = 0;
44
    unsigned shift = 0;
41
    unsigned shift = 0;
45
    size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
42
    size_t last = std::min(maxLEBByteLength, length - offset - 1);
46
    for (unsigned i = 0; true; ++i) {
43
    for (unsigned i = 0; true; ++i) {
47
        uint8_t byte = bytes[offset++];
44
        uint8_t byte = bytes[offset++];
48
        result |= (byte & 0x7f) << shift;
45
        result |= (byte & 0x7f) << shift;
Lines 56-67 inline bool WARN_UNUSED_RETURN decodeUInt32(const Vector<uint8_t>& bytes, size_t a/Source/WTF/wtf/LEBDecoder.h_sec2
56
    return true;
53
    return true;
57
}
54
}
58
55
59
inline bool WARN_UNUSED_RETURN decodeInt32(const Vector<uint8_t>& bytes, size_t& offset, int32_t& result)
56
inline bool WARN_UNUSED_RETURN decodeInt32(const uint8_t* bytes, size_t length, size_t& offset, int32_t& result)
60
{
57
{
61
    ASSERT(bytes.size() > offset);
58
    ASSERT(length > offset);
62
    result = 0;
59
    result = 0;
63
    unsigned shift = 0;
60
    unsigned shift = 0;
64
    size_t last = std::min(maxLEBByteLength, bytes.size() - offset - 1);
61
    size_t last = std::min(maxLEBByteLength, length - offset - 1);
65
    uint8_t byte;
62
    uint8_t byte;
66
    for (unsigned i = 0; true; ++i) {
63
    for (unsigned i = 0; true; ++i) {
67
        byte = bytes[offset++];
64
        byte = bytes[offset++];

Return to Bug 160681