• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
GetBegin()27     uint8_t *GetBegin() const override
28     {
29         return assembler.GetBegin();
30     }
31 
GetBufferCurrentSize()32     size_t GetBufferCurrentSize() const override
33     {
34         return assembler.GetCurrentPosition();
35     }
36 
GetRelocInfo()37     RelocMap &GetRelocInfo() override
38     {
39         return assembler.GetRelocInfo();
40     }
41 
42     void Move(const StackSlotOperand &dstStackSlot, Immediate value) override;
43     void Move(const StackSlotOperand &dstStackSlot, const StackSlotOperand &srcStackSlot) override;
44     void Cmp(const StackSlotOperand &stackSlot, Immediate value) override;
45     void Bind(JumpLabel &label) override;
46     void Jz(JumpLabel &label) override;
47     void Jnz(JumpLabel &label) override;
48     void Jump(JumpLabel &label) override;
49     void SaveReturnRegister(const StackSlotOperand &dstStackSlot) override;
50     void CallBuiltin(Address funcAddress,
51                      const std::vector<MacroParameter> &parameters) override;
52 
53 private:
54     x64::AssemblerX64 assembler;
55     static constexpr uint32_t PARAM_REGISTER_COUNT = 6;
56     const std::vector<x64::Register> registerParamVec {
57         x64::rdi, x64::rsi, x64::rdx, x64::rcx, x64::r8, x64::r9 };
58     static constexpr x64::Register GLUE_REGISTER = x64::r13;   // same with ghc callconv
59     static constexpr x64::Register LOCAL_SCOPE_REGISTER = x64::r10;
60     static constexpr x64::Register RETURN_REGISTER = x64::rax;
61     void MovParameterIntoParamReg(MacroParameter param, x64::Register paramReg);
62 };
63 }  // namespace panda::ecmascript::kungfu
64 #endif  // ECMASCRIPT_COMPILER_ASSEMBLER_X64_MACRO_ASSEMBLER_X64_H
65