Fixed HiFi modes.
[AROS.git] / compiler / purify / src / posinfo.c
blobfca1bd66430c3a8ee3c7eda4ca0f5e1a4ed7f14a
1 #include <stdio.h>
2 #include "posinfo.h"
3 #include "util.h"
4 #include "error.h"
6 int Purify_Lineno;
7 const char * Purify_Filename;
8 const char * Purify_Functionname;
10 CallStackNode * Purify_CallStack;
11 CallStackEntry * Purify_CurrentFrame;
13 static int usedEntries;
14 static int callLevels;
16 static void _Purify_MakeRoom (void)
18 if (!Purify_CallStack)
20 Purify_CallStack = xmalloc (sizeof (CallStackNode));
21 Purify_CurrentFrame = &Purify_CallStack->entries[0];
23 Purify_CallStack->next = NULL;
25 usedEntries = 1;
27 else
29 if (usedEntries == PURIFY_CSNE)
31 CallStackNode * node = xmalloc (sizeof (CallStackNode));
33 node->next = Purify_CallStack;
34 Purify_CallStack = node;
35 Purify_CurrentFrame = &Purify_CallStack->entries[0];
37 usedEntries = 1;
39 else
41 usedEntries ++;
42 Purify_CurrentFrame ++;
47 void Purify_EnterFunction (const char * filename, const char * functionname,
48 int lineno, const void * fp)
50 _Purify_MakeRoom ();
52 callLevels ++;
54 SETPOS(&Purify_CurrentFrame->caller);
56 Purify_Filename = filename;
57 Purify_Functionname = functionname;
58 Purify_Lineno = lineno;
60 SETPOS(&Purify_CurrentFrame->called);
62 Purify_CurrentFrame->fp = fp;
64 #if 0
65 printf ("EnterFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
66 usedEntries, Purify_CurrentFrame
68 printf ("at " POSINFO_FORMAT " fp=%p\n",
69 POSINFO_ARG(&Purify_CurrentFrame->called),
72 printf ("called from " POSINFO_FORMAT "\n",
73 POSINFO_ARG(&Purify_CurrentFrame->caller)
75 #endif
78 void Purify_LeaveFunction (void)
80 Purify_Filename = Purify_CurrentFrame->caller.filename;
81 Purify_Functionname = Purify_CurrentFrame->caller.functionname;
82 Purify_Lineno = Purify_CurrentFrame->caller.lineno;
84 #if 0
85 printf ("LeaveFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
86 usedEntries, Purify_CurrentFrame
88 printf ("to " POSINFO_FORMAT "\n",
89 POSINFO_ARG(&Purify_CurrentFrame->caller)
91 #endif
93 usedEntries --;
94 callLevels --;
96 if (usedEntries > 0)
97 Purify_CurrentFrame --;
98 else if (callLevels)
100 CallStackNode * node = Purify_CallStack;
102 Purify_CallStack = node->next;
104 xfree (node);
106 if (Purify_CallStack)
108 usedEntries = PURIFY_CSNE;
109 Purify_CurrentFrame = &Purify_CallStack->entries[PURIFY_CSNE-1];
111 else
113 usedEntries = 0;
114 Purify_CurrentFrame = NULL;
119 void Purify_RememberCallers (RememberData * rd)
121 int n = 0;
122 int entry = usedEntries;
123 CallStackEntry * cse;
125 cse = Purify_CurrentFrame;
127 SETPOS(&rd->current);
129 while (n < PURIFY_RememberDepth && n < callLevels)
131 rd->stack[n] = cse->caller;
133 entry --;
134 n ++;
136 if (entry > 0)
137 cse --;
138 else
140 if (!Purify_CallStack->next)
141 break;
143 entry = PURIFY_CSNE;
144 cse = &Purify_CallStack->next->entries[PURIFY_CSNE-1];
148 rd->nstack = n;
151 void Purify_PrintCallers (RememberData * rd)
153 int t;
155 if (rd->nstack == -1)
156 return;
158 fprintf (stderr, "at " POSINFO_FORMAT "\n",
159 POSINFO_ARG(&rd->current)
162 for (t=0; t<rd->nstack; t++)
164 fprintf (stderr, "called by " POSINFO_FORMAT "\n",
165 POSINFO_ARG(&rd->stack[t])