Changeset 204484 in webkit
- Timestamp:
- Aug 15, 2016 2:35:07 PM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 4 added
- 8 edited
- 7 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r204480 r204484 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 Benjamin Poulain. 7 8 This patch adds the skeleton for a WebAssembly pipeline. The 9 pipeline is designed in order to make it easy to have as much of 10 the compilation process threaded as possible. The flow of the 11 pipeline roughly goes as follows: 12 13 1) Create a WASMPlan with the VM and a Vector of the 14 assembly. Currently the plan will process all the work 15 synchronously, however, in the future this can be offloaded to 16 other threads. 17 18 2) The plan will run the WASMModuleParser, which collates all the 19 information needed to compile each module function 20 independently. Since, we are still in the early phases, the only 21 information is the starting and ending byte of the function's 22 body. The module parser, however, still scans both and 23 semi-validates the type and the function sections. 24 25 3) Each function is decoded and compiled. In the future this 26 should also include a opcode validation phase. The 27 WASMFunctionParser is templatized so that a validator should be 28 able to use most of the same code the B3 IR generator does. 29 30 4) When the plan has finished it will fill a Vector of 31 B3::Compilation objects that correspond to the respective function 32 in the WASM module. 33 34 35 The current testing plan for the modules is to inline the the 36 binary generated by the spec's OCaml prototype. The inlined binary 37 is passed to a WASMPlan then invoked to check the result of the 38 function. In the future we should add a more robust testing 39 infrastructure. 40 41 * JavaScriptCore.xcodeproj/project.pbxproj: 42 * testWASM.cpp: 43 (printUsageStatement): 44 (CommandLine::parseArguments): 45 (invoke): 46 (runWASMTests): 47 (main): 48 * wasm/JSWASMModule.h: 49 (JSC::JSWASMModule::globalVariableTypes): 50 * wasm/WASMB3IRGenerator.cpp: Added. 51 (JSC::WASM::B3IRGenerator::B3IRGenerator): 52 (JSC::WASM::B3IRGenerator::addLocal): 53 (JSC::WASM::B3IRGenerator::binaryOp): 54 (JSC::WASM::B3IRGenerator::addConstant): 55 (JSC::WASM::B3IRGenerator::addBlock): 56 (JSC::WASM::B3IRGenerator::endBlock): 57 (JSC::WASM::B3IRGenerator::addReturn): 58 (JSC::WASM::B3IRGenerator::unify): 59 (JSC::WASM::B3IRGenerator::initializeIncommingTypes): 60 (JSC::WASM::B3IRGenerator::unifyValuesWithLevel): 61 (JSC::WASM::B3IRGenerator::stackForControlLevel): 62 (JSC::WASM::B3IRGenerator::blockForControlLevel): 63 (JSC::WASM::parseAndCompile): 64 * wasm/WASMB3IRGenerator.h: Copied from Source/WTF/wtf/DataLog.h. 65 * wasm/WASMFormat.h: 66 * wasm/WASMFunctionParser.h: Added. 67 (JSC::WASM::WASMFunctionParser<Context>::WASMFunctionParser): 68 (JSC::WASM::WASMFunctionParser<Context>::parse): 69 (JSC::WASM::WASMFunctionParser<Context>::parseBlock): 70 (JSC::WASM::WASMFunctionParser<Context>::parseExpression): 71 * wasm/WASMModuleParser.cpp: Added. 72 (JSC::WASM::WASMModuleParser::parse): 73 (JSC::WASM::WASMModuleParser::parseFunctionTypes): 74 (JSC::WASM::WASMModuleParser::parseFunctionSignatures): 75 (JSC::WASM::WASMModuleParser::parseFunctionDefinitions): 76 * wasm/WASMModuleParser.h: Copied from Source/WTF/wtf/DataLog.h. 77 (JSC::WASM::WASMModuleParser::WASMModuleParser): 78 (JSC::WASM::WASMModuleParser::functionInformation): 79 * wasm/WASMOps.h: Copied from Source/WTF/wtf/DataLog.h. 80 * wasm/WASMParser.h: Added. 81 (JSC::WASM::WASMParser::parseVarUInt32): 82 (JSC::WASM::WASMParser::WASMParser): 83 (JSC::WASM::WASMParser::consumeCharacter): 84 (JSC::WASM::WASMParser::consumeString): 85 (JSC::WASM::WASMParser::parseUInt32): 86 (JSC::WASM::WASMParser::parseUInt7): 87 (JSC::WASM::WASMParser::parseVarUInt1): 88 (JSC::WASM::WASMParser::parseValueType): 89 * wasm/WASMPlan.cpp: Copied from Source/WTF/wtf/DataLog.h. 90 (JSC::WASM::Plan::Plan): 91 * wasm/WASMPlan.h: Copied from Source/WTF/wtf/DataLog.h. 92 * wasm/WASMSections.cpp: Copied from Source/WTF/wtf/DataLog.h. 93 (JSC::WASM::WASMSections::lookup): 94 * wasm/WASMSections.h: Copied from Source/WTF/wtf/DataLog.h. 95 (JSC::WASM::WASMSections::validateOrder): 96 1 97 2016-08-15 Benjamin Poulain <bpoulain@apple.com> 2 98 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r204393 r204484 1179 1179 52C952B719A289850069B386 /* TypeProfiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 52C952B619A289850069B386 /* TypeProfiler.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1180 1180 52C952B919A28A1C0069B386 /* TypeProfiler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */; }; 1181 531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */ = {isa = PBXBuildFile; fileRef = 531374BC1D5CE67600AF7A0B /* WASMPlan.h */; }; 1182 531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */; }; 1181 1183 53486BB71C1795C300F6F3AF /* JSTypedArray.h in Headers */ = {isa = PBXBuildFile; fileRef = 53486BB61C1795C300F6F3AF /* JSTypedArray.h */; settings = {ATTRIBUTES = (Public, ); }; }; 1182 1184 53486BBB1C18E84500F6F3AF /* JSTypedArray.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */; }; … … 1192 1194 539EB0811D55608A00C82EF7 /* testWASM.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 539EB0711D553DF800C82EF7 /* testWASM.cpp */; }; 1193 1195 539FB8BA1C99DA7C00940FA1 /* JSArrayInlines.h in Headers */ = {isa = PBXBuildFile; fileRef = 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */; }; 1196 53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E841D58F9770099A1B6 /* WASMSections.h */; }; 1197 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */; }; 1198 53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */; }; 1199 53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E8C1D5901F20099A1B6 /* WASMParser.h */; }; 1200 53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */; }; 1201 53F40E911D5903020099A1B6 /* WASMOps.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E901D5903020099A1B6 /* WASMOps.h */; }; 1202 53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */; }; 1203 53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */; }; 1204 53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */; }; 1194 1205 53F6BF6D1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h in Headers */ = {isa = PBXBuildFile; fileRef = 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */; settings = {ATTRIBUTES = (Private, ); }; }; 1195 1206 53FA2AE11CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h in Headers */ = {isa = PBXBuildFile; fileRef = 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */; settings = {ATTRIBUTES = (Private, ); }; }; … … 3354 3365 52C952B619A289850069B386 /* TypeProfiler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TypeProfiler.h; sourceTree = "<group>"; }; 3355 3366 52C952B819A28A1C0069B386 /* TypeProfiler.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = TypeProfiler.cpp; sourceTree = "<group>"; }; 3367 531374BC1D5CE67600AF7A0B /* WASMPlan.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMPlan.h; sourceTree = "<group>"; }; 3368 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMPlan.cpp; sourceTree = "<group>"; }; 3356 3369 53486BB61C1795C300F6F3AF /* JSTypedArray.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSTypedArray.h; sourceTree = "<group>"; }; 3357 3370 53486BBA1C18E84500F6F3AF /* JSTypedArray.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArray.cpp; sourceTree = "<group>"; }; … … 3371 3384 539FB8B91C99DA7C00940FA1 /* JSArrayInlines.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSArrayInlines.h; sourceTree = "<group>"; }; 3372 3385 53F256E11B87E28000B4B768 /* JSTypedArrayViewPrototype.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSTypedArrayViewPrototype.cpp; sourceTree = "<group>"; }; 3386 53F40E841D58F9770099A1B6 /* WASMSections.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMSections.h; sourceTree = "<group>"; }; 3387 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMSections.cpp; sourceTree = "<group>"; }; 3388 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMFunctionParser.h; sourceTree = "<group>"; }; 3389 53F40E8C1D5901F20099A1B6 /* WASMParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMParser.h; sourceTree = "<group>"; }; 3390 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMB3IRGenerator.cpp; sourceTree = "<group>"; }; 3391 53F40E901D5903020099A1B6 /* WASMOps.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMOps.h; sourceTree = "<group>"; }; 3392 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMB3IRGenerator.h; sourceTree = "<group>"; }; 3393 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WASMModuleParser.h; sourceTree = "<group>"; }; 3394 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WASMModuleParser.cpp; sourceTree = "<group>"; }; 3373 3395 53F6BF6C1C3F060A00F41E5D /* InternalFunctionAllocationProfile.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InternalFunctionAllocationProfile.h; sourceTree = "<group>"; }; 3374 3396 53FA2AE01CF37F3F0022711D /* LLIntPrototypeLoadAdaptiveStructureWatchpoint.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LLIntPrototypeLoadAdaptiveStructureWatchpoint.h; sourceTree = "<group>"; }; … … 5540 5562 7B98D1341B60CD5A0023B1A4 /* JSWASMModule.cpp */, 5541 5563 7B98D1351B60CD5A0023B1A4 /* JSWASMModule.h */, 5564 53F40E901D5903020099A1B6 /* WASMOps.h */, 5542 5565 7BC547D21B69599B00959B58 /* WASMFormat.h */, 5566 53F40E8E1D5902820099A1B6 /* WASMB3IRGenerator.cpp */, 5567 53F40E921D5A4AB30099A1B6 /* WASMB3IRGenerator.h */, 5568 53F40E8A1D5901BB0099A1B6 /* WASMFunctionParser.h */, 5569 53F40E961D5A7BEC0099A1B6 /* WASMModuleParser.cpp */, 5570 53F40E941D5A7AEF0099A1B6 /* WASMModuleParser.h */, 5571 531374BE1D5CE95000AF7A0B /* WASMPlan.cpp */, 5572 531374BC1D5CE67600AF7A0B /* WASMPlan.h */, 5573 53F40E8C1D5901F20099A1B6 /* WASMParser.h */, 5574 53F40E861D58F9D60099A1B6 /* WASMSections.cpp */, 5575 53F40E841D58F9770099A1B6 /* WASMSections.h */, 5543 5576 ); 5544 5577 path = wasm; … … 7212 7245 C2FCAE1317A9C24E0034C735 /* BytecodeLivenessAnalysis.h in Headers */, 7213 7246 0F666EC0183566F900D017F1 /* BytecodeLivenessAnalysisInlines.h in Headers */, 7247 53F40E951D5A7AEF0099A1B6 /* WASMModuleParser.h in Headers */, 7214 7248 6514F21918B3E1670098FF8B /* Bytecodes.h in Headers */, 7215 7249 0F885E111849A3BE00F1E3FA /* BytecodeUseDef.h in Headers */, … … 7297 7331 6AD2CB4D19B9140100065719 /* DebuggerEvalEnabler.h in Headers */, 7298 7332 FEA08621182B7A0400F6D851 /* DebuggerPrimitives.h in Headers */, 7333 53F40E851D58F9770099A1B6 /* WASMSections.h in Headers */, 7299 7334 DC9A0C1F1D2D9CB10085124E /* B3CaseCollectionInlines.h in Headers */, 7300 7335 0F2D4DDE19832D34007D4B19 /* DebuggerScope.h in Headers */, … … 7443 7478 0F392C8A1B46188400844728 /* DFGOSRExitFuzz.h in Headers */, 7444 7479 0FEFC9AB1681A3B600567F53 /* DFGOSRExitJumpPlaceholder.h in Headers */, 7480 53F40E8D1D5901F20099A1B6 /* WASMParser.h in Headers */, 7445 7481 0F40E4A81C497F7400A577FA /* AirOpcodeGenerated.h in Headers */, 7446 7482 0F235BEE17178E7300690C7F /* DFGOSRExitPreparation.h in Headers */, … … 7597 7633 0F2B66AE17B6B54500A7AE3F /* GCIncomingRefCountedSet.h in Headers */, 7598 7634 0F2B66AF17B6B54500A7AE3F /* GCIncomingRefCountedSetInlines.h in Headers */, 7635 531374BD1D5CE67600AF7A0B /* WASMPlan.h in Headers */, 7599 7636 2AABCDE718EF294200002096 /* GCLogging.h in Headers */, 7600 7637 0F2BBD981C5FF3F50023EF23 /* B3Variable.h in Headers */, … … 7808 7845 797E07AA1B8FCFB9008400BA /* JSGlobalLexicalEnvironment.h in Headers */, 7809 7846 BC18C4210E16F5CD00B34460 /* JSGlobalObject.h in Headers */, 7847 53F40E8B1D5901BB0099A1B6 /* WASMFunctionParser.h in Headers */, 7810 7848 996B731D1BDA08EF00331B84 /* JSGlobalObject.lut.h in Headers */, 7811 7849 A5FD0086189B1B7E00633231 /* JSGlobalObjectConsoleAgent.h in Headers */, … … 7867 7905 FE1220271BE7F58C0039E6F2 /* JITAddGenerator.h in Headers */, 7868 7906 0F919D11157F332C004A4E7D /* JSSegmentedVariableObject.h in Headers */, 7907 53F40E911D5903020099A1B6 /* WASMOps.h in Headers */, 7869 7908 A7299D9E17D12837005F5FF9 /* JSSet.h in Headers */, 7870 7909 A790DD70182F499700588807 /* JSSetIterator.h in Headers */, … … 7915 7954 99DA00B01BD5994E00F4575C /* lazywriter.py in Headers */, 7916 7955 BC18C4310E16F5CD00B34460 /* Lexer.h in Headers */, 7956 53F40E931D5A4AB30099A1B6 /* WASMB3IRGenerator.h in Headers */, 7917 7957 BC18C52E0E16FCE100B34460 /* Lexer.lut.h in Headers */, 7918 7958 DCF3D56B1CD29472003D5C65 /* LazyClassStructureInlines.h in Headers */, … … 8948 8988 A7D89CF517A0B8CC00773AD8 /* DFGCriticalEdgeBreakingPhase.cpp in Sources */, 8949 8989 0F6183291C45BF070072450B /* AirCCallingConvention.cpp in Sources */, 8990 53F40E871D58F9D60099A1B6 /* WASMSections.cpp in Sources */, 8950 8991 0FFFC95914EF90A600C72532 /* DFGCSEPhase.cpp in Sources */, 8951 8992 0F2FC77216E12F710038D976 /* DFGDCEPhase.cpp in Sources */, … … 9161 9202 A513E5B7185B8BD3007E95AD /* InjectedScript.cpp in Sources */, 9162 9203 A514B2C2185A684400F3C7CB /* InjectedScriptBase.cpp in Sources */, 9204 531374BF1D5CE95000AF7A0B /* WASMPlan.cpp in Sources */, 9163 9205 A58E35911860DECF001F24FE /* InjectedScriptHost.cpp in Sources */, 9164 9206 A513E5CA185F9624007E95AD /* InjectedScriptManager.cpp in Sources */, … … 9537 9579 FE5932A7183C5A2600A1ECCC /* VMEntryScope.cpp in Sources */, 9538 9580 FE187A011BFBE55E0038BBCA /* JITMulGenerator.cpp in Sources */, 9581 53F40E8F1D5902820099A1B6 /* WASMB3IRGenerator.cpp in Sources */, 9539 9582 26718BA41BE99F780052017B /* AirIteratedRegisterCoalescing.cpp in Sources */, 9540 9583 FED94F2E171E3E2300BE77A4 /* Watchdog.cpp in Sources */, … … 9546 9589 0F338DF91BE96AA80013C88F /* B3CCallValue.cpp in Sources */, 9547 9590 A7CA3AEB17DA5168006538AF /* WeakMapData.cpp in Sources */, 9591 53F40E971D5A7BEC0099A1B6 /* WASMModuleParser.cpp in Sources */, 9548 9592 A7CA3AE517DA41AE006538AF /* WeakMapPrototype.cpp in Sources */, 9549 9593 14E84FA014EE1ACC00D6D5D4 /* WeakSet.cpp in Sources */, -
trunk/Source/JavaScriptCore/testWASM.cpp
r204218 r204484 26 26 #include "config.h" 27 27 28 #include "B3Compilation.h" 29 #include "InitializeThreading.h" 28 30 #include "JSString.h" 31 #include "VM.h" 32 #include "WASMPlan.h" 29 33 #include <wtf/DataLog.h> 30 34 #include <wtf/LEBDecoder.h> … … 39 43 Vector<String> m_arguments; 40 44 bool m_runLEBTests { false }; 45 bool m_runWASMTests { false }; 41 46 42 47 void parseArguments(int, char**); … … 48 53 fprintf(stderr, " -h|--help Prints this help message\n"); 49 54 fprintf(stderr, " -l|--leb Runs the LEB decoder tests\n"); 55 fprintf(stderr, " -w|--web Run the WASM tests\n"); 50 56 fprintf(stderr, "\n"); 51 57 … … 64 70 if (!strcmp(arg, "-l") || !strcmp(arg, "--leb")) 65 71 m_runLEBTests = true; 72 73 if (!strcmp(arg, "-w") || !strcmp(arg, "--web")) 74 m_runWASMTests = true; 66 75 } 67 76 … … 110 119 size_t offset = startOffset; \ 111 120 uint32_t result; \ 112 bool status = decodeUInt32(vector , offset, result); \121 bool status = decodeUInt32(vector.data(), vector.size(), offset, result); \ 113 122 RELEASE_ASSERT(status == expectedStatus); \ 114 123 if (expectedStatus) { \ … … 158 167 size_t offset = startOffset; \ 159 168 int32_t result; \ 160 bool status = decodeInt32(vector , offset, result); \169 bool status = decodeInt32(vector.data(), vector.size(), offset, result); \ 161 170 RELEASE_ASSERT(status == expectedStatus); \ 162 171 if (expectedStatus) { \ … … 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 297 int main(int argc, char** argv) … … 182 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 316 return EXIT_SUCCESS; 185 317 } -
trunk/Source/JavaScriptCore/wasm/JSWASMModule.h
r189993 r204484 80 80 Vector<WASMFunctionImport>& functionImports() { return m_functionImports; } 81 81 Vector<WASMFunctionImportSignature>& functionImportSignatures() { return m_functionImportSignatures; } 82 Vector<WASM Type>& globalVariableTypes() { return m_globalVariableTypes; }82 Vector<WASMValueType>& globalVariableTypes() { return m_globalVariableTypes; } 83 83 Vector<WASMFunctionDeclaration>& functionDeclarations() { return m_functionDeclarations; } 84 84 Vector<WASMFunctionPointerTable>& functionPointerTables() { return m_functionPointerTables; } … … 100 100 Vector<WASMFunctionImport> m_functionImports; 101 101 Vector<WASMFunctionImportSignature> m_functionImportSignatures; 102 Vector<WASM Type> m_globalVariableTypes;102 Vector<WASMValueType> m_globalVariableTypes; 103 103 Vector<WASMFunctionDeclaration> m_functionDeclarations; 104 104 Vector<WASMFunctionPointerTable> m_functionPointerTables; -
trunk/Source/JavaScriptCore/wasm/WASMB3IRGenerator.h
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef DataLog_h 27 #define DataLog_h 26 #pragma once 28 27 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <wtf/FilePrintStream.h> 32 #include <wtf/StdLibExtras.h> 28 #include "B3Compilation.h" 29 #include "VM.h" 30 #include "WASMFormat.h" 33 31 34 namespace WTF { 32 #if ENABLE(WEBASSEMBLY) 35 33 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 34 namespace JSC { 37 35 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 36 namespace WASM { 41 37 42 template<typename... Types> 43 void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 38 std::unique_ptr<B3::Compilation> parseAndCompile(VM&, Vector<uint8_t>&, WASMFunctionInformation, unsigned optLevel = 1); 47 39 48 } // namespace W TF40 } // namespace WASM 49 41 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 42 } // namespace JSC 53 43 54 #endif // DataLog_h 55 44 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/wasm/WASMFormat.h
r189892 r204484 53 53 class JSFunction; 54 54 55 enum class WASM Type : uint8_t {55 enum class WASMValueType : uint8_t { 56 56 I32, 57 I64, 57 58 F32, 58 59 F64, … … 60 61 }; 61 62 62 enum class WASM ExpressionType : uint8_t {63 enum class WASMFunctionReturnType : uint8_t { 63 64 I32, 65 I64, 64 66 F32, 65 67 F64, … … 69 71 70 72 struct WASMSignature { 71 WASM ExpressionType returnType;72 Vector<WASM Type> arguments;73 WASMFunctionReturnType returnType; 74 Vector<WASMValueType> arguments; 73 75 }; 74 76 … … 92 94 }; 93 95 96 struct WASMFunctionInformation { 97 size_t start; 98 size_t end; 99 }; 100 94 101 } // namespace JSC 95 102 -
trunk/Source/JavaScriptCore/wasm/WASMModuleParser.h
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef DataLog_h 27 #define DataLog_h 26 #pragma once 28 27 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <wtf/FilePrintStream.h> 32 #include <wtf/StdLibExtras.h> 28 #include "WASMOps.h" 29 #include "WASMParser.h" 30 #include <wtf/Vector.h> 33 31 34 namespace WTF { 32 #if ENABLE(WEBASSEMBLY) 35 33 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 34 namespace JSC { 37 35 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 36 namespace WASM { 41 37 42 template<typename... Types> 43 void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 38 class WASMModuleParser : public WASMParser { 39 public: 47 40 48 } // namespace WTF 41 static const unsigned magicNumber = 0xc; 49 42 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 43 WASMModuleParser(const Vector<uint8_t>& sourceBuffer) 44 : WASMParser(sourceBuffer, 0, sourceBuffer.size()) 45 { 46 } 53 47 54 #endif // DataLog_h 48 bool WARN_UNUSED_RETURN parse(); 55 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) -
trunk/Source/JavaScriptCore/wasm/WASMOps.h
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef DataLog_h 27 #define DataLog_h 26 #pragma once 28 27 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <wtf/FilePrintStream.h> 32 #include <wtf/StdLibExtras.h> 28 #if ENABLE(WEBASSEMBLY) 33 29 34 namespace WTF{30 namespace JSC { 35 31 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 32 namespace WASM { 37 33 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 34 #define FOR_EACH_WASM_SPECIAL_OP(macro) \ 35 macro(I32Const, 0x10) 41 36 42 template<typename... Types> 43 void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 37 #define FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \ 38 macro(Block, 0x01) \ 39 macro(Return, 0x09) \ 40 macro(End, 0x0f) 47 41 48 } // namespace WTF 42 #define FOR_EACH_WASM_UNARY_OP(macro) 49 43 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 44 #define FOR_EACH_WASM_BINARY_OP(macro) \ 45 macro(I32Add, 0x40) 53 46 54 #endif // DataLog_h 47 #define FOR_EACH_WASM_OP(macro) \ 48 FOR_EACH_WASM_SPECIAL_OP(macro) \ 49 FOR_EACH_WASM_CONTROL_FLOW_OP(macro) \ 50 FOR_EACH_WASM_UNARY_OP(macro) \ 51 FOR_EACH_WASM_BINARY_OP(macro) 55 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) -
trunk/Source/JavaScriptCore/wasm/WASMPlan.cpp
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #i fndef DataLog_h27 # define DataLog_h26 #include "config.h" 27 #include "WASMPlan.h" 28 28 29 #include <stdarg.h>30 #include <stdio.h>31 #include <wtf/FilePrintStream.h>32 #include <wtf/ StdLibExtras.h>29 #include "B3Compilation.h" 30 #include "WASMB3IRGenerator.h" 31 #include "WASMModuleParser.h" 32 #include <wtf/DataLog.h> 33 33 34 namespace WTF { 34 #if ENABLE(WEBASSEMBLY) 35 35 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 36 namespace JSC { 37 37 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 38 namespace WASM { 41 39 42 template<typename... Types> 43 void dataLog(const Types&... values) 40 static const bool verbose = false; 41 42 Plan::Plan(VM& vm, Vector<uint8_t> source) 44 43 { 45 dataFile().print(values...); 44 if (verbose) 45 dataLogLn("Starting plan."); 46 WASMModuleParser moduleParser(source); 47 if (!moduleParser.parse()) { 48 dataLogLn("Parsing module failed."); 49 return; 50 } 51 52 if (verbose) 53 dataLogLn("Parsed module."); 54 55 for (const WASMFunctionInformation& info : moduleParser.functionInformation()) { 56 if (verbose) 57 dataLogLn("Processing funcion starting at: ", info.start, " and ending at: ", info.end); 58 result.append(parseAndCompile(vm, source, info)); 59 } 46 60 } 47 61 48 } // namespace W TF62 } // namespace WASM 49 63 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 64 } // namespace JSC 53 65 54 #endif // DataLog_h 55 66 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/wasm/WASMPlan.h
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef DataLog_h 27 #define DataLog_h 26 #pragma once 28 27 29 #include <stdarg.h>30 #include <stdio.h>31 #include <wtf/ FilePrintStream.h>32 #include <wtf/ StdLibExtras.h>28 #include "CompilationResult.h" 29 #include "VM.h" 30 #include <wtf/ThreadSafeRefCounted.h> 31 #include <wtf/Vector.h> 33 32 34 namespace WTF { 33 #if ENABLE(WEBASSEMBLY) 35 34 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 35 namespace JSC { 37 36 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2);40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 37 namespace B3 { 38 class Compilation; 39 } // namespace B3 41 40 42 template<typename... Types> 43 void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 41 namespace WASM { 47 42 48 } // namespace WTF 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); 49 47 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 48 Vector<std::unique_ptr<B3::Compilation>> result; 49 }; 53 50 54 #endif // DataLog_h 51 } // namespace WASM 55 52 53 } // namespace JSC 54 55 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/wasm/WASMSections.cpp
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #i fndef DataLog_h27 # define DataLog_h26 #include "config.h" 27 #include "WASMSections.h" 28 28 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <wtf/FilePrintStream.h> 32 #include <wtf/StdLibExtras.h> 29 #include <wtf/DataLog.h> 30 #include <wtf/text/WTFString.h> 33 31 34 namespace WTF { 32 #if ENABLE(WEBASSEMBLY) 35 33 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 34 namespace JSC { 37 35 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 36 namespace WASM { 41 37 42 template<typename... Types> 43 void dataLog(const Types&... values) 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) 44 53 { 45 dataFile().print(values...); 54 if (verbose) 55 dataLogLn("Decoding section with name: ", String(name, length)); 56 for (unsigned i = 0; i < sectionDataLength; ++i) { 57 if (sectionData[i].length != length) 58 continue; 59 if (!memcmp(name, sectionData[i].name, length)) 60 return static_cast<WASMSections::Section>(i); 61 } 62 return WASMSections::Section::Unknown; 46 63 } 47 64 48 } // namespace W TF65 } // namespace WASM 49 66 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 67 } // namespace JSC 53 68 54 #endif // DataLog_h 55 69 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/JavaScriptCore/wasm/WASMSections.h
r204483 r204484 1 1 /* 2 * Copyright (C) 201 2Apple Inc. All rights reserved.2 * Copyright (C) 2016 Apple Inc. All rights reserved. 3 3 * 4 4 * Redistribution and use in source and binary forms, with or without … … 21 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 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. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 24 */ 25 25 26 #ifndef DataLog_h 27 #define DataLog_h 26 #pragma once 28 27 29 #include <stdarg.h> 30 #include <stdio.h> 31 #include <wtf/FilePrintStream.h> 32 #include <wtf/StdLibExtras.h> 28 #if ENABLE(WEBASSEMBLY) 33 29 34 namespace WTF{30 namespace JSC { 35 31 36 WTF_EXPORT_PRIVATE FilePrintStream& dataFile(); 32 namespace WASM { 37 33 38 WTF_EXPORT_PRIVATE void dataLogFV(const char* format, va_list) WTF_ATTRIBUTE_PRINTF(1, 0); 39 WTF_EXPORT_PRIVATE void dataLogF(const char* format, ...) WTF_ATTRIBUTE_PRINTF(1, 2); 40 WTF_EXPORT_PRIVATE void dataLogFString(const char*); 34 // These should be in the order that we expect them to be in the binary. 35 #define FOR_EACH_WASM_SECTION_TYPE(macro) \ 36 macro(FunctionTypes, "type") \ 37 macro(Signatures, "function") \ 38 macro(Definitions, "code") \ 39 macro(End, "end") 41 40 42 template<typename... Types> 43 void dataLog(const Types&... values) 44 { 45 dataFile().print(values...); 46 } 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 }; 47 58 48 } // namespace W TF59 } // namespace WASM 49 60 50 using WTF::dataLog; 51 using WTF::dataLogF; 52 using WTF::dataLogFString; 61 } // namespace JSC 53 62 54 #endif // DataLog_h 55 63 #endif // ENABLE(WEBASSEMBLY) -
trunk/Source/WTF/ChangeLog
r204472 r204484 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 Benjamin Poulain. 7 8 * wtf/DataLog.h: 9 (WTF::dataLogLn): Add a new dataLog function, dataLogLn that 10 automagically includes a new line at the end of the print. 11 * wtf/LEBDecoder.h: 12 (decodeUInt32): 13 (decodeInt32): Change the LEBDecoder to take a pointer and length 14 rather than a Vector. 15 1 16 2016-08-15 Keith Rollin <krollin@apple.com> 2 17 -
trunk/Source/WTF/wtf/DataLog.h
r164424 r204484 46 46 } 47 47 48 template<typename... Types> 49 void dataLogLn(const Types&... values) 50 { 51 dataFile().print(values..., "\n"); 52 } 53 48 54 } // namespace WTF 49 55 50 56 using WTF::dataLog; 57 using WTF::dataLogLn; 51 58 using WTF::dataLogF; 52 59 using WTF::dataLogFString; -
trunk/Source/WTF/wtf/LEBDecoder.h
r204218 r204484 27 27 28 28 #include "Compiler.h" 29 #include "Vector.h"30 29 #include <algorithm> 31 32 #include "DataLog.h"33 30 34 31 // This file contains a bunch of helper functions for decoding LEB numbers. … … 38 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 40 result = 0; 44 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 43 for (unsigned i = 0; true; ++i) { 47 44 uint8_t byte = bytes[offset++]; … … 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 59 result = 0; 63 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 62 uint8_t byte; 66 63 for (unsigned i = 0; true; ++i) {
Note: See TracChangeset
for help on using the changeset viewer.