AsmJs.h 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. // Portions of this file are copyright 2014 Mozilla Foundation, available under the Apache 2.0 license.
  5. //-------------------------------------------------------------------------------------------------------
  6. //-------------------------------------------------------------------------------------------------------
  7. // Copyright 2014 Mozilla Foundation
  8. //
  9. // Licensed under the Apache License, Version 2.0 (the "License");
  10. // you may not use this file except in compliance with the License.
  11. // You may obtain a copy of the License at
  12. //
  13. // http ://www.apache.org/licenses/LICENSE-2.0
  14. //
  15. // Unless required by applicable law or agreed to in writing, software
  16. // distributed under the License is distributed on an "AS IS" BASIS,
  17. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  18. // See the License for the specific language governing permissions and
  19. // limitations under the License.
  20. //-------------------------------------------------------------------------------------------------------
  21. #pragma once
  22. #ifdef ASMJS_PLAT
  23. namespace Js
  24. {
  25. struct ExclusiveContext
  26. {
  27. ByteCodeGenerator* byteCodeGenerator;
  28. ScriptContext *scriptContext;
  29. ExclusiveContext( ByteCodeGenerator *_byteCodeGenerator, ScriptContext * _scriptContext ) :byteCodeGenerator( _byteCodeGenerator ), scriptContext( _scriptContext ){};
  30. };
  31. class AsmJSCompiler
  32. {
  33. public:
  34. static bool CheckModule( ExclusiveContext *cx, AsmJSParser &parser, ParseNode *stmtList );
  35. static bool CheckIdentifier( AsmJsModuleCompiler &m, ParseNode *usepn, PropertyName name );
  36. static bool CheckModuleLevelName( AsmJsModuleCompiler &m, ParseNode *usepn, PropertyName name );
  37. static bool CheckFunctionHead( AsmJsModuleCompiler &m, ParseNode *fn, bool isGlobal = true );
  38. static bool CheckTypeAnnotation( AsmJsModuleCompiler &m, ParseNode *coercionNode, AsmJSCoercion *coercion, ParseNode **coercedExpr = nullptr);
  39. static bool CheckModuleArgument( AsmJsModuleCompiler &m, ParseNode *arg, PropertyName *name, AsmJsModuleArg::ArgType type);
  40. static bool CheckModuleArguments( AsmJsModuleCompiler &m, ParseNode *fn );
  41. static bool CheckModuleGlobals( AsmJsModuleCompiler &m );
  42. static bool CheckModuleGlobal( AsmJsModuleCompiler &m, ParseNode *var );
  43. static bool CheckGlobalDotImport( AsmJsModuleCompiler &m, PropertyName varName, ParseNode *initNode );
  44. static bool CheckNewArrayView( AsmJsModuleCompiler &m, PropertyName varName, ParseNode *newExpr );
  45. static bool CheckFunction( AsmJsModuleCompiler &m, ParseNodeFnc* fncNode );
  46. static bool CheckFunctionsSequential(AsmJsModuleCompiler &m);
  47. static bool CheckChangeHeap(AsmJsModuleCompiler &m);
  48. static bool CheckByteLengthCall(AsmJsModuleCompiler &m, ParseNode * node, ParseNode * newBufferDecl);
  49. static bool CheckGlobalVariableInitImport( AsmJsModuleCompiler &m, PropertyName varName, ParseNode *initNode, bool isMutable = true );
  50. static bool CheckGlobalVariableImportExpr(AsmJsModuleCompiler &m, PropertyName varName, AsmJSCoercion coercion, ParseNode *coercedExpr);
  51. static bool CheckFunctionTables(AsmJsModuleCompiler& m);
  52. static bool CheckModuleReturn( AsmJsModuleCompiler& m );
  53. static bool CheckFuncPtrTables( AsmJsModuleCompiler &m );
  54. static void OutputError(ScriptContext * scriptContext, const wchar * message, ...);
  55. static void OutputMessage(ScriptContext * scriptContext, const DEBUG_EVENT_INFO_TYPE messageType, const wchar * message, ...);
  56. static void VOutputMessage(ScriptContext * scriptContext, const DEBUG_EVENT_INFO_TYPE messageType, const wchar * message, va_list argptr);
  57. public:
  58. bool static Compile(ExclusiveContext *cx, AsmJSParser parser, ParseNode *stmtList);
  59. };
  60. }
  61. #endif