]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/asmjit/CodeGenerator.h
update
[l4.git] / l4 / pkg / plr / server / src / asmjit / CodeGenerator.h
1 // AsmJit - Complete JIT Assembler for C++ Language.
2
3 // Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
4 //
5 // Permission is hereby granted, free of charge, to any person
6 // obtaining a copy of this software and associated documentation
7 // files (the "Software"), to deal in the Software without
8 // restriction, including without limitation the rights to use,
9 // copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following
12 // conditions:
13 // 
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
16 // 
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
19 // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 // OTHER DEALINGS IN THE SOFTWARE.
25
26 // [Guard]
27 #ifndef _ASMJIT_CODEGENERATOR_H
28 #define _ASMJIT_CODEGENERATOR_H
29
30 // [Dependencies]
31 #include "Build.h"
32
33 namespace AsmJit {
34
35 // ============================================================================
36 // [Forward Declarations]
37 // ============================================================================
38
39 struct Assembler;
40 struct JitCodeGenerator;
41 struct MemoryManager;
42
43 // ============================================================================
44 // [AsmJit::CodeGenerator]
45 // ============================================================================
46
47 //! @brief Code generator is core class for changing behavior of code generated
48 //! by @c Assembler or @c Compiler.
49 struct ASMJIT_API CodeGenerator
50 {
51   // --------------------------------------------------------------------------
52   // [Construction / Destruction]
53   // --------------------------------------------------------------------------
54
55   //! @brief Create a @c CodeGenerator instance.
56   CodeGenerator();
57   //! @brief Destroy the @c CodeGenerator instance.
58   virtual ~CodeGenerator();
59
60   // --------------------------------------------------------------------------
61   // [Interface]
62   // --------------------------------------------------------------------------
63
64   //! @brief Allocate memory for code generated in @a assembler and reloc it
65   //! to target location.
66   //!
67   //! This method is universal allowing any pre-process / post-process work
68   //! with code generated by @c Assembler or @c Compiler. Because @c Compiler
69   //! always uses @c Assembler it's allowed to access only the @c Assembler
70   //! instance.
71   //!
72   //! This method is always last step when using code generation. You can use
73   //! it to allocate memory for JIT code, saving code to remote process or a 
74   //! shared library.
75   //!
76   //! @retrurn Error value, see @c ERROR_CODE.
77   virtual uint32_t generate(void** dest, Assembler* assembler) = 0;
78
79   // --------------------------------------------------------------------------
80   // [Statics]
81   // --------------------------------------------------------------------------
82
83   static CodeGenerator* getGlobal();
84
85 private:
86   ASMJIT_DISABLE_COPY(CodeGenerator)
87 };
88
89 // ============================================================================
90 // [AsmJit::JitCodeGenerator]
91 // ============================================================================
92
93 struct JitCodeGenerator : public CodeGenerator
94 {
95   // --------------------------------------------------------------------------
96   // [Construction / Destruction]
97   // --------------------------------------------------------------------------
98
99   //! @brief Create a @c JitCodeGenerator instance.
100   JitCodeGenerator();
101   //! @brief Destroy the @c JitCodeGenerator instance.
102   virtual ~JitCodeGenerator();
103
104   // --------------------------------------------------------------------------
105   // [Memory Manager and Alloc Type]
106   // --------------------------------------------------------------------------
107
108   // Note: These members can be ignored by all derived classes. They are here
109   // only to privide default implementation. All other implementations (remote
110   // code patching or making dynamic loadable libraries/executables) ignore
111   // members accessed by these accessors.
112
113   //! @brief Get the @c MemoryManager instance.
114   inline MemoryManager* getMemoryManager() const { return _memoryManager; }
115   //! @brief Set the @c MemoryManager instance.
116   inline void setMemoryManager(MemoryManager* memoryManager) { _memoryManager = memoryManager; }
117
118   //! @brief Get the type of allocation.
119   inline uint32_t getAllocType() const { return _allocType; }
120   //! @brief Set the type of allocation.
121   inline void setAllocType(uint32_t allocType) { _allocType = allocType; }
122
123   // --------------------------------------------------------------------------
124   // [Interface]
125   // --------------------------------------------------------------------------
126
127   virtual uint32_t generate(void** dest, Assembler* assembler);
128
129   // --------------------------------------------------------------------------
130   // [Members]
131   // --------------------------------------------------------------------------
132
133 protected:
134   //! @brief Memory manager.
135   MemoryManager* _memoryManager;
136   //! @brief Type of allocation.
137   uint32_t _allocType;
138
139 private:
140   ASMJIT_DISABLE_COPY(JitCodeGenerator)
141 };
142
143 } // AsmJit namespace
144
145 // [Guard]
146 #endif // _ASMJIT_CODEGENERATOR_H