A SystemC productivity library for virtual platform development utilizing SCV and TLM2.0 https://www.minres.com/#opensource

report.h 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*******************************************************************************
  2. * Copyright 2016, 2018 MINRES Technologies GmbH
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *******************************************************************************/
  16. #ifndef _SYSC_REPORT_H_
  17. #define _SYSC_REPORT_H_
  18. #include "utilities.h"
  19. #include <iomanip>
  20. #include <sstream>
  21. #include <sysc/kernel/sc_time.h>
  22. #include <sysc/utils/sc_report.h>
  23. #include <util/logging.h>
  24. namespace logging {
  25. class SystemC {};
  26. }
  27. namespace scc {
  28. /**
  29. * initializes the SystemC logging system to use logging::Logger with a particular logging level
  30. *
  31. * @param level the logging level
  32. */
  33. void init_logging(logging::log_level level = logging::WARNING);
  34. /**
  35. * the logger class
  36. */
  37. template <sc_core::sc_severity SEVERITY> struct ScLogger {
  38. /**
  39. * the constructor
  40. *
  41. * @param file file where the log entry originates
  42. * @param line the line where the log entry originates
  43. * @param level the log level
  44. */
  45. ScLogger(const char *file, int line, sc_core::sc_verbosity level = sc_core::SC_MEDIUM)
  46. : t(nullptr)
  47. , file(file)
  48. , line(line)
  49. , level(level){};
  50. /**
  51. * no default constructor
  52. */
  53. ScLogger() = delete;
  54. /**
  55. * no copy constructor
  56. * @param
  57. */
  58. ScLogger(const ScLogger &) = delete;
  59. /**
  60. * no move constructor
  61. * @param
  62. */
  63. ScLogger(ScLogger &&) = delete;
  64. /**
  65. * no copy assignment
  66. * @param
  67. * @return
  68. */
  69. ScLogger &operator=(const ScLogger &) = delete;
  70. /**
  71. * no move assignment
  72. * @param
  73. * @return
  74. */
  75. ScLogger &operator=(ScLogger &&) = delete;
  76. /**
  77. * the destructor generating the SystemC report
  78. */
  79. virtual ~ScLogger() {
  80. ::sc_core::sc_report_handler::report(SEVERITY, t ? t : "SystemC", os.str().c_str(), level, file, line);
  81. }
  82. /**
  83. * reset the category of the log entry
  84. *
  85. * @return
  86. */
  87. inline ScLogger &type() {
  88. this->t=nullptr;
  89. return *this;
  90. }
  91. /**
  92. * set the category of the log entry
  93. *
  94. * @param t
  95. * @return
  96. */
  97. inline ScLogger &type(const char *t) {
  98. this->t = const_cast<char *>(t);
  99. return *this;
  100. }
  101. /**
  102. * return the underlying ostringstream
  103. *
  104. * @return the output stream collecting the log message
  105. */
  106. inline std::ostream &get() { return os; };
  107. protected:
  108. std::ostringstream os;
  109. char *t;
  110. const char *file;
  111. const int line;
  112. const sc_core::sc_verbosity level;
  113. };
  114. //! macro for debug trace lavel output
  115. #define SCDBGTRC(...) \
  116. if (::sc_core::sc_report_handler::get_verbosity_level() >= sc_core::SC_DEBUG) \
  117. ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, sc_core::SC_DEBUG).type(__VA_ARGS__).get()
  118. //! macro for trace level output
  119. #define SCTRACE(...) \
  120. if (::sc_core::sc_report_handler::get_verbosity_level() >= sc_core::SC_FULL) \
  121. ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, sc_core::SC_FULL).type(__VA_ARGS__).get()
  122. //! macro for debug level output
  123. #define SCDEBUG(...) \
  124. if (::sc_core::sc_report_handler::get_verbosity_level() >= sc_core::SC_HIGH) \
  125. ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, sc_core::SC_HIGH).type(__VA_ARGS__).get()
  126. //! macro for info level output
  127. #define SCINFO(...) \
  128. if (::sc_core::sc_report_handler::get_verbosity_level() >= sc_core::SC_MEDIUM) \
  129. ::scc::ScLogger<::sc_core::SC_INFO>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
  130. //! macro for warning level output
  131. #define SCWARN(...) \
  132. ::scc::ScLogger<::sc_core::SC_WARNING>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
  133. //! macro for error level output
  134. #define SCERR(...) ::scc::ScLogger<::sc_core::SC_ERROR>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
  135. //! macro for fatal message output
  136. #define SCFATAL(...) \
  137. ::scc::ScLogger<::sc_core::SC_FATAL>(__FILE__, __LINE__, sc_core::SC_MEDIUM).type(__VA_ARGS__).get()
  138. }
  139. #endif /* _SYSC_REPORT_H_ */