1 // AsmJit - Complete JIT Assembler for C++ Language.
3 // Copyright (c) 2008-2010, Petr Kobalicek <kobalicek.petr@gmail.com>
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
14 // The above copyright notice and this permission notice shall be
15 // included in all copies or substantial portions of the Software.
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.
27 #ifndef _ASMJIT_LOGGER_H
28 #define _ASMJIT_LOGGER_H
42 //! @addtogroup AsmJit_Logging
45 //! @brief Abstract logging class.
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.
51 //! This class also contain @c _enabled member that can be used to enable
52 //! or disable logging.
53 struct ASMJIT_API Logger
55 // --------------------------------------------------------------------------
56 // [Construction / Destruction]
57 // --------------------------------------------------------------------------
59 //! @brief Create logger.
60 Logger() ASMJIT_NOTHROW;
61 //! @brief Destroy logger.
62 virtual ~Logger() ASMJIT_NOTHROW;
64 // --------------------------------------------------------------------------
66 // --------------------------------------------------------------------------
68 //! @brief Abstract method to log output.
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;
74 //! @brief Log formatter message (like sprintf) sending output to @c logString() method.
75 virtual void logFormat(const char* fmt, ...) ASMJIT_NOTHROW;
77 // --------------------------------------------------------------------------
79 // --------------------------------------------------------------------------
81 //! @brief Return @c true if logging is enabled.
82 inline bool isEnabled() const ASMJIT_NOTHROW { return _enabled; }
84 //! @brief Set logging to enabled or disabled.
85 virtual void setEnabled(bool enabled) ASMJIT_NOTHROW;
87 // --------------------------------------------------------------------------
89 // --------------------------------------------------------------------------
91 //! @brief Get whether the logger should be used.
92 inline bool isUsed() const ASMJIT_NOTHROW { return _used; }
94 // --------------------------------------------------------------------------
96 // --------------------------------------------------------------------------
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; }
103 // --------------------------------------------------------------------------
105 // --------------------------------------------------------------------------
109 //! @brief Whether logger is enabled or disabled.
114 //! @brief Whether logger is enabled and can be used.
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).
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.
129 //! @brief Whether to log instruction in binary form.
133 ASMJIT_DISABLE_COPY(Logger)
136 //! @brief Logger that can log to standard C @c FILE* stream.
137 struct ASMJIT_API FileLogger : public Logger
139 // --------------------------------------------------------------------------
140 // [Construction / Destruction]
141 // --------------------------------------------------------------------------
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;
148 // --------------------------------------------------------------------------
150 // --------------------------------------------------------------------------
152 virtual void logString(const char* buf, sysuint_t len = (sysuint_t)-1) ASMJIT_NOTHROW;
154 // --------------------------------------------------------------------------
156 // --------------------------------------------------------------------------
158 virtual void setEnabled(bool enabled) ASMJIT_NOTHROW;
160 // --------------------------------------------------------------------------
162 // --------------------------------------------------------------------------
164 //! @brief Get @c FILE* stream.
166 //! @note Return value can be @c NULL.
167 inline FILE* getStream() const ASMJIT_NOTHROW { return _stream; }
169 //! @brief Set @c FILE* stream.
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;
175 // --------------------------------------------------------------------------
177 // --------------------------------------------------------------------------
180 //! @brief C file stream.
183 ASMJIT_DISABLE_COPY(FileLogger)
188 } // AsmJit namespace
194 #endif // _ASMJIT_LOGGER_H