1/* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#ifndef ECMASCRIPT_COMPILER_BASELINE_BASELINE_STUBS_H 17#define ECMASCRIPT_COMPILER_BASELINE_BASELINE_STUBS_H 18 19#include "ecmascript/compiler/baseline/baseline_compiler_builtins.h" 20#include "ecmascript/compiler/baseline/baseline_stub_csigns.h" 21#include "ecmascript/compiler/stub_builder.h" 22#include "ecmascript/base/config.h" 23#include "ecmascript/compiler/profiler_operation.h" 24 25namespace panda::ecmascript::kungfu { 26 27class BaselineStubBuilder : public StubBuilder { 28public: 29 BaselineStubBuilder(CallSignature *callSignature, Environment *env) 30 : StubBuilder(callSignature, env) {} 31 ~BaselineStubBuilder() override = default; 32 NO_MOVE_SEMANTIC(BaselineStubBuilder); 33 NO_COPY_SEMANTIC(BaselineStubBuilder); 34 virtual void GenerateCircuit() override = 0; 35 36 inline void SetEnvToFrame(GateRef glue, GateRef frame, GateRef value); 37 inline void CheckExceptionWithVar(GateRef glue, GateRef sp, GateRef res, GateRef acc); 38 inline void CheckException(GateRef glue, GateRef sp, GateRef res); 39 inline void CheckExceptionReturn(GateRef glue, GateRef sp, GateRef res); 40 inline void CheckExceptionWithJump(GateRef glue, GateRef sp, GateRef res, GateRef acc, Label *jump); 41 inline void CheckExceptionWithJumpAndReturn(GateRef glue, GateRef sp, GateRef res, GateRef acc, Label *jump); 42 inline void CheckPendingException(GateRef glue, GateRef sp, GateRef res, GateRef acc); 43 inline void DispatchLast(GateRef glue, GateRef sp, GateRef acc); 44 inline GateRef GetFunctionFromFrame(GateRef frame); 45 inline GateRef GetEnvFromFrame(GateRef frame); 46 inline GateRef GetAccFromFrame(GateRef frame); 47 inline GateRef GetConstpoolFromMethod(GateRef method); 48 inline GateRef GetProfileTypeInfoFromFunction(GateRef function); 49 inline GateRef GetHotnessCounterFromMethod(GateRef method); 50 inline GateRef GetModuleFromFunction(GateRef function); 51 inline GateRef GetHomeObjectFromFunction(GateRef function); 52 inline GateRef GetModule(GateRef sp); 53 inline GateRef GetCurrentFrame(GateRef glue); 54 inline GateRef GetFrame(GateRef CurrentSp); 55 inline GateRef GetPcFromFrame(GateRef frame); 56 inline GateRef GetCallSizeFromFrame(GateRef frame); 57 inline GateRef GetThisFromFrame(GateRef frame); 58 inline GateRef GetNewTarget(GateRef sp); 59 inline GateRef GetStartIdxAndNumArgs(GateRef sp, GateRef restIdx); 60 inline void SetVregValue(GateRef glue, GateRef sp, GateRef idx, GateRef val); 61 inline GateRef GetVregValue(GateRef sp, GateRef idx); 62 inline GateRef GetResumeModeFromGeneratorObject(GateRef obj); 63 inline GateRef GetResumeModeFromAsyncGeneratorObject(GateRef obj); 64 inline GateRef GetLastLeaveFrame(GateRef glue); 65 inline GateRef CallBaselineStub(GateRef glue, int index, const std::initializer_list<GateRef>& args); 66}; 67 68#define DECLARE_STUB_CLASS(name) \ 69 class name##StubBuilder : public BaselineStubBuilder { \ 70 public: \ 71 name##StubBuilder(CallSignature *callSignature, Environment *env) \ 72 : BaselineStubBuilder(callSignature, env) \ 73 { \ 74 env->GetCircuit()->SetFrameType(FrameType::BASELINE_BUILTIN_FRAME); \ 75 } \ 76 ~name##StubBuilder() = default; \ 77 NO_MOVE_SEMANTIC(name##StubBuilder); \ 78 NO_COPY_SEMANTIC(name##StubBuilder); \ 79 void GenerateCircuit() override; \ 80 }; 81 BASELINE_COMPILER_BUILTIN_LIST(DECLARE_STUB_CLASS) 82#undef DECLARE_STUB_CLASS 83} // namespace panda::ecmascript::kungfu 84#endif // ECMASCRIPT_COMPILER_BASELINE_BASELINE_STUBS_H 85