ContextStatement WASMFunctionParser::parseIfElseStatement(Context& context) { parseExpressionI32(context); PROPAGATE_ERROR(); parseStatement(context); PROPAGATE_ERROR(); parseStatement(context); // FIXME: Implement this instruction. return UNUSED; }
void WASMModuleParser::parseModule(ExecState* exec) { uint32_t magicNumber; READ_UINT32_OR_FAIL(magicNumber, "Cannot read the magic number."); FAIL_IF_FALSE(magicNumber == wasmMagicNumber, "The magic number is incorrect."); uint32_t outputSizeInASMJS; READ_UINT32_OR_FAIL(outputSizeInASMJS, "Cannot read the output size in asm.js format."); parseConstantPoolSection(); PROPAGATE_ERROR(); parseSignatureSection(); PROPAGATE_ERROR(); parseFunctionImportSection(exec); PROPAGATE_ERROR(); parseGlobalSection(exec); PROPAGATE_ERROR(); parseFunctionDeclarationSection(); PROPAGATE_ERROR(); parseFunctionPointerTableSection(); PROPAGATE_ERROR(); parseFunctionDefinitionSection(); PROPAGATE_ERROR(); parseExportSection(); PROPAGATE_ERROR(); FAIL_IF_FALSE(!m_module->arrayBuffer() || m_module->arrayBuffer()->impl()->byteLength() < (1u << 31), "The ArrayBuffer's length must be less than 2^31."); }
ContextStatement WASMFunctionParser::parseWhileStatement(Context& context) { parseExpressionI32(context); PROPAGATE_ERROR(); m_breakScopeDepth++; m_continueScopeDepth++; parseStatement(context); PROPAGATE_ERROR(); m_continueScopeDepth--; m_breakScopeDepth--; // FIXME: Implement this instruction. return UNUSED; }
void WASMModuleParser::parseFunctionDefinitionSection() { for (size_t i = 0; i < m_module->functionDeclarations().size(); ++i) { parseFunctionDefinition(); PROPAGATE_ERROR(); } }
ContextStatement WASMFunctionParser::parseSwitchStatement(Context& context) { uint32_t numberOfCases; READ_COMPACT_UINT32_OR_FAIL(numberOfCases, "Cannot read the number of cases."); parseExpressionI32(context); PROPAGATE_ERROR(); m_breakScopeDepth++; for (uint32_t i = 0; i < numberOfCases; ++i) { WASMSwitchCase switchCase; READ_SWITCH_CASE_OR_FAIL(switchCase, "Cannot read the switch case."); switch (switchCase) { case WASMSwitchCase::CaseWithNoStatements: case WASMSwitchCase::CaseWithStatement: case WASMSwitchCase::CaseWithBlockStatement: { uint32_t value; READ_COMPACT_INT32_OR_FAIL(value, "Cannot read the value of the switch case."); if (switchCase == WASMSwitchCase::CaseWithStatement) { parseStatement(context); PROPAGATE_ERROR(); } else if (switchCase == WASMSwitchCase::CaseWithBlockStatement) { parseBlockStatement(context); PROPAGATE_ERROR(); } break; } case WASMSwitchCase::DefaultWithNoStatements: case WASMSwitchCase::DefaultWithStatement: case WASMSwitchCase::DefaultWithBlockStatement: { FAIL_IF_FALSE(i == numberOfCases - 1, "The default case must be the last case."); if (switchCase == WASMSwitchCase::DefaultWithStatement) { parseStatement(context); PROPAGATE_ERROR(); } else if (switchCase == WASMSwitchCase::DefaultWithBlockStatement) { parseBlockStatement(context); PROPAGATE_ERROR(); } break; } default: ASSERT_NOT_REACHED(); } } m_breakScopeDepth--; // FIXME: Implement this instruction. return UNUSED; }
void WASMModuleParser::parseModule() { uint32_t magicNumber; READ_UINT32_OR_FAIL(magicNumber, "Cannot read the magic number."); FAIL_IF_FALSE(magicNumber == wasmMagicNumber, "The magic number is incorrect."); uint32_t outputSizeInASMJS; READ_UINT32_OR_FAIL(outputSizeInASMJS, "Cannot read the output size in asm.js format."); parseConstantPoolSection(); PROPAGATE_ERROR(); parseSignatureSection(); PROPAGATE_ERROR(); parseFunctionImportSection(); PROPAGATE_ERROR(); parseGlobalSection(); PROPAGATE_ERROR(); parseFunctionDeclarationSection(); PROPAGATE_ERROR(); parseFunctionPointerTableSection(); PROPAGATE_ERROR(); parseFunctionDefinitionSection(); PROPAGATE_ERROR(); parseExportSection(); }
ContextStatement WASMFunctionParser::parseLabelStatement(Context& context) { m_labelDepth++; parseStatement(context); PROPAGATE_ERROR(); m_labelDepth--; // FIXME: Implement this instruction. return UNUSED; }
ContextStatement WASMFunctionParser::parseBlockStatement(Context& context) { uint32_t numberOfStatements; READ_COMPACT_UINT32_OR_FAIL(numberOfStatements, "Cannot read the number of statements."); for (uint32_t i = 0; i < numberOfStatements; ++i) { parseStatement(context); PROPAGATE_ERROR(); } return UNUSED; }
void WASMModuleParser::parseFunctionDefinitionSection() { for (size_t functionIndex = 0; functionIndex < m_module->functionDeclarations().size(); ++functionIndex) { parseFunctionDefinition(functionIndex); PROPAGATE_ERROR(); } for (WASMFunctionPointerTable& functionPointerTable : m_module->functionPointerTables()) { for (size_t i = 0; i < functionPointerTable.functionIndices.size(); ++i) functionPointerTable.functions.uncheckedAppend(m_module->functions()[functionPointerTable.functionIndices[i]].get()); } }
bool WASMFunctionParser::parseFunction(Context& context) { const WASMSignature& signature = m_module->signatures()[m_module->functionDeclarations()[m_functionIndex].signatureIndex]; m_returnType = signature.returnType; parseLocalVariables(); PROPAGATE_ERROR(); const Vector<WASMType>& arguments = signature.arguments; for (size_t i = 0; i < arguments.size(); ++i) m_localTypes.append(arguments[i]); for (uint32_t i = 0; i < m_numberOfI32LocalVariables; ++i) m_localTypes.append(WASMType::I32); for (uint32_t i = 0; i < m_numberOfF32LocalVariables; ++i) m_localTypes.append(WASMType::F32); for (uint32_t i = 0; i < m_numberOfF64LocalVariables; ++i) m_localTypes.append(WASMType::F64); parseBlockStatement(context); return true; }
void WASMModuleParser::parseFunctionImportSection(ExecState* exec) { uint32_t numberOfFunctionImports; uint32_t numberOfFunctionImportSignatures; READ_COMPACT_UINT32_OR_FAIL(numberOfFunctionImports, "Cannot read the number of function imports."); READ_COMPACT_UINT32_OR_FAIL(numberOfFunctionImportSignatures, "Cannot read the number of function import signatures."); m_module->functionImports().reserveInitialCapacity(numberOfFunctionImports); m_module->functionImportSignatures().reserveInitialCapacity(numberOfFunctionImportSignatures); m_module->importedFunctions().reserveInitialCapacity(numberOfFunctionImports); for (uint32_t functionImportIndex = 0; functionImportIndex < numberOfFunctionImports; ++functionImportIndex) { WASMFunctionImport functionImport; READ_STRING_OR_FAIL(functionImport.functionName, "Cannot read the function import name."); m_module->functionImports().uncheckedAppend(functionImport); uint32_t numberOfSignatures; READ_COMPACT_UINT32_OR_FAIL(numberOfSignatures, "Cannot read the number of signatures."); FAIL_IF_FALSE(numberOfSignatures <= numberOfFunctionImportSignatures - m_module->functionImportSignatures().size(), "The number of signatures is incorrect."); for (uint32_t i = 0; i < numberOfSignatures; ++i) { WASMFunctionImportSignature functionImportSignature; READ_COMPACT_UINT32_OR_FAIL(functionImportSignature.signatureIndex, "Cannot read the signature index."); FAIL_IF_FALSE(functionImportSignature.signatureIndex < m_module->signatures().size(), "The signature index is incorrect."); functionImportSignature.functionImportIndex = functionImportIndex; m_module->functionImportSignatures().uncheckedAppend(functionImportSignature); } JSValue value; getImportedValue(exec, functionImport.functionName, value); PROPAGATE_ERROR(); FAIL_IF_FALSE(value.isFunction(), "\"" + functionImport.functionName + "\" is not a function."); JSFunction* function = jsCast<JSFunction*>(value.asCell()); m_module->importedFunctions().uncheckedAppend(WriteBarrier<JSFunction>(m_vm, m_module.get(), function)); } FAIL_IF_FALSE(m_module->functionImportSignatures().size() == numberOfFunctionImportSignatures, "The number of function import signatures is incorrect."); }
MINIMGAPI_API int TransposeMinImage( const MinImg *p_dst_image, const MinImg *p_src_image) { #if defined(MINSTOPWATCH_ENABLED) DECLARE_MINSTOPWATCH_CTL(gsw_TransposeMinImage); #endif // defined(MINSTOPWATCH_ENABLED) PROPAGATE_ERROR(_AssureMinImageIsValid(p_dst_image)); PROPAGATE_ERROR(_AssureMinImageIsValid(p_src_image)); DECLARE_GUARDED_MINIMG(tmp_image); PROPAGATE_ERROR(CloneTransposedMinImagePrototype(&tmp_image, p_dst_image, AO_EMPTY)); if (CompareMinImagePrototypes(&tmp_image, p_src_image)) return BAD_ARGS; if (_AssureMinImageIsEmpty(p_src_image) == NO_ERRORS) return NO_ERRORS; if (p_dst_image->addressSpace != 0) return NOT_IMPLEMENTED; const MinImg *p_work_dst_image = p_dst_image; const MinImg *p_work_src_image = p_src_image; uint32_t tangling = 0; PROPAGATE_ERROR(CheckMinImagesTangle(&tangling, p_dst_image, p_src_image)); if (tangling != TCR_INDEPENDENT_IMAGES) { PROPAGATE_ERROR(AllocMinImage(&tmp_image)); PROPAGATE_ERROR(CopyMinImage(&tmp_image, p_src_image)); p_work_src_image = &tmp_image; } int bits_per_pixel = GetMinImageBitsPerPixel(p_work_src_image); if (bits_per_pixel == 1) return Transpose1BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); if (bits_per_pixel & 0x07) return TransposeNBitsImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height, bits_per_pixel); int bytes_per_pixel = bits_per_pixel >> 3; switch (bytes_per_pixel) { case 1: #ifdef USE_NEON_SIMD // Transpose8BitImage16x128Vertical is not always faster than Transpose8BitImage, // so it is not used here. It was tested on 'odroid' platform. return Transpose8BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); #else // !USE_NEON_SIMD if (p_work_src_image->height >= 16 && p_work_src_image->width >= 128) return Transpose8BitImage16x128Vertical ( p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); else return Transpose8BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); #endif // !USE_NEON_SIMD case 2: return Transpose16BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); case 4: return Transpose32BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); case 8: return Transpose64BitImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height); default: return TransposeNBytesImage(p_work_dst_image->pScan0, p_work_dst_image->stride, p_work_src_image->pScan0, p_work_src_image->stride, p_work_src_image->width, p_work_src_image->height, bytes_per_pixel); } }
void WASMModuleParser::parseGlobalSection(ExecState* exec) { uint32_t numberOfInternalI32GlobalVariables; uint32_t numberOfInternalF32GlobalVariables; uint32_t numberOfInternalF64GlobalVariables; uint32_t numberOfImportedI32GlobalVariables; uint32_t numberOfImportedF32GlobalVariables; uint32_t numberOfImportedF64GlobalVariables; READ_COMPACT_UINT32_OR_FAIL(numberOfInternalI32GlobalVariables, "Cannot read the number of internal int32 global variables."); READ_COMPACT_UINT32_OR_FAIL(numberOfInternalF32GlobalVariables, "Cannot read the number of internal float32 global variables."); READ_COMPACT_UINT32_OR_FAIL(numberOfInternalF64GlobalVariables, "Cannot read the number of internal float64 global variables."); READ_COMPACT_UINT32_OR_FAIL(numberOfImportedI32GlobalVariables, "Cannot read the number of imported int32 global variables."); READ_COMPACT_UINT32_OR_FAIL(numberOfImportedF32GlobalVariables, "Cannot read the number of imported float32 global variables."); READ_COMPACT_UINT32_OR_FAIL(numberOfImportedF64GlobalVariables, "Cannot read the number of imported float64 global variables."); uint32_t numberOfGlobalVariables = numberOfInternalI32GlobalVariables + numberOfInternalF32GlobalVariables + numberOfInternalF64GlobalVariables + numberOfImportedI32GlobalVariables + numberOfImportedF32GlobalVariables + numberOfImportedF64GlobalVariables; Vector<WASMType>& globalVariableTypes = m_module->globalVariableTypes(); globalVariableTypes.reserveInitialCapacity(numberOfGlobalVariables); Vector<JSWASMModule::GlobalVariable>& globalVariables = m_module->globalVariables(); globalVariables.reserveInitialCapacity(numberOfGlobalVariables); for (uint32_t i = 0; i < numberOfInternalI32GlobalVariables; ++i) { globalVariableTypes.uncheckedAppend(WASMType::I32); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0)); } for (uint32_t i = 0; i < numberOfInternalF32GlobalVariables; ++i) { globalVariableTypes.uncheckedAppend(WASMType::F32); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0f)); } for (uint32_t i = 0; i < numberOfInternalF64GlobalVariables; ++i) { globalVariableTypes.uncheckedAppend(WASMType::F64); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(0.0)); } for (uint32_t i = 0; i < numberOfImportedI32GlobalVariables; ++i) { String importName; READ_STRING_OR_FAIL(importName, "Cannot read the import name of an int32 global variable."); globalVariableTypes.uncheckedAppend(WASMType::I32); JSValue value; getImportedValue(exec, importName, value); PROPAGATE_ERROR(); FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toInt32(exec))); } for (uint32_t i = 0; i < numberOfImportedF32GlobalVariables; ++i) { String importName; READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float32 global variable."); globalVariableTypes.uncheckedAppend(WASMType::F32); JSValue value; getImportedValue(exec, importName, value); PROPAGATE_ERROR(); FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(static_cast<float>(value.toNumber(exec)))); } for (uint32_t i = 0; i < numberOfImportedF64GlobalVariables; ++i) { String importName; READ_STRING_OR_FAIL(importName, "Cannot read the import name of a float64 global variable."); globalVariableTypes.uncheckedAppend(WASMType::F64); JSValue value; getImportedValue(exec, importName, value); PROPAGATE_ERROR(); FAIL_IF_FALSE(value.isPrimitive() && !value.isSymbol(), "\"" + importName + "\" is not a primitive or is a Symbol."); globalVariables.uncheckedAppend(JSWASMModule::GlobalVariable(value.toNumber(exec))); } }