Changeset 189382 in webkit
- Timestamp:
- Sep 4, 2015 2:00:56 PM (9 years ago)
- Location:
- trunk/Source/JavaScriptCore
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/ChangeLog
r189376 r189382 1 2015-09-04 Sukolsak Sakshuwong <sukolsak@gmail.com> 2 3 Implement the GetLocal and SetLocal instructions in WebAssembly 4 https://bugs.webkit.org/show_bug.cgi?id=148793 5 6 Reviewed by Saam Barati. 7 8 This patch implements the GetLocal and SetLocal instructions for locals 9 of type int32 in WebAssembly. A "local" in this context is either an 10 argument or a local variable. 11 12 * tests/stress/wasm-locals.js: Added. 13 (shouldBe): 14 * tests/stress/wasm-locals.wasm: Added. 15 * wasm/WASMFunctionCompiler.h: 16 (JSC::WASMFunctionCompiler::buildSetLocal): 17 (JSC::WASMFunctionCompiler::buildGetLocal): 18 * wasm/WASMFunctionParser.cpp: 19 (JSC::WASMFunctionParser::parseSetLocalStatement): 20 (JSC::WASMFunctionParser::parseExpressionI32): 21 (JSC::WASMFunctionParser::parseGetLocalExpressionI32): 22 * wasm/WASMFunctionParser.h: 23 * wasm/WASMFunctionSyntaxChecker.h: 24 (JSC::WASMFunctionSyntaxChecker::buildSetLocal): 25 (JSC::WASMFunctionSyntaxChecker::buildGetLocal): 26 1 27 2015-09-04 Basile Clement <basile_clement@apple.com> 2 28 -
trunk/Source/JavaScriptCore/wasm/WASMFunctionCompiler.h
r189303 r189382 128 128 } 129 129 130 void buildSetLocal(uint32_t localIndex, int, WASMType type) 131 { 132 switch (type) { 133 case WASMType::I32: 134 load32(temporaryAddress(m_tempStackTop - 1), GPRInfo::regT0); 135 m_tempStackTop--; 136 store32(GPRInfo::regT0, localAddress(localIndex)); 137 break; 138 default: 139 ASSERT_NOT_REACHED(); 140 } 141 } 142 130 143 void buildReturn(int, WASMExpressionType returnType) 131 144 { … … 149 162 { 150 163 store32(TrustedImm32(immediate), temporaryAddress(m_tempStackTop++)); 164 return UNUSED; 165 } 166 167 int buildGetLocal(uint32_t localIndex, WASMType type) 168 { 169 switch (type) { 170 case WASMType::I32: 171 load32(localAddress(localIndex), GPRInfo::regT0); 172 m_tempStackTop++; 173 store32(GPRInfo::regT0, temporaryAddress(m_tempStackTop - 1)); 174 break; 175 default: 176 ASSERT_NOT_REACHED(); 177 } 151 178 return UNUSED; 152 179 } -
trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.cpp
r189303 r189382 211 211 FAIL_IF_FALSE(localIndex < m_localTypes.size(), "The local variable index is incorrect."); 212 212 WASMType type = m_localTypes[localIndex]; 213 parseExpression(context, WASMExpressionType(type)); 214 // FIXME: Implement this instruction. 213 ContextExpression expression = parseExpression(context, WASMExpressionType(type)); 214 PROPAGATE_ERROR(); 215 context.buildSetLocal(localIndex, expression, type); 215 216 return UNUSED; 216 217 } … … 426 427 case WASMOpExpressionI32::Immediate: 427 428 return parseImmediateExpressionI32(context); 429 case WASMOpExpressionI32::GetLocal: 430 return parseGetLocalExpressionI32(context); 428 431 case WASMOpExpressionI32::Add: 429 432 case WASMOpExpressionI32::Sub: 430 433 return parseBinaryExpressionI32(context, op); 431 434 case WASMOpExpressionI32::ConstantPoolIndex: 432 case WASMOpExpressionI32::GetLocal:433 435 case WASMOpExpressionI32::GetGlobal: 434 436 case WASMOpExpressionI32::SetLocal: … … 508 510 case WASMOpExpressionI32WithImmediate::Immediate: 509 511 return parseImmediateExpressionI32(context, immediate); 512 case WASMOpExpressionI32WithImmediate::GetLocal: 513 return parseGetLocalExpressionI32(context, immediate); 510 514 case WASMOpExpressionI32WithImmediate::ConstantPoolIndex: 511 case WASMOpExpressionI32WithImmediate::GetLocal:512 515 // FIXME: Implement these instructions. 513 516 FAIL_WITH_MESSAGE("Unsupported instruction."); … … 534 537 535 538 template <class Context> 539 ContextExpression WASMFunctionParser::parseGetLocalExpressionI32(Context& context, uint32_t localIndex) 540 { 541 FAIL_IF_FALSE(localIndex < m_localTypes.size(), "The local index is incorrect."); 542 FAIL_IF_FALSE(m_localTypes[localIndex] == WASMType::I32, "Expected a local of type int32."); 543 return context.buildGetLocal(localIndex, WASMType::I32); 544 } 545 546 template <class Context> 547 ContextExpression WASMFunctionParser::parseGetLocalExpressionI32(Context& context) 548 { 549 uint32_t localIndex; 550 READ_COMPACT_UINT32_OR_FAIL(localIndex, "Cannot read the local index."); 551 return parseGetLocalExpressionI32(context, localIndex); 552 } 553 554 template <class Context> 536 555 ContextExpression WASMFunctionParser::parseBinaryExpressionI32(Context& context, WASMOpExpressionI32 op) 537 556 { -
trunk/Source/JavaScriptCore/wasm/WASMFunctionParser.h
r189303 r189382 81 81 template <class Context> ContextExpression parseImmediateExpressionI32(Context&, uint32_t immediate); 82 82 template <class Context> ContextExpression parseImmediateExpressionI32(Context&); 83 template <class Context> ContextExpression parseGetLocalExpressionI32(Context&, uint32_t localIndex); 84 template <class Context> ContextExpression parseGetLocalExpressionI32(Context&); 83 85 template <class Context> ContextExpression parseBinaryExpressionI32(Context&, WASMOpExpressionI32); 84 86 -
trunk/Source/JavaScriptCore/wasm/WASMFunctionSyntaxChecker.h
r189303 r189382 48 48 } 49 49 50 void buildSetLocal(uint32_t, int, WASMType) 51 { 52 m_tempStackTop--; 53 } 54 50 55 void buildReturn(int, WASMExpressionType returnType) 51 56 { … … 55 60 56 61 int buildImmediateI32(uint32_t) 62 { 63 m_tempStackTop++; 64 updateTempStackHeight(); 65 return UNUSED; 66 } 67 68 int buildGetLocal(uint32_t, WASMType) 57 69 { 58 70 m_tempStackTop++;
Note: See TracChangeset
for help on using the changeset viewer.