Backend.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. NativeCodeGenerator *
  7. NewNativeCodeGenerator(Js::ScriptContext * scriptContext)
  8. {
  9. return HeapNew(NativeCodeGenerator, scriptContext);
  10. }
  11. void
  12. DeleteNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
  13. {
  14. HeapDelete(nativeCodeGen);
  15. }
  16. void
  17. CloseNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
  18. {
  19. nativeCodeGen->Close();
  20. }
  21. bool
  22. IsClosedNativeCodeGenerator(NativeCodeGenerator * nativeCodeGen)
  23. {
  24. return nativeCodeGen->IsClosed();
  25. }
  26. void SetProfileModeNativeCodeGen(NativeCodeGenerator *pNativeCodeGen, BOOL fSet)
  27. {
  28. pNativeCodeGen->SetProfileMode(fSet);
  29. }
  30. void UpdateNativeCodeGeneratorForDebugMode(NativeCodeGenerator* nativeCodeGen)
  31. {
  32. nativeCodeGen->UpdateQueueForDebugMode();
  33. }
  34. CriticalSection *GetNativeCodeGenCriticalSection(NativeCodeGenerator *pNativeCodeGen)
  35. {
  36. return pNativeCodeGen->Processor()->GetCriticalSection();
  37. }
  38. ///----------------------------------------------------------------------------
  39. ///
  40. /// GenerateFunction
  41. ///
  42. /// This is the main entry point for the runtime to call the native code
  43. /// generator for js function.
  44. ///
  45. ///----------------------------------------------------------------------------
  46. void
  47. GenerateFunction(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody * fn, Js::ScriptFunction * function)
  48. {
  49. nativeCodeGen->GenerateFunction(fn, function);
  50. }
  51. CodeGenAllocators* GetForegroundAllocator(NativeCodeGenerator * nativeCodeGen, PageAllocator* pageallocator)
  52. {
  53. return nativeCodeGen->GetCodeGenAllocator(pageallocator);
  54. }
  55. #ifdef ENABLE_PREJIT
  56. void
  57. GenerateAllFunctions(NativeCodeGenerator * nativeCodeGen, Js::FunctionBody *fn)
  58. {
  59. nativeCodeGen->GenerateAllFunctions(fn);
  60. }
  61. #endif
  62. #ifdef IR_VIEWER
  63. Js::Var
  64. RejitIRViewerFunction(NativeCodeGenerator *nativeCodeGen, Js::FunctionBody *fn, Js::ScriptContext *scriptContext)
  65. {
  66. return nativeCodeGen->RejitIRViewerFunction(fn, scriptContext);
  67. }
  68. #endif
  69. void
  70. GenerateLoopBody(NativeCodeGenerator *nativeCodeGen, Js::FunctionBody *fn, Js::LoopHeader * loopHeader, Js::EntryPointInfo* info, uint localCount, Js::Var localSlots[])
  71. {
  72. nativeCodeGen->GenerateLoopBody(fn, loopHeader, info, localCount, localSlots);
  73. }
  74. void
  75. NativeCodeGenEnterScriptStart(NativeCodeGenerator * nativeCodeGen)
  76. {
  77. if (nativeCodeGen)
  78. {
  79. nativeCodeGen->EnterScriptStart();
  80. }
  81. }
  82. BOOL IsIntermediateCodeGenThunk(Js::JavascriptMethod codeAddress)
  83. {
  84. return NativeCodeGenerator::IsThunk(codeAddress);
  85. }
  86. BOOL IsAsmJsCodeGenThunk(Js::JavascriptMethod codeAddress)
  87. {
  88. return NativeCodeGenerator::IsAsmJsCodeGenThunk(codeAddress);
  89. }
  90. CheckCodeGenFunction GetCheckCodeGenFunction(Js::JavascriptMethod codeAddress)
  91. {
  92. return NativeCodeGenerator::GetCheckCodeGenFunction(codeAddress);
  93. }
  94. uint GetBailOutRegisterSaveSlotCount()
  95. {
  96. // REVIEW: not all registers are used, we are allocating more space then necessary.
  97. return LinearScanMD::GetRegisterSaveSlotCount();
  98. }
  99. uint
  100. GetBailOutReserveSlotCount()
  101. {
  102. return 1; //For arguments id
  103. }
  104. #if DBG
  105. void CheckIsExecutable(Js::RecyclableObject * function, Js::JavascriptMethod entrypoint)
  106. {
  107. Js::ScriptContext * scriptContext = function->GetScriptContext();
  108. // it's easy to call the default entry point from RecyclableObject.
  109. AssertMsg((Js::JavascriptFunction::Is(function) && Js::JavascriptFunction::FromVar(function)->IsExternalFunction())
  110. || Js::CrossSite::IsThunk(entrypoint) || !scriptContext->IsActuallyClosed() ||
  111. (scriptContext->GetThreadContext()->IsScriptActive() && !Js::JavascriptConversion::IsCallable(function)),
  112. "Can't call function when the script context is closed");
  113. if (scriptContext->GetThreadContext()->IsScriptActive())
  114. {
  115. return;
  116. }
  117. if (function->IsExternal())
  118. {
  119. return;
  120. }
  121. if (Js::JavascriptOperators::GetTypeId(function) == Js::TypeIds_HostDispatch)
  122. {
  123. AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
  124. }
  125. else if (Js::JavascriptFunction::Is(function))
  126. {
  127. if (((Js::JavascriptFunction*)function)->IsExternalFunction())
  128. {
  129. return;
  130. }
  131. else if (((Js::JavascriptFunction*)function)->IsWinRTFunction())
  132. {
  133. return;
  134. }
  135. else
  136. {
  137. AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
  138. }
  139. }
  140. else
  141. {
  142. AssertMsg(false, "Has to go through CallRootFunction to start calling Javascript function");
  143. }
  144. }
  145. #endif
  146. #ifdef PROFILE_EXEC
  147. void
  148. CreateProfilerNativeCodeGen(NativeCodeGenerator * nativeCodeGen, Js::ScriptContextProfiler * profiler)
  149. {
  150. nativeCodeGen->CreateProfiler(profiler);
  151. }
  152. void
  153. ProfilePrintNativeCodeGen(NativeCodeGenerator * nativeCodeGen)
  154. {
  155. nativeCodeGen->ProfilePrint();
  156. }
  157. void
  158. SetProfilerFromNativeCodeGen(NativeCodeGenerator * toNativeCodeGen, NativeCodeGenerator * fromNativeCodeGen)
  159. {
  160. toNativeCodeGen->SetProfilerFromNativeCodeGen(fromNativeCodeGen);
  161. }
  162. #endif
  163. void DeleteNativeCodeData(NativeCodeData * data)
  164. {
  165. delete data;
  166. }