source: trunk/IPs/systemC/processor/Morpheo/Common/include/Debug.h @ 112

Last change on this file since 112 was 112, checked in by rosiere, 15 years ago

1) Stat_list : fix retire old and new register bug
2) Stat_list : remove read_counter and valid flag, because validation of destination is in retire step (not in commit step)
3) Model : add class Model (cf Morpheo.sim)
4) Allocation : alloc_interface_begin and alloc_interface_end to delete temporary array.
5) Script : add distexe.sh
6) Add Comparator, Multiplier, Divider. But this component are not implemented
7) Software : add Dhrystone

  • Property svn:keywords set to Id
File size: 7.3 KB
Line 
1#ifndef Morpheo_Debug_h
2#define Morpheo_Debug_h
3
4/*
5 * $Id: Debug.h 112 2009-03-18 22:36:26Z rosiere $
6 *
7 * [ Description ]
8 *
9 * function to help the debugging :
10 *
11 *  - log_printf
12 *  - log_begin
13 *  - log_end
14 *  - log_function
15 *  - msg_print
16 *  - breakpoint
17 *
18 *  Debug's Level :
19 *  - None    : print elementary information
20 *  - Info    : print basic information
21 *  - Trace   : trace internal variable
22 *  - Func    : trace call and return function
23 *  - All     : print all information
24 */
25
26#include "Common/include/Message.h"
27#include "Common/include/FromString.h"
28#include "Common/include/ChangeCase.h"
29#include "Behavioural/include/Debug_component.h"
30#include <systemc.h>
31#include <stdio.h>
32#include <string.h>
33#include <iostream>
34#include <sstream>
35#include <string>
36#include "Common/include/MemCheck.h"
37
38namespace morpheo {
39
40typedef enum 
41  {
42    DEBUG_NONE ,
43    DEBUG_INFO ,
44    DEBUG_TRACE,
45    DEBUG_FUNC ,
46    DEBUG_ALL
47  } debug_verbosity_t;
48
49  extern debug_verbosity_t debug;
50  extern bool              debug_cycle_test;
51  extern double            debug_cycle_start;
52  extern double            debug_cycle_stop ;
53  extern double            debug_idle_cycle;
54  extern uint32_t          debug_idle_time;
55
56  void        debug_init    (void);
57  void        debug_init    (debug_verbosity_t level,
58                             double            cycle_start,
59                             double            cycle_stop ,
60                             double            idle_cycle ,
61                             uint32_t          idle_time  );
62
63#ifdef SYSTEMC
64#define debug_test_simulation_time                                      \
65  (not debug_cycle_test or                                              \
66   ( (sc_simulation_time() >= debug_cycle_start) and                    \
67    ((sc_simulation_time() <= debug_cycle_stop) or                      \
68      (debug_cycle_stop == -1))))
69#else
70#define debug_test_simulation_time true
71#endif
72 
73#ifdef DEBUG
74# define log_printf(level, component, func, str... )                    \
75  do                                                                    \
76    {                                                                   \
77      debug_init();                                                     \
78                                                                        \
79      if (debug_test_simulation_time)                                   \
80        if ((debug == DEBUG_ALL ) or                                    \
81            (DEBUG_ ## level == DEBUG_NONE) or                          \
82            (( DEBUG_ ## level     <= debug) and                        \
83             ( DEBUG_ ## component == true )) )                         \
84          {                                                             \
85            if (DEBUG_ ## level <= DEBUG_INFO)                          \
86              {                                                         \
87                msg("%s ",MSG_INFORMATION);                             \
88              }                                                         \
89            else                                                        \
90              {                                                         \
91                msg("%s ",MSG_DEBUG);                                   \
92              }                                                         \
93                                                                        \
94            if (debug >= DEBUG_ALL )                                    \
95              {                                                         \
96                switch (DEBUG_ ## level)                                \
97                  {                                                     \
98                  case DEBUG_NONE  : msg(_("(none       ) ")); break;   \
99                  case DEBUG_INFO  : msg(_("(information) ")); break;   \
100                  case DEBUG_TRACE : msg(_("(trace      ) ")); break;   \
101                  case DEBUG_FUNC  : msg(_("(function   ) ")); break;   \
102                  case DEBUG_ALL   : msg(_("(all        ) ")); break;   \
103                  default          : msg(_("(undefine   ) ")); break;   \
104                  }                                                     \
105              }                                                         \
106            if (debug >= DEBUG_FUNC)                                    \
107              {                                                         \
108                msg(  "<%s> " ,func);                                   \
109                msg(_("In file %s, "),__FILE__);                        \
110                msg(_("at line %d " ),__LINE__);                        \
111                msg(  ": " );                                           \
112              }                                                         \
113            msg(str);                                                   \
114            msg("\n");                                                  \
115          }                                                             \
116    } while(0)
117
118# define log_begin(component, func)                                     \
119  do                                                                    \
120    {                                                                   \
121      log_printf(FUNC,component,func,_("Begin"));                       \
122    } while(0)
123
124# define log_end(component, func)                                       \
125  do                                                                    \
126    {                                                                   \
127      log_printf(FUNC,component,func,_("End"));                         \
128    } while(0)
129
130#else
131# define log_printf(level, component, func, str... )                    \
132  do                                                                    \
133    {                                                                   \
134    } while(0)
135
136# define log_begin(component, func)                                     \
137  do                                                                    \
138    {                                                                   \
139    } while(0)
140
141# define log_end(component, func)                                       \
142  do                                                                    \
143    {                                                                   \
144    } while(0)
145
146#endif // DEBUG
147
148# define log_function(component,func,name)                              \
149  do                                                                    \
150    {                                                                   \
151      log_printf(TRACE,component,func,_("[%d] %s.%s"),static_cast<uint32_t>(sc_simulation_time()),name,func); \
152    } while(0)
153
154
155#define msg_printf(type,str...)                                         \
156  do                                                                    \
157    {                                                                   \
158      msg("%s ",MSG_ ## type);                                          \
159      msg(str);                                                         \
160      msg("\n");                                                        \
161    } while(0)
162
163
164#define breakpoint(str...)                                              \
165  do                                                                    \
166    {                                                                   \
167      fprintf(stdout,_("%s "),MSG_BREAKPOINT);                                     \
168      fprintf(stdout,_("Breakpoint in file %s, line %d.\n"),__FILE__,__LINE__);    \
169      fprintf(stdout,_("%s "),MSG_NONE);                                           \
170      fprintf(stdout,str);                                                              \
171      fprintf(stdout,_("\n"));                                                     \
172      fprintf(stdout,_("%s "),MSG_NONE);                                           \
173      fprintf(stdout,_("Enter any key to continue\n"));                            \
174      getchar();                                                        \
175    } while(0)
176
177#ifdef DEBUG_TEST
178#define TEST_PTR(x)                                                     \
179  do                                                                    \
180    {                                                                   \
181      if (x == NULL)                                                    \
182        err(_("File %s, Line %d, this pointeur is null\n"),__FILE__,__LINE__); \
183    }                                                                   \
184  while (0)
185#else
186#define TEST_PTR(x)      \
187  do                     \
188    {                    \
189    }                    \
190  while (0)
191#endif
192
193
194  template<> inline debug_verbosity_t fromString<debug_verbosity_t> (const std::string& x)
195  {
196    std::string y=x;
197    LowerCase(y);
198
199    if ( (y.compare("0")     == 0) or
200         (y.compare("none")  == 0))
201      return DEBUG_NONE ;
202    if ( (y.compare("1")     == 0) or
203         (y.compare("info")  == 0))
204      return DEBUG_INFO ;
205    if ( (y.compare("2")     == 0) or
206         (y.compare("trace") == 0))
207      return DEBUG_TRACE;
208    if ( (y.compare("3")     == 0) or
209         (y.compare("func")  == 0))
210      return DEBUG_FUNC ;
211    if ( (y.compare("4")     == 0) or
212         (y.compare("all")   == 0))
213      return DEBUG_ALL  ;
214
215#ifdef DEBUG
216    return DEBUG;
217#else
218    return DEBUG_NONE ;
219#endif
220  }
221
222}; // end namespace morpheo
223#endif // !DEBUG_H
Note: See TracBrowser for help on using the repository browser.