]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/plr/server/src/asmjit/Logger.h
update
[l4.git] / l4 / pkg / plr / server / src / asmjit / Logger.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_LOGGER_H
28 #define _ASMJIT_LOGGER_H
29
30 // [Dependencies]
31 #include "Defs.h"
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <stdarg.h>
36
37 // [Api-Begin]
38 #include "ApiBegin.h"
39
40 namespace AsmJit {
41
42 //! @addtogroup AsmJit_Logging
43 //! @{
44
45 //! @brief Abstract logging class.
46 //!
47 //! This class can be inherited and reimplemented to fit into your logging
48 //! subsystem. When reimplementing use @c AsmJit::Logger::log() method to
49 //! log into your stream.
50 //!
51 //! This class also contain @c _enabled member that can be used to enable
52 //! or disable logging.
53 struct ASMJIT_API Logger
54 {
55   // --------------------------------------------------------------------------
56   // [Construction / Destruction]
57   // --------------------------------------------------------------------------
58
59   //! @brief Create logger.
60   Logger() ASMJIT_NOTHROW;
61   //! @brief Destroy logger.
62   virtual ~Logger() ASMJIT_NOTHROW;
63
64   // --------------------------------------------------------------------------
65   // [Logging]
66   // --------------------------------------------------------------------------
67
68   //! @brief Abstract method to log output.
69   //!
70   //! Default implementation that is in @c AsmJit::Logger is to do nothing.
71   //! It's virtual to fit to your logging system.
72   virtual void logString(const char* buf, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW = 0;
73
74   //! @brief Log formatter message (like sprintf) sending output to @c logString() method.
75   virtual void logFormat(const char* fmt, ...) ASMJIT_NOTHROW;
76
77   // --------------------------------------------------------------------------
78   // [Enabled]
79   // --------------------------------------------------------------------------
80
81   //! @brief Return @c true if logging is enabled.
82   inline bool isEnabled() const ASMJIT_NOTHROW { return _enabled; }
83
84   //! @brief Set logging to enabled or disabled.
85   virtual void setEnabled(bool enabled) ASMJIT_NOTHROW;
86
87   // --------------------------------------------------------------------------
88   // [Used]
89   // --------------------------------------------------------------------------
90
91   //! @brief Get whether the logger should be used.
92   inline bool isUsed() const ASMJIT_NOTHROW { return _used; }
93
94   // --------------------------------------------------------------------------
95   // [LogBinary]
96   // --------------------------------------------------------------------------
97
98   //! @brief Get whether logging binary output.
99   inline bool getLogBinary() const { return _logBinary; }
100   //! @brief Get whether to log binary output.
101   inline void setLogBinary(bool val) { _logBinary = val; }
102
103   // --------------------------------------------------------------------------
104   // [Members]
105   // --------------------------------------------------------------------------
106
107 protected:
108
109   //! @brief Whether logger is enabled or disabled.
110   //!
111   //! Default @c true.
112   bool _enabled;
113
114   //! @brief Whether logger is enabled and can be used.
115   //!
116   //! This value can be set by inherited classes to inform @c Logger that
117   //! assigned stream (or something that can log output) is invalid. If
118   //! @c _used is false it means that there is no logging output and AsmJit
119   //! shouldn't use this logger (because all messages will be lost).
120   //!
121   //! This is designed only to optimize cases that logger exists, but its
122   //! configured not to output messages. The API inside Logging and AsmJit
123   //! should only check this value when needed. The API outside AsmJit should
124   //! check only whether logging is @c _enabled.
125   //!
126   //! Default @c true.
127   bool _used;
128
129   //! @brief Whether to log instruction in binary form.
130   bool _logBinary;
131
132 private:
133   ASMJIT_DISABLE_COPY(Logger)
134 };
135
136 //! @brief Logger that can log to standard C @c FILE* stream.
137 struct ASMJIT_API FileLogger : public Logger
138 {
139   // --------------------------------------------------------------------------
140   // [Construction / Destruction]
141   // --------------------------------------------------------------------------
142
143   //! @brief Create new @c FileLogger.
144   //! @param stream FILE stream where logging will be sent (can be @c NULL
145   //! to disable logging).
146   FileLogger(FILE* stream = NULL) ASMJIT_NOTHROW;
147
148   // --------------------------------------------------------------------------
149   // [Logging]
150   // --------------------------------------------------------------------------
151
152   virtual void logString(const char* buf, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW;
153
154   // --------------------------------------------------------------------------
155   // [Enabled]
156   // --------------------------------------------------------------------------
157
158   virtual void setEnabled(bool enabled) ASMJIT_NOTHROW;
159
160   // --------------------------------------------------------------------------
161   // [Stream]
162   // --------------------------------------------------------------------------
163
164   //! @brief Get @c FILE* stream.
165   //!
166   //! @note Return value can be @c NULL.
167   inline FILE* getStream() const ASMJIT_NOTHROW { return _stream; }
168
169   //! @brief Set @c FILE* stream.
170   //!
171   //! @param stream @c FILE stream where to log output (can be @c NULL to
172   //! disable logging).
173   void setStream(FILE* stream) ASMJIT_NOTHROW;
174
175   // --------------------------------------------------------------------------
176   // [Members]
177   // --------------------------------------------------------------------------
178
179 protected:
180   //! @brief C file stream.
181   FILE* _stream;
182
183   ASMJIT_DISABLE_COPY(FileLogger)
184 };
185
186 //! @}
187
188 } // AsmJit namespace
189
190 // [Api-End]
191 #include "ApiEnd.h"
192
193 // [Guard]
194 #endif // _ASMJIT_LOGGER_H