BackendOpCodeAttrAsmJs.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //-------------------------------------------------------------------------------------------------------
  5. #include "Backend.h"
  6. #ifdef ASMJS_PLAT
  7. namespace OpCodeAttrAsmJs
  8. {
  9. // OpSideEffect:
  10. // Opcode has side effect not just to the dst/src on the instruction.
  11. // The opcode cannot be deadstored. (e.g. StFld, LdFld from DOM, call valueOf/toString/getter/setter)
  12. // Doesn't include all "exit" script (e.g. LdThis doesn't have side effect for HostDispatch for exiting script to getting the name space parent)
  13. // OpHasImplicitCall:
  14. // Include all possible exit scripts, call valueOf/toString/getter/setter
  15. // OpSerialized:
  16. // Op is a serialized (indirected) variant of another op code
  17. enum OpCodeAttrEnum
  18. {
  19. None = 0,
  20. OpNoFallThrough = 1 << 0, // Opcode doesn't fallthrough in flow and its always jump to the return from this opcode.
  21. OpHasMultiSizeLayout = 1 << 1,
  22. };
  23. static const int OpcodeAttributesAsmJs[] =
  24. {
  25. #define DEF_OP(name, jnLayout, attrib, ...) attrib,
  26. #include "ByteCode/OpCodeListAsmJs.h"
  27. #undef DEF_OP
  28. };
  29. static const int ExtendedOpcodeAttributesAsmJs[] =
  30. {
  31. #define DEF_OP(name, jnLayout, attrib, ...) attrib,
  32. #include "ByteCode/ExtendedOpCodeListAsmJs.h"
  33. #undef DEF_OP
  34. };
  35. static const int GetOpCodeAttributes( Js::OpCodeAsmJs op )
  36. {
  37. uint opIndex = (uint)op;
  38. if (opIndex <= (uint)Js::OpCodeAsmJs::MaxByteSizedOpcodes)
  39. {
  40. AnalysisAssert(opIndex < _countof(OpcodeAttributesAsmJs));
  41. return OpcodeAttributesAsmJs[opIndex];
  42. }
  43. opIndex -= ( Js::OpCodeAsmJs::MaxByteSizedOpcodes + 1 );
  44. AnalysisAssert(opIndex < _countof(ExtendedOpcodeAttributesAsmJs));
  45. return ExtendedOpcodeAttributesAsmJs[opIndex];
  46. }
  47. #define CheckHasFlag(flag) (!!(GetOpCodeAttributes(opcode) & flag))
  48. #define CheckNoHasFlag(flag) (!(GetOpCodeAttributes(opcode) & flag))
  49. bool HasFallThrough( Js::OpCodeAsmJs opcode )
  50. {
  51. return CheckNoHasFlag( OpNoFallThrough );
  52. }
  53. bool HasMultiSizeLayout( Js::OpCodeAsmJs opcode )
  54. {
  55. return CheckHasFlag( OpHasMultiSizeLayout );
  56. }
  57. }; // OpCodeAttrAsmJs
  58. #endif