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_ASSEMBLER_X64_MACRO_ASSEMBLER_X64_H 17 #define ECMASCRIPT_COMPILER_ASSEMBLER_X64_MACRO_ASSEMBLER_X64_H 18 19 #include "ecmascript/compiler/assembler/macro_assembler.h" 20 #include "ecmascript/compiler/assembler/x64/assembler_x64.h" 21 22 namespace panda::ecmascript::kungfu { 23 class MacroAssemblerX64 : public MacroAssembler { 24 public: MacroAssemblerX64()25 explicit MacroAssemblerX64() : MacroAssembler(), assembler(&chunk) {} 26 ~MacroAssemblerX64() = default; 27 uint8_t *GetBegin() const override 28 { 29 return assembler.GetBegin(); 30 } 31 32 size_t GetBufferCurrentSize() const override 33 { 34 return assembler.GetCurrentPosition(); 35 } 36 37 void Move(const StackSlotOperand &dstStackSlot, Immediate value) override; 38 void Move(const StackSlotOperand &dstStackSlot, const StackSlotOperand &srcStackSlot) override; 39 void Cmp(const StackSlotOperand &stackSlot, Immediate value) override; 40 void Bind(JumpLabel &label) override; 41 void Jz(JumpLabel &label) override; 42 void Jnz(JumpLabel &label) override; 43 void Jump(JumpLabel &label) override; 44 void SaveReturnRegister(const StackSlotOperand &dstStackSlot) override; 45 void CallBuiltin(Address funcAddress, 46 const std::vector<MacroParameter> ¶meters) override; 47 48 private: 49 x64::AssemblerX64 assembler; 50 static constexpr uint32_t PARAM_REGISTER_COUNT = 6; 51 const std::vector<x64::Register> registerParamVec { 52 x64::rdi, x64::rsi, x64::rdx, x64::rcx, x64::r8, x64::r9 }; 53 static constexpr x64::Register GLUE_REGISTER = x64::r13; // same with ghc callconv 54 static constexpr x64::Register LOCAL_SCOPE_REGISTER = x64::r10; 55 static constexpr x64::Register RETURN_REGISTER = x64::rax; 56 void MovParameterIntoParamReg(MacroParameter param, x64::Register paramReg); 57 }; 58 } // namespace panda::ecmascript::kungfu 59 #endif // ECMASCRIPT_COMPILER_ASSEMBLER_X64_MACRO_ASSEMBLER_X64_H 60