debug.c 1.72 KB
Newer Older
Götz Lindenmaier's avatar
Götz Lindenmaier committed
1
2
3
4
5
6
7
8
9
10
11
/*
 * Project:     libFIRM
 * File name:   ir/adt/debug.c
 * Purpose:     Debug --- run time debug level management
 * Author:      Christian von Roques
 * Modified by:
 * Created:     1999 by getting from fiasco
 * CVS-ID:      $Id$
 * Copyright:   (c) 1995, 1996 Markus Armbruster
 * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
 */
Boris Boesler's avatar
Boris Boesler committed
12

Götz Lindenmaier's avatar
Götz Lindenmaier committed
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif

#include <stdlib.h>
#include <string.h>
#include "debug.h"
#include "misc.h"


int
(d_) (int flag, unsigned level)
{
  return d_ (flag, level);
}


int
(d_level) (int flag)
{
  return d_level (flag);
}


int
(d_set_level) (int flag, unsigned level)
{
  return d_set_level (flag, level);
}


#ifdef DEBUG
int nflags;
unsigned char *d_vec;
#endif


/*
 * Set debug flags according to the following syntax:
 * number ["-" number] ["." number]
 * 1st number is number of first flag to set.
 * 2nd number is number of last flag to set. [defaults to 1st number]
 * 3rd number is level to set the flags to. [defaults to 1]
 */
void
(d_parse) (const char *s)
{
#ifdef DEBUG
  long first, last, level;
  char *end;

  first = strtol(s, &end, 10);
  last = (s != end) ? first : nflags-1;

  s = end;
  if (*s == '-') {
    ++s;
    last = strtol(s, &end, 10);
    if (end == s) last = nflags-1; /* 3-  ==> 3..nflags-1 */
  }

  s = end;
  if (*s == '.') {
    ++s;
    level = strtol(s, &end, 10);
    /* . with no number gives level 0 */
  } else {
    level = 1;
  }

  if (first<0) first=0;
  if (last>=nflags) last = nflags-1;

  while (first<=last) d_vec[first++] = level;
#endif /* DEBUG */
}


void
(d_init) (int n)
{
#ifdef DEBUG
  nflags = n;
  d_vec = xmalloc (sizeof (unsigned char) * n);
  memset(d_vec, 0, sizeof (unsigned char) * n);
#endif
}