Made bitfield a distinct type from bit so that bitfields
[fw/sdcc] / src / cdbFile.c
1
2
3 #include "common.h"
4
5
6 /*************************************************************
7  *
8  *
9  *
10  *
11  *************************************************************/
12
13 int cdbOpenFile(char *file);
14 int cdbCloseFile(void);
15 int cdbWriteFunction(symbol *pSym);
16 int cdbWriteSymbol(symbol *pSym);
17 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag);
18 int cdbWriteModule(char *name);
19 int cdbWriteCLine(char *module, int Line, int Level, int Block);
20 int cdbWriteALine(char *module, int Line);
21 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc);
22 void cdbTypeInfo (sym_link * type);
23      
24
25 DEBUGFILE cdbDebugFile = 
26   {
27     &cdbOpenFile,
28     &cdbCloseFile,
29     &cdbWriteModule,
30     &cdbWriteFunction,
31     &cdbWriteSymbol,
32     &cdbWriteType,
33     &cdbWriteCLine,
34     &cdbWriteALine
35   };
36
37 FILE *cdbFilePtr = NULL;
38 char *cdbModuleName = NULL;
39
40 /******************************************************************
41  *
42  *
43  *
44  *
45  *****************************************************************/
46
47 int cdbOpenFile(char *file)
48 {
49   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
50     fprintf (stderr, "cdbFile.c:cdbOpenFile(%s)\n", file);
51
52   return (cdbFilePtr = fopen(file, "w")) ? 1 : 0; 
53 }
54
55 /******************************************************************
56  *
57  *
58  *
59  *
60  *****************************************************************/
61 int cdbCloseFile(void)
62 {
63   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
64     fprintf (stderr, "cdbFile.c:cdbCloseFile()\n");
65
66   if(!cdbFilePtr) return 0;
67  
68   fclose(cdbFilePtr);
69   cdbFilePtr = NULL;
70   cdbModuleName = NULL;
71
72   return 1;
73 }
74
75 /******************************************************************
76  *
77  *
78  *
79  *
80  *****************************************************************/
81
82 int cdbWriteFunction(symbol *pSym)
83 {
84   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
85     fprintf (stderr, "cdbFile.c:cdbWriteFunction()\n");
86
87
88   if(!cdbFilePtr) return 0;
89
90   return cdbWriteBasicSymbol(pSym, FALSE, TRUE);
91 }
92
93 /******************************************************************
94  *
95  *
96  *
97  *
98  *****************************************************************/
99
100 int cdbWriteSymbol(symbol *pSym)
101 {
102   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
103     fprintf (stderr, "cdbFile.c:cdbWriteSymbol()\n");
104
105   if(!cdbFilePtr) return 0;
106
107   return cdbWriteBasicSymbol(pSym, FALSE, FALSE);
108 }
109
110 /******************************************************************
111  *
112  *
113  *
114  *
115  *****************************************************************/
116
117 int cdbWriteType(structdef *sdef, int block, int inStruct, char *tag)
118 {
119   symbol *sym;
120
121   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
122     fprintf (stderr, "cdbFile.c:cdbWriteType()\n");
123
124   if(!cdbFilePtr) return 0;
125
126   fprintf (cdbFilePtr, "T:");
127
128   /* if block # then must have function scope */
129   fprintf (cdbFilePtr, "F%s$", moduleName);
130
131   fprintf (cdbFilePtr, "%s[", (tag ? tag : sdef->tag));
132
133   for (sym = sdef->fields; sym; sym = sym->next)
134     {
135       fprintf (cdbFilePtr, "({%d}", sym->offset);
136       cdbWriteBasicSymbol(sym, TRUE, FALSE);
137       fprintf(cdbFilePtr, ")");
138     }
139
140   fprintf (cdbFilePtr, "]");
141
142   if (!inStruct)
143     fprintf (cdbFilePtr, "\n");
144
145   return 1;
146 }
147
148 /******************************************************************
149  *
150  *
151  *
152  *
153  *****************************************************************/
154
155 int cdbWriteModule(char *name)
156 {
157   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
158     fprintf (stderr, "cdbFile.c:cdbWriteModule()\n");
159
160   if(!cdbFilePtr) return 0;
161   cdbModuleName = name;
162
163   fprintf(cdbFilePtr, "M:%s\n", cdbModuleName);
164
165   return 1;
166 }
167
168 /******************************************************************
169  *
170  *
171  *
172  *
173  *****************************************************************/
174 int cdbWriteCLine(char *module, int Line, int Level, int Block)
175 {
176   if(!cdbFilePtr) return 0;
177
178   return 1;
179 }
180
181 /******************************************************************
182  *
183  *
184  *
185  *
186  *****************************************************************/
187
188 int cdbWriteALine(char *module, int Line)
189 {
190   if(!cdbFilePtr) return 0;
191
192   return 1;
193 }
194
195 /******************************************************************
196  *
197  *
198  *
199  *
200  *****************************************************************/
201
202 int cdbWriteBasicSymbol(symbol *sym, int isStructSym, int isFunc)
203 {
204   memmap *map;
205
206   if (getenv("SDCC_DEBUG_FUNCTION_POINTERS"))
207     fprintf (stderr, "cdbFile.c:cdbWriteBasicSymbol()\n");
208
209   if(!cdbFilePtr) return 0;
210
211   if (!sym) return 0;
212
213   /* WRITE HEADER, Function or Symbol */
214   if (isFunc)
215     fprintf (cdbFilePtr, "F:");   
216   else
217     fprintf (cdbFilePtr, "S:");
218
219   /* STRUCTS do not have scope info.. */
220
221   if (!isStructSym)
222     {
223       if (!sym->level)
224         {
225           /* global */
226           if (IS_STATIC (sym->etype))
227             fprintf (cdbFilePtr, "F%s$", moduleName);   /* scope is file */
228           else
229             fprintf (cdbFilePtr, "G$"); /* scope is global */
230         }
231       else
232         /* symbol is local */
233         fprintf (cdbFilePtr, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
234     }
235   else
236     fprintf (cdbFilePtr, "S$");         /* scope is structure */
237
238   /* print the name, & mangled name */
239   fprintf (cdbFilePtr, "%s$%d$%d(", sym->name,
240            sym->level, sym->block);
241
242   cdbTypeInfo (sym->type);
243
244   fprintf (cdbFilePtr, "),");
245
246   /* CHECK FOR REGISTER SYMBOL... */ 
247   if(sym->reqv)
248   {
249     int a;
250     symbol *TempSym = OP_SYMBOL (sym->reqv);
251
252     fprintf(cdbFilePtr, "R,0,0,[");
253
254     for(a = 0; a < 4; a++)
255       if(TempSym->regs[a])     
256         fprintf(cdbFilePtr, "%s%s", port->getRegName(TempSym->regs[a]),
257                 ((a < 3) && (TempSym->regs[a+1])) ? "," : "");
258
259     fprintf(cdbFilePtr, "]");
260   }
261   else
262   {
263     /* print the address space */
264     map = SPEC_OCLS (sym->etype);
265
266     fprintf (cdbFilePtr, "%c,%d,%d",
267              (map ? map->dbName : 'Z'), sym->onStack, SPEC_STAK (sym->etype));
268   }
269
270   /* if assigned to registers then output register names */
271   /* if this is a function then print
272      if is it an interrupt routine & interrupt number
273      and the register bank it is using */
274   if (isFunc)
275     fprintf (cdbFilePtr, ",%d,%d,%d", FUNC_ISISR (sym->type),
276              FUNC_INTNO (sym->type), FUNC_REGBANK (sym->type));
277   
278
279 /* alternate location to find this symbol @ : eg registers
280      or spillication */
281
282   if (!isStructSym)
283     fprintf (cdbFilePtr, "\n");
284
285   return 1;
286 }
287
288 /******************************************************************
289  *
290  *
291  *
292  *
293  *****************************************************************/
294
295 /*-----------------------------------------------------------------*/
296 /* cdbTypeInfo - print the type information for debugger           */
297 /*-----------------------------------------------------------------*/
298 void cdbTypeInfo (sym_link * type)
299 {
300   fprintf (cdbFilePtr, "{%d}", getSize (type));
301
302   while (type)
303     {
304       if (IS_DECL (type))
305         {
306           switch (DCL_TYPE (type))
307             {
308             case FUNCTION: fprintf (cdbFilePtr, "DF,"); break;
309             case GPOINTER: fprintf (cdbFilePtr, "DG,"); break;
310             case CPOINTER: fprintf (cdbFilePtr, "DC,"); break;
311             case FPOINTER: fprintf (cdbFilePtr, "DX,"); break;
312             case POINTER:  fprintf (cdbFilePtr, "DD,"); break;
313             case IPOINTER: fprintf (cdbFilePtr, "DI,"); break;
314             case PPOINTER: fprintf (cdbFilePtr, "DP,"); break;
315             case EEPPOINTER: fprintf (cdbFilePtr, "DA,"); break;
316             case ARRAY: fprintf (cdbFilePtr, "DA%d,", DCL_ELEM (type)); break;
317             default:
318               break;
319             }
320         }
321       else
322         {
323           switch (SPEC_NOUN (type))
324             {
325             case V_INT:
326               if (IS_LONG (type))
327                 fprintf (cdbFilePtr, "SL");
328               else
329                 fprintf (cdbFilePtr, "SI");
330               break;
331
332             case V_CHAR: fprintf (cdbFilePtr, "SC"); break;
333             case V_VOID: fprintf (cdbFilePtr, "SV"); break;
334             case V_FLOAT: fprintf (cdbFilePtr, "SF"); break;
335             case V_STRUCT: 
336               fprintf (cdbFilePtr, "ST%s", SPEC_STRUCT (type)->tag); 
337               break;
338             
339             case V_SBIT: fprintf (cdbFilePtr, "SX"); break;
340             case V_BIT: 
341             case V_BITFIELD: 
342               fprintf (cdbFilePtr, "SB%d$%d", SPEC_BSTR (type), 
343                        SPEC_BLEN (type));
344               break;
345
346             default:
347               break;
348             }
349           fputs (":", cdbFilePtr);
350           if (SPEC_USIGN (type))
351             fputs ("U", cdbFilePtr);
352           else
353             fputs ("S", cdbFilePtr);
354         }
355       type = type->next;
356     }
357 }
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376