]> git.sur5r.net Git - cc65/blob - src/cc65/symentry.c
Added .dbg statement generation for the assembler
[cc65] / src / cc65 / symentry.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                symentry.c                                 */
4 /*                                                                           */
5 /*               Symbol table entries for the cc65 C compiler                */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2000-2001 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #include <string.h>
37
38 /* common */
39 #include "xmalloc.h"
40
41 /* cc65 */
42 #include "symentry.h"
43
44
45
46 /*****************************************************************************/
47 /*                                   Code                                    */
48 /*****************************************************************************/
49
50
51
52 SymEntry* NewSymEntry (const char* Name, unsigned Flags)
53 /* Create a new symbol table with the given name */
54 {
55     /* Get the length of the name */
56     unsigned Len = strlen (Name);
57
58     /* Allocate memory for the symbol entry */
59     SymEntry* E = xmalloc (sizeof (SymEntry) + Len);
60
61     /* Initialize the entry */
62     E->NextHash = 0;
63     E->PrevSym  = 0;
64     E->NextSym  = 0;
65     E->Link     = 0;
66     E->Owner    = 0;
67     E->Flags    = Flags;
68     E->Type     = 0;
69     memcpy (E->Name, Name, Len+1);
70
71     /* Return the new entry */
72     return E;
73 }
74
75
76
77 void FreeSymEntry (SymEntry* E)
78 /* Free a symbol entry */
79 {
80     TypeFree (E->Type);
81     xfree (E);
82 }
83
84
85
86 void DumpSymEntry (FILE* F, const SymEntry* E)
87 /* Dump the given symbol table entry to the file in readable form */
88 {
89     static const struct {
90         const char*         Name;
91         unsigned            Val;
92     } Flags [] = {
93         /* Beware: Order is important! */
94         { "SC_TYPEDEF",     SC_TYPEDEF  },
95         { "SC_SFLD",        SC_SFLD     },
96         { "SC_STRUCT",      SC_STRUCT   },
97         { "SC_AUTO",        SC_AUTO     },
98         { "SC_REGISTER",    SC_REGISTER },
99         { "SC_STATIC",      SC_STATIC   },
100         { "SC_EXTERN",      SC_EXTERN   },
101         { "SC_ENUM",        SC_ENUM     },
102         { "SC_CONST",       SC_CONST    },
103         { "SC_LABEL",       SC_LABEL    },
104         { "SC_PARAM",       SC_PARAM    },
105         { "SC_FUNC",        SC_FUNC     },
106         { "SC_STORAGE",     SC_STORAGE  },
107         { "SC_DEF",         SC_DEF      },
108         { "SC_REF",         SC_REF      },
109         { "SC_ZEROPAGE",    SC_ZEROPAGE },
110     };
111
112     unsigned I;
113     unsigned SymFlags;
114
115     /* Print the name */
116     fprintf (F, "%s:\n", E->Name);
117
118     /* Print the flags */
119     SymFlags = E->Flags;
120     fprintf (F, "    Flags: ");
121     for (I = 0; I < sizeof (Flags) / sizeof (Flags[0]) && SymFlags != 0; ++I) {
122         if ((SymFlags & Flags[I].Val) == Flags[I].Val) {
123             SymFlags &= ~Flags[I].Val;
124             fprintf (F, "%s ", Flags[I].Name);
125         }
126     }
127     if (SymFlags != 0) {
128         fprintf (F, "%04X", SymFlags);
129     }
130     fprintf (F, "\n");
131
132     /* Print the type */
133     fprintf (F, "    Type:  ");
134     if (E->Type) {
135         PrintType (F, E->Type);
136     } else {
137         fprintf (F, "(none)");
138     }
139     fprintf (F, "\n");
140 }
141
142
143
144 int IsTypeDef (const SymEntry* E)
145 /* Return true if the given entry is a typedef entry */
146 {
147     return ((E->Flags & SC_TYPEDEF) == SC_TYPEDEF);
148 }
149
150
151
152 void ChangeSymType (SymEntry* Entry, type* Type)
153 /* Change the type of the given symbol */
154 {
155     TypeFree (Entry->Type);
156     Entry->Type = TypeDup (Type);
157 }
158
159
160
161