14514f5e3Sopenharmony_ci/* 24514f5e3Sopenharmony_ci * Copyright (c) 2021-2024 Huawei Device Co., Ltd. 34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License. 54514f5e3Sopenharmony_ci * You may obtain a copy of the License at 64514f5e3Sopenharmony_ci * 74514f5e3Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 84514f5e3Sopenharmony_ci * 94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and 134514f5e3Sopenharmony_ci * limitations under the License. 144514f5e3Sopenharmony_ci */ 154514f5e3Sopenharmony_ci 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/base/config.h" 204514f5e3Sopenharmony_ci#include "ecmascript/ecma_runtime_call_info.h" 214514f5e3Sopenharmony_ci#include "ecmascript/frames.h" 224514f5e3Sopenharmony_ci#include "ecmascript/method.h" 234514f5e3Sopenharmony_ci#include "ecmascript/js_tagged_value.h" 244514f5e3Sopenharmony_ci#include "ecmascript/js_function.h" 254514f5e3Sopenharmony_ci#include "ecmascript/js_handle.h" 264514f5e3Sopenharmony_ci#include "ecmascript/js_thread.h" 274514f5e3Sopenharmony_ci 284514f5e3Sopenharmony_cinamespace panda::ecmascript { 294514f5e3Sopenharmony_ciusing DispatchEntryPoint = 304514f5e3Sopenharmony_ci void (*)(JSThread *, const uint8_t *, JSTaggedType *, JSTaggedValue, JSTaggedValue, JSTaggedValue, int16_t); 314514f5e3Sopenharmony_ciclass ConstantPool; 324514f5e3Sopenharmony_ciclass ECMAObject; 334514f5e3Sopenharmony_ciclass GeneratorContext; 344514f5e3Sopenharmony_cistruct CallParams; 354514f5e3Sopenharmony_ci 364514f5e3Sopenharmony_ciclass InterpreterAssembly { 374514f5e3Sopenharmony_cipublic: 384514f5e3Sopenharmony_ci enum ActualNumArgsOfCall : uint8_t { CALLARG0 = 0, CALLARG1, CALLARGS2, CALLARGS3 }; 394514f5e3Sopenharmony_ci static void InitStackFrame(JSThread *thread); 404514f5e3Sopenharmony_ci static void InitStackFrame(EcmaContext *context); 414514f5e3Sopenharmony_ci static JSTaggedValue Execute(EcmaRuntimeCallInfo *info); 424514f5e3Sopenharmony_ci static JSTaggedValue GeneratorReEnterInterpreter(JSThread *thread, JSHandle<GeneratorContext> context); 434514f5e3Sopenharmony_ci static inline size_t GetJumpSizeAfterCall(const uint8_t *prevPc); 444514f5e3Sopenharmony_ci static inline void MethodEntry(JSThread *thread, Method *method, JSTaggedValue env); 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ci static inline JSTaggedValue UpdateHotnessCounter(JSThread* thread, JSTaggedType *sp); 474514f5e3Sopenharmony_ci static inline void InterpreterFrameCopyArgs(JSTaggedType *newSp, uint32_t numVregs, uint32_t numActualArgs, 484514f5e3Sopenharmony_ci uint32_t numDeclaredArgs, bool haveExtraArgs = true); 494514f5e3Sopenharmony_ci static JSTaggedValue GetFunction(JSTaggedType *sp); 504514f5e3Sopenharmony_ci static JSTaggedValue GetNewTarget(JSTaggedType *sp); 514514f5e3Sopenharmony_ci static JSTaggedValue GetThis(JSTaggedType *sp); 524514f5e3Sopenharmony_ci static JSTaggedValue GetConstantPool(JSTaggedType *sp); 534514f5e3Sopenharmony_ci static JSTaggedValue GetUnsharedConstpool(JSThread* thread, JSTaggedType *sp); 544514f5e3Sopenharmony_ci static JSTaggedValue GetModule(JSTaggedType *sp); 554514f5e3Sopenharmony_ci static JSTaggedValue GetProfileTypeInfo(JSTaggedType *sp); 564514f5e3Sopenharmony_ci static uint32_t GetNumArgs(JSTaggedType *sp, uint32_t restIdx, uint32_t &startIdx); 574514f5e3Sopenharmony_ci static JSTaggedType *GetAsmInterpreterFramePointer(AsmInterpretedFrame *state); 584514f5e3Sopenharmony_ci 594514f5e3Sopenharmony_ci static bool AssemblyIsFastNewFrameEnter(JSFunction *ctor, JSHandle<Method> method); 604514f5e3Sopenharmony_ci 614514f5e3Sopenharmony_ci#ifndef EXCLUDE_C_INTERPRETER 624514f5e3Sopenharmony_ci#define DEF_HANDLER(name) \ 634514f5e3Sopenharmony_ci static void name(JSThread *thread, const uint8_t *pc, JSTaggedType *sp, \ 644514f5e3Sopenharmony_ci JSTaggedValue constpool, JSTaggedValue profileTypeInfo, \ 654514f5e3Sopenharmony_ci JSTaggedValue acc, int16_t hotnessCounter); 664514f5e3Sopenharmony_ci ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 674514f5e3Sopenharmony_ci ASM_INTERPRETER_SECOND_BC_STUB_ID_LIST(DEF_HANDLER) 684514f5e3Sopenharmony_ci#undef DEF_HANDLER 694514f5e3Sopenharmony_ci#endif 704514f5e3Sopenharmony_ciprivate: 714514f5e3Sopenharmony_ci static void InitStackFrameForSP(JSTaggedType *prevSp); 724514f5e3Sopenharmony_ci}; 734514f5e3Sopenharmony_ci 744514f5e3Sopenharmony_ci#ifndef EXCLUDE_C_INTERPRETER 754514f5e3Sopenharmony_ci#define DEF_HANDLER(name) InterpreterAssembly::name, 764514f5e3Sopenharmony_cistatic std::array<DispatchEntryPoint, BCStubEntries::BC_HANDLER_COUNT> asmDispatchTable { 774514f5e3Sopenharmony_ci ASM_INTERPRETER_BC_STUB_ID_LIST(DEF_HANDLER) 784514f5e3Sopenharmony_ci}; 794514f5e3Sopenharmony_cistatic std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_DEPRECATED_STUBS> deprecatedDispatchTable { 804514f5e3Sopenharmony_ci ASM_INTERPRETER_DEPRECATED_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 814514f5e3Sopenharmony_ci}; 824514f5e3Sopenharmony_cistatic std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_WIDE_STUBS> wideDispatchTable { 834514f5e3Sopenharmony_ci ASM_INTERPRETER_WIDE_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 844514f5e3Sopenharmony_ci}; 854514f5e3Sopenharmony_cistatic std::array<DispatchEntryPoint, kungfu::BytecodeStubCSigns::NUM_OF_THROW_STUBS> throwDispatchTable { 864514f5e3Sopenharmony_ci ASM_INTERPRETER_THROW_STUB_LIST(DEF_HANDLER, DEF_HANDLER, DEF_HANDLER) 874514f5e3Sopenharmony_ci}; 884514f5e3Sopenharmony_ci#undef DEF_HANDLER 894514f5e3Sopenharmony_ci#endif 904514f5e3Sopenharmony_ci 914514f5e3Sopenharmony_ci} // namespace panda::ecmascript 924514f5e3Sopenharmony_ci#endif // ECMASCRIPT_INTERPRETER_INTERPRETER_ASSEMBLY_64BIT_H 93