tools/genmodule: Add 'writethunk' emitter
[AROS.git] / compiler / purify / src / posinfo.c
blob203c2ef77f20a42a86ddb72796a70af2778946ee
1 /*
2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <stdio.h>
7 #include "posinfo.h"
8 #include "util.h"
9 #include "error.h"
11 int Purify_Lineno;
12 const char * Purify_Filename;
13 const char * Purify_Functionname;
15 CallStackNode * Purify_CallStack;
16 CallStackEntry * Purify_CurrentFrame;
18 static int usedEntries;
19 static int callLevels;
21 static void _Purify_MakeRoom (void)
23 if (!Purify_CallStack)
25 Purify_CallStack = xmalloc (sizeof (CallStackNode));
26 Purify_CurrentFrame = &Purify_CallStack->entries[0];
28 Purify_CallStack->next = NULL;
30 usedEntries = 1;
32 else
34 if (usedEntries == PURIFY_CSNE)
36 CallStackNode * node = xmalloc (sizeof (CallStackNode));
38 node->next = Purify_CallStack;
39 Purify_CallStack = node;
40 Purify_CurrentFrame = &Purify_CallStack->entries[0];
42 usedEntries = 1;
44 else
46 usedEntries ++;
47 Purify_CurrentFrame ++;
52 void Purify_EnterFunction (const char * filename, const char * functionname,
53 int lineno, const void * fp)
55 _Purify_MakeRoom ();
57 callLevels ++;
59 SETPOS(&Purify_CurrentFrame->caller);
61 Purify_Filename = filename;
62 Purify_Functionname = functionname;
63 Purify_Lineno = lineno;
65 SETPOS(&Purify_CurrentFrame->called);
67 Purify_CurrentFrame->fp = fp;
69 #if 0
70 printf ("EnterFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
71 usedEntries, Purify_CurrentFrame
73 printf ("at " POSINFO_FORMAT " fp=%p\n",
74 POSINFO_ARG(&Purify_CurrentFrame->called),
77 printf ("called from " POSINFO_FORMAT "\n",
78 POSINFO_ARG(&Purify_CurrentFrame->caller)
80 #endif
83 void Purify_LeaveFunction (void)
85 Purify_Filename = Purify_CurrentFrame->caller.filename;
86 Purify_Functionname = Purify_CurrentFrame->caller.functionname;
87 Purify_Lineno = Purify_CurrentFrame->caller.lineno;
89 #if 0
90 printf ("LeaveFunction() usedEntries=%d Purify_CurrentFrame=%p\n",
91 usedEntries, Purify_CurrentFrame
93 printf ("to " POSINFO_FORMAT "\n",
94 POSINFO_ARG(&Purify_CurrentFrame->caller)
96 #endif
98 usedEntries --;
99 callLevels --;
101 if (usedEntries > 0)
102 Purify_CurrentFrame --;
103 else if (callLevels)
105 CallStackNode * node = Purify_CallStack;
107 Purify_CallStack = node->next;
109 xfree (node);
111 if (Purify_CallStack)
113 usedEntries = PURIFY_CSNE;
114 Purify_CurrentFrame = &Purify_CallStack->entries[PURIFY_CSNE-1];
116 else
118 usedEntries = 0;
119 Purify_CurrentFrame = NULL;
124 void Purify_RememberCallers (RememberData * rd)
126 int n = 0;
127 int entry = usedEntries;
128 CallStackEntry * cse;
130 cse = Purify_CurrentFrame;
132 SETPOS(&rd->current);
134 while (n < PURIFY_RememberDepth && n < callLevels)
136 rd->stack[n] = cse->caller;
138 entry --;
139 n ++;
141 if (entry > 0)
142 cse --;
143 else
145 if (!Purify_CallStack->next)
146 break;
148 entry = PURIFY_CSNE;
149 cse = &Purify_CallStack->next->entries[PURIFY_CSNE-1];
153 rd->nstack = n;
156 void Purify_PrintCallers (RememberData * rd)
158 int t;
160 if (rd->nstack == -1)
161 return;
163 fprintf (stderr, "at " POSINFO_FORMAT "\n",
164 POSINFO_ARG(&rd->current)
167 for (t=0; t<rd->nstack; t++)
169 fprintf (stderr, "called by " POSINFO_FORMAT "\n",
170 POSINFO_ARG(&rd->stack[t])