1 // AsmJit - Machine code generation for C++
2 //
3 //  * Official AsmJit Home Page: https://asmjit.com
4 //  * Official Github Repository: https://github.com/asmjit/asmjit
5 //
6 // Copyright (c) 2008-2020 The AsmJit Authors
7 //
8 // This software is provided 'as-is', without any express or implied
9 // warranty. In no event will the authors be held liable for any damages
10 // arising from the use of this software.
11 //
12 // Permission is granted to anyone to use this software for any purpose,
13 // including commercial applications, and to alter it and redistribute it
14 // freely, subject to the following restrictions:
15 //
16 // 1. The origin of this software must not be misrepresented; you must not
17 //    claim that you wrote the original software. If you use this software
18 //    in a product, an acknowledgment in the product documentation would be
19 //    appreciated but is not required.
20 // 2. Altered source versions must be plainly marked as such, and must not be
21 //    misrepresented as being the original software.
22 // 3. This notice may not be removed or altered from any source distribution.
23 
24 #ifndef ASMJIT_X86_X86INTERNAL_P_H_INCLUDED
25 #define ASMJIT_X86_X86INTERNAL_P_H_INCLUDED
26 
27 #include "../core/api-config.h"
28 
29 #include "../core/func.h"
30 #include "../x86/x86emitter.h"
31 #include "../x86/x86operand.h"
32 
33 ASMJIT_BEGIN_SUB_NAMESPACE(x86)
34 
35 //! \cond INTERNAL
36 //! \addtogroup asmjit_x86
37 //! \{
38 
39 // ============================================================================
40 // [asmjit::X86Internal]
41 // ============================================================================
42 
43 //! X86 utilities used at multiple places, not part of public API, not exported.
44 struct X86Internal {
45   //! Initialize `FuncDetail` (X86 specific).
46   static Error initFuncDetail(FuncDetail& func, const FuncSignature& signature, uint32_t registerSize) noexcept;
47 
48   //! Initialize `FuncFrame` (X86 specific).
49   static Error initFuncFrame(FuncFrame& frame, const FuncDetail& signature) noexcept;
50 
51   //! Finalize `FuncFrame` (X86 specific).
52   static Error finalizeFuncFrame(FuncFrame& frame) noexcept;
53 
54   static Error argsToFuncFrame(const FuncArgsAssignment& args, FuncFrame& frame) noexcept;
55 
56   //! Emit function prolog.
57   static Error emitProlog(Emitter* emitter, const FuncFrame& frame);
58 
59   //! Emit function epilog.
60   static Error emitEpilog(Emitter* emitter, const FuncFrame& frame);
61 
62   //! Emit a pure move operation between two registers or the same type or
63   //! between a register and its home slot. This function does not handle
64   //! register conversion.
65   static Error emitRegMove(Emitter* emitter,
66     const Operand_& dst_,
67     const Operand_& src_, uint32_t typeId, bool avxEnabled, const char* comment = nullptr);
68 
69   //! Emit move from a function argument (either register or stack) to a register.
70   //!
71   //! This function can handle the necessary conversion from one argument to
72   //! another, and from one register type to another, if it's possible. Any
73   //! attempt of conversion that requires third register of a different group
74   //! (for example conversion from K to MMX) will fail.
75   static Error emitArgMove(Emitter* emitter,
76     const Reg& dst_, uint32_t dstTypeId,
77     const Operand_& src_, uint32_t srcTypeId, bool avxEnabled, const char* comment = nullptr);
78 
79   static Error emitArgsAssignment(Emitter* emitter, const FuncFrame& frame, const FuncArgsAssignment& args);
80 };
81 
82 //! \}
83 //! \endcond
84 
85 ASMJIT_END_SUB_NAMESPACE
86 
87 #endif // ASMJIT_X86_X86INTERNAL_P_H_INCLUDED
88